1 5 package prefuse.data; 6 7 import java.util.BitSet ; 8 import java.util.Iterator ; 9 import java.util.LinkedList ; 10 11 import prefuse.data.tuple.TupleManager; 12 import prefuse.visual.tuple.TableEdgeItem; 13 14 23 public class SpanningTree extends Tree { 24 25 27 public static final String SOURCE_EDGE = "source"; 28 29 protected static final Schema EDGE_SCHEMA = new Schema(); 30 static { 31 EDGE_SCHEMA.addColumn(DEFAULT_SOURCE_KEY, int.class, new Integer (-1)); 32 EDGE_SCHEMA.addColumn(DEFAULT_TARGET_KEY, int.class, new Integer (-1)); 33 EDGE_SCHEMA.addColumn(SOURCE_EDGE, int.class); 34 } 35 36 37 protected Graph m_backing; 38 39 44 public SpanningTree(Graph g, Node root) { 45 super(g.getNodeTable(), EDGE_SCHEMA.instantiate()); 46 m_backing = g; 47 TupleManager etm = new TupleManager(getEdgeTable(), null, 48 TableEdgeItem.class) { 49 public Tuple getTuple(int row) { 50 return m_backing.getEdge(m_table.getInt(row, SOURCE_EDGE)); 51 } 52 }; 53 getEdgeTable().setTupleManager(etm); 54 super.setTupleManagers(g.m_nodeTuples, etm); 55 buildSpanningTree(root); 56 } 57 58 63 public void buildSpanningTree(Node root) { 64 super.clearEdges(); 66 super.setRoot(root); 67 68 LinkedList q = new LinkedList (); 70 BitSet visit = new BitSet (); 71 q.add(root); visit.set(root.getRow()); 72 Table edges = getEdgeTable(); 73 74 while ( !q.isEmpty() ) { 75 Node p = (Node)q.removeFirst(); 76 for ( Iterator iter = p.edges(); iter.hasNext(); ) { 77 Edge e = (Edge)iter.next(); 78 Node n = e.getAdjacentNode(p); 79 if ( !visit.get(n.getRow()) ) { 80 q.add(n); visit.set(n.getRow()); 81 int er = super.addChildEdge(p.getRow(), n.getRow()); 82 edges.setInt(er, SOURCE_EDGE, e.getRow()); 83 } 84 } 85 } 86 } 87 88 91 95 public int addChild(int parent) { 96 throw new UnsupportedOperationException ( 97 "Changes to tree structure not allowed for spanning trees."); 98 } 99 100 104 public Node addChild(Node parent) { 105 throw new UnsupportedOperationException ( 106 "Changes to tree structure not allowed for spanning trees."); 107 } 108 109 113 public int addChildEdge(int parent, int child) { 114 throw new UnsupportedOperationException ( 115 "Changes to tree structure not allowed for spanning trees."); 116 } 117 118 122 public Edge addChildEdge(Node parent, Node child) { 123 throw new UnsupportedOperationException ( 124 "Changes to tree structure not allowed for spanning trees."); 125 } 126 127 131 public Node addRoot() { 132 throw new UnsupportedOperationException ( 133 "Changes to tree structure not allowed for spanning trees."); 134 } 135 136 140 public int addRootRow() { 141 throw new UnsupportedOperationException ( 142 "Changes to tree structure not allowed for spanning trees."); 143 } 144 145 149 public boolean removeChild(int node) { 150 throw new UnsupportedOperationException ( 151 "Changes to tree structure not allowed for spanning trees."); 152 } 153 154 158 public boolean removeChild(Node n) { 159 throw new UnsupportedOperationException ( 160 "Changes to tree structure not allowed for spanning trees."); 161 } 162 163 167 public boolean removeChildEdge(Edge e) { 168 throw new UnsupportedOperationException ( 169 "Changes to tree structure not allowed for spanning trees."); 170 } 171 172 176 public boolean removeChildEdge(int edge) { 177 throw new UnsupportedOperationException ( 178 "Changes to tree structure not allowed for spanning trees."); 179 } 180 181 185 void setRoot(Node root) { 186 throw new UnsupportedOperationException ( 187 "Changes to tree structure not allowed for spanning trees."); 188 } 189 190 194 public int addEdge(int s, int t) { 195 throw new UnsupportedOperationException ( 196 "Changes to graph structure not allowed for spanning trees."); 197 } 198 199 203 public Edge addEdge(Node s, Node t) { 204 throw new UnsupportedOperationException ( 205 "Changes to graph structure not allowed for spanning trees."); 206 } 207 208 212 public Node addNode() { 213 throw new UnsupportedOperationException ( 214 "Changes to graph structure not allowed for spanning trees."); 215 } 216 217 221 public int addNodeRow() { 222 throw new UnsupportedOperationException ( 223 "Changes to graph structure not allowed for spanning trees."); 224 } 225 226 230 public void clear() { 231 throw new UnsupportedOperationException ( 232 "Changes to graph structure not allowed for spanning trees."); 233 } 234 235 239 public boolean removeEdge(Edge e) { 240 throw new UnsupportedOperationException ( 241 "Changes to graph structure not allowed for spanning trees."); 242 } 243 244 248 public boolean removeEdge(int edge) { 249 throw new UnsupportedOperationException ( 250 "Changes to graph structure not allowed for spanning trees."); 251 } 252 253 257 public boolean removeNode(int node) { 258 throw new UnsupportedOperationException ( 259 "Changes to graph structure not allowed for spanning trees."); 260 } 261 262 266 public boolean removeNode(Node n) { 267 throw new UnsupportedOperationException ( 268 "Changes to graph structure not allowed for spanning trees."); 269 } 270 271 275 public boolean removeTuple(Tuple t) { 276 throw new UnsupportedOperationException ( 277 "Changes to graph structure not allowed for spanning trees."); 278 } 279 280 284 public void setEdgeTable(Table edges) { 285 throw new UnsupportedOperationException ( 286 "Changes to graph structure not allowed for spanning trees."); 287 } 288 289 293 public void setTupleManagers(TupleManager ntm, TupleManager etm) { 294 throw new UnsupportedOperationException ( 295 "Changes to graph structure not allowed for spanning trees."); 296 } 297 298 } | Popular Tags |