01: package com.xoetrope.swing.helper;
02:
03: import java.awt.event.ActionEvent;
04: import java.awt.event.ActionListener;
05: import javax.swing.JComponent;
06: import javax.swing.Timer;
07:
08: /**
09: *
10: * <p> Copyright (c) Xoetrope Ltd., 2001-2007, This software is licensed under
11: * the GNU Public License (GPL), please see license.txt for more details. If
12: * you make commercial use of this software you must purchase a commercial
13: * license from Xoetrope.</p>
14: * @author luano
15: */
16: public abstract class AnimationHelper implements ActionListener {
17: private Timer animationTimer;
18: private float animationMax = 1.0F;
19: private float animationMin = 0.0F;
20: private float anaimationValueInc = 0.1F;
21:
22: protected float animationValue;
23: protected JComponent targetComp;
24:
25: /** Creates a new instance of AnimationHelper */
26: public AnimationHelper() {
27: animationTimer = new Timer(1, this );
28: animationTimer.setDelay(32);
29: animationTimer.setInitialDelay(32);
30: animationTimer.setCoalesce(true);
31: animationTimer.setRepeats(true);
32: }
33:
34: public void animate(JComponent comp) {
35: targetComp = comp;
36: init();
37:
38: animationValue = animationMax;
39: animationTimer.start();
40: }
41:
42: public void actionPerformed(ActionEvent ae) {
43: if (animationValue > 0.0)
44: animationValue -= getAnaimationValueInc();
45:
46: if ((animationValue <= 0.0) || (animationValue > 1.0))
47: animationTimer.stop();
48:
49: updateComponent();
50: }
51:
52: public abstract void init();
53:
54: public abstract void updateComponent();
55:
56: public float getAnaimationValueInc() {
57: return anaimationValueInc;
58: }
59:
60: public void setAnaimationValueInc(float inc) {
61: anaimationValueInc = inc;
62: }
63: }
|