Package com.mxgraph.view

Examples of com.mxgraph.view.mxGraph


    boolean source = isSource(index);

    if (source || isTarget(index))
    {
      mxGraph graph = graphComponent.getGraph();
      mxIGraphModel model = graph.getModel();
      Object terminal = model.getTerminal(state.getCell(), source);

      if ((terminal == null && !graph.isTerminalPointMovable(
          state.getCell(), source))
          || (terminal != null && !graph.isCellDisconnectable(
              state.getCell(), terminal, source)))
      {
        first = null;
      }
    }
View Full Code Here


  /**
   *
   */
  public void mouseReleased(MouseEvent e)
  {
    mxGraph graph = graphComponent.getGraph();

    if (!e.isConsumed() && first != null)
    {
      double dx = e.getX() - first.x;
      double dy = e.getY() - first.y;

      if (graphComponent.isSignificant(dx, dy))
      {
        if (error != null)
        {
          if (error.length() > 0)
          {
            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();
      }
    }

    if (!e.isConsumed() && isFlipEvent(e))
    {
      graph.flipEdge(state.getCell());
      e.consume();
    }

    super.mouseReleased(e);
  }
View Full Code Here

   * @param isSource
   */
  protected void connect(Object edge, Object terminal, boolean isSource,
      boolean isClone)
  {
    mxGraph graph = graphComponent.getGraph();
    mxIGraphModel model = graph.getModel();

    model.beginUpdate();
    try
    {
      if (isClone)
      {
        Object clone = graph.cloneCells(new Object[] { edge })[0];

        Object parent = model.getParent(edge);
        graph.addCells(new Object[] { clone }, parent);

        Object other = model.getTerminal(edge, !isSource);
        graph.connectCell(clone, other, !isSource);

        graph.setSelectionCell(clone);
        edge = clone;
      }

      // Passes an empty constraint to reset constraint information
      graph.connectCell(edge, terminal, isSource,
          new mxConnectionConstraint());
    }
    finally
    {
      model.endUpdate();
View Full Code Here

  /**
   * Moves the label to the given position.
   */
  protected void moveLabelTo(mxCellState edgeState, double x, double y)
  {
    mxGraph graph = graphComponent.getGraph();
    mxIGraphModel model = graph.getModel();
    mxGeometry geometry = model.getGeometry(state.getCell());

    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 void refresh(mxCellState state)
  {
    this.state = state;
    handles = createHandles();
    mxGraph graph = graphComponent.getGraph();
    mxRectangle tmp = graph.getBoundingBox(state.getCell());

    if (tmp != null)
    {
      bounds = tmp.getRectangle();

View Full Code Here

  /**
   * Returns true if the label is movable.
   */
  public boolean isLabelMovable()
  {
    mxGraph graph = graphComponent.getGraph();
    String label = graph.getLabel(state.getCell());

    return graph.isLabelMovable(state.getCell()) && label != null
        && label.length() > 0;
  }
View Full Code Here

  /**
   * Returns a dirty rectangle to be repainted in mxGraphControl.
   */
  public mxRectangle show()
  {
    mxGraph graph = graphComponent.getGraph();
    mxIGraphModel model = graph.getModel();

    // Stores a copy of the cell states
    List<mxCellState> previousStates = null;

    if (isCloned())
    {
      previousStates = new LinkedList<mxCellState>();
      Iterator<mxCellState> it = deltas.keySet().iterator();

      while (it.hasNext())
      {
        mxCellState state = it.next();
        previousStates.addAll(snapshot(state));
      }
    }

    // Translates the states in step
    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)
View Full Code Here

  /**
   *
   */
  public void restore(List<mxCellState> snapshot)
  {
    mxGraph graph = graphComponent.getGraph();
    Iterator<mxCellState> it = snapshot.iterator();

    while (it.hasNext())
    {
      mxCellState state = it.next();
      mxCellState orig = graph.getView().getState(state.getCell());

      if (orig != null && orig != state)
      {
        restoreState(orig, state);
      }
View Full Code Here

    if (state != null)
    {
      result.add((mxCellState) state.clone());

      mxGraph graph = graphComponent.getGraph();
      mxIGraphModel model = graph.getModel();
      Object cell = state.getCell();
      int childCount = model.getChildCount(cell);

      for (int i = 0; i < childCount; i++)
      {
        result.addAll(snapshot(graph.getView().getState(
            model.getChildAt(cell, i))));
      }
    }

    return result;
View Full Code Here

  protected void translateState(mxCellState parentState, mxCellState state,
      double dx, double dy)
  {
    if (state != null)
    {
      mxGraph graph = graphComponent.getGraph();
      mxIGraphModel model = graph.getModel();
      Object cell = state.getCell();

      if (model.isVertex(cell))
      {
        state.getView().updateCellState(state);
        mxGeometry geo = graph.getCellGeometry(cell);

        // Moves selection cells and non-relative vertices in
        // the first phase so that edge terminal points will
        // be updated in the second phase
        if ((dx != 0 || dy != 0) && geo != null
            && (!geo.isRelative() || deltas.get(state) != null))
        {
          state.setX(state.getX() + dx);
          state.setY(state.getY() + dy);
        }
      }

      int childCount = model.getChildCount(cell);

      for (int i = 0; i < childCount; i++)
      {
        translateState(state,
            graph.getView().getState(model.getChildAt(cell, i)),
            dx, dy);
      }
    }
  }
View Full Code Here

TOP

Related Classes of com.mxgraph.view.mxGraph

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.