
Indefinite Progress Indicator #47
Chapter 6, Transparent and Animated Windows
|
253
HACK
Build the Circular Shape
Everything begins when the start( ) method is invoked:
public void start( )
{
addMouseListener(this);
setVisible(true);
ticker = buildTicker( );
animation = new Thread(new Animator(true));
animation.start( );
}
Before running the animation, this method takes care of adding a mouse lis-
tener that is responsible for catching all the mouse events and preventing
them from being forwarded to the underlying user interface. Thus, the user
will not be able to perform any action. The second step is to set the glass
pane to be visible. Finally, the
ticker, the circular shape, is built and the ani-
mation is started. Building the shape is done with two methods:
private Area buildPrimitive( )
{
Rectangle2D.Double body = new Rectangle2D.Double(6, 0, 30, 12);
Ellipse2D.Double head = new Ellipse2D.Double(0, 0, 12, 12);
Ellipse2D.Double tail = new Ellipse2D.Double(30, 0, 12, 12);
Area tick = new Area(body);
tick.add(new Area(head));
tick.add(new Area(tail));
return tick;
}
private Area[] buildTicker( )
{
Area[] ticker = new Area[barsCount];
Point2D.Double center = new Point2D.Double((double) getWidth( ) / 2,
(double) getHeight( ) / 2);
double fixedAngle = 2.0 * Math.PI / ((double) barsCount);
for (double i = 0.0; i < (double) barsCount; i++)
{
Area primitive = buildPrimitive( );
AffineTransform toCenter ...