@Override public void setSize(Dimension size) { super.setSize(size); for(V v : getGraph().getVertices()) { initializeLocation(v,apply(v),getSize()); } }
/** * Set vertex v to be level 0. * @param v the vertex to set as root */ public void setRoot(V v) { minLevels.put(v, new Integer(0)); // set all the levels. propagateMinimumLevel(v); }
@Override public void setSize(Dimension size) { super.setSize(size); for(V v : getGraph().getVertices()) { initializeLocation(v,transform(v),getSize()); } }
/** * A recursive method for allocating the level for each vertex. Ensures * that all predecessors of v have a level which is at least one greater * than the level of v. * * @param v the vertex whose minimum level is to be calculated */ public void propagateMinimumLevel(V v) { int level = minLevels.get(v).intValue(); for(V child : getGraph().getPredecessors(v)) { int oldLevel, newLevel; Number o = minLevels.get(child); if (o != null) oldLevel = o.intValue(); else oldLevel = 0; newLevel = Math.max(oldLevel, level + 1); minLevels.put(child, new Integer(newLevel)); if (newLevel > graphHeight) graphHeight = newLevel; propagateMinimumLevel(child); } }
for(E e : getGraph().getEdges()) { Pair<V> endpoints = getGraph().getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); Point2D p1 = apply(v1); Point2D p2 = apply(v2); double vx = p1.getX() - p2.getX(); double vy = p1.getY() - p2.getY(); (getGraph().degree(v1) + getGraph().degree(v2) -2));
for(E e : getGraph().getEdges()) { Pair<V> endpoints = getGraph().getEndpoints(e); V v1 = endpoints.getFirst(); V v2 = endpoints.getSecond(); Point2D p1 = transform(v1); Point2D p2 = transform(v2); double vx = p1.getX() - p2.getX(); double vy = p1.getY() - p2.getY(); (getGraph().degree(v1) + getGraph().degree(v2) -2));
/** * Had to override this one as well, to ensure that setRoot() is called. */ @Override public void initialize() { super.initialize(); setRoot(); }
/** * Override forceMove so that if someone moves a node, we can re-layout * everything. */ @Override public void setLocation(V picked, double x, double y) { Point2D coord = transform(picked); coord.setLocation(x,y); stoppingIncrements = false; }
/** * Override forceMove so that if someone moves a node, we can re-layout * everything. * @param picked the vertex whose location is to be set * @param x the x coordinate of the location to set * @param y the y coordinate of the location to set */ @Override public void setLocation(V picked, double x, double y) { Point2D coord = apply(picked); coord.setLocation(x,y); stoppingIncrements = false; }
/** * Override forceMove so that if someone moves a node, we can re-layout * everything. * @param picked the vertex whose location is to be set * @param p the location to set */ @Override public void setLocation(V picked, Point2D p) { setLocation(picked, p.getX(), p.getY()); }
@Override public void actionPerformed(ActionEvent e) { final GraphViewerPanel viewerPanel = (GraphViewerPanel) frame.getTabbedPane().getSelectedComponent(); DAGLayout dagLayout = new DAGLayout(viewerPanel.getCurrentGraph()); MyVisualizationViewer vv = (MyVisualizationViewer) viewerPanel.getVisualizationViewer(); vv.setGraphLayout(dagLayout); vv.repaint(); } }
/** * A recursive method for allocating the level for each vertex. Ensures * that all predecessors of v have a level which is at least one greater * than the level of v. * * @param v */ public void propagateMinimumLevel(V v) { int level = minLevels.get(v).intValue(); for(V child : getGraph().getPredecessors(v)) { int oldLevel, newLevel; Number o = minLevels.get(child); if (o != null) oldLevel = o.intValue(); else oldLevel = 0; newLevel = Math.max(oldLevel, level + 1); minLevels.put(child, new Integer(newLevel)); if (newLevel > graphHeight) graphHeight = newLevel; propagateMinimumLevel(child); } }
/** * Override forceMove so that if someone moves a node, we can re-layout * everything. */ @Override public void setLocation(V picked, Point2D p) { Point2D coord = transform(picked); coord.setLocation(p); stoppingIncrements = false; }
/** * Calculates the level of each vertex in the graph. Level 0 is * allocated to each vertex with no successors. Level n+1 is allocated to * any vertex whose successors' maximum level is n. */ public void setRoot() { numRoots = 0; Graph<V, E> g = getGraph(); for(V v : g.getVertices()) { if (g.getSuccessors(v).isEmpty()) { setRoot(v); numRoots++; } } }
/** * Set vertex v to be level 0. */ public void setRoot(V v) { minLevels.put(v, new Integer(0)); // set all the levels. propagateMinimumLevel(v); }
/** * setRoot calculates the level of each vertex in the graph. Level 0 is * allocated to any vertex with no successors. Level n+1 is allocated to * any vertex whose successors' maximum level is n. */ public void setRoot(Graph<V,E> g) { numRoots = 0; for(V v : g.getVertices()) { Collection<V> successors = getGraph().getSuccessors(v); if (successors.size() == 0) { setRoot(v); numRoots++; } } }