KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > visual > VisualGraph


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

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

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

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

59                 if ( i < 0 ) {
60                     System.err.println("catch me - VisualGraph fireGraphEvent");
61                 }
62 // try {
63
IntIterator erows = edgeRows(i);
64                 while ( erows.hasNext() ) {
65                     int erow = erows.nextInt();
66                     edges.setValidated(erow, false);
67                 }
68 // } catch ( Exception ex ) {
69
// ex.printStackTrace();
70
// }
71
}
72         }
73         // fire the event off to listeners
74
super.fireGraphEvent(t, first, last, col, type);
75     }
76     
77     /**
78      * Get the node row index value for the given key.
79      * TODO: test this more thoroughly?
80      */

81     public int getNodeIndex(int key) {
82         if ( m_nkey == null ) {
83             return ((VisualTable)getNodeTable()).getChildRow(key);
84         } else {
85             return super.getNodeIndex(key);
86         }
87     }
88     
89     // ------------------------------------------------------------------------
90
// VisualGraph Methods
91

92     /**
93      * @see prefuse.visual.VisualTupleSet#getVisualization()
94      */

95     public Visualization getVisualization() {
96         return m_vis;
97     }
98     
99     /**
100      * Set the visualization associated with this VisualGraph
101      * @param vis the visualization to set
102      */

103     public void setVisualization(Visualization vis) {
104         m_vis = vis;
105     }
106     
107     /**
108      * Get the visualization data group name for this graph
109      * @return the data group name
110      */

111     public String JavaDoc getGroup() {
112         return m_group;
113     }
114     
115     /**
116      * Set the visualization data group name for this graph
117      * @return the data group name to use
118      */

119     public void setGroup(String JavaDoc group) {
120         m_group = group;
121     }
122     
123 } // end of class VisualGraph
124
Popular Tags