KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > action > Action


1 package prefuse.action;
2
3 import java.util.logging.Logger JavaDoc;
4
5 import prefuse.Visualization;
6 import prefuse.activity.Activity;
7
8 /**
9  * <p>Actions are building blocks that perform any number of operations on a
10  * Visualization, typically processing VisualItems to set various visual
11  * attributes. This class is a base implementation for Action instances.
12  * Developers can subclass this class and implement the <code>run</code> method
13  * to create their own custom Actions.</p>
14  *
15  * <p>After instantiating an Action, you should register it with a particular
16  * Visualization before running it. Use the
17  * {@link prefuse.Visualization#putAction(String, Action)} to do this. This
18  * will ensure that the Action is configured to use that Visualization. If
19  * an Action is part of an {@link ActionList} or {@link ActionSwitch}, it is
20  * sufficient to only register that CompositeAction with the Visualization
21  * -- all contained Action instances will be configured appropriately. You
22  * can then run the Actions using the {@link prefuse.Visualization#run(String)}
23  * method and other similar methods of the {@link prefuse.Visualization} class.
24  * </p>
25  *
26  * <p>As a subclass of Activity, Actions can be of two kinds.
27  * <i>Run-once</i> action lists have
28  * a duration value of zero, and simply run once when scheduled. Actions
29  * with a duration greater than zero can be executed multiple times, waiting
30  * a specified step time between each execution until the activity has run for
31  * its full duration. A duration of Activity.INFINITE will result in a
32  * continually re-running Action.</p>
33  *
34  * @author <a HREF="http://jheer.org">jeffrey heer</a>
35  */

36 public abstract class Action extends Activity {
37     
38     private final static Logger JavaDoc s_logger
39         = Logger.getLogger(Action.class.getName());
40     
41     /** A reference to the visualization processed by this Action. */
42     protected Visualization m_vis;
43     
44     /**
45      * Creates an action instance with zero duration. This Action will only
46      * run once if invoked.
47      */

48     public Action() {
49         this(null);
50     }
51     
52     /**
53      * Create a new Action with a specified duration.
54      * @param duration the Action duration in milliseconds
55      */

56     public Action(long duration) {
57         super(duration, Activity.DEFAULT_STEP_TIME);
58     }
59     
60     /**
61      * Create a new Action with a specified duration and step time.
62      * @param duration the Action duration in milliseconds
63      * @param stepTime the time to wait between invocation of the Action
64      */

65     public Action(long duration, long stepTime) {
66         super(duration, stepTime);
67     }
68     
69     /**
70      * Create a new Action with a specified Visualization and zero duration.
71      * @param vis the Visualization this Action should process. If this
72      * Action is registered with another Visualization, this value will
73      * be overwritten.
74      */

75     public Action(Visualization vis) {
76         this(vis, 0);
77     }
78     
79     /**
80      * Create a new Action with a specified Visualization and duration.
81      * @param vis the Visualization this Action should process. If this
82      * Action is registered with another Visualization, this value will
83      * be overwritten.
84      * @param duration the Action duration in milliseconds
85      */

86     public Action(Visualization vis, long duration) {
87         super(duration, Activity.DEFAULT_STEP_TIME);
88         m_vis = vis;
89     }
90     
91     /**
92      * Create a new Action with a specified Visualization, duration and
93      * step time.
94      * @param vis the Visualization this Action should process. If this
95      * Action is registered with another Visualization, this value will
96      * be overwritten.
97      * @param duration the Action duration in milliseconds
98      * @param stepTime the time to wait between invocation of the Action
99      */

100     public Action(Visualization vis, long duration, long stepTime) {
101         super(duration, stepTime);
102         m_vis = vis;
103     }
104     
105     // ------------------------------------------------------------------------
106

107     /**
108      * Runs this Action, triggering whatever processing this Action performs.
109      * Subclass this method to create custom Actions.
110      * @param frac the fraction of this Action's duration that has elapsed.
111      */

112     public abstract void run(double frac);
113
114     /**
115      * Runs this Action (as an Activity). Called by the Activity super-class.
116      * @see prefuse.activity.Activity#run(long)
117      */

118     protected void run(long elapsedTime) {
119         Visualization vis = getVisualization();
120         if ( vis != null ) {
121             synchronized (vis) {
122                 run(getPace(elapsedTime));
123             }
124         } else {
125             s_logger.info("Running unsynchronized Action");
126             run(getPace(elapsedTime));
127         }
128     }
129     
130     /**
131      * Return the Visualization processed by this Action.
132      * @return the {@link prefuse.Visualization} instance.
133      */

134     public Visualization getVisualization() {
135         return m_vis;
136     }
137     
138     /**
139      * Set the Visualization processed by this Action.
140      * @return the {@link prefuse.Visualization} to process.
141      */

142     public void setVisualization(Visualization vis) {
143         m_vis = vis;
144     }
145
146 } // end of class Action
147
Popular Tags