
Indefinite Progress Indicator #47
Chapter 6, Transparent and Animated Windows
|
255
HACK
To make things clearer, this code does not contain the painting of the text.
To allow the glass pane to be visible even when the animation is not started,
the application first checks the value of
started
. When false,
start( )
has
not been called yet and nothing must be drawn. In the other case, the white
veil is first painted all over the glass pane. The fourth parameter of the
Color
object used by
fillRect( )
defines the opacity. Opacity depends on two
parameters here:
shield and alphaLevel. The latter is computed by the ani-
mation thread to fade in and fade out the glass pane. As
alphaLevel is
between 0 and 255, and you multiply it by
shield, which is in the range 0.0
to 1.0, to obtain the opacity of the veil. Finally, the
for
loop computes a new
color for each bar and paints it. The colors are computed so as to create a
circular gradient and give an impression of movement when the circular
shape is rotated.
Run the Animation Thread
The most complicated part of InfiniteProgressPanel is the Animator thread
since its
run( ) method handles the fade-in and -out animations, as well as
the main animation. The only constructor of
Animator requires a boolean
parameter called
rampUp. When true, the thread will play both main and
fade-in animations. Otherwise, the fade-out animation is played. This is
what happens when you call
InfiniteProgressPanel.stop( ...