Examples of mxGraph


Examples of com.mxgraph.view.mxGraph

  /**
   *
   */
  public void refresh()
  {
    mxGraph graph = graphComponent.getGraph();

    // Creates a new map for the handlers and tries to
    // to reuse existing handlers from the old map
    Map<Object, mxCellHandler> oldHandlers = handlers;
    handlers = new LinkedHashMap<Object, mxCellHandler>();

    // Creates handles for all selection cells
    Object[] tmp = graph.getSelectionCells();
    boolean handlesVisible = tmp.length <= getMaxHandlers();
    Rectangle handleBounds = null;

    for (int i = 0; i < tmp.length; i++)
    {
      mxCellState state = graph.getView().getState(tmp[i]);

      if (state != null)
      {
        mxCellHandler handler = oldHandlers.get(tmp[i]);

View Full Code Here

Examples of com.mxgraph.view.mxGraph

  /**
   *
   */
  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

Examples of com.mxgraph.view.mxGraph

   * @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

Examples of com.mxgraph.view.mxGraph

  /**
   * 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

Examples of com.mxgraph.view.mxGraph

   */
  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

Examples of com.mxgraph.view.mxGraph

  /**
   * 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

Examples of com.mxgraph.view.mxGraph

  /**
   * Creates a new instance of mxShape for previewing the edge.
   */
  protected Object createCell(mxCellState startState, String style)
  {
    mxGraph graph = graphComponent.getGraph();
    mxICell cell = ((mxICell) graph
        .createEdge(null, null, "",
            (startState != null) ? startState.getCell() : null,
            null, style));
    ((mxICell) startState.getCell()).insertEdge(cell, true);

View Full Code Here

Examples of com.mxgraph.view.mxGraph

  /**
   * Updates the style of the edge preview from the incoming edge
   */
  public void start(MouseEvent e, mxCellState startState, String style)
  {
    mxGraph graph = graphComponent.getGraph();
    sourceState = startState;
    startPoint = transformScreenPoint(startState.getCenterX(),
        startState.getCenterY());
    previewState = graph.getView().getState(createCell(startState, style),
        true);
    fireEvent(new mxEventObject(mxEvent.START, "event", e, "state",
        previewState));
  }
View Full Code Here

Examples of com.mxgraph.view.mxGraph

  {
    boolean source = isSource(index);

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

      if (terminal == null
          && !graphComponent.getGraph().isTerminalPointMovable(
              state.getCell(), source))
View Full Code Here

Examples of com.mxgraph.view.mxGraph

   * @param gridEnabled
   * @return Returns the scaled, translated and grid-aligned point.
   */
  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);
    }

    point.setX(x - state.getOrigin().getX());
    point.setY(y - state.getOrigin().getY());

View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.