Examples of mxIGraphModel


Examples of com.mxgraph.model.mxIGraphModel

   * @param evt
   *            Optional event that triggered the change.
   */
  public Object labelChanged(Object cell, Object value, EventObject evt)
  {
    mxIGraphModel model = graph.getModel();

    model.beginUpdate();
    try
    {
      graph.cellLabelChanged(cell, value, graph.isAutoSizeCell(cell));
      eventSource.fireEvent(new mxEventObject(mxEvent.LABEL_CHANGED,
          "cell", cell, "value", value, "event", evt));
    }
    finally
    {
      model.endUpdate();
    }

    return cell;
  }
View Full Code Here

Examples of com.mxgraph.model.mxIGraphModel

      try
      {
        canvas.setScale(graph.getView().getScale());
        canvas.setTranslate(0, 0);

        mxIGraphModel model = graph.getModel();
        mxGraphView view = graph.getView();

        Rectangle hit = new Rectangle(x, y, 1, 1);
        int childCount = model.getChildCount(parent);

        for (int i = childCount - 1; i >= 0; i--)
        {
          Object cell = model.getChildAt(parent, i);
          Object result = getCellAt(x, y, hitSwimlaneContent, cell);

          if (result != null)
          {
            return result;
View Full Code Here

Examples of com.mxgraph.model.mxIGraphModel

        try
        {
          canvas.setScale(graph.getView().getScale());
          canvas.setTranslate(0, 0);

          mxIGraphModel model = graph.getModel();
          mxGraphView view = graph.getView();

          int childCount = model.getChildCount(parent);

          for (int i = 0; i < childCount; i++)
          {
            Object cell = model.getChildAt(parent, i);
            mxCellState state = view.getState(cell);

            if (graph.isCellVisible(cell) && state != null)
            {
              if (canvas.contains(this, rect, state))
View Full Code Here

Examples of com.mxgraph.model.mxIGraphModel

  /**
   *
   */
  public Rectangle getFoldingIconBounds(mxCellState state, ImageIcon icon)
  {
    mxIGraphModel model = graph.getModel();
    boolean isEdge = model.isEdge(state.getCell());
    double scale = getGraph().getView().getScale();

    int x = (int) Math.round(state.getX() + 4 * scale);
    int y = (int) Math.round(state.getY() + 4 * scale);
    int w = (int) Math.max(8, icon.getIconWidth() * scale);
 
View Full Code Here

Examples of com.mxgraph.model.mxIGraphModel

   */
  public boolean hitFoldingIcon(Object cell, int x, int y)
  {
    if (cell != null)
    {
      mxIGraphModel model = graph.getModel();

      // Draws the collapse/expand icons
      boolean isEdge = model.isEdge(cell);

      if (foldingEnabled && (model.isVertex(cell) || isEdge))
      {
        mxCellState state = graph.getView().getState(cell);

        if (state != null)
        {
View Full Code Here

Examples of com.mxgraph.model.mxIGraphModel

   * @param context
   *            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.model.mxIGraphModel

   *            Optional cell that represents the root of the subtree to
   *            remove the overlays from. Default is the root in the model.
   */
  public void clearCellOverlays(Object cell)
  {
    mxIGraphModel model = graph.getModel();

    if (cell == null)
    {
      cell = model.getRoot();
    }

    removeCellOverlays(cell);

    // Recursively removes all overlays from the children
    int childCount = model.getChildCount(cell);

    for (int i = 0; i < childCount; i++)
    {
      Object child = model.getChildAt(cell, i);
      clearCellOverlays(child); // recurse
    }
  }
View Full Code Here

Examples of com.mxgraph.model.mxIGraphModel

   * the tree. Else, <mxGraph.findTreeRoots> will be used to find a suitable
   * root node within the set of children of the given parent.
   */
  public void execute(Object parent, Object root)
  {
    mxIGraphModel model = graph.getModel();

    if (root == null)
    {
      // Takes the parent as the root if it has outgoing edges
      if (graph.getEdges(parent, model.getParent(parent), invert,
          !invert, false).length > 0)
      {
        root = parent;
      }

      // Tries to find a suitable root in the parent's
      // children
      else
      {
        List<Object> roots = graph.findTreeRoots(parent, true, invert);

        if (roots.size() > 0)
        {
          for (int i = 0; i < roots.size(); i++)
          {
            if (!isVertexIgnored(roots.get(i))
                && graph.getEdges(roots.get(i), null, invert,
                    !invert, false).length > 0)
            {
              root = roots.get(i);
              break;
            }
          }
        }
      }
    }

    if (root != null)
    {
      parent = model.getParent(root);
      model.beginUpdate();

      try
      {
        TreeNode node = dfs(root, parent, null);

        if (node != null)
        {
          layout(node);

          double x0 = graph.getGridSize();
          double y0 = x0;

          if (!moveTree || model.getParent(parent) == model.getRoot())
          {
            mxGeometry g = model.getGeometry(root);

            if (g != null)
            {
              x0 = g.getX();
              y0 = g.getY();
            }
          }

          mxRectangle bounds = null;

          if (horizontal)
          {
            bounds = horizontalLayout(node, x0, y0, null);
          }
          else
          {
            bounds = verticalLayout(node, null, x0, y0, null);
          }

          if (bounds != null)
          {
            double dx = 0;
            double dy = 0;

            if (bounds.getX() < 0)
            {
              dx = Math.abs(x0 - bounds.getX());
            }

            if (bounds.getY() < 0)
            {
              dy = Math.abs(y0 - bounds.getY());
            }

            if (parent != null)
            {
              mxRectangle size = graph.getStartSize(parent);
              dx += size.getWidth();
              dy += size.getHeight();

              // Resize parent swimlane
              if (resizeParent && !graph.isCellCollapsed(parent))
              {
                mxGeometry g = model.getGeometry(parent);

                if (g != null)
                {
                  double width = bounds.getWidth()
                      + size.getWidth() - bounds.getX()
                      + 2 * x0;
                  double height = bounds.getHeight()
                      + size.getHeight() - bounds.getY()
                      + 2 * y0;

                  g = (mxGeometry) g.clone();

                  if (g.getWidth() > width)
                  {
                    dx += (g.getWidth() - width) / 2;
                  }
                  else
                  {
                    g.setWidth(width);
                  }

                  if (g.getHeight() > height)
                  {
                    if (horizontal)
                    {
                      dy += (g.getHeight() - height) / 2;
                    }
                  }
                  else
                  {
                    g.setHeight(height);
                  }

                  model.setGeometry(parent, g);
                }
              }
            }

            moveNode(node, dx, dy);
          }
        }
      }
      finally
      {
        model.endUpdate();
      }
    }
  }
View Full Code Here

Examples of com.mxgraph.model.mxIGraphModel

    if (cell != null && !visited.contains(cell) && !isVertexIgnored(cell))
    {
      visited.add(cell);
      node = createNode(cell);

      mxIGraphModel model = graph.getModel();
      TreeNode prev = null;
      Object[] out = graph.getEdges(cell, parent, invert, !invert, false);

      for (int i = 0; i < out.length; i++)
      {
        Object edge = out[i];

        if (!isEdgeIgnored(edge))
        {
          // Resets the points on the traversed edge
          if (resetEdges)
          {
            setEdgePoints(edge, null);
          }

          // Checks if terminal in same swimlane
          Object target = graph.getView().getVisibleTerminal(edge,
              invert);
          TreeNode tmp = dfs(target, parent, visited);

          if (tmp != null && model.getGeometry(target) != null)
          {
            if (prev == null)
            {
              node.child = tmp;
            }
View Full Code Here

Examples of com.mxgraph.model.mxIGraphModel

  /* (non-Javadoc)
   * @see com.mxgraph.layout.mxIGraphLayout#execute(java.lang.Object)
   */
  public void execute(Object parent)
  {
    mxIGraphModel model = graph.getModel();

    // Finds the relevant vertices for the layout
    Object[] vertices = graph.getChildVertices(parent);
    List<Object> tmp = new ArrayList<Object>(vertices.length);

    for (int i = 0; i < vertices.length; i++)
    {
      if (!isVertexIgnored(vertices[i]))
      {
        tmp.add(vertices[i]);
      }
    }

    vertexArray = tmp.toArray();
    mxRectangle initialBounds = (useInputOrigin) ? graph.getBoundsForCells(
        vertexArray, false, false, true) : null;
    int n = vertexArray.length;

    dispX = new double[n];
    dispY = new double[n];
    cellLocation = new double[n][];
    isMoveable = new boolean[n];
    neighbours = new int[n][];
    radius = new double[n];
    radiusSquared = new double[n];

    minDistanceLimitSquared = minDistanceLimit * minDistanceLimit;

    if (forceConstant < 0.001)
    {
      forceConstant = 0.001;
    }

    forceConstantSquared = forceConstant * forceConstant;

    // Create a map of vertices first. This is required for the array of
    // arrays called neighbours which holds, for each vertex, a list of
    // ints which represents the neighbours cells to that vertex as
    // the indices into vertexArray
    for (int i = 0; i < vertexArray.length; i++)
    {
      Object vertex = vertexArray[i];
      cellLocation[i] = new double[2];

      // Set up the mapping from array indices to cells
      indices.put(vertex, new Integer(i));
      mxRectangle bounds = getVertexBounds(vertex);

      // Set the X,Y value of the internal version of the cell to
      // the center point of the vertex for better positioning
      double width = bounds.getWidth();
      double height = bounds.getHeight();

      // Randomize (0, 0) locations
      double x = bounds.getX();
      double y = bounds.getY();

      cellLocation[i][0] = x + width / 2.0;
      cellLocation[i][1] = y + height / 2.0;

      radius[i] = Math.min(width, height);
      radiusSquared[i] = radius[i] * radius[i];
    }

    // Moves cell location back to top-left from center locations used in
    // algorithm, resetting the edge points is part of the transaction
    model.beginUpdate();
    try
    {
      for (int i = 0; i < n; i++)
      {
        dispX[i] = 0;
        dispY[i] = 0;
        isMoveable[i] = isVertexMovable(vertexArray[i]);

        // Get lists of neighbours to all vertices, translate the cells
        // obtained in indices into vertexArray and store as an array
        // against the original cell index
        Object[] edges = graph.getConnections(vertexArray[i], parent);
        for (int k = 0; k < edges.length; k++)
        {
          if (isResetEdges())
          {
            graph.resetEdge(edges[k]);
          }

          if (isDisableEdgeStyle())
          {
            setEdgeStyleEnabled(edges[k], false);
          }
        }
       
        Object[] cells = graph.getOpposites(edges, vertexArray[i]);

        neighbours[i] = new int[cells.length];

        for (int j = 0; j < cells.length; j++)
        {
          Integer index = indices.get(cells[j]);

          // Check the connected cell in part of the vertex list to be
          // acted on by this layout
          if (index != null)
          {
            neighbours[i][j] = index.intValue();
          }

          // Else if index of the other cell doesn't correspond to
          // any cell listed to be acted upon in this layout. Set
          // the index to the value of this vertex (a dummy self-loop)
          // so the attraction force of the edge is not calculated
          else
          {
            neighbours[i][j] = i;
          }
        }
      }

      temperature = initialTemp;

      // If max number of iterations has not been set, guess it
      if (maxIterations == 0)
      {
        maxIterations = (int) (20 * Math.sqrt(n));
      }

      // Main iteration loop
      for (iteration = 0; iteration < maxIterations; iteration++)
      {
        if (!allowedToRun)
        {
          return;
        }

        // Calculate repulsive forces on all vertices
        calcRepulsion();

        // Calculate attractive forces through edges
        calcAttraction();

        calcPositions();
        reduceTemperature();
      }

      Double minx = null;
      Double miny = null;

      for (int i = 0; i < vertexArray.length; i++)
      {
        Object vertex = vertexArray[i];
        mxGeometry geo = model.getGeometry(vertex);

        if (geo != null)
        {
          cellLocation[i][0] -= geo.getWidth() / 2.0;
          cellLocation[i][1] -= geo.getHeight() / 2.0;

          double x = graph.snap(cellLocation[i][0]);
          double y = graph.snap(cellLocation[i][1]);
          setVertexLocation(vertex, x, y);

          if (minx == null)
          {
            minx = new Double(x);
          }
          else
          {
            minx = new Double(Math.min(minx.doubleValue(), x));
          }

          if (miny == null)
          {
            miny = new Double(y);
          }
          else
          {
            miny = new Double(Math.min(miny.doubleValue(), y));
          }
        }
      }

      // Modifies the cloned geometries in-place. Not needed
      // to clone the geometries again as we're in the same
      // undoable change.
      double dx = (minx != null) ? -minx.doubleValue() - 1 : 0;
      double dy = (miny != null) ? -miny.doubleValue() - 1 : 0;

      if (initialBounds != null)
      {
        dx += initialBounds.getX();
        dy += initialBounds.getY();
      }

      graph.moveCells(vertexArray, dx, dy);
    }
    finally
    {
      model.endUpdate();
    }
  }
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.