Package com.mxgraph.util

Examples of com.mxgraph.util.mxRectangle


            Shape shape = gv.getGlyphOutline(j, -vectorOffset, 0);

            LabelGlyphCache qlyph = new LabelGlyphCache();
            glyphList.add(qlyph);
            qlyph.glyphShape = shape;
            mxRectangle size = new mxRectangle(gv.getGlyphLogicalBounds(j).getBounds2D());
            qlyph.labelGlyphBounds = size;
            labelSize += size.getWidth();
            vectorOffset += size.getWidth();

            charCount++;
          }
        }
      }
      else
      {
        rtlGlyphVectors = null;
        //String locale = System.getProperty("user.language");
        // Character iterator required where character is split over
        // string elements
        BreakIterator it = BreakIterator.getCharacterInstance(Locale.getDefault());
        it.setText(label);

        for (int i = 0; i < label.length();)
        {
          int next = it.next();
          int characterLen = 1;
         
          if (next != BreakIterator.DONE)
          {
            characterLen = next - i;
          }

          String glyph = label.substring(i, i + characterLen);
         
          LabelGlyphCache labelGlyph = new LabelGlyphCache();
          glyphList.add(labelGlyph);
          labelGlyph.glyph = glyph;
          GlyphVector vector = font.createGlyphVector(frc, glyph);
          labelGlyph.glyphShape = vector.getOutline();

          if (fm == null)
          {
            mxRectangle size = new mxRectangle(
                font.getStringBounds(glyph,
                    mxCurveLabelShape.frc));
            labelGlyph.labelGlyphBounds = size;
            labelSize += size.getWidth();
          }
          else
          {
            double width = fm.stringWidth(glyph);
            labelGlyph.labelGlyphBounds = new mxRectangle(0, 0,
                width, ascent);
            labelSize += width;
          }

          i += characterLen;
         

        }
      }

      // Update values used to determine whether or not the label cache
      // is valid or not
      lastValue = label;
      lastFont = font;
      lastPoints = curve.getGuidePoints();
      this.labelGlyphs = glyphList.toArray(new LabelGlyphCache[glyphList.size()]);
    }

    // Store the start/end buffers that pad out the ends of the branch so the label is
    // visible. We work initially as the start section being at the start of the
    // branch and the end at the end of the branch. Note that the actual label curve
    // might be reversed, so we allow for this after completing the buffer calculations,
    // otherwise they'd need to be constant isReversed() checks throughout
    labelPosition.startBuffer = LABEL_BUFFER * scale;
    labelPosition.endBuffer = LABEL_BUFFER * scale;

    calculationLabelPosition(style, label);

    if (curve.isLabelReversed())
    {
      double temp = labelPosition.startBuffer;
      labelPosition.startBuffer = labelPosition.endBuffer;
      labelPosition.endBuffer = temp;
    }

    double curveLength = curve.getCurveLength(mxCurve.LABEL_CURVE);
    double currentPos = labelPosition.startBuffer / curveLength;
    double endPos = 1.0 - (labelPosition.endBuffer / curveLength);

    mxRectangle overallLabelBounds = null;
    centerVisibleIndex = 0;

    double currentCurveDelta = 0.0;
    double curveDeltaSignificant = 0.3;
    double curveDeltaMax = 0.5;
    mxLine nextParallel = null;

    // TODO on translation just move the points, don't recalculate
    // Might be better than the curve is the only thing updated and
    // the curve shapes listen to curve events
    // !lastPoints.equals(curve.getGuidePoints())
    for (int j = 0; j < labelGlyphs.length; j++)
    {
      if (currentPos > endPos)
      {
        labelGlyphs[j].visible = false;
        continue;
      }

      mxLine parallel = nextParallel;

      if (currentCurveDelta > curveDeltaSignificant
          || nextParallel == null)
      {
        parallel = curve.getCurveParallel(mxCurve.LABEL_CURVE,
            currentPos);

        currentCurveDelta = 0.0;
        nextParallel = null;
      }

      labelGlyphs[j].glyphGeometry = parallel;

      if (parallel == mxCurve.INVALID_POSITION)
      {
        continue;
      }

      // Get the four corners of the rotated rectangle bounding the glyph
      // The drawing bounds of the glyph is the unrotated rect that
      // just bounds those four corners
      final double w = labelGlyphs[j].labelGlyphBounds.getWidth();
      final double h = labelGlyphs[j].labelGlyphBounds.getHeight();
      final double x = parallel.getEndPoint().getX();
      final double y = parallel.getEndPoint().getY();
      // Bottom left
      double p1X = parallel.getX() - (descent * y);
      double minX = p1X, maxX = p1X;
      double p1Y = parallel.getY() + (descent * x);
      double minY = p1Y, maxY = p1Y;
      // Top left
      double p2X = p1X + ((h + descent) * y);
      double p2Y = p1Y - ((h + descent) * x);
      minX = Math.min(minX, p2X);
      maxX = Math.max(maxX, p2X);
      minY = Math.min(minY, p2Y);
      maxY = Math.max(maxY, p2Y);
      // Bottom right
      double p3X = p1X + (w * x);
      double p3Y = p1Y + (w * y);
      minX = Math.min(minX, p3X);
      maxX = Math.max(maxX, p3X);
      minY = Math.min(minY, p3Y);
      maxY = Math.max(maxY, p3Y);
      // Top right
      double p4X = p2X + (w * x);
      double p4Y = p2Y + (w * y);
      minX = Math.min(minX, p4X);
      maxX = Math.max(maxX, p4X);
      minY = Math.min(minY, p4Y);
      maxY = Math.max(maxY, p4Y);

      minX -= 2 * scale;
      minY -= 2 * scale;
      maxX += 2 * scale;
      maxY += 2 * scale;

      // Hook for sub-classers
      postprocessGlyph(curve, label, j, currentPos);

      // Need to allow for text on inside of curve bends. Need to get the
      // parallel for the next section, if there is an excessive
      // inner curve, advance the current position accordingly

      double currentPosCandidate = currentPos
          + (labelGlyphs[j].labelGlyphBounds.getWidth() + labelPosition.defaultInterGlyphSpace)
          / curveLength;

      nextParallel = curve.getCurveParallel(mxCurve.LABEL_CURVE,
          currentPosCandidate);

      currentPos = currentPosCandidate;

      mxPoint nextVector = nextParallel.getEndPoint();
      double end2X = nextVector.getX();
      double end2Y = nextVector.getY();

      if (nextParallel != mxCurve.INVALID_POSITION
          && j + 1 < label.length())
      {
        // Extend the current parallel line in its direction
        // by the length of the next parallel. Use the approximate
        // deviation to work out the angle change
        double deltaX = Math.abs(x - end2X);
        double deltaY = Math.abs(y - end2Y);

        // The difference as a proportion of the length of the next
        // vector. 1 means a variation of 60 degrees.
        currentCurveDelta = Math
            .sqrt(deltaX * deltaX + deltaY * deltaY);
      }

      if (currentCurveDelta > curveDeltaSignificant)
      {
        // Work out which direction the curve is going in
        int ccw = Line2D.relativeCCW(0, 0, x, y, end2X, end2Y);

        if (ccw == 1)
        {
          // Text is on inside of curve
          if (currentCurveDelta > curveDeltaMax)
          {
            // Don't worry about excessive deltas, if they
            // are big the label curve will be screwed anyway
            currentCurveDelta = curveDeltaMax;
          }

          double textBuffer = currentCurveDelta
              * CURVE_TEXT_STRETCH_FACTOR / curveLength;
          currentPos += textBuffer;
          endPos += textBuffer;
        }
      }

      if (labelGlyphs[j].drawingBounds != null)
      {
        labelGlyphs[j].drawingBounds.setRect(minX, minY, maxX - minX,
            maxY - minY);
      }
      else
      {
        labelGlyphs[j].drawingBounds = new mxRectangle(minX, minY, maxX
            - minX, maxY - minY);
      }

      if (overallLabelBounds == null)
      {
        overallLabelBounds = (mxRectangle) labelGlyphs[j].drawingBounds
            .clone();
      }
      else
      {
        overallLabelBounds.add(labelGlyphs[j].drawingBounds);
      }

      labelGlyphs[j].visible = true;
      centerVisibleIndex++;
    }

    centerVisibleIndex /= 2;

    if (overallLabelBounds == null)
    {
      // Return a small rectangle in the center of the label curve
      // Null label bounds causes NPE when editing
      mxLine labelCenter = curve.getCurveParallel(mxCurve.LABEL_CURVE,
          0.5);
      overallLabelBounds = new mxRectangle(labelCenter.getX(),
          labelCenter.getY(), 1, 1);
    }

    this.labelBounds = overallLabelBounds;
    return overallLabelBounds;
View Full Code Here


        tmp.add(vertices[i]);
      }
    }

    vertexArray = tmp.toArray();
    mxRectangle initialBounds = (useInputOrigin) ? graph.getBoundsForCells(
        vertexArray, false, false, true) : null;
    int n = vertexArray.length;

    dispX = new double[n];
    dispY = new double[n];
    cellLocation = new double[n][];
    isMoveable = new boolean[n];
    neighbours = new int[n][];
    radius = new double[n];
    radiusSquared = new double[n];

    minDistanceLimitSquared = minDistanceLimit * minDistanceLimit;

    if (forceConstant < 0.001)
    {
      forceConstant = 0.001;
    }

    forceConstantSquared = forceConstant * forceConstant;

    // Create a map of vertices first. This is required for the array of
    // arrays called neighbours which holds, for each vertex, a list of
    // ints which represents the neighbours cells to that vertex as
    // the indices into vertexArray
    for (int i = 0; i < vertexArray.length; i++)
    {
      Object vertex = vertexArray[i];
      cellLocation[i] = new double[2];

      // Set up the mapping from array indices to cells
      indices.put(vertex, new Integer(i));
      mxRectangle bounds = getVertexBounds(vertex);

      // Set the X,Y value of the internal version of the cell to
      // the center point of the vertex for better positioning
      double width = bounds.getWidth();
      double height = bounds.getHeight();

      // Randomize (0, 0) locations
      double x = bounds.getX();
      double y = bounds.getY();

      cellLocation[i][0] = x + width / 2.0;
      cellLocation[i][1] = y + height / 2.0;

      radius[i] = Math.min(width, height);
View Full Code Here

      int x = (int) source.getCenterX() - imgWidth / 2;
      int y = (int) source.getCenterY() - imgHeight / 2;

      if (graphComponent.getGraph().isSwimlane(source.getCell()))
      {
        mxRectangle size = graphComponent.getGraph().getStartSize(
            source.getCell());

        if (size.getWidth() > 0)
        {
          x = (int) (source.getX() + size.getWidth() / 2 - imgWidth / 2);
        }
        else
        {
          y = (int) (source.getY() + size.getHeight() / 2 - imgHeight / 2);
        }
      }

      setBounds(new Rectangle(x, y, imgWidth, imgHeight));
    }
View Full Code Here

          model.getParent(state.getCell()));
      translateState(parentState, state, delta.getX(), delta.getY());
    }

    // Revalidates the states in step
    mxRectangle dirty = null;
    it = deltas.keySet().iterator();

    while (it.hasNext())
    {
      mxCellState state = it.next();
      mxPoint delta = deltas.get(state);
      mxCellState parentState = graph.getView().getState(
          model.getParent(state.getCell()));
      mxRectangle tmp = revalidateState(parentState, state, delta.getX(),
          delta.getY());

      if (dirty != null)
      {
        dirty.add(tmp);
View Full Code Here

   *
   */
  protected mxRectangle revalidateState(mxCellState parentState,
      mxCellState state, double dx, double dy)
  {
    mxRectangle dirty = null;

    if (state != null)
    {
      mxGraph graph = graphComponent.getGraph();
      mxIGraphModel model = graph.getModel();
      Object cell = state.getCell();

      // Updates the edge terminal points and restores the
      // (relative) positions of any (relative) children
      state.setInvalid(true);
      dirty = graph.getView().validatePoints(parentState, cell);

      // Moves selection vertices which are relative
      mxGeometry geo = graph.getCellGeometry(cell);

      if ((dx != 0 || dy != 0)
          && geo != null
          && geo.isRelative()
          && model.isVertex(cell)
          && (parentState == null
              || model.isVertex(parentState.getCell()) || deltas
              .get(state) != null))
      {
        state.setX(state.getX() + dx);
        state.setY(state.getY() + dy);

        // TODO: Check this change
        dirty.setX(dirty.getX() + dx);
        dirty.setY(dirty.getY() + dy);

        graph.getView().updateLabelBounds(state);
      }

      int childCount = model.getChildCount(cell);

      for (int i = 0; i < childCount; i++)
      {
        mxRectangle tmp = revalidateState(state, graph.getView()
            .getState(model.getChildAt(cell, i)), dx, dy);

        if (dirty != null)
        {
          dirty.add(tmp);
View Full Code Here

    {
      h = new Rectangle[1];
    }

    int s = mxConstants.LABEL_HANDLE_SIZE;
    mxRectangle bounds = state.getLabelBounds();
    h[h.length - 1] = new Rectangle((int) (bounds.getX()
        + bounds.getWidth() / 2 - s), (int) (bounds.getY()
        + bounds.getHeight() / 2 - s), 2 * s, 2 * s);

    return h;
  }
View Full Code Here

        {
          dx = graph.snap(dx / scale) * scale;
          dy = graph.snap(dy / scale) * scale;
        }

        mxRectangle bounds = union(getState(), dx, dy, index);
        bounds.setWidth(bounds.getWidth() + 1);
        bounds.setHeight(bounds.getHeight() + 1);
        preview.setBounds(bounds.getRectangle());
      }

      if (!preview.isVisible() && graphComponent.isSignificant(dx, dy))
      {
        preview.setVisible(true);
View Full Code Here

        geometry.setOffset(new mxPoint(dx, dy));
        graph.getModel().setGeometry(cell, geometry);
      }
      else
      {
        mxRectangle bounds = union(geometry, dx, dy, index);
        Rectangle rect = bounds.getRectangle();

        // Snaps new bounds to grid (unscaled)
        if (gridEnabledEvent)
        {
          int x = (int) graph.snap(rect.x);
          int y = (int) graph.snap(rect.y);
          rect.width = (int) graph.snap(rect.width - x + rect.x);
          rect.height = (int) graph.snap(rect.height - y + rect.y);
          rect.x = x;
          rect.y = y;
        }

        graph.resizeCell(cell, new mxRectangle(rect));
      }
    }
  }
View Full Code Here

    {
      top += height;
      height = Math.abs(height);
    }

    return new mxRectangle(left, top, width, height);
  }
View Full Code Here

      int right = rect.x + rect.width;
      int bottom = rect.y + rect.height;

      Dimension d = new Dimension(getPreferredSize());
      Dimension sp = getScaledPreferredSizeForGraph();
      mxRectangle min = graph.getMinimumGraphSize();
      double scale = graph.getView().getScale();
      boolean update = false;

      if (rect.x < 0)
      {
        translate.x = Math.max(translate.x, Math.max(0, -rect.x));
        d.width = sp.width;

        if (min != null)
        {
          d.width = (int) Math.max(d.width,
              Math.round(min.getWidth() * scale));
        }

        d.width += translate.x;
        update = true;
      }
      else if (right > getWidth())
      {
        d.width = Math.max(right, getWidth());
        update = true;
      }

      if (rect.y < 0)
      {
        translate.y = Math.max(translate.y, Math.max(0, -rect.y));
        d.height = sp.height;

        if (min != null)
        {
          d.height = (int) Math.max(d.height,
              Math.round(min.getHeight() * scale));
        }

        d.height += translate.y;
        update = true;
      }
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.