66 *
67 * @author Igor Kushnirskiy
68 */
69 class AnimationController implements ActionListener, PropertyChangeListener {
70
71 private static final boolean VISTA_ANIMATION_DISABLED =
72 AccessController.doPrivileged(new GetBooleanAction("swing.disablevistaanimation"));
73
74
75 private static final Object ANIMATION_CONTROLLER_KEY =
76 new StringBuilder("ANIMATION_CONTROLLER_KEY");
77
78 private final Map<JComponent, Map<Part, AnimationState>> animationStateMap =
79 new WeakHashMap<JComponent, Map<Part, AnimationState>>();
80
81 //this timer is used to cause repaint on animated components
82 //30 repaints per second should give smooth animation affect
83 private final javax.swing.Timer timer =
84 new javax.swing.Timer(1000/30, this);
85
86 private static synchronized AnimationController getAnimationController() {
87 AppContext appContext = AppContext.getAppContext();
88 Object obj = appContext.get(ANIMATION_CONTROLLER_KEY);
89 if (obj == null) {
90 obj = new AnimationController();
91 appContext.put(ANIMATION_CONTROLLER_KEY, obj);
92 }
93 return (AnimationController) obj;
94 }
95
96 private AnimationController() {
97 timer.setRepeats(true);
98 timer.setCoalesce(true);
99 //we need to dispose the controller on l&f change
100 UIManager.addPropertyChangeListener(this);
101 }
102
103 private static void triggerAnimation(JComponent c,
104 Part part, State newState) {
105 if (c instanceof javax.swing.JTabbedPane
106 || part == Part.TP_BUTTON) {
187 }
188 return rv;
189 }
190
191 private synchronized State getState(JComponent component, Part part) {
192 State rv = null;
193 Object tmpObject =
194 component.getClientProperty(PartUIClientPropertyKey.getKey(part));
195 if (tmpObject instanceof State) {
196 rv = (State) tmpObject;
197 }
198 return rv;
199 }
200
201 private synchronized void putState(JComponent component, Part part,
202 State state) {
203 component.putClientProperty(PartUIClientPropertyKey.getKey(part),
204 state);
205 }
206
207 private synchronized void startAnimation(JComponent component,
208 Part part,
209 State startState,
210 State endState,
211 long millis) {
212 boolean isForwardAndReverse = false;
213 if (endState == State.DEFAULTED) {
214 isForwardAndReverse = true;
215 }
216 Map<Part, AnimationState> map = animationStateMap.get(component);
217 if (millis <= 0) {
218 if (map != null) {
219 map.remove(part);
220 if (map.size() == 0) {
221 animationStateMap.remove(component);
222 }
223 }
224 return;
225 }
226 if (map == null) {
227 map = new EnumMap<Part, AnimationState>(Part.class);
374 progress = 0;
375 isForward = ! isForward;
376 }
377 }
378 }
379 void paintSkin(Skin skin, Graphics _g,
380 int dx, int dy, int dw, int dh, State state) {
381 assert SwingUtilities.isEventDispatchThread();
382
383 updateProgress();
384 if (! isDone()) {
385 Graphics2D g = (Graphics2D) _g.create();
386 skin.paintSkinRaw(g, dx, dy, dw, dh, startState);
387 float alpha;
388 if (isForward) {
389 alpha = progress;
390 } else {
391 alpha = 1 - progress;
392 }
393 g.setComposite(AlphaComposite.SrcOver.derive(alpha));
394 skin.paintSkinRaw(g, dx, dy, dw, dh, state);
395 g.dispose();
396 } else {
397 skin.paintSkinRaw(_g, dx, dy, dw, dh, state);
398 }
399 }
400 boolean isDone() {
401 assert SwingUtilities.isEventDispatchThread();
402
403 return progress >= 1;
404 }
405 }
406
407 private static class PartUIClientPropertyKey
408 implements UIClientPropertyKey {
409
410 private static final Map<Part, PartUIClientPropertyKey> map =
411 new EnumMap<Part, PartUIClientPropertyKey>(Part.class);
412
413 static synchronized PartUIClientPropertyKey getKey(Part part) {
|
66 *
67 * @author Igor Kushnirskiy
68 */
69 class AnimationController implements ActionListener, PropertyChangeListener {
70
71 private static final boolean VISTA_ANIMATION_DISABLED =
72 AccessController.doPrivileged(new GetBooleanAction("swing.disablevistaanimation"));
73
74
75 private static final Object ANIMATION_CONTROLLER_KEY =
76 new StringBuilder("ANIMATION_CONTROLLER_KEY");
77
78 private final Map<JComponent, Map<Part, AnimationState>> animationStateMap =
79 new WeakHashMap<JComponent, Map<Part, AnimationState>>();
80
81 //this timer is used to cause repaint on animated components
82 //30 repaints per second should give smooth animation affect
83 private final javax.swing.Timer timer =
84 new javax.swing.Timer(1000/30, this);
85
86 static synchronized AnimationController getAnimationController() {
87 AppContext appContext = AppContext.getAppContext();
88 Object obj = appContext.get(ANIMATION_CONTROLLER_KEY);
89 if (obj == null) {
90 obj = new AnimationController();
91 appContext.put(ANIMATION_CONTROLLER_KEY, obj);
92 }
93 return (AnimationController) obj;
94 }
95
96 private AnimationController() {
97 timer.setRepeats(true);
98 timer.setCoalesce(true);
99 //we need to dispose the controller on l&f change
100 UIManager.addPropertyChangeListener(this);
101 }
102
103 private static void triggerAnimation(JComponent c,
104 Part part, State newState) {
105 if (c instanceof javax.swing.JTabbedPane
106 || part == Part.TP_BUTTON) {
187 }
188 return rv;
189 }
190
191 private synchronized State getState(JComponent component, Part part) {
192 State rv = null;
193 Object tmpObject =
194 component.getClientProperty(PartUIClientPropertyKey.getKey(part));
195 if (tmpObject instanceof State) {
196 rv = (State) tmpObject;
197 }
198 return rv;
199 }
200
201 private synchronized void putState(JComponent component, Part part,
202 State state) {
203 component.putClientProperty(PartUIClientPropertyKey.getKey(part),
204 state);
205 }
206
207 synchronized void startAnimation(JComponent component,
208 Part part,
209 State startState,
210 State endState,
211 long millis) {
212 boolean isForwardAndReverse = false;
213 if (endState == State.DEFAULTED) {
214 isForwardAndReverse = true;
215 }
216 Map<Part, AnimationState> map = animationStateMap.get(component);
217 if (millis <= 0) {
218 if (map != null) {
219 map.remove(part);
220 if (map.size() == 0) {
221 animationStateMap.remove(component);
222 }
223 }
224 return;
225 }
226 if (map == null) {
227 map = new EnumMap<Part, AnimationState>(Part.class);
374 progress = 0;
375 isForward = ! isForward;
376 }
377 }
378 }
379 void paintSkin(Skin skin, Graphics _g,
380 int dx, int dy, int dw, int dh, State state) {
381 assert SwingUtilities.isEventDispatchThread();
382
383 updateProgress();
384 if (! isDone()) {
385 Graphics2D g = (Graphics2D) _g.create();
386 skin.paintSkinRaw(g, dx, dy, dw, dh, startState);
387 float alpha;
388 if (isForward) {
389 alpha = progress;
390 } else {
391 alpha = 1 - progress;
392 }
393 g.setComposite(AlphaComposite.SrcOver.derive(alpha));
394 if (state == null) { // used for animating buttons in a specific JToolBar
395 g.setColor(Color.WHITE);
396 g.fillRect(dx, dy, dw, dh);
397 }
398 skin.paintSkinRaw(g, dx, dy, dw, dh, state);
399 g.dispose();
400 } else {
401 skin.paintSkinRaw(_g, dx, dy, dw, dh, state);
402 }
403 }
404 boolean isDone() {
405 assert SwingUtilities.isEventDispatchThread();
406
407 return progress >= 1;
408 }
409 }
410
411 private static class PartUIClientPropertyKey
412 implements UIClientPropertyKey {
413
414 private static final Map<Part, PartUIClientPropertyKey> map =
415 new EnumMap<Part, PartUIClientPropertyKey>(Part.class);
416
417 static synchronized PartUIClientPropertyKey getKey(Part part) {
|