Exemplo n.º 1
0
  /** 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;
  }
  private static Image setUpGui() throws PropertyException, IOException {
    Color defaultFillColor = Utils.parseColor(nodeColor);
    IconSize iconsize = null;
    iconsize = EditorProperties.getInstance().getIconSize();
    int size = iconsize.getSize();

    Image image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB_PRE);
    Graphics g = image.getGraphics();
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    mxRectangle bounds = new mxRectangle(0, 0, size, size);
    float x1 = (float) bounds.getX();
    float y1 = (float) bounds.getY();
    float x2 = (float) bounds.getX();
    float y2 = (float) bounds.getY();

    GradientPaint fillPaint =
        new GradientPaint(x1, y1, defaultFillColor, x2, y2, defaultFillColor, false);
    g2.setPaint(fillPaint);
    int transitionSize = (size - 1) / 2;
    g2.fillRect(
        transitionSize - (transitionSize / 2),
        transitionSize - (transitionSize / 2),
        transitionSize + (transitionSize / 2),
        transitionSize + (transitionSize / 2));
    g2.setColor(new Color(0, 0, 0));
    g2.setStroke(new BasicStroke(1));
    g2.drawRect(
        transitionSize - (transitionSize / 2),
        transitionSize - (transitionSize / 2),
        transitionSize + (transitionSize / 2),
        transitionSize + (transitionSize / 2));

    int placeSize = (size - 1) / 2;
    Color bgcolor = UIManager.getColor("Panel.background");
    g2.setColor(bgcolor);
    g2.fillOval(0, 0, placeSize + placeSize / 2 + 2, placeSize + placeSize / 2 + 2);
    g2.setColor(defaultFillColor);
    g2.fillOval(0, 0, placeSize + placeSize / 2, placeSize + placeSize / 2);
    g2.setColor(new Color(0, 0, 0));
    g2.setStroke(new BasicStroke(1));
    g2.drawOval(0, 0, placeSize + placeSize / 2, placeSize + placeSize / 2);

    g2.dispose();
    return image;
  }
Exemplo n.º 3
0
  /**
   * 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();
      }
    }
  }
Exemplo n.º 6
0
 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);
 }