Java Reference
In-Depth Information
Listing 12.21
ProgressBarSkin - Text Elements
text = Text {
translateX : bind (progressBar.width -
text.layoutBounds.width)/2.0 - text.layoutBounds.minX
translateY : bind (progressBar.height -
text.layoutBounds.height)/2.0- text.layoutBounds.minY
content: bind msg
font: bind font
textOrigin: TextOrigin.TOP
fill: bind textFill
},
Text {
x : bind (progressBar.width -
text.layoutBounds.width)/2.0 - text.layoutBounds.minX
y : bind (progressBar.height -
text.layoutBounds.height)/2.0- text.layoutBounds.minY
content: bind msg
font: bind font
textOrigin: TextOrigin.TOP
fill: bind textHighlightFill
clip: bind progressRect
},
There are a couple of things to note here. First, the second Text object needs to
be located using its x and y variables rather than using its translateX and
translateY variables. This is because the clipping region is based on the geom-
etry of the progressRect before the transformations take effect. If we had used
translateX and translateY , the clipping action would actually be shifted to the
left and the text would show in the alternate color too soon.
The other issue is that in calculating the center position for the second text
object, we could not use the layoutBounds for the second text, but had to use the
layout bounds from the first text. This is because the layoutBounds for the sec-
ond text change as the clip region changes. Remember, both Text objects are
identical except for color, so the first Text 's dimensions stay constant and still
represent the dimensions of the second Text object.
The last important point to this is the second text must appear on top of the first
text. This is dictated by the order that the Text s are added to the overall Group 's
content sequence. Nodes added at the end of the content sequence will paint on
top of nodes added earlier into the Group 's content sequence. Normally, the sec-
ond text would obscure the first text, but because we are using a clipping region
on the second Text object, the first node is not obscured until the progress rect-
angle crosses over it.
 
Search WWH ::




Custom Search