KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > visual > VisualTree


1 package prefuse.visual;
2
3 import prefuse.Visualization;
4 import prefuse.data.Table;
5 import prefuse.data.Tree;
6 import prefuse.data.event.EventConstants;
7 import prefuse.util.collections.IntIterator;
8
9 /**
10  * A visual abstraction of a tree data structure. NodeItem and EdgeItem tuples
11  * provide the visual representations for the nodes and edges of the tree.
12  * VisualTrees should not be created directly, they are created automatically
13  * by adding data to a Visualization, for example by using the
14  * {@link Visualization#addTree(String, Tree)} method.
15  *
16  * @author <a HREF="http://jheer.org">jeffrey heer</a>
17  */

18 public class VisualTree extends Tree implements VisualTupleSet {
19     
20     private Visualization m_vis;
21     private String JavaDoc m_group;
22     
23     /**
24      * Create a new VisualTree.
25      * @param nodes the visual node table
26      * @param edges the visual edge table
27      * @param nodeKey the node table field by which to index the nodes.
28      * This value can be null, indicating that just the row indices should be
29      * used.
30      * @param sourceKey the edge table field storing source (parent) node keys
31      * @param targetKey the edge table field storing target (child) node keys
32      */

33     public VisualTree(VisualTable nodes, VisualTable edges,
34             String JavaDoc nodeKey, String JavaDoc sourceKey, String JavaDoc targetKey)
35     {
36         super(nodes, edges, nodeKey, sourceKey, targetKey);
37     }
38     
39     /**
40      * Fire a graph event. Makes sure to invalidate all edges connected
41      * to a node that has been updated.
42      * @see prefuse.data.Graph#fireGraphEvent(prefuse.data.Table, int, int, int, int)
43      */

44     protected void fireGraphEvent(Table t,
45             int first, int last, int col, int type)
46     {
47         // if a node is invalidated, invalidate the edges, too
48
if ( type==EventConstants.UPDATE &&
49              col==VisualItem.IDX_VALIDATED && t==getNodeTable() )
50         {
51             VisualTable nodes = (VisualTable)t;
52             VisualTable edges = (VisualTable)getEdgeTable();
53             
54             for ( int i=first; i<=last; ++i ) {
55                 if ( nodes.isValidated(i) )
56                     continue; // look only for invalidations
57

58                 IntIterator erows = edgeRows(i);
59                 while ( erows.hasNext() ) {
60                     int erow = erows.nextInt();
61                     edges.setValidated(erow, false);
62                 }
63             }
64         }
65         // fire the event off to listeners
66
super.fireGraphEvent(t, first, last, col, type);
67     }
68     
69     // ------------------------------------------------------------------------
70
// VisualItemTable Methods
71

72     /**
73      * @see prefuse.visual.VisualTupleSet#getVisualization()
74      */

75     public Visualization getVisualization() {
76         return m_vis;
77     }
78     
79     /**
80      * Set the visualization associated with this VisualGraph
81      * @param vis the visualization to set
82      */

83     public void setVisualization(Visualization vis) {
84         m_vis = vis;
85     }
86     
87     /**
88      * Get the visualization data group name for this graph
89      * @return the data group name
90      */

91     public String JavaDoc getGroup() {
92         return m_group;
93     }
94     
95     /**
96      * Set the visualization data group name for this graph
97      * @return the data group name to use
98      */

99     public void setGroup(String JavaDoc group) {
100         m_group = group;
101     }
102     
103 } // end of class VisualTree
104
Popular Tags