/** * */ protected mxRectangle apply(TreeNode node, mxRectangle bounds) { mxRectangle g = graph.getModel().getGeometry(node.cell); if (node.cell != null && g != null) { if (isVertexMovable(node.cell)) { g = setVertexLocation(node.cell, node.x, node.y); } if (bounds == null) { bounds = new mxRectangle(g.getX(), g.getY(), g.getWidth(), g.getHeight()); } else { bounds = new mxRectangle(Math.min(bounds.getX(), g.getX()), Math.min(bounds.getY(), g.getY()), Math.max(bounds.getX() + bounds.getWidth(), g.getX() + g.getWidth()), Math.max(bounds.getY() + bounds.getHeight(), g.getY() + g.getHeight())); } } return bounds; }
/** * */ protected TreeNode createNode(Object cell) { TreeNode node = new TreeNode(cell); mxRectangle geo = getVertexBounds(cell); if (geo != null) { if (horizontal) { node.width = geo.getHeight(); node.height = geo.getWidth(); } else { node.width = geo.getWidth(); node.height = geo.getHeight(); } } return node; }
/** * Returns the bounds to be used for the given group and children. This * implementation computes the bounding box of the geometries of all * vertices in the given children array. Edges are ignored. If the group * cell is a swimlane the title region is added to the bounds. */ public mxRectangle getBoundsForGroup(Object group, Object[] children, double border) { mxRectangle result = getBoundingBoxFromGeometry(children); if (result != null) { if (isSwimlane(group)) { mxRectangle size = getStartSize(group); result.setX(result.getX() - size.getWidth()); result.setY(result.getY() - size.getHeight()); result.setWidth(result.getWidth() + size.getWidth()); result.setHeight(result.getHeight() + size.getHeight()); } // Adds the border result.setX(result.getX() - border); result.setY(result.getY() - border); result.setWidth(result.getWidth() + 2 * border); result.setHeight(result.getHeight() + 2 * border); } return result; }
double cx = bounds.getCenterX(); double cy = bounds.getCenterY(); double dx = next.getX() - cx; double dy = next.getY() - cy; double pi2 = Math.PI / 2; double beta = pi2 - alpha; double t = Math.atan2(bounds.getHeight(), bounds.getWidth()); p.setX(bounds.getX()); p.setY(cy - bounds.getWidth() * Math.tan(alpha) / 2); p.setY(bounds.getY()); p.setX(cx - bounds.getHeight() * Math.tan(beta) / 2); p.setX(bounds.getX() + bounds.getWidth()); p.setY(cy + bounds.getWidth() * Math.tan(alpha) / 2); p.setY(bounds.getY() + bounds.getHeight()); p.setX(cx + bounds.getHeight() * Math.tan(beta) / 2); if (next.getX() >= bounds.getX() && next.getX() <= bounds.getX() + bounds.getWidth()) else if (next.getY() >= bounds.getY() && next.getY() <= bounds.getY() + bounds.getHeight()) if (next.getX() < bounds.getX())
mxRectangle tmp = mxUtils.getBoundingBox(new mxRectangle(state), rotation); mxConstants.STYLE_STROKEWIDTH) * graph.getView().getScale()) + 1; tmp.grow(border); tmp.setWidth(tmp.getWidth() + mxConstants.SHADOW_OFFSETX); tmp.setHeight(tmp.getHeight() + mxConstants.SHADOW_OFFSETX); tmp.add(state.getLabelBounds()); rect = tmp.getRectangle(); return rect;
bounds.setHeight(Math.max(bounds.getHeight(), size.getHeight())); bounds.setWidth(Math.max(bounds.getWidth(), size.getWidth())); geo.setAlternateBounds(new mxRectangle(geo.getX(), geo.getY(), bounds.getWidth(), bounds.getHeight())); geo.getAlternateBounds().setX(geo.getX()); geo.getAlternateBounds().setY(geo.getY());
/** * Scrolls the graph so that it shows the given cell. * * @param cell */ public void scrollCellToVisible(Object cell, boolean center) { mxCellState state = graph.getView().getState(cell); if (state != null) { mxRectangle bounds = state; if (center) { bounds = (mxRectangle) bounds.clone(); bounds.setX(bounds.getCenterX() - getWidth() / 2); bounds.setWidth(getWidth()); bounds.setY(bounds.getCenterY() - getHeight() / 2); bounds.setHeight(getHeight()); } getGraphControl().scrollRectToVisible(bounds.getRectangle()); } }
double angle = java.lang.Math.atan(bounds.getHeight()/bounds.getWidth()); double rotation = Math.toDegrees(angle); if(quad){ double diff = labelbounds.getHeight()*(1-Math.cos(angle)); double plusy = diff * Math.sin(angle); double plusx = diff * Math.cos(angle); labelbounds.getCenterX(), labelbounds.getCenterY()); temporaryGraphics.translate( - plusx, plusy);
/** * Hook for subclassers to return the container size. */ public mxRectangle getContainerSize() { return new mxRectangle(); }
/** * Returns the start size of the given swimlane, that is, the width or * height of the part that contains the title, depending on the * horizontal style. The return value is an <mxRectangle> with either * width or height set as appropriate. * * @param swimlane <mxCell> whose start size should be returned. * @return Returns the startsize for the given swimlane. */ public mxRectangle getStartSize(Object swimlane) { mxRectangle result = new mxRectangle(); mxCellState state = view.getState(swimlane); Map<String, Object> style = (state != null) ? state.getStyle() : getCellStyle(swimlane); if (style != null) { double size = mxUtils.getDouble(style, mxConstants.STYLE_STARTSIZE, mxConstants.DEFAULT_STARTSIZE); if (mxUtils.isTrue(style, mxConstants.STYLE_HORIZONTAL, true)) { result.setHeight(size); } else { result.setWidth(size); } } return result; }
/** * */ public void mouseDragged(MouseEvent e) { if (graphComponent.isEnabled() && isEnabled() && !e.isConsumed() && first != null) { mxRectangle dirty = current; current = new mxRectangle(first.x, first.y, 0, 0); current.add(new mxRectangle(e.getX(), e.getY(), 0, 0)); if (dirty != null) { dirty.add(current); } else { dirty = current; } Rectangle tmp = dirty.getRectangle(); int b = (int) Math.ceil(lineWidth); graphComponent.getGraphControl().repaint(tmp.x - b, tmp.y - b, tmp.width + 2 * b, tmp.height + 2 * b); e.consume(); } }
/** * */ public void paint(Graphics g) { if (first != null && current != null) { ((Graphics2D) g).setStroke(new BasicStroke(lineWidth)); g.setColor(lineColor); Rectangle rect = current.getRectangle(); if (rounded) { g.drawRoundRect(rect.x, rect.y, rect.width, rect.height, 8, 8); } else { g.drawRect(rect.x, rect.y, rect.width, rect.height); } } }
state.setLabelBounds(new mxRectangle(state)); vertexBounds = new mxRectangle(0, 0, geo.getWidth() * this.getScale(), 0); state.getLabelBounds().setX(state.getX()); state.getLabelBounds().setWidth(state.getWidth());
/** * Returns the rectangle that should be used as the perimeter of the cell. * * @return Returns the rectangle that defines the perimeter. */ public mxRectangle getPerimeterBounds(double border) { mxRectangle bounds = new mxRectangle(getRectangle()); if (border != 0) { bounds.grow(border); } return bounds; }
/** * Constructs a rectangle using the given parameters. * * @param x X-coordinate of the new rectangle. * @param y Y-coordinate of the new rectangle. * @param width Width of the new rectangle. * @param height Height of the new rectangle. */ public mxRectangle(double x, double y, double width, double height) { super(x, y); setWidth(width); setHeight(height); }
/** * */ public Graphics2D createTemporaryGraphics(Map<String, Object> style, float opacity, mxRectangle bounds) { Graphics2D temporaryGraphics = (Graphics2D) g.create(); // Applies the default translate temporaryGraphics.translate(translate.x, translate.y); // Applies the rotation on the graphics object if (bounds != null) { double rotation = mxUtils.getDouble(style, mxConstants.STYLE_ROTATION, 0); if (rotation != 0) { temporaryGraphics.rotate(Math.toRadians(rotation), bounds.getCenterX(), bounds.getCenterY()); } } // Applies the opacity to the graphics object if (opacity != 100) { temporaryGraphics.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC_OVER, opacity / 100)); } return temporaryGraphics; }
/** * Returns the bounds to be used for the given group and children. This * implementation computes the bounding box of the geometries of all * vertices in the given children array. Edges are ignored. If the group * cell is a swimlane the title region is added to the bounds. */ public mxRectangle getBoundsForGroup(Object group, Object[] children, double border) { mxRectangle result = getBoundingBoxFromGeometry(children); if (result != null) { if (isSwimlane(group)) { mxRectangle size = getStartSize(group); result.setX(result.getX() - size.getWidth()); result.setY(result.getY() - size.getHeight()); result.setWidth(result.getWidth() + size.getWidth()); result.setHeight(result.getHeight() + size.getHeight()); } // Adds the border result.setX(result.getX() - border); result.setY(result.getY() - border); result.setWidth(result.getWidth() + 2 * border); result.setHeight(result.getHeight() + 2 * border); } return result; }