KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > action > ActionSwitch


1 package prefuse.action;
2
3 /**
4  * The ActionSwitch selects between a set of Actions, allowing only one
5  * of a group of Actions to be executed at a time.
6  *
7  * @version 1.0
8  * @author <a HREF="http://jheer.org">jeffrey heer</a>
9  */

10 public class ActionSwitch extends CompositeAction {
11
12     private int m_switchVal;
13     
14     /**
15      * Creates an empty action switch.
16      */

17     public ActionSwitch() {
18         m_switchVal = 0;
19     }
20     
21     /**
22      * Creates a new ActionSwitch with the given actions and switch value.
23      * @param acts the Actions to include in this switch
24      * @param switchVal the switch value indicating which Action to run
25      */

26     public ActionSwitch(Action[] acts, int switchVal) {
27         for ( int i=0; i<acts.length; i++ )
28             m_actions.add(acts[i]);
29         setSwitchValue(switchVal);
30     }
31     
32     /**
33      * @see prefuse.action.Action#run(double)
34      */

35     public void run(double frac) {
36         if ( m_actions.size() > 0 ) {
37             get(getSwitchValue()).run(frac);
38         }
39     }
40     
41     /**
42      * Returns the current switch value, indicating the index of the Action
43      * that will be executed in reponse to run() invocations.
44      * @return the switch value
45      */

46     public int getSwitchValue() {
47         return m_switchVal;
48     }
49     
50     /**
51      * Set the switch value. This is the index of the Action that will be
52      * executed in response to run() invocations.
53      * @param s the new switch value
54      */

55     public void setSwitchValue(int s) {
56         if ( s < 0 || s >= size() )
57             throw new IllegalArgumentException JavaDoc(
58                     "Switch value out of legal range");
59         m_switchVal = s;
60     }
61
62 } // end of class ActionSwitch
63
Popular Tags