KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > action > CompositeAction


1 package prefuse.action;
2
3 import prefuse.Visualization;
4 import prefuse.activity.Activity;
5 import prefuse.util.collections.CopyOnWriteArrayList;
6
7 /**
8  * Abstract base class for Action implementations that hold a collection
9  * of subclasses.
10  *
11  * @author <a HREF="http://jheer.org">jeffrey heer</a>
12  */

13 public abstract class CompositeAction extends Action {
14
15     protected CopyOnWriteArrayList m_actions = new CopyOnWriteArrayList();
16     
17     /**
18      * Creates a new run-once CompositeAction.
19      */

20     public CompositeAction() {
21         super(null, 0);
22     }
23
24     /**
25      * Creates a new run-once CompositeAction that processes the given
26      * Visualization.
27      * @param vis the {@link prefuse.Visualization} processed by this Action
28      */

29     public CompositeAction(Visualization vis) {
30         super(vis, 0);
31     }
32     
33     /**
34      * Creates a new CompositeAction of specified duration and default
35      * step time of 20 milliseconds.
36      * @param duration the duration of this Activity, in milliseconds
37      */

38     public CompositeAction(long duration) {
39         super(null, duration, Activity.DEFAULT_STEP_TIME);
40     }
41     
42     /**
43      * Creates a new CompositeAction of specified duration and default
44      * step time of 20 milliseconds that processes the given
45      * Visualization.
46      * @param vis the {@link prefuse.Visualization} processed by this Action
47      * @param duration the duration of this Activity, in milliseconds
48      */

49     public CompositeAction(Visualization vis, long duration) {
50         super(vis, duration, Activity.DEFAULT_STEP_TIME);
51     }
52     
53     /**
54      * Creates a new CompositeAction of specified duration and step time.
55      * @param duration the duration of this Activity, in milliseconds
56      * @param stepTime the time to wait in milliseconds between executions
57      * of the action list
58      */

59     public CompositeAction(long duration, long stepTime) {
60         super(null, duration, stepTime);
61     }
62     
63     // ------------------------------------------------------------------------
64

65     /**
66      * Set the Visualization processed by this Action. This also calls
67      * {@link Action#setVisualization(Visualization)} on all Action instances
68      * contained within this composite.
69      * @param vis the {@link prefuse.Visualization} to process
70      */

71     public void setVisualization(Visualization vis) {
72         super.setVisualization(vis);
73         for ( int i=0; i<m_actions.size(); ++i ) {
74             get(i).setVisualization(vis);
75         }
76     }
77     
78     /**
79      * Returns the number of Actions in the composite.
80      * @return the size of this composite
81      */

82     public int size() {
83         return m_actions.size();
84     }
85     
86     /**
87      * Adds an Action to the end of the composite list.
88      * @param a the Action instance to add
89      */

90     public void add(Action a) {
91         m_actions.add(a);
92     }
93     
94     /**
95      * Adds an Action at the given index.
96      * @param i the index at which to add the Action
97      * @param a the Action instance to add
98      */

99     public void add(int i, Action a) {
100         m_actions.add(i, a);
101     }
102     
103     /**
104      * Returns the Action at the specified index.
105      * @param i the index
106      * @return the requested Action
107      */

108     public Action get(int i) {
109         return (Action)m_actions.get(i);
110     }
111     
112     /**
113      * Removes a given Action from the composite.
114      * @param a the Action to remove
115      * @return true if the Action was found and removed, false otherwise
116      */

117     public boolean remove(Action a) {
118         return m_actions.remove(a);
119     }
120     
121     /**
122      * Removes the Action at the specified index.
123      * @param i the index
124      * @return the removed Action
125      */

126     public Action remove(int i) {
127         return (Action)m_actions.remove(i);
128     }
129     
130 } // end of class CompositeAction
131
Popular Tags