Examples of mxGraph


Examples of com.mxgraph.view.mxGraph

      {
        TransferHandler th = graphComponent.getTransferHandler();
        boolean isLocal = th instanceof mxGraphTransferHandler
            && ((mxGraphTransferHandler) th).isLocalDrag();

        mxGraph graph = graphComponent.getGraph();
        Object cell = super.getCell(e);
        Object[] cells = (isLocal) ? graph.getSelectionCells()
            : dragCells;
        cell = graph.getDropTarget(cells, e.getPoint(), cell);
        boolean clone = graphComponent.isCloneEvent(e) && cloneEnabled;

        if (isLocal && cell != null && cells.length > 0 && !clone
            && graph.getModel().getParent(cells[0]) == cell)
        {
          cell = null;
        }

        return cell;
View Full Code Here

Examples of com.mxgraph.view.mxGraph

              .getTransferData(mxGraphTransferable.dataFlavor);
          dragCells = gt.getCells();

          if (gt.getBounds() != null)
          {
            mxGraph graph = graphComponent.getGraph();
            double scale = graph.getView().getScale();
            transferBounds = gt.getBounds();
            int w = (int) Math.ceil((transferBounds.getWidth() + 1)
                * scale);
            int h = (int) Math
                .ceil((transferBounds.getHeight() + 1) * scale);
            setPreviewBounds(new Rectangle(
                (int) transferBounds.getX(),
                (int) transferBounds.getY(), w, h));

            if (imagePreview)
            {
              // Does not render fixed cells for local preview
              // but ignores movable state for non-local previews
              if (isLocal)
              {
                if (!isLivePreview())
                {
                  updateDragImage(graph
                      .getMovableCells(dragCells));
                }
              }
              else
              {
View Full Code Here

Examples of com.mxgraph.view.mxGraph

  /**
   *
   */
  public Object[] getCells(Object initialCell)
  {
    mxGraph graph = graphComponent.getGraph();

    return graph.getMovableCells(graph.getSelectionCells());
  }
View Full Code Here

Examples of com.mxgraph.view.mxGraph

      movePreview.start(e,
          graphComponent.getGraph().getView().getState(initialCell));
    }
    else
    {
      mxGraph graph = graphComponent.getGraph();

      // Constructs an array with cells that are indeed movable
      cells = getCells(initialCell);
      cellBounds = graph.getView().getBounds(cells);

      if (cellBounds != null)
      {
        // Updates the size of the graph handler that is in
        // charge of painting all other handlers
        bbox = graph.getView().getBoundingBox(cells);

        Rectangle bounds = cellBounds.getRectangle();
        bounds.width += 1;
        bounds.height += 1;
        setPreviewBounds(bounds);
View Full Code Here

Examples of com.mxgraph.view.mxGraph

      mouseDragged(createEvent(e));
      mxGraphTransferHandler handler = getGraphTransferHandler(e);

      if (handler != null)
      {
        mxGraph graph = graphComponent.getGraph();
        double scale = graph.getView().getScale();
        Point pt = SwingUtilities.convertPoint(graphComponent,
            e.getLocation(), graphComponent.getGraphControl());

        pt = graphComponent.snapScaledPoint(new mxPoint(pt)).getPoint();
        handler.setLocation(new Point(pt));

        int dx = 0;
        int dy = 0;

        // Centers the preview image
        if (centerPreview && transferBounds != null)
        {
          dx -= Math.round(transferBounds.getWidth() * scale / 2);
          dy -= Math.round(transferBounds.getHeight() * scale / 2);
        }

        // Sets the drop offset so that the location in the transfer
        // handler reflects the actual mouse position
        handler.setOffset(new Point((int) graph.snap(dx / scale),
            (int) graph.snap(dy / scale)));
        pt.translate(dx, dy);

        // Shifts the preview so that overlapping parts do not
        // affect the centering
        if (transferBounds != null && dragImage != null)
View Full Code Here

Examples of com.mxgraph.view.mxGraph

          double dx = e.getX() - first.x;
          double dy = e.getY() - first.y;

          if (graphComponent.isGridEnabledEvent(e))
          {
            mxGraph graph = graphComponent.getGraph();

            dx = graph.snap(dx);
            dy = graph.snap(dy);
          }

          boolean clone = isCloneEnabled()
              && graphComponent.isCloneEvent(e);
          movePreview.update(e, dx, dy, clone);
View Full Code Here

Examples of com.mxgraph.view.mxGraph

    int x = 0;
    int y = 0;

    if (first != null && cellBounds != null)
    {
      mxGraph graph = graphComponent.getGraph();
      double scale = graph.getView().getScale();
      mxPoint trans = graph.getView().getTranslate();

      // LATER: Drag image _size_ depends on the initial position and may sometimes
      // not align with the grid when dragging. This is because the rounding of the width
      // and height at the initial position may be different than that at the current
      // position as the left and bottom side of the shape must align to the grid lines.
      // Only fix is a full repaint of the drag cells at each new mouse location.
      double dx = e.getX() - first.x;
      double dy = e.getY() - first.y;

      double dxg = ((cellBounds.getX() + dx) / scale) - trans.getX();
      double dyg = ((cellBounds.getY() + dy) / scale) - trans.getY();

      if (gridEnabled)
      {
        dxg = graph.snap(dxg);
        dyg = graph.snap(dyg);
      }

      x = (int) Math.round((dxg + trans.getX()) * scale)
          + (int) Math.round(bbox.getX())
          - (int) Math.round(cellBounds.getX());
View Full Code Here

Examples of com.mxgraph.view.mxGraph

   */
  public void mouseReleased(MouseEvent e)
  {
    if (graphComponent.isEnabled() && isEnabled() && !e.isConsumed())
    {
      mxGraph graph = graphComponent.getGraph();
      double dx = 0;
      double dy = 0;

      if (first != null && (cellBounds != null || movePreview.isActive()))
      {
        double scale = graph.getView().getScale();
        mxPoint trans = graph.getView().getTranslate();

        // TODO: Simplify math below, this was copy pasted from
        // getPreviewLocation with the rounding removed
        dx = e.getX() - first.x;
        dy = e.getY() - first.y;

        if (cellBounds != null)
        {
          double dxg = ((cellBounds.getX() + dx) / scale)
              - trans.getX();
          double dyg = ((cellBounds.getY() + dy) / scale)
              - trans.getY();

          if (gridEnabledEvent)
          {
            dxg = graph.snap(dxg);
            dyg = graph.snap(dyg);
          }

          double x = ((dxg + trans.getX()) * scale) + (bbox.getX())
              - (cellBounds.getX());
          double y = ((dyg + trans.getY()) * scale) + (bbox.getY())
              - (cellBounds.getY());

          dx = Math.round((x - bbox.getX()) / scale);
          dy = Math.round((y - bbox.getY()) / scale);
        }
      }

      if (first == null
          || !graphComponent.isSignificant(e.getX() - first.x,
              e.getY() - first.y))
      {
        // Delayed handling of selection
        if (cell != null && !e.isPopupTrigger() && isSelectEnabled()
            && (first != null || !isMoveEnabled()))
        {
          graphComponent.selectCellForEvent(cell, e);
        }

        // Delayed folding for cell that was initially under the mouse
        if (graphComponent.isFoldingEnabled()
            && graphComponent.hitFoldingIcon(initialCell, e.getX(),
                e.getY()))
        {
          fold(initialCell);
        }
        else
        {
          // Handles selection if no cell was initially under the mouse
          Object tmp = graphComponent.getCellAt(e.getX(), e.getY(),
              graphComponent.isSwimlaneSelectionEnabled());

          if (cell == null && first == null)
          {
            if (tmp == null)
            {
              if (!graphComponent.isToggleEvent(e))
              {
                graph.clearSelection();
              }
            }
            else if (graph.isSwimlane(tmp)
                && graphComponent.getCanvas()
                    .hitSwimlaneContent(graphComponent,
                        graph.getView().getState(tmp),
                        e.getX(), e.getY()))
            {
              graphComponent.selectCellForEvent(tmp, e);
            }
          }

          if (graphComponent.isFoldingEnabled()
              && graphComponent.hitFoldingIcon(tmp, e.getX(),
                  e.getY()))
          {
            fold(tmp);
            e.consume();
          }
        }
      }
      else if (movePreview.isActive())
      {
        if (graphComponent.isConstrainedEvent(e))
        {
          if (Math.abs(dx) > Math.abs(dy))
          {
            dy = 0;
          }
          else
          {
            dx = 0;
          }
        }

        mxCellState markedState = marker.getMarkedState();
        Object target = (markedState != null) ? markedState.getCell()
            : null;

        // FIXME: Cell is null if selection was carried out, need other variable
        //trace("cell", cell);

        if (target == null
            && isRemoveCellsFromParent()
            && shouldRemoveCellFromParent(graph.getModel()
                .getParent(initialCell), cells, e))
        {
          target = graph.getDefaultParent();
        }

        boolean clone = isCloneEnabled()
            && graphComponent.isCloneEvent(e);
        Object[] result = movePreview.stop(true, e, dx, dy, clone,
            target);

        if (cells != result)
        {
          graph.setSelectionCells(result);
        }

        e.consume();
      }
      else if (isVisible())
      {
        if (constrainedEvent)
        {
          if (Math.abs(dx) > Math.abs(dy))
          {
            dy = 0;
          }
          else
          {
            dx = 0;
          }
        }

        mxCellState targetState = marker.getValidState();
        Object target = (targetState != null) ? targetState.getCell()
            : null;

        if (graph.isSplitEnabled()
            && graph.isSplitTarget(target, cells))
        {
          graph.splitEdge(target, cells, dx, dy);
        }
        else
        {
          moveCells(cells, dx, dy, target, e);
        }
View Full Code Here

Examples of com.mxgraph.view.mxGraph

   * @param e
   */
  protected void moveCells(Object[] cells, double dx, double dy,
      Object target, MouseEvent e)
  {
    mxGraph graph = graphComponent.getGraph();
    boolean clone = e.isControlDown() && isCloneEnabled();

    if (clone)
    {
      cells = graph.getCloneableCells(cells);
    }

    // Removes cells from parent
    if (target == null
        && isRemoveCellsFromParent()
        && shouldRemoveCellFromParent(
            graph.getModel().getParent(initialCell), cells, e))
    {
      target = graph.getDefaultParent();
    }

    Object[] tmp = graph.moveCells(cells, dx, dy, clone, target,
        e.getPoint());

    if (isSelectEnabled() && clone && tmp != null
        && tmp.length == cells.length)
    {
      graph.setSelectionCells(tmp);
    }
  }
View Full Code Here

Examples of com.mxgraph.view.mxGraph

    // Listens to all mouse events on the rendering control
    graphComponent.getGraphControl().addMouseListener(this);
    graphComponent.getGraphControl().addMouseMotionListener(this);

    // Refreshes the handles after any changes
    mxGraph graph = graphComponent.getGraph();
    graph.getSelectionModel().addListener(mxEvent.CHANGE, refreshHandler);
    graph.getModel().addListener(mxEvent.CHANGE, refreshHandler);
    graph.getView().addListener(mxEvent.SCALE, refreshHandler);
    graph.getView().addListener(mxEvent.TRANSLATE, refreshHandler);
    graph.getView()
        .addListener(mxEvent.SCALE_AND_TRANSLATE, refreshHandler);
    graph.getView().addListener(mxEvent.DOWN, refreshHandler);
    graph.getView().addListener(mxEvent.UP, refreshHandler);

    // Refreshes the handles if moveVertexLabels or moveEdgeLabels changes
    graph.addPropertyChangeListener(new PropertyChangeListener()
    {

      /*
       * (non-Javadoc)
       * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
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.