/** 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); }
/** Paints the text of the <tt>VisualEdge</tt>. */ public void paintText(Graphics2D g2d, Font font, Color fontColor, String text, float x, float y) { g2d.setFont(font); g2d.setColor(fontColor); g2d.drawString(text, x, y); }