/** Helper method to configure the given wrapper canvas. */ protected mxGraphicsCanvas2D configureCanvas( mxGraphics2DCanvas canvas, mxCellState state, mxGraphicsCanvas2D c) { c.setShadow(hasShadow(canvas, state)); c.setStrokeColor( mxUtils.getString(state.getStyle(), mxConstants.STYLE_STROKECOLOR, mxConstants.NONE)); c.setStrokeWidth(mxUtils.getInt(state.getStyle(), mxConstants.STYLE_STROKEWIDTH, 1)); c.setDashed(mxUtils.isTrue(state.getStyle(), mxConstants.STYLE_DASHED, false)); String fill = mxUtils.getString(state.getStyle(), mxConstants.STYLE_FILLCOLOR, mxConstants.NONE); String gradient = mxUtils.getString(state.getStyle(), mxConstants.STYLE_GRADIENTCOLOR, mxConstants.NONE); if (!mxConstants.NONE.equals(fill) && !mxConstants.NONE.equals(gradient)) { mxRectangle b = getGradientBounds(canvas, state); c.setGradient( fill, gradient, b.getX(), b.getY(), b.getWidth(), b.getHeight(), mxUtils.getString( state.getStyle(), mxConstants.STYLE_GRADIENT_DIRECTION, mxConstants.DIRECTION_NORTH), 1, 1); } else { c.setFillColor(fill); } return c; }
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; }
/** * Allocate a superBlock * * @param parentGraph the base graph * @param selection the selected blocks * @return the allocated super block (without specific listeners) */ private SuperBlock allocateSuperBlock(final XcosDiagram parentGraph, final Object[] selection) { final SuperBlock superBlock = (SuperBlock) BlockFactory.createBlock(INTERFUNCTION_NAME); superBlock.setStyle(INTERFUNCTION_NAME); /* * Allocate the diagram */ final SuperBlockDiagram diag = new SuperBlockDiagram(superBlock); superBlock.setChild(diag); superBlock.setParentDiagram(parentGraph); /* * Place the super block */ final mxRectangle dims = parentGraph.getBoundingBoxFromGeometry(selection); final double minX = dims.getX(); final double maxX = minX + dims.getWidth(); final double minY = dims.getY(); final double maxY = minY + dims.getHeight(); superBlock.getGeometry().setX((maxX + minX - superBlock.getGeometry().getWidth()) / 2.0); superBlock.getGeometry().setY((maxY + minY - superBlock.getGeometry().getHeight()) / 2.0); /* * get statistics */ int angleCounter = 0; int flipCounter = 0; int mirrorCounter = 0; for (Object object : selection) { if (object instanceof BasicBlock) { final BasicBlock b = (BasicBlock) object; angleCounter += b.getAngle(); if (b.getFlip()) { flipCounter++; } if (b.getMirror()) { mirrorCounter++; } } } /* * apply statistics */ final int halfSize = selection.length / 2; superBlock.setAngle(BlockPositioning.roundAngle(angleCounter / selection.length)); superBlock.setFlip(flipCounter > halfSize); superBlock.setMirror(mirrorCounter > halfSize); return superBlock; }
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; }
/** * Implements <mxGraphLayout.execute>. * * <p>If the parent has any connected edges, then it is used as the root of the tree. Else, * <mxGraph.findTreeRoots> will be used to find a suitable root node within the set of children of * the given parent. */ public void execute(Object parent, Object root) { mxIGraphModel model = graph.getModel(); if (root == null) { // Takes the parent as the root if it has outgoing edges if (graph.getEdges(parent, model.getParent(parent), invert, !invert, false).length > 0) { root = parent; } // Tries to find a suitable root in the parent's // children else { List<Object> roots = graph.findTreeRoots(parent, true, invert); if (roots != null && roots.size() > 0) { for (int i = 0; i < roots.size(); i++) { if (!isVertexIgnored(roots.get(i)) && graph.getEdges(roots.get(i), null, invert, !invert, false).length > 0) { root = roots.get(i); break; } } } } } if (root != null) { parent = model.getParent(root); model.beginUpdate(); try { TreeNode node = dfs(root, parent, null); if (node != null) { layout(node); double x0 = graph.getGridSize(); double y0 = x0; if (!moveTree || model.getParent(parent) == model.getRoot()) { mxGeometry g = model.getGeometry(root); if (g != null) { x0 = g.getX(); y0 = g.getY(); } } mxRectangle bounds = null; if (horizontal) { bounds = horizontalLayout(node, x0, y0, null); } else { bounds = verticalLayout(node, null, x0, y0, null); } if (bounds != null) { double dx = 0; double dy = 0; if (bounds.getX() < 0) { dx = Math.abs(x0 - bounds.getX()); } if (bounds.getY() < 0) { dy = Math.abs(y0 - bounds.getY()); } if (parent != null) { mxRectangle size = graph.getStartSize(parent); dx += size.getWidth(); dy += size.getHeight(); // Resize parent swimlane if (resizeParent && !graph.isCellCollapsed(parent)) { mxGeometry g = model.getGeometry(parent); if (g != null) { double width = bounds.getWidth() + size.getWidth() - bounds.getX() + 2 * x0; double height = bounds.getHeight() + size.getHeight() - bounds.getY() + 2 * y0; g = (mxGeometry) g.clone(); if (g.getWidth() > width) { dx += (g.getWidth() - width) / 2; } else { g.setWidth(width); } if (g.getHeight() > height) { if (horizontal) { dy += (g.getHeight() - height) / 2; } } else { g.setHeight(height); } model.setGeometry(parent, g); } } } moveNode(node, dx, dy); } } } finally { model.endUpdate(); } } }
public mxRectangle relativizeRectangleToThisState(mxRectangle r, double s, mxPoint tr) { // r is not normalized to the scale return new mxRectangle( (r.getX() - getX()) / s, (r.getY() - getY()) / s, r.getWidth() / s, r.getHeight() / s); }