Lines 20-40
Link Here
|
20 |
|
20 |
|
21 |
import org.netbeans.api.visual.widget.Scene; |
21 |
import org.netbeans.api.visual.widget.Scene; |
22 |
|
22 |
|
|
|
23 |
import java.util.concurrent.CopyOnWriteArrayList; |
24 |
|
23 |
/** |
25 |
/** |
24 |
* Represents an animator. An animator is registed to a scene animator and could be started. |
26 |
* Represents an animator. An animator is registed to a scene animator and could be started. |
25 |
* From that moment the scene animator automatically calls Animator.tick method for a solid period of time set by the scene animator. |
27 |
* From that moment the scene animator automatically calls Animator.tick method for a solid period of time set by the scene animator. |
26 |
* In the tick method the animation has to implemented. The animation should be independent on time-duration. |
28 |
* In the tick method the animation has to implemented. The animation should be independent on time-duration. |
|
|
29 |
* <p> |
30 |
* Since 2.2, it is possible to listener on important events of the animator using <code>AnimatorListener</code> interface. |
27 |
* |
31 |
* |
28 |
* @author David Kaspar |
32 |
* @author David Kaspar |
29 |
*/ |
33 |
*/ |
30 |
public abstract class Animator { |
34 |
public abstract class Animator { |
31 |
|
35 |
|
|
|
36 |
private CopyOnWriteArrayList<AnimatorListener> listeners = new CopyOnWriteArrayList<AnimatorListener> (); |
32 |
private SceneAnimator sceneAnimator; |
37 |
private SceneAnimator sceneAnimator; |
33 |
private boolean reset; |
38 |
private boolean reset; |
34 |
|
39 |
|
35 |
/** |
40 |
/** |
36 |
* Creates an animator and assigns a scene animator. |
41 |
* Creates an animator and assigns a scene animator. |
37 |
* @param sceneAnimator |
42 |
* @param sceneAnimator the scene animator |
38 |
*/ |
43 |
*/ |
39 |
protected Animator (SceneAnimator sceneAnimator) { |
44 |
protected Animator (SceneAnimator sceneAnimator) { |
40 |
assert sceneAnimator != null; |
45 |
assert sceneAnimator != null; |
Lines 53-58
Link Here
|
53 |
* Registers and starts the animation. |
58 |
* Registers and starts the animation. |
54 |
*/ |
59 |
*/ |
55 |
protected final void start () { |
60 |
protected final void start () { |
|
|
61 |
if (! listeners.isEmpty ()) { |
62 |
AnimatorEvent event = new AnimatorEvent (this); |
63 |
for (AnimatorListener listener : listeners) |
64 |
listener.animatorStarted (event); |
65 |
} |
56 |
sceneAnimator.start (this); |
66 |
sceneAnimator.start (this); |
57 |
} |
67 |
} |
58 |
|
68 |
|
Lines 65-70
Link Here
|
65 |
} |
75 |
} |
66 |
|
76 |
|
67 |
final void reset () { |
77 |
final void reset () { |
|
|
78 |
if (! listeners.isEmpty ()) { |
79 |
AnimatorEvent event = new AnimatorEvent (this); |
80 |
for (AnimatorListener listener : listeners) |
81 |
listener.animatorReset (event); |
82 |
} |
68 |
reset = true; |
83 |
reset = true; |
69 |
} |
84 |
} |
70 |
|
85 |
|
Lines 73-79
Link Here
|
73 |
reset = false; |
88 |
reset = false; |
74 |
return; |
89 |
return; |
75 |
} |
90 |
} |
|
|
91 |
|
92 |
if (! listeners.isEmpty ()) { |
93 |
AnimatorEvent event = new AnimatorEvent (this, progress); |
94 |
for (AnimatorListener listener : listeners) |
95 |
listener.animatorPreTick (event); |
96 |
} |
97 |
|
76 |
tick (progress); |
98 |
tick (progress); |
|
|
99 |
|
100 |
if (! listeners.isEmpty ()) { |
101 |
AnimatorEvent event = new AnimatorEvent (this, progress); |
102 |
for (AnimatorListener listener : listeners) |
103 |
listener.animatorPostTick (event); |
104 |
} |
105 |
|
106 |
if (progress >= 1.0) { |
107 |
if (! listeners.isEmpty ()) { |
108 |
AnimatorEvent event = new AnimatorEvent (this); |
109 |
for (AnimatorListener listener : listeners) |
110 |
listener.animatorFinished (event); |
111 |
} |
112 |
} |
77 |
} |
113 |
} |
78 |
|
114 |
|
79 |
/** |
115 |
/** |
Lines 82-86
Link Here
|
82 |
* @param progress the progress |
118 |
* @param progress the progress |
83 |
*/ |
119 |
*/ |
84 |
protected abstract void tick (double progress); |
120 |
protected abstract void tick (double progress); |
|
|
121 |
|
122 |
/** |
123 |
* Adds an animator listener to the animator. |
124 |
* @param listener the animator listener |
125 |
* @since 2.2 |
126 |
*/ |
127 |
public void addAnimatorListener (AnimatorListener listener) { |
128 |
listeners.add (listener); |
129 |
} |
130 |
|
131 |
/** |
132 |
* Removes an animator listener from the animator. |
133 |
* @param listener the animator listener |
134 |
* @since 2.2 |
135 |
*/ |
136 |
public void removeAnimatorListener (AnimatorListener listener) { |
137 |
listeners.remove (listener); |
138 |
} |
85 |
|
139 |
|
86 |
} |
140 |
} |