KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtriver > open > vectorvisuals > task > IndefiniteRotationTask


1 /*
2  * IndefiniteRotationTask.java
3  *
4  * Created on 3 June 2003, 23:09
5  */

6
7 package com.thoughtriver.open.vectorvisuals.task;
8
9 import java.awt.geom.*;
10
11 import com.thoughtriver.open.vectorvisuals.*;
12
13 /**
14  * This task can be used to make a <CODE>VisualObject</CODE> rotate at a
15  * controlled rate indefinitely. Examples of objects that would employ such a
16  * rotation might be a pinwheel, a cog, or a windmill.
17  *
18  * @author Brandon Franklin
19  * @version $Date: 2006/11/25 09:15:41 $
20  */

21 public class IndefiniteRotationTask extends AnimationTask {
22
23     /** The <CODE>VisualObject</CODE> that will be rotated by this task */
24     private final VisualObject target;
25
26     /** The rate of rotation, expressed in Theta Per Second */
27     private double rate = 0;
28
29     /**
30      * Creates a new instance of <CODE>IndefiniteRotationTask</CODE> with the
31      * specified <CODE>VisualObject</CODE> as its target. Initially, the
32      * rotation speed will be set to 0.
33      *
34      * @param target the <CODE>VisualObject</CODE> that will be rotated by
35      * this task
36      */

37     public IndefiniteRotationTask(final VisualObject target) {
38         super(-1);
39         this.target = target;
40     }
41
42     /**
43      * Sets the desired rate of rotation, expressed in Theta Per Second. The
44      * change will take effect immediately.
45      *
46      * @param rate the desired rate of rotation, expressed in Theta Per Second
47      */

48     public void setRate(final double rate) {
49         this.rate = rate;
50     }
51
52     /**
53      * Causes the task to change its state to reflect an amount of change based
54      * on the supplied number of milliseconds having passed.
55      *
56      * @param progress the amount of progress this <CODE>AnimationTask</CODE>
57      * should be changed to reflect
58      */

59     @Override JavaDoc
60     protected void update(final double progress) {
61
62         synchronized (target) {
63             Point2D rotationPoint = target.getRotationPoint();
64             AffineTransform transform = target.getTransform();
65             double thetaToRotate = rate * (progress / 1000);
66             transform.rotate(thetaToRotate, rotationPoint.getX(), rotationPoint.getY());
67             target.setTransform(transform);
68         }
69     }
70
71 }
72
Popular Tags