001: package prefuse.visual;
002:
003: import prefuse.Visualization;
004: import prefuse.data.Graph;
005: import prefuse.data.Table;
006: import prefuse.data.event.EventConstants;
007: import prefuse.util.collections.IntIterator;
008:
009: /**
010: * A visual abstraction of a graph data structure. NodeItem and EdgeItem tuples
011: * provide the visual representations for the nodes and edges of the graph.
012: * VisualGraphs should not be created directly, they are created automatically
013: * by adding data to a Visualization, for example by using the
014: * {@link Visualization#addGraph(String, Graph)} method.
015: *
016: * @author <a href="http://jheer.org">jeffrey heer</a>
017: */
018: public class VisualGraph extends Graph implements VisualTupleSet {
019:
020: private Visualization m_vis;
021: private String m_group;
022:
023: /**
024: * Create a new VisualGraph
025: * @param nodes the visual node table
026: * @param edges the visual edge table
027: * @param directed indicates if graph edges are directed or undirected
028: * @param nodeKey the node table field by which to index the nodes.
029: * This value can be null, indicating that just the row indices should be
030: * used.
031: * @param sourceKey the edge table field storing source node keys
032: * @param targetKey the edge table field storing target node keys
033: */
034: public VisualGraph(VisualTable nodes, VisualTable edges,
035: boolean directed, String nodeKey, String sourceKey,
036: String targetKey) {
037: super (nodes, edges, directed, nodeKey, sourceKey, targetKey);
038: }
039:
040: /**
041: * Fire a graph event. Makes sure to invalidate all edges connected
042: * to a node that has been updated.
043: * @see prefuse.data.Graph#fireGraphEvent(prefuse.data.Table, int, int, int, int)
044: */
045: protected void fireGraphEvent(Table t, int first, int last,
046: int col, int type) {
047: // if a node is invalidated, invalidate the edges, too
048: if (type == EventConstants.UPDATE
049: && col == VisualItem.IDX_VALIDATED
050: && t == getNodeTable()) {
051: VisualTable nodes = (VisualTable) t;
052: VisualTable edges = (VisualTable) getEdgeTable();
053:
054: for (int i = first; i <= last; ++i) {
055: if (nodes.isValidated(i))
056: continue; // look only for invalidations
057:
058: if (i < 0) {
059: System.err
060: .println("catch me - VisualGraph fireGraphEvent");
061: }
062: // try {
063: IntIterator erows = edgeRows(i);
064: while (erows.hasNext()) {
065: int erow = erows.nextInt();
066: edges.setValidated(erow, false);
067: }
068: // } catch ( Exception ex ) {
069: // ex.printStackTrace();
070: // }
071: }
072: }
073: // fire the event off to listeners
074: super .fireGraphEvent(t, first, last, col, type);
075: }
076:
077: /**
078: * Get the node row index value for the given key.
079: * TODO: test this more thoroughly?
080: */
081: public int getNodeIndex(int key) {
082: if (m_nkey == null) {
083: return ((VisualTable) getNodeTable()).getChildRow(key);
084: } else {
085: return super .getNodeIndex(key);
086: }
087: }
088:
089: // ------------------------------------------------------------------------
090: // VisualGraph Methods
091:
092: /**
093: * @see prefuse.visual.VisualTupleSet#getVisualization()
094: */
095: public Visualization getVisualization() {
096: return m_vis;
097: }
098:
099: /**
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 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 group) {
120: m_group = group;
121: }
122:
123: } // end of class VisualGraph
|