KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > action > layout > SpecifiedLayout


1 package prefuse.action.layout;
2
3 import java.util.Iterator JavaDoc;
4
5 import prefuse.visual.VisualItem;
6
7
8 /**
9  * Layout Action that sets x, y coordinates for a visual item by simply
10  * looking them up from another data field.
11  *
12  * @author <a HREF="http://jheer.org">jeffrey heer</a>
13  */

14 public class SpecifiedLayout extends Layout {
15
16     private String JavaDoc m_xfield = null;
17     private String JavaDoc m_yfield = null;
18     private String JavaDoc m_fixedfield = null;
19     
20     /**
21      * Create a new SpecifiedLayout.
22      * @param group the data group to layout
23      * @param xField the field from which to lookup x coordinate values
24      * @param yField the field from which to lookup y coordinate values
25      */

26     public SpecifiedLayout(String JavaDoc group, String JavaDoc xField, String JavaDoc yField) {
27         super(group);
28         m_xfield = xField;
29         m_yfield = yField;
30     }
31
32     // ------------------------------------------------------------------------
33

34     /**
35      * Get the field to lookup to set the x-coordinate.
36      * @return the x-value field. If null, this action
37      * does not set the x-coordiante.
38      */

39     public String JavaDoc getXField() {
40         return m_xfield;
41     }
42
43     /**
44      * Set the field to lookup to set the x-coordinate.
45      * @param xField the x-value field to use. If null, this action
46      * will not set the x-coordiante.
47      */

48     public void setXField(String JavaDoc xField) {
49         m_xfield = xField;
50     }
51
52     /**
53      * Get the field to lookup to set the y-coordinate.
54      * @return the y-value field. If null, this action
55      * does not set the y-coordiante.
56      */

57     public String JavaDoc getYField() {
58         return m_yfield;
59     }
60
61     /**
62      * Set the field to lookup to set the y-coordinate.
63      * @param yField the y-value field to use. If null, this action
64      * will not set the y-coordiante.
65      */

66     public void setYField(String JavaDoc yField) {
67         m_yfield = yField;
68     }
69     
70     /**
71      * Get the field to lookup to set the fixed property.
72      * @return the fixed field. If null, this action
73      * does not set the fixed field.
74      */

75     public String JavaDoc getFixedField() {
76         return m_fixedfield;
77     }
78
79     /**
80      * Set the field to lookup to set the fixed property.
81      * @param fixedField the fixed field to use. If null, this action
82      * will not set the fixed field.
83      */

84     public void setFixedField(String JavaDoc fixedField) {
85         m_fixedfield = fixedField;
86     }
87
88     /**
89      * @see prefuse.action.Action#run(double)
90      */

91     public void run(double frac) {
92         Iterator JavaDoc iter = m_vis.items(m_group);
93         while ( iter.hasNext() ) {
94             VisualItem item = (VisualItem)iter.next();
95             try {
96                 if ( m_xfield != null )
97                     setX(item, null, item.getDouble(m_xfield));
98                 if ( m_yfield != null )
99                     setY(item, null, item.getDouble(m_yfield));
100                 if ( m_fixedfield != null )
101                     item.setFixed(item.getBoolean(m_fixedfield));
102             } catch ( Exception JavaDoc e ) {
103             }
104         }
105     }
106
107 } // end of class SpecifiedLayout
108
Popular Tags