Package com.mxgraph.model

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 = findTreeRoots(parent, 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)
    {
      if (resizeParent)
      {
        parentsChanged = new HashSet<Object>();
      }
      else
      {
        parentsChanged = null;
      }

      model.beginUpdate();

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

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

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

          if (!moveTree)
          {
            mxRectangle g = getVertexBounds(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 (dx != 0 || dy != 0)
            {
              moveNode(node, dx, dy);
            }

            if (resizeParent)
            {
              adjustParents();
            }

            if (edgeRouting)
            {
              // Iterate through all edges setting their positions
              localEdgeProcessing(node);
            }
          }
        }
      }
      finally
      {
        model.endUpdate();
      }
    }
  }
View Full Code Here


  {
    List<Object> roots = new ArrayList<Object>();

    if (parent != null)
    {
      mxIGraphModel model = graph.getModel();
      int childCount = model.getChildCount(parent);
      Object best = null;
      int maxDiff = 0;

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

        if (model.isVertex(cell) && graph.isCellVisible(cell))
        {
          Object[] conns = graph.getConnections(cell, parent, true);
          int fanOut = 0;
          int fanIn = 0;
View Full Code Here

    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,
          true);
      mxGraphView view = graph.getView();

      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);
          }

          if (edgeRouting)
          {
            setEdgeStyleEnabled(edge, false);
            setEdgePoints(edge, null);
          }

          // Checks if terminal in same swimlane
          mxCellState state = view.getState(edge);
          Object target = (state != null) ? state
              .getVisibleTerminal(invert) : view
              .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

   * @param bounds
   * @return
   */
  protected mxRectangle apply(TreeNode node, mxRectangle bounds)
  {
    mxIGraphModel model = graph.getModel();
    Object cell = node.cell;
    mxRectangle g = model.getGeometry(cell);

    if (cell != null && g != null)
    {
      if (isVertexMovable(cell))
      {
        g = setVertexLocation(cell, node.x, node.y);

        if (resizeParent)
        {
          parentsChanged.add(model.getParent(cell));
        }
      }

      if (bounds == null)
      {
View Full Code Here

   * @param node
   *            the root node of the tree
   */
  protected void processNodeOutgoing(TreeNode node)
  {
    mxIGraphModel model = graph.getModel();

    TreeNode child = node.child;
    Object parentCell = node.cell;

    int childCount = 0;
View Full Code Here

      throw new IllegalArgumentException();
    }

    Object parent = graph.getDefaultParent();
    Object[] vertices = aGraph.getChildVertices(parent);
    mxIGraphModel model = graph.getModel();

    for (int i = 0; i < numRows; i++)
    {
      for (int j = 0; j < numColumns; j++)
      {
        Object currVertex = vertices[i * numColumns + j];
        mxGeometry geometry = model.getGeometry(currVertex);
        geometry.setX(j * xSpacing);
        geometry.setY(i * ySpacing);
      }
    }
  };
 
View Full Code Here

    mxGraph graph = aGraph.getGraph();
    double group1StartY = 0;
    double group2StartY = 0;
    Object parent = graph.getDefaultParent();
    mxIGraphModel model = graph.getModel();

    if (numVerticesGroup1 < numVerticesGroup2)
    {
      double centerYtimes2 = (numVerticesGroup2 * vertexSpacing);
      group1StartY = (centerYtimes2 - (numVerticesGroup1 * vertexSpacing)) / 2;
    }
    else
    {
      double centerYtimes2 = (numVerticesGroup1 * vertexSpacing);
      group2StartY = (centerYtimes2 - (numVerticesGroup2 * vertexSpacing)) / 2;
    }

    Object[] vertices = aGraph.getChildVertices(parent);

    // position vertexes for group 1
    for (int i = 0; i < numVerticesGroup1; i++)
    {
      Object currVertex = vertices[i];
      mxGeometry geometry = model.getGeometry(currVertex);
      geometry.setX(0);
      geometry.setY(group1StartY + i * vertexSpacing);
    }

    // position vertexes for group 2
    for (int i = numVerticesGroup1; i < numVerticesGroup1 + numVerticesGroup2; i++)
    {
      Object currVertex = vertices[i];
      mxGeometry geometry = model.getGeometry(currVertex);
      geometry.setX(groupSpacing);
      geometry.setY(group2StartY + (i - numVerticesGroup1) * vertexSpacing);
    }
  };
 
View Full Code Here

    }

    mxGraph graph = aGraph.getGraph();
    Object parent = graph.getDefaultParent();
    Object[] vertices = aGraph.getChildVertices(parent);
    mxIGraphModel model = graph.getModel();

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

      mxGeometry geometry = model.getGeometry(currVertex);
      geometry.setX(0);
      geometry.setY(i * spacing);
    }
  };
 
View Full Code Here

    }

    mxGraph graph = aGraph.getGraph();
    Object parent = graph.getDefaultParent();
    Object[] vertices = aGraph.getChildVertices(parent);
    mxIGraphModel model = graph.getModel();
    int vertexNum = vertices.length;
    double centerX = graphSize / 2f;
    double centerY = centerX;

    int numVertexesInPerimeter = vertexNum - 1;

    //create the circle
    for (int i = 0; i < numVertexesInPerimeter; i++)
    {
      //calc the position
      double x = 0;
      double y = 0;
      double currRatio = ((double) i / (double) numVertexesInPerimeter);
      currRatio = currRatio * 2;
      currRatio = currRatio * (double) Math.PI;
      x = Math.round(centerX + Math.round(graphSize * Math.sin(currRatio) / 2));
      y = Math.round(centerY - Math.round(graphSize * Math.cos(currRatio) / 2));
      Object currVertex = vertices[i];
      mxGeometry geometry = model.getGeometry(currVertex);
      geometry.setX(x);
      geometry.setY(y);
    }

    mxGeometry geometry = model.getGeometry(vertices[vertexNum - 1]);
    geometry.setX(centerX);
    geometry.setY(centerY);
  };
View Full Code Here

    }

    mxGraph graph = aGraph.getGraph();
    Object parent = graph.getDefaultParent();
    Object[] vertices = aGraph.getChildVertices(parent);
    mxIGraphModel model = graph.getModel();
    int vertexNum = vertices.length;
    double centerX = graphSize / 2f;
    double centerY = centerX;
    boolean isBranchSizeEven = ((numVerticesInBranch) % 2 == 0);
    int middleIndex = (int) Math.ceil(numVerticesInBranch / 2f);

    //create the circle
    for (int i = 0; i < numBranches; i++)
    {
      for (int j = 0; j < numVerticesInBranch; j++)
      {
        double currSize = this.getRingSize(j + 1, numVerticesInBranch, graphSize);

        //calc the position
        double x = 0;
        double y = 0;
        int numVertexesInPerimeter = 0;
        double currRatio = 0;
        numVertexesInPerimeter = numBranches;

        // need to detect the 2 middle vertices for even sized branches
        if (isBranchSizeEven && j == middleIndex - 1)
        {
          //full size
          currRatio = ((double) i - (0.0005f * graphSize / Math.pow(numVerticesInBranch, 1))) / (double) numVertexesInPerimeter;
        }
        else if (isBranchSizeEven && j == middleIndex)
        {
          currRatio = ((double) i + (0.0005f * graphSize / Math.pow(numVerticesInBranch, 1))) / (double) numVertexesInPerimeter;
        }
        else if (!isBranchSizeEven && currSize == graphSize)
        {
          currRatio = ((double) i / (double) numVertexesInPerimeter);
        }
        else
        {
          if (j + 1 < middleIndex)
          {
            //before middle
            currRatio = ((double) (i - 1f / Math.pow(currSize, 0.25) + 0.00000000000015f * Math.pow(currSize, 4)) / (double) numVertexesInPerimeter);
          }
          else
          {
            //after middle
            currRatio = ((double) (i + 1f / Math.pow(currSize, 0.25) - 0.00000000000015f * Math.pow(currSize, 4)) / (double) numVertexesInPerimeter);
          }
        }

        currRatio = currRatio * 2;
        currRatio = currRatio * (double) Math.PI;
        x = Math.round(centerX + Math.round(currSize * Math.sin(currRatio) / 2));
        y = Math.round(centerY - Math.round(currSize * Math.cos(currRatio) / 2));
        //shoot
        int currIndex = i * (numVerticesInBranch) + j;
        Object currVertex = vertices[currIndex];
        mxGeometry geometry = model.getGeometry(currVertex);
        geometry.setX(x);
        geometry.setY(y);
      }
    }

    //the center vertex is the last one
    Object currVertex = vertices[vertexNum - 1];
    mxGeometry geometry = model.getGeometry(currVertex);
    geometry.setX(centerX);
    geometry.setY(centerY);
  };
View Full Code Here

TOP

Related Classes of com.mxgraph.model.mxIGraphModel

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.