KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > action > ItemAction


1 package prefuse.action;
2
3 import java.util.Iterator JavaDoc;
4
5 import prefuse.Visualization;
6 import prefuse.data.expression.Predicate;
7 import prefuse.visual.VisualItem;
8 import prefuse.visual.expression.VisiblePredicate;
9
10 /**
11  * An Action that processes VisualItems one item at a time. By default,
12  * it only processes items that are visible. Use the
13  * {@link #setFilterPredicate(Predicate)} method
14  * to change the filtering criteria.
15  *
16  * @author <a HREF="http://jheer.org">jeffrey heer</a>
17  */

18 public abstract class ItemAction extends GroupAction {
19     
20     /** A reference to filtering predicate for this Action */
21     protected Predicate m_predicate;
22     
23     /**
24      * Create a new ItemAction that processes all groups.
25      * @see Visualization#ALL_ITEMS
26      */

27     public ItemAction() {
28         this((Visualization)null);
29     }
30     
31     /**
32      * Create a new ItemAction that processes all groups.
33      * @param vis the {@link prefuse.Visualization} to process
34      * @see Visualization#ALL_ITEMS
35      */

36     public ItemAction(Visualization vis) {
37         this(vis, Visualization.ALL_ITEMS);
38     }
39     
40     /**
41      * Create a new ItemAction that processes the specified group.
42      * @param group the name of the group to process
43      */

44     public ItemAction(String JavaDoc group) {
45         this(null, group);
46     }
47     
48     /**
49      * Create a new ItemAction that processes the specified group.
50      * @param group the name of the group to process
51      * @param filter the filtering {@link prefuse.data.expression.Predicate}
52      */

53     public ItemAction(String JavaDoc group, Predicate filter) {
54         this(null, group, filter);
55     }
56     
57     /**
58      * Create a new ItemAction that processes the specified group.
59      * @param vis the {@link prefuse.Visualization} to process
60      * @param group the name of the group to process
61      */

62     public ItemAction(Visualization vis, String JavaDoc group) {
63         this(vis, group, VisiblePredicate.TRUE);
64     }
65
66     /**
67      * Create a new ItemAction that processes the specified group.
68      * @param vis the {@link prefuse.Visualization} to process
69      * @param group the name of the group to process
70      * @param filter the filtering {@link prefuse.data.expression.Predicate}
71      */

72     public ItemAction(Visualization vis, String JavaDoc group, Predicate filter) {
73         super(vis, group);
74         m_predicate = filter;
75     }
76     
77     // ------------------------------------------------------------------------
78

79     /**
80      * Returns the filtering predicate used by this Action.
81      * @return the filtering {@link prefuse.data.expression.Predicate}
82      */

83     public Predicate getFilterPredicate() {
84         return m_predicate;
85     }
86
87     /**
88      * Sets the filtering predicate used by this Action.
89      * @param filter the filtering {@link prefuse.data.expression.Predicate}
90      * to use
91      */

92     public void setFilterPredicate(Predicate filter) {
93         m_predicate = filter;
94     }
95     
96     /**
97      * @see prefuse.action.Action#run(double)
98      */

99     public void run(double frac) {
100         Iterator JavaDoc items = getVisualization().items(m_group, m_predicate);
101         while ( items.hasNext() ) {
102             process((VisualItem)items.next(), frac);
103         }
104     }
105     
106     /**
107      * Processes an individual item.
108      * @param item the VisualItem to process
109      * @param frac the fraction of elapsed duration time
110      */

111     public abstract void process(VisualItem item, double frac);
112
113 } // end of class ItemAction
114
Popular Tags