/** * Returns the label size of the specified view in the given graph. */ public Dimension getLabelSize(EdgeView view, String label) { if (label != null && fontGraphics != null) { fontGraphics.setFont(GraphConstants .getFont(view.getAllAttributes())); metrics = fontGraphics.getFontMetrics(); int sw = (int)(metrics.stringWidth(label) * LABELWIDTHBUFFER); int sh = metrics.getHeight(); return new Dimension(sw, sh); } return null; }
/** * Removes the point at position <code>index</code>. */ public void removeExtraLabel(int index) { Object[] labels = GraphConstants.getExtraLabels(getAllAttributes()); Point2D[] pts = GraphConstants .getExtraLabelPositions(getAllAttributes()); if (labels == null || labels.length > 1) { Object[] newLabels = new Object[labels.length - 1]; Point2D[] newPts = new Point2D[pts.length - 1]; System.arraycopy(labels, 0, newLabels, 0, index); if (index < newLabels.length) System.arraycopy(labels, index + 1, newLabels, index, newLabels.length - index); System.arraycopy(pts, 0, newPts, 0, index); if (index < newPts.length) System.arraycopy(pts, index + 1, newPts, index, newPts.length - index); GraphConstants.setExtraLabels(getAllAttributes(), newLabels); GraphConstants.setExtraLabelPositions(getAllAttributes(), newPts); } else { // TODO: Remove via REMOVEATTRIBUTES GraphConstants.setExtraLabels(getAllAttributes(), new Object[0]); GraphConstants.setExtraLabelPositions(getAllAttributes(), new Point2D[0]); } }
/** * Adds an extra label. */ public void addExtraLabel(Point2D location, Object label) { Object[] extraLabels = GraphConstants .getExtraLabels(getAllAttributes()); Point2D[] positions = GraphConstants .getExtraLabelPositions(getAllAttributes()); // Inserts a new extra label if (extraLabels == null) { extraLabels = new Object[1]; positions = new Point2D[1]; } else { Object[] tmp = new Object[extraLabels.length + 1]; System.arraycopy(extraLabels, 0, tmp, 0, extraLabels.length); extraLabels = tmp; Point2D[] pts = new Point2D[positions.length + 1]; System.arraycopy(positions, 0, pts, 0, positions.length); positions = pts; } int newIndex = extraLabels.length - 1; extraLabels[newIndex] = label; positions[newIndex] = location; GraphConstants.setExtraLabels(getAllAttributes(), extraLabels); GraphConstants.setExtraLabelPositions(getAllAttributes(), positions); }
/** * Returns the absolute position of the main label * @return the absolute position of the main label */ protected Point2D getAbsoluteLabelPosition() { Point2D result = getAbsoluteLabelPositionFromRelative(GraphConstants.getLabelPosition(getAllAttributes())); return result; }
/** * Converts relative label position to absolute and allows for * any label offset. * @param geometry the relative label position * @return the absolute label position including any offset */ protected Point2D getAbsoluteLabelPositionFromRelative(Point2D geometry) { Point2D result = convertRelativeLabelPositionToAbsolute(geometry); if (result != null) { double offsetX = 0; double offsetY = 0; Point2D offset = GraphConstants.getOffset(getAllAttributes()); if (offset != null) { offsetX = offset.getX(); offsetY = offset.getY(); } double x = result.getX() + offsetX; double y = result.getY() + offsetY; return new Point2D.Double(x, y); } return null; }
/** * Returns the absolute position of the specified extra label * @param index the index of the extra label * @return the absolute position of the specified extra label */ protected Point2D getAbsoluteExtraLabelPosition(int index) { Point2D[] positions = GraphConstants .getExtraLabelPositions(getAllAttributes()); if (positions != null && positions.length > index) { Point2D result = getAbsoluteLabelPositionFromRelative(positions[index]); return result; } return null; }
/** * Returns the label size of the specified view in the given graph. */ public Dimension getExtraLabelSize(JGraph paintingContext, EdgeView view, int index) { Object[] labels = GraphConstants .getExtraLabels(view.getAllAttributes()); if (labels != null && index < labels.length) { String label = (paintingContext != null) ? paintingContext .convertValueToString(labels[index]) : String .valueOf(labels[index]); return getLabelSize(view, label); } return null; }
/** * 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; }
/** * Subclassers can override this to decide whether or not "port magic" * should appear on a given edge. (Port magic means the port tries to make * the edge horizontal or vertical if the closest control point lies within * the bounds of the parent vertex.) */ protected boolean shouldInvokePortMagic(EdgeView edge) { return allowPortMagic && !(getParentView() instanceof EdgeView) && edge.getPointCount() > 2 && GraphConstants.getLineStyle(edge.getAllAttributes()) == GraphConstants.STYLE_ORTHOGONAL; }
g2.rotate(angle); if (GraphConstants.isOpaque(view.getAllAttributes())){ g.setColor(GraphConstants.getBackground(view.getAllAttributes())); g.fillRect(dx-2 , -10, sw + 4, dy+sh*lines.length+2); if (GraphConstants.getBorderColor(view.getAllAttributes())!=null){ Stroke os = g2.getStroke(); BasicStroke bs= new BasicStroke(2.0f, // Width 0.0f); // Dash phase g2.setStroke(bs); g.setColor(GraphConstants.getBorderColor(view.getAllAttributes())); g.drawRect(dx -2, -10, sw + 4, dy+sh*lines.length+2 );
Rectangle2D.union(r, rect, r); Object[] labels = GraphConstants.getExtraLabels(view .getAllAttributes()); if (labels != null) { for (int i = 0; i < labels.length; i++) {
GraphConstants.setRemoveAttributes(edge.getAllAttributes(), new Object[] {GraphConstants.OFFSET}); edge.getAllAttributes().remove(GraphConstants.OFFSET); } else { Point2D off = new Point2D.Double(p.getX() - storedRelativePosition.getX(), p.getY() - storedRelativePosition.getY()); GraphConstants.setOffset(edge.getAllAttributes(), off);
public EdgeHandle(EdgeView edge, GraphContext ctx) { this.graph = ctx.getGraph(); this.edge = edge; editing = graph.getEditingCell() == edge.getCell(); loc = new Rectangle(); Object[] labels = GraphConstants.getExtraLabels(edge .getAllAttributes()); if (labels != null) { extraLabelLocations = new Rectangle[labels.length]; for (int i = 0; i < extraLabelLocations.length; i++) extraLabelLocations[i] = new Rectangle(); } orig = (EdgeView) graph.getGraphLayoutCache().getMapping( edge.getCell(), false); reloadPoints(orig); isEdgeConnectable = GraphConstants.isConnectable(edge .getAllAttributes()); // Configures the panel for highlighting ports highlight = createHighlight(); }
/** * Invoked when the mouse pointer has been moved on a component (with no * buttons down). */ public void mouseMoved(MouseEvent event) { for (int i = 0; i < r.length; i++) if (r[i].contains(event.getPoint())) { graph.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); event.consume(); return; } if (loc.contains(event.getPoint()) && graph.isMoveable() && GraphConstants.isMoveable(edge.getAllAttributes())) { graph.setCursor(new Cursor(Cursor.HAND_CURSOR)); event.consume(); } if (extraLabelLocations != null && graph.isMoveable() && GraphConstants.isMoveable(edge.getAllAttributes())) { for (int i = 0; i < extraLabelLocations.length; i++) { if (extraLabelLocations[i].contains(event.getPoint())) { graph.setCursor(new Cursor(Cursor.HAND_CURSOR)); event.consume(); } } } }
/** * Returns the label bounds of the specified view in the given graph. Note: * The index is the position of the String object for the label in the extra * labels array of the view. */ public Rectangle2D getExtraLabelBounds(JGraph paintingContext, EdgeView view, int index) { if (paintingContext == null && graph != null) { JGraph graph = (JGraph)this.graph.get(); paintingContext = graph; } setView(view); Object[] labels = GraphConstants .getExtraLabels(view.getAllAttributes()); if (labels != null && index < labels.length) { Point2D p = getExtraLabelPosition(this.view, index); Dimension d = getExtraLabelSize(paintingContext, this.view, index); String label = (paintingContext != null) ? paintingContext .convertValueToString(labels[index]) : String .valueOf(labels[index]); return getLabelBounds(p, d, label); } return new Rectangle2D.Double(getX(), getY(), 0, 0); }
: getFont()); Object[] labels = GraphConstants.getExtraLabels(view .getAllAttributes()); JGraph graph = (JGraph)this.graph.get(); if (labels != null) {
return true; Object[] labels = GraphConstants.getExtraLabels(view .getAllAttributes()); if (labels != null) { for (int i = 0; i < labels.length; i++) {
return; boolean bendable = graph.isBendable() && GraphConstants.isBendable(edge.getAllAttributes()); int x = event.getX(); int y = event.getY(); .getAllAttributes())) && GraphConstants.isMoveable(edge.getAllAttributes()) && loc != null && loc.contains(x, y) && !isAddPointEvent(event) && !isRemovePointEvent(event) && GraphConstants.isMoveable(edge.getAllAttributes())) { for (int i = 0; i < extraLabelLocations.length; i++) { if (extraLabelLocations[i] != null
Point2D location = null; Object[] extraLabels = GraphConstants.getExtraLabels(edge .getAllAttributes()); if (label) { location = (Point2D) edge.getLabelPosition().clone();
EdgeView view = (EdgeView) cells[i]; CellView port = view.getSource(); if (GraphConstants.isDisconnectable(view.getAllAttributes())) { if (port != null && GraphConstants.isDisconnectable(port