/** * Returns the label position of the specified view in the given graph. */ public Point2D getLabelPosition(EdgeView view) { setView(view); return getLabelPosition(view.getLabelPosition()); }
Point2D p = getLabelPosition(view); double angle = 0; if (p != null && label != null && label.length() > 0) {
/** * Estimates whether the transform for label should be applied. With the * transform, the label will be painted along the edge. To apply transform, * rotate graphics by the angle returned from {@link #getLabelAngle} * * @return true, if transform can be applied, false otherwise */ private boolean isLabelTransform(String label) { if (!isLabelTransformEnabled()) { return false; } Point2D p = getLabelPosition(view); if (p != null && label != null && label.length() > 0) { int sw = metrics.stringWidth(label); Point2D p1 = view.getPoint(0); Point2D p2 = view.getPoint(view.getPointCount() - 1); double length = Math.sqrt((p2.getX() - p1.getX()) * (p2.getX() - p1.getX()) + (p2.getY() - p1.getY()) * (p2.getY() - p1.getY())); if (!(length <= Double.NaN || length < sw)) { return true; } } return false; }
/** * Returns the label position of the specified view in the given graph. */ public Point2D getExtraLabelPosition(EdgeView view, int index) { setView(view); Point2D[] pts = GraphConstants.getExtraLabelPositions(view .getAllAttributes()); if (pts != null && index < pts.length) return getLabelPosition(pts[index]); return null; }
/** * Returns the label bounds of the specified view in the given graph. */ public Rectangle2D getLabelBounds(JGraph paintingContext, EdgeView view) { if (paintingContext == null && graph != null) { JGraph graph = (JGraph)this.graph.get(); paintingContext = graph; } // No need to call setView as getLabelPosition will String label = (paintingContext != null) ? paintingContext .convertValueToString(view) : String.valueOf(view.getCell()); if (label != null) { Point2D p = getLabelPosition(view); Dimension d = getLabelSize(view, label); return getLabelBounds(p, d, label); } else { return null; } }
/** * Subclassers may override this to provide a better location for the * in-place editing of edges (if you do not inherit from the EdgeRenderer * class). */ protected Point2D getEditorLocation(Object cell, Dimension2D editorSize, Point2D pt) { // Edges have different editor position and size CellView view = graphLayoutCache.getMapping(cell, false); if (view instanceof EdgeView) { EdgeView edgeView = (EdgeView) view; CellViewRenderer renderer = edgeView.getRenderer(); if (renderer instanceof EdgeRenderer) { Point2D tmp = ((EdgeRenderer) renderer) .getLabelPosition(edgeView); if (tmp != null) pt = tmp; else pt = AbstractCellView.getCenterPoint(edgeView); pt.setLocation( Math.max(0, pt.getX() - editorSize.getWidth() / 2), Math.max(0, pt.getY() - editorSize.getHeight() / 2)); } graph.toScreen(pt); } return pt; }
int handlesize = graph.getHandleSize(); EdgeRenderer er = (EdgeRenderer) edge.getRenderer(); Point2D labelPosition = er.getLabelPosition(e); Point2D p = null; if (labelPosition != null) {
Object label = graph.convertValueToString(view); if (label != null) { paintLabel(g, label.toString(), getLabelPosition(view), true);