Package com.mxgraph.util

Examples of com.mxgraph.util.mxRectangle


   * (non-Javadoc)
   * @see com.mxgraph.canvas.mxICanvas#drawLabel()
   */
  public Object drawLabel(String label, mxCellState state, boolean html)
  {
    mxRectangle bounds = state.getLabelBounds();

    if (drawLabels && bounds != null)
    {
      int x = (int) bounds.getX() + translate.x;
      int y = (int) bounds.getY() + translate.y;
      int w = (int) bounds.getWidth();
      int h = (int) bounds.getHeight();
      Map<String, Object> style = state.getStyle();

      return drawText(label, x, y, w, h, style);
    }

View Full Code Here


              mxConstants.STYLE_IMAGE_HEIGHT,
              mxConstants.DEFAULT_IMAGESIZE) * scale);
          int spacing = (int) (mxUtils.getInt(style,
              mxConstants.STYLE_SPACING, 2) * scale);

          mxRectangle imageBounds = new mxRectangle(x, y, w, h);

          if (imgAlign.equals(mxConstants.ALIGN_CENTER))
          {
            imageBounds.setX(imageBounds.getX()
                + (imageBounds.getWidth() - imgWidth) / 2);
          }
          else if (imgAlign.equals(mxConstants.ALIGN_RIGHT))
          {
            imageBounds.setX(imageBounds.getX()
                + imageBounds.getWidth() - imgWidth - spacing
                - 2);
          }
          else
          // LEFT
          {
            imageBounds.setX(imageBounds.getX() + spacing + 4);
          }

          if (imgValign.equals(mxConstants.ALIGN_TOP))
          {
            imageBounds.setY(imageBounds.getY() + spacing);
          }
          else if (imgValign.equals(mxConstants.ALIGN_BOTTOM))
          {
            imageBounds
                .setY(imageBounds.getY()
                    + imageBounds.getHeight() - imgHeight
                    - spacing);
          }
          else
          // MIDDLE
          {
            imageBounds.setY(imageBounds.getY()
                + (imageBounds.getHeight() - imgHeight) / 2);
          }

          imageBounds.setWidth(imgWidth);
          imageBounds.setHeight(imgHeight);

          elem = document.createElement("g");
          elem.appendChild(background);

          Element imageElement = createImageElement(
              imageBounds.getX(), imageBounds.getY(),
              imageBounds.getWidth(), imageBounds.getHeight(),
              img, false, false, false, isEmbedded());

          if (opacity != 100)
          {
            String value = String.valueOf(opacity / 100);
View Full Code Here

  public void mouseDragged(MouseEvent e)
  {
    if (graphComponent.isEnabled() && isEnabled() && !e.isConsumed()
        && first != null)
    {
      mxRectangle dirty = mxUtils.getBoundingBox(currentState,
          currentAngle * mxConstants.DEG_PER_RAD);
      Point pt = SwingUtilities.convertPoint(e.getComponent(),
          e.getPoint(), graphComponent.getGraphControl());

      double cx = currentState.getCenterX();
      double cy = currentState.getCenterY();
      double dx = pt.getX() - cx;
      double dy = pt.getY() - cy;
      double c = Math.sqrt(dx * dx + dy * dy);

      currentAngle = ((pt.getX() > cx) ? -1 : 1) * Math.acos(dy / c)
          + PI4 + initialAngle;

      dirty.add(mxUtils.getBoundingBox(currentState, currentAngle
          * mxConstants.DEG_PER_RAD));
      dirty.grow(1);

      // TODO: Compute dirty rectangle and repaint
      graphComponent.getGraphControl().repaint(dirty.getRectangle());
      e.consume();
    }
    else if (handle.getParent() != null)
    {
      handle.getParent().remove(handle);
View Full Code Here

    if (handle.getParent() != null)
    {
      handle.getParent().remove(handle);
    }

    mxRectangle dirty = null;

    if (currentState != null && first != null)
    {
      dirty = mxUtils.getBoundingBox(currentState, currentAngle
          * mxConstants.DEG_PER_RAD);
      dirty.grow(1);
    }

    currentState = null;
    currentAngle = 0;
    first = null;

    if (dirty != null)
    {
      graphComponent.getGraphControl().repaint(dirty.getRectangle());
    }
  }
View Full Code Here

  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();
 
View Full Code Here

   * @param cells
   * @return Returns the bounding box for the given cells.
   */
  public mxRectangle getBounds(Object[] cells, boolean boundingBox)
  {
    mxRectangle result = null;

    if (cells != null && cells.length > 0)
    {
      mxIGraphModel model = graph.getModel();

      for (int i = 0; i < cells.length; i++)
      {
        if (model.isVertex(cells[i]) || model.isEdge(cells[i]))
        {
          mxCellState state = getState(cells[i]);

          if (state != null)
          {
            mxRectangle tmp = (boundingBox) ? state
                .getBoundingBox() : state;

            if (tmp != null)
            {
              if (result == null)
              {
                result = new mxRectangle(tmp);
              }
              else
              {
                result.add(tmp);
              }
View Full Code Here

   * First validates all bounds and then validates all points recursively on
   * all visible cells.
   */
  public void validate()
  {
    mxRectangle graphBounds = getBoundingBox(validateCellState(validateCell((currentRoot != null) ? currentRoot
        : graph.getModel().getRoot())));
    setGraphBounds((graphBounds != null) ? graphBounds : new mxRectangle());
  }
View Full Code Here

   * @param recurse
   *            Boolean indicating if the children should be included.
   */
  public mxRectangle getBoundingBox(mxCellState state, boolean recurse)
  {
    mxRectangle bbox = null;

    if (state != null)
    {
      if (state.getBoundingBox() != null)
      {
        bbox = (mxRectangle) state.getBoundingBox().clone();
      }

      if (recurse)
      {
        mxIGraphModel model = graph.getModel();
        int childCount = model.getChildCount(state.getCell());

        for (int i = 0; i < childCount; i++)
        {
          mxRectangle bounds = getBoundingBox(
              getState(model.getChildAt(state.getCell(), i)), true);

          if (bounds != null)
          {
            if (bbox == null)
View Full Code Here

    String overflow = mxUtils.getString(style, mxConstants.STYLE_OVERFLOW,
        "");

    if (overflow.equals("fill"))
    {
      state.setLabelBounds(new mxRectangle(state));
    }
    else if (state.getLabel() != null)
    {
      // For edges, the width of the geometry is used for wrapping HTML
      // labels or no wrapping is applied if the width is set to 0
      mxRectangle vertexBounds = state;

      if (graph.getModel().isEdge(cell))
      {
        mxGeometry geo = graph.getCellGeometry(cell);

        if (geo != null && geo.getWidth() > 0)
        {
          vertexBounds = new mxRectangle(0, 0, geo.getWidth()
              * this.getScale(), 0);
        }
        else
        {
          vertexBounds = null;
View Full Code Here

   *            Cell state whose bounding box should be updated.
   */
  public mxRectangle updateBoundingBox(mxCellState state)
  {
    // Gets the cell bounds and adds shadows and markers
    mxRectangle rect = new mxRectangle(state);
    Map<String, Object> style = state.getStyle();

    // Adds extra pixels for the marker and stroke assuming
    // that the border stroke is centered around the bounds
    // and the first pixel is drawn inside the bounds
    double strokeWidth = Math.max(
        1,
        Math.round(mxUtils.getInt(style, mxConstants.STYLE_STROKEWIDTH,
            1) * scale));
    strokeWidth -= Math.max(1, strokeWidth / 2);

    if (graph.getModel().isEdge(state.getCell()))
    {
      int ms = 0;

      if (style.containsKey(mxConstants.STYLE_ENDARROW)
          || style.containsKey(mxConstants.STYLE_STARTARROW))
      {
        ms = (int) Math.round(mxConstants.DEFAULT_MARKERSIZE * scale);
      }

      // Adds the strokewidth
      rect.grow(ms + strokeWidth);

      // Adds worst case border for an arrow shape
      if (mxUtils.getString(style, mxConstants.STYLE_SHAPE, "").equals(
          mxConstants.SHAPE_ARROW))
      {
        rect.grow(mxConstants.ARROW_WIDTH / 2);
      }
    }
    else
    {
      rect.grow(strokeWidth);
    }

    // Adds extra pixels for the shadow
    if (mxUtils.isTrue(style, mxConstants.STYLE_SHADOW))
    {
      rect.setWidth(rect.getWidth() + mxConstants.SHADOW_OFFSETX);
      rect.setHeight(rect.getHeight() + mxConstants.SHADOW_OFFSETY);
    }

    // Adds oversize images in labels
    if (mxUtils.getString(style, mxConstants.STYLE_SHAPE, "").equals(
        mxConstants.SHAPE_LABEL))
    {
      if (mxUtils.getString(style, mxConstants.STYLE_IMAGE) != null)
      {
        double w = mxUtils.getInt(style, mxConstants.STYLE_IMAGE_WIDTH,
            mxConstants.DEFAULT_IMAGESIZE) * scale;
        double h = mxUtils.getInt(style,
            mxConstants.STYLE_IMAGE_HEIGHT,
            mxConstants.DEFAULT_IMAGESIZE)
            * scale;

        double x = state.getX();
        double y = 0;

        String imgAlign = mxUtils.getString(style,
            mxConstants.STYLE_IMAGE_ALIGN, mxConstants.ALIGN_LEFT);
        String imgValign = mxUtils.getString(style,
            mxConstants.STYLE_IMAGE_VERTICAL_ALIGN,
            mxConstants.ALIGN_MIDDLE);

        if (imgAlign.equals(mxConstants.ALIGN_RIGHT))
        {
          x += state.getWidth() - w;
        }
        else if (imgAlign.equals(mxConstants.ALIGN_CENTER))
        {
          x += (state.getWidth() - w) / 2;
        }

        if (imgValign.equals(mxConstants.ALIGN_TOP))
        {
          y = state.getY();
        }
        else if (imgValign.equals(mxConstants.ALIGN_BOTTOM))
        {
          y = state.getY() + state.getHeight() - h;
        }
        else
        // MIDDLE
        {
          y = state.getY() + (state.getHeight() - h) / 2;
        }

        rect.add(new mxRectangle(x, y, w, h));
      }
    }

    // Adds the rotated bounds to the bounding box if the
    // shape is rotated
    double rotation = mxUtils.getDouble(style, mxConstants.STYLE_ROTATION);
    mxRectangle bbox = mxUtils.getBoundingBox(rect, rotation);

    // Add the rotated bounding box to the non-rotated so
    // that all handles are also covered
    rect.add(bbox);

View Full Code Here

TOP

Related Classes of com.mxgraph.util.mxRectangle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.