public void adjust() { List children; try { children = this.tree.getChildren(parentNode); } catch (GraphException ex) { ex.printStackTrace(); return; } // Find the child that that is immediately to the right and to the left // of the inserted column VisualVertex immediateRightChild = null, immediateLeftChild = null; int immediateRightChildX = grid.getWidth(); int immediateLeftChildX = 0; for (int i = 0; i < children.size(); i++) { VisualVertex vVertex; vVertex = this.vGraph.getVisualVertex(children.get(i)); Point vertexPoint = grid.findVisualVertex(vVertex); if (vertexPoint.x > insertedColumnX && (immediateRightChild == null || vertexPoint.x < immediateRightChildX)) { immediateRightChild = vVertex; immediateRightChildX = vertexPoint.x; } if (vertexPoint.x < insertedColumnX && (immediateLeftChild == null || vertexPoint.x > immediateLeftChildX)) { immediateLeftChild = vVertex; immediateLeftChildX = vertexPoint.x; } } // Move the granchild nodes to the right // whose parent is immediately to the right of the inserted colunm grid // but itself is to the left of the inserted column grid if (immediateRightChild != null) { this.adjustToRight = true; this.visit(immediateRightChild.getVertex()); } // Move the granchild nodes to the left // whose parent is immediately to the left of the inserted colunm grid // but itself is to the right of the inserted column grid if (immediateLeftChild != null) { this.adjustToRight = false; this.visit(immediateLeftChild.getVertex()); } }
public void routeEdge(Graphics2D g2d, VisualEdge vEdge) { Rectangle fromvertexBounds; Rectangle tovertexBounds; GeneralPath drawPath; VisualVertex visualVertexA = vEdge.getVisualVertexA(); VisualVertex visualVertexB = vEdge.getVisualVertexB(); drawPath = new GeneralPath(); ; fromvertexBounds = visualVertexA.getBounds(); tovertexBounds = visualVertexB.getBounds(); // Make sure to clear the GeneralPath() first. Otherwise, the edge's previous // path will be redrawn as well. drawPath.reset(); // Start the line from the center of the vEdgertex drawPath.moveTo((float) fromvertexBounds.getCenterX(), (float) fromvertexBounds.getCenterY()); drawPath.lineTo((float) tovertexBounds.getCenterX(), (float) tovertexBounds.getCenterY()); vEdge.setShape(new VisualGraphComponentPath(drawPath)); }
/** Paints the <tt>visualEdge</tt>. No arrowhead is drawn. */ public void paint(VisualGraphComponent component, Graphics2D g2d) { VisualEdge vEdge = (VisualEdge) component; Rectangle fromvertexBounds; Rectangle tovertexBounds; GeneralPath drawPath; VisualVertex visualVertexA = vEdge.getVisualVertexA(); VisualVertex visualVertexB = vEdge.getVisualVertexB(); GraphLayoutManager layoutmanager = vEdge.getVisualGraph().getGraphLayoutManager(); drawPath = vEdge.getGeneralPath(); // If there is no layoutmanager or there is one but the layout has not // been initialised, by default, let us route edges as straight lines. if (layoutmanager == null || (layoutmanager != null && !layoutmanager.isInitialized())) { fromvertexBounds = visualVertexA.getBounds(); tovertexBounds = visualVertexB.getBounds(); // Make sure to clear the GeneralPath() first. Otherwise, the edge's previous // path will be redrawn as well. drawPath.reset(); // Start the line from the center of the vEdgertex drawPath.moveTo((float) fromvertexBounds.getCenterX(), (float) fromvertexBounds.getCenterY()); drawPath.lineTo((float) tovertexBounds.getCenterX(), (float) tovertexBounds.getCenterY()); } else { // Let the layout manager determine how the edge will be routed. layoutmanager.routeEdge(g2d, vEdge); } // Draw the line g2d.setColor(vEdge.getOutlinecolor()); g2d.draw(drawPath); // Draw the edge label this.paintText(vEdge, g2d); }