Package com.mxgraph.util

Examples of com.mxgraph.util.mxPoint


   */
  protected mxPoint convertPoint(mxPoint point, boolean gridEnabled)
  {
    mxGraph graph = graphComponent.getGraph();
    double scale = graph.getView().getScale();
    mxPoint trans = graph.getView().getTranslate();
    double x = point.getX() / scale - trans.getX();
    double y = point.getY() / scale - trans.getY();

    if (gridEnabled)
    {
      x = graph.snap(x);
      y = graph.snap(y);
View Full Code Here


      Object source = null;
      Object target = null;

      if (isLabel(index))
      {
        mxPoint abs = state.getAbsoluteOffset();
        double dx = abs.getX() - first.x;
        double dy = abs.getY() - first.y;

        mxPoint pt = new mxPoint(e.getPoint());

        if (gridEnabledEvent)
        {
          pt = graphComponent.snapScaledPoint(pt, dx, dy);
        }

        if (constrainedEvent)
        {
          if (Math.abs(e.getX() - first.x) > Math.abs(e.getY()
              - first.y))
          {
            pt.setY(abs.getY());
          }
          else
          {
            pt.setX(abs.getX());
          }
        }

        Rectangle rect = getPreviewBounds();
        rect.translate((int) Math.round(pt.getX() - first.x),
            (int) Math.round(pt.getY() - first.y));
        preview.setBounds(rect);
      }
      else
      {
        // Clones the cell state and updates the absolute points using
        // the current state of this handle. This is required for
        // computing the correct perimeter points and edge style.
        mxGeometry geometry = graphComponent.getGraph()
            .getCellGeometry(state.getCell());
        mxCellState clone = (mxCellState) state.clone();
        List<mxPoint> points = geometry.getPoints();
        mxGraphView view = clone.getView();

        if (isSource || isTarget)
        {
          marker.process(e);
          mxCellState currentState = marker.getValidState();
          target = state.getVisibleTerminal(!isSource);

          if (currentState != null)
          {
            source = currentState.getCell();
          }
          else
          {
            mxPoint pt = new mxPoint(e.getPoint());

            if (gridEnabledEvent)
            {
              pt = graphComponent.snapScaledPoint(pt);
            }

            clone.setAbsoluteTerminalPoint(pt, isSource);
          }

          if (!isSource)
          {
            Object tmp = source;
            source = target;
            target = tmp;
          }
        }
        else
        {
          mxPoint point = convertPoint(new mxPoint(e.getPoint()),
              gridEnabledEvent);

          if (points == null)
          {
            points = Arrays.asList(new mxPoint[] { point });
View Full Code Here

        {
          return true;
        }
        else
        {
          mxPoint p0 = state.getAbsolutePoint(0);

          for (int i = 0; i < pointCount; i++)
          {
            mxPoint p1 = state.getAbsolutePoint(i);

            if (rect.intersectsLine(p0.getX(), p0.getY(),
                p1.getX(), p1.getY()))
            {
              return true;
            }

            p0 = p1;
View Full Code Here

            JOptionPane.showMessageDialog(graphComponent, error);
          }
        }
        else if (isLabel(index))
        {
          mxPoint abs = state.getAbsoluteOffset();
          dx = abs.getX() - first.x;
          dy = abs.getY() - first.y;

          mxPoint pt = new mxPoint(e.getPoint());

          if (gridEnabledEvent)
          {
            pt = graphComponent.snapScaledPoint(pt, dx, dy);
          }

          if (constrainedEvent)
          {
            if (Math.abs(e.getX() - first.x) > Math.abs(e.getY()
                - first.y))
            {
              pt.setY(abs.getY());
            }
            else
            {
              pt.setX(abs.getX());
            }
          }

          moveLabelTo(state, pt.getX() + dx, pt.getY() + dy);
        }
        else if (marker.hasValidState()
            && (isSource(index) || isTarget(index)))
        {
          connect(state.getCell(), marker.getValidState().getCell(),
              isSource(index), graphComponent.isCloneEvent(e)
                  && isCloneEnabled());
        }
        else if ((!isSource(index) && !isTarget(index))
            || graphComponent.getGraph().isAllowDanglingEdges())
        {
          movePoint(
              state.getCell(),
              index,
              convertPoint(new mxPoint(e.getPoint()),
                  gridEnabledEvent));
        }

        e.consume();
      }
View Full Code Here

    if (geometry != null)
    {
      geometry = (mxGeometry) geometry.clone();

      // Resets the relative location stored inside the geometry
      mxPoint pt = graph.getView().getRelativePoint(edgeState, x, y);
      geometry.setX(pt.getX());
      geometry.setY(pt.getY());

      // Resets the offset inside the geometry to find the offset
      // from the resulting point
      double scale = graph.getView().getScale();
      geometry.setOffset(new mxPoint(0, 0));
      pt = graph.getView().getPoint(edgeState, geometry);
      geometry.setOffset(new mxPoint(Math.round((x - pt.getX()) / scale),
          Math.round((y - pt.getY()) / scale)));

      model.setGeometry(edgeState.getCell(), geometry);
    }
  }
View Full Code Here

   *
   */
  public mxPoint moveState(mxCellState state, double dx, double dy,
      boolean add, boolean includeEdges)
  {
    mxPoint delta = deltas.get(state);

    if (delta == null)
    {
      delta = new mxPoint(dx, dy);
      deltas.put(state, delta);
      count++;
    }
    else
    {
      if (add)
      {
        delta.setX(delta.getX() + dx);
        delta.setY(delta.getY() + dy);
      }
      else
      {
        delta.setX(dx);
        delta.setY(dy);
      }
    }

    if (includeEdges)
    {
View Full Code Here

    Iterator<mxCellState> 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()));
      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 mxPoint transformScreenPoint(double x, double y)
  {
    mxGraph graph = graphComponent.getGraph();
    mxPoint tr = graph.getView().getTranslate();
    double scale = graph.getView().getScale();

    return new mxPoint(graph.snap(x / scale - tr.getX()), graph.snap(y
        / scale - tr.getY()));
  }
View Full Code Here

    if (strokeColor != null && strokeWidth > 0)
    {
      // Draws the start marker
      Object marker = style.get(mxConstants.STYLE_STARTARROW);

      mxPoint pt = pts.get(1);
      mxPoint p0 = pts.get(0);
      mxPoint offset = null;

      if (marker != null)
      {
        float size = (mxUtils.getFloat(style,
            mxConstants.STYLE_STARTSIZE,
            mxConstants.DEFAULT_MARKERSIZE));
        offset = drawMarker(group, marker, pt, p0, size, tmpStroke,
            strokeColor);
      }
      else
      {
        double dx = pt.getX() - p0.getX();
        double dy = pt.getY() - p0.getY();

        double dist = Math.max(1, Math.sqrt(dx * dx + dy * dy));
        double nx = dx * strokeWidth / dist;
        double ny = dy * strokeWidth / dist;

        offset = new mxPoint(nx / 2, ny / 2);
      }

      // Applies offset to the point
      if (offset != null)
      {
        p0 = (mxPoint) p0.clone();
        p0.setX(p0.getX() + offset.getX());
        p0.setY(p0.getY() + offset.getY());

        offset = null;
      }

      // Draws the end marker
      marker = style.get(mxConstants.STYLE_ENDARROW);

      pt = pts.get(pts.size() - 2);
      mxPoint pe = pts.get(pts.size() - 1);

      if (marker != null)
      {
        float size = (mxUtils.getFloat(style,
            mxConstants.STYLE_ENDSIZE,
            mxConstants.DEFAULT_MARKERSIZE));
        offset = drawMarker(group, marker, pt, pe, size, tmpStroke,
            strokeColor);
      }
      else
      {
        double dx = pt.getX() - p0.getX();
        double dy = pt.getY() - p0.getY();

        double dist = Math.max(1, Math.sqrt(dx * dx + dy * dy));
        double nx = dx * strokeWidth / dist;
        double ny = dy * strokeWidth / dist;

        offset = new mxPoint(nx / 2, ny / 2);
      }

      // Applies offset to the point
      if (offset != null)
      {
        pe = (mxPoint) pe.clone();
        pe.setX(pe.getX() + offset.getX());
        pe.setY(pe.getY() + offset.getY());

        offset = null;
      }

      // Draws the line segments
      double arcSize = mxConstants.LINE_ARCSIZE * scale;
      pt = p0;
      String d = "M " + pt.getX() + " " + pt.getY();

      for (int i = 1; i < pts.size() - 1; i++)
      {
        mxPoint tmp = pts.get(i);
        double dx = pt.getX() - tmp.getX();
        double dy = pt.getY() - tmp.getY();

        if ((rounded && i < pts.size() - 1) && (dx != 0 || dy != 0))
        {
          // Draws a line from the last point to the current
          // point with a spacing of size off the current point
          // into direction of the last point
          double dist = Math.sqrt(dx * dx + dy * dy);
          double nx1 = dx * Math.min(arcSize, dist / 2) / dist;
          double ny1 = dy * Math.min(arcSize, dist / 2) / dist;

          double x1 = tmp.getX() + nx1;
          double y1 = tmp.getY() + ny1;
          d += " L " + x1 + " " + y1;

          // Draws a curve from the last point to the current
          // point with a spacing of size off the current point
          // into direction of the next point
          mxPoint next = pts.get(i + 1);
          dx = next.getX() - tmp.getX();
          dy = next.getY() - tmp.getY();

          dist = Math.max(1, Math.sqrt(dx * dx + dy * dy));
          double nx2 = dx * Math.min(arcSize, dist / 2) / dist;
          double ny2 = dy * Math.min(arcSize, dist / 2) / dist;

          double x2 = tmp.getX() + nx2;
          double y2 = tmp.getY() + ny2;

          d += " Q " + tmp.getX() + " " + tmp.getY() + " " + x2 + " "
              + y2;
          tmp = new mxPoint(x2, y2);
        }
        else
        {
          d += " L " + tmp.getX() + " " + tmp.getY();
        }
View Full Code Here

   * Draws the specified marker as a child path in the given parent.
   */
  public mxPoint drawMarker(Element parent, Object type, mxPoint p0,
      mxPoint pe, float size, float strokeWidth, String color)
  {
    mxPoint offset = null;

    // Computes the norm and the inverse norm
    double dx = pe.getX() - p0.getX();
    double dy = pe.getY() - p0.getY();

View Full Code Here

TOP

Related Classes of com.mxgraph.util.mxPoint

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.