Examples of mxGraphView


Examples of com.mxgraph.view.mxGraphView

   *            Object that represents the global validation state.
   */
  public String validateGraph(Object cell, Hashtable<Object, Object> context)
  {
    mxIGraphModel model = graph.getModel();
    mxGraphView view = graph.getView();
    boolean isValid = true;
    int childCount = model.getChildCount(cell);

    for (int i = 0; i < childCount; i++)
    {
      Object tmp = model.getChildAt(cell, i);
      Hashtable<Object, Object> ctx = context;

      if (graph.isValidRoot(tmp))
      {
        ctx = new Hashtable<Object, Object>();
      }

      String warn = validateGraph(tmp, ctx);

      if (warn != null)
      {
        String html = warn.replaceAll("\n", "<br>");
        int len = html.length();
        setCellWarning(tmp, html.substring(0, Math.max(0, len - 4)));
      }
      else
      {
        setCellWarning(tmp, null);
      }

      isValid = isValid && warn == null;
    }

    StringBuffer warning = new StringBuffer();

    // Adds error for invalid children if collapsed (children invisible)
    if (graph.isCellCollapsed(cell) && !isValid)
    {
      warning.append(mxResources.get("containsValidationErrors",
          "Contains Validation Errors") + "\n");
    }

    // Checks edges and cells using the defined multiplicities
    if (model.isEdge(cell))
    {
      String tmp = graph.getEdgeValidationError(cell,
          model.getTerminal(cell, true),
          model.getTerminal(cell, false));

      if (tmp != null)
      {
        warning.append(tmp);
      }
    }
    else
    {
      String tmp = graph.getCellValidationError(cell);

      if (tmp != null)
      {
        warning.append(tmp);
      }
    }

    // Checks custom validation rules
    String err = graph.validateCell(cell, context);

    if (err != null)
    {
      warning.append(err);
    }

    // Updates the display with the warning icons before any potential
    // alerts are displayed
    if (model.getParent(cell) == null)
    {
      view.validate();
    }

    return (warning.length() > 0 || !isValid) ? warning.toString() : null;
  }
View Full Code Here

Examples of com.mxgraph.view.mxGraphView

          else
          {
            sy = 0;
          }

          mxGraphView view = graphComponent.getGraph().getView();
          double scale = view.getScale();
          double newScale = scale - (dx * scale) / w;
          double factor = newScale / scale;
          view.setScale(newScale);

          if (hs != null)
          {
            hs.setValue((int) (sx * hs.getMaximum() * factor));
          }
 
View Full Code Here

Examples of com.mxgraph.view.mxGraphView

    mxGraphControl graphControl = graphComponent.getGraphControl();
    graphControl.addMouseListener(this);
    graphControl.addMouseMotionListener(this);

    mxGraphView view = graphComponent.getGraph().getView();
    view.addListener(mxEvent.SCALE, resetHandler);
    view.addListener(mxEvent.TRANSLATE, resetHandler);
    view.addListener(mxEvent.SCALE_AND_TRANSLATE, resetHandler);

    mxIGraphModel model = graphComponent.getGraph().getModel();
    model.addListener(mxEvent.CHANGE, resetHandler);

    marker = new mxCellMarker(graphComponent)
View Full Code Here

Examples of com.mxgraph.view.mxGraphView

 
  public void center(Point2D center) {
    Dimension viewportSize = getViewport().getSize();
 
    Rectangle2D sceneRect = getGraph().getGraphBounds().getRectangle();
    mxGraphView graphView = getGraph().getView();
    final Dimension preferredSize = new Dimension(Math.max(
        (int) sceneRect.getWidth(), viewportSize.width), Math.max(
        (int) sceneRect.getHeight(), viewportSize.height));

    //mxPoint p = graphView.getTranslate();
    double x = -sceneRect.getX()
        + (preferredSize.getWidth() - sceneRect.getWidth()) / 2.0;
    double y = -sceneRect.getY()
        + (preferredSize.getHeight() - sceneRect.getHeight()) / 2.0;

    //TODO at this point the view should center on the traffic light - using the given center point
    graphView.setEventsEnabled(false);
    mxPoint translate = null;
    translate = new mxPoint(x, y);
    logger.info("TRANSLATE TO "+translate.getX()+"; "+translate.getY()+ " TEST");
//    translate = new mxPoint(p.getX() + x, p.getY() + y);
//    logger.info("TRANSLATE TO "+translate.getX()+"; "+translate.getY());
   
    graphView.setTranslate(translate);
    graphView.revalidate();
    graphView.setEventsEnabled(true);
  };
View Full Code Here

Examples of com.mxgraph.view.mxGraphView

   * zoom with a given scale overriden for the needed behavior TODO try to
   * employ the original zoom method instead of this
   */
  @Override
  public void zoom(double newScale) {
    mxGraphView view = getGraph().getView();
    double oldScale = view.getScale();

    view.scaleAndTranslate(oldScale * newScale, view.getTranslate().getX(),
        view.getTranslate().getY());
    centerViewport(newScale);

    view.revalidate();
  }
View Full Code Here

Examples of com.mxgraph.view.mxGraphView

      Dimension viewportSize = new Dimension();
      if ((parent != null) && (parent instanceof JViewport)) {
        viewportSize = ((JViewport) parent).getSize();
      }
      Rectangle2D sceneRect = getGraph().getGraphBounds().getRectangle();
      mxGraphView graphView = getGraph().getView();
      final Dimension preferredSize = new Dimension(Math.max(
          (int) sceneRect.getWidth(), viewportSize.width), Math.max(
          (int) sceneRect.getHeight(), viewportSize.height));

      mxPoint p = graphView.getTranslate();
      double x = -sceneRect.getX()
          + (preferredSize.getWidth() - sceneRect.getWidth()) / 2.0;
      double y = -sceneRect.getY()
          + (preferredSize.getHeight() - sceneRect.getHeight()) / 2.0;

      /**
       * Workaround for the StackOverflow Exception
       */
      graphView.setEventsEnabled(false);
      graphView.setTranslate(new mxPoint(p.getX() + x, p.getY() + y));
      graphView.revalidate();
      graphView.setEventsEnabled(true);

      return preferredSize;
    }
View Full Code Here

Examples of com.mxgraph.view.mxGraphView

    this.graphController = controller;
    initializeGraph();
  }

  private void initializeGraph() {
    this.modelGraph.setView(new mxGraphView(this.modelGraph));
    // Loads the defalt stylesheet from an external file
    /*
     * FIXME currently we are doing nearly everything by our own - try to
     * use the build in handlers to resize oder drag and drop
     * modelGraph.setConnectableEdges(false);
 
View Full Code Here

Examples of com.mxgraph.view.mxGraphView

        mxConstants.STYLE_FILLCOLOR),
        "/com/mxgraph/examples/swing/images/fillcolor.gif"));

    addSeparator();

    final mxGraphView view = editor.getGraphComponent().getGraph()
        .getView();
    final JComboBox zoomCombo = new JComboBox(new Object[] { "400%",
        "200%", "150%", "100%", "75%", "50%", mxResources.get("page"),
        mxResources.get("width"), mxResources.get("actualSize") });
    zoomCombo.setEditable(true);
    zoomCombo.setMinimumSize(new Dimension(75, 0));
    zoomCombo.setPreferredSize(new Dimension(75, 0));
    zoomCombo.setMaximumSize(new Dimension(75, 100));
    zoomCombo.setMaximumRowCount(9);
    add(zoomCombo);

    // Sets the zoom in the zoom combo the current value
    mxIEventListener scaleTracker = new mxIEventListener()
    {
      /**
       *
       */
      public void invoke(Object sender, mxEventObject evt)
      {
        ignoreZoomChange = true;

        try
        {
          zoomCombo.setSelectedItem((int) Math.round(100 * view
              .getScale())
              + "%");
        }
        finally
        {
          ignoreZoomChange = false;
        }
      }
    };

    // Installs the scale tracker to update the value in the combo box
    // if the zoom is changed from outside the combo box
    view.getGraph().getView().addListener(mxEvent.SCALE, scaleTracker);
    view.getGraph().getView().addListener(mxEvent.SCALE_AND_TRANSLATE,
        scaleTracker);

    // Invokes once to sync with the actual zoom value
    scaleTracker.invoke(null, null);

View Full Code Here

Examples of com.mxgraph.view.mxGraphView

   * the given event.
   */
  protected mxCellState getState(MouseEvent e)
  {
    Object cell = getCell(e);
    mxGraphView view = graphComponent.getGraph().getView();
    mxCellState state = getStateToMark(view.getState(cell));

    return (state != null && intersects(state, e)) ? state : null;
  }
View Full Code Here

Examples of com.mxgraph.view.mxGraphView

        // 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 });
          }
          else if (index - 1 < points.size())
          {
            points = new ArrayList<mxPoint>(points);
            points.set(index - 1, point);
          }

          source = view.getVisibleTerminal(state.getCell(), true);
          target = view.getVisibleTerminal(state.getCell(), false);
        }

        // Computes the points for the edge style and terminals
        mxCellState sourceState = view.getState(source);
        mxCellState targetState = view.getState(target);

        mxConnectionConstraint sourceConstraint = graphComponent
            .getGraph().getConnectionConstraint(clone, sourceState,
                true);
        mxConnectionConstraint targetConstraint = graphComponent
            .getGraph().getConnectionConstraint(clone, targetState,
                false);

        /* TODO: Implement mxConstraintHandler
        mxConnectionConstraint constraint = constraintHandler.currentConstraint;

        if (constraint == null)
        {
          constraint = new mxConnectionConstraint();
        }
       
        if (isSource)
        {
          sourceConstraint = constraint;
        }
        else if (isTarget)
        {
          targetConstraint = constraint;
        }
        */

        if (!isSource || sourceState != null)
        {
          view.updateFixedTerminalPoint(clone, sourceState, true,
              sourceConstraint);
        }

        if (!isTarget || targetState != null)
        {
          view.updateFixedTerminalPoint(clone, targetState, false,
              targetConstraint);
        }

        view.updatePoints(clone, points, sourceState, targetState);
        view.updateFloatingTerminalPoints(clone, sourceState,
            targetState);

        // Uses the updated points from the cloned state to draw the preview
        p = createPoints(clone);
        preview.setBounds(getPreviewBounds());
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.