Package com.mxgraph.model

Examples of com.mxgraph.model.mxIGraphModel


   * @return Returns true if the graph has at least one cycle, taking edge direction into account
   */
  public static boolean isCyclicDirected(mxAnalysisGraph aGraph)
  {
    mxGraph graph = aGraph.getGraph();
    mxIGraphModel model = graph.getModel();
    Object[] cells = model.cloneCells(aGraph.getChildCells(graph.getDefaultParent(), true, true), true);
    mxGraphModel modelCopy = new mxGraphModel();
    mxGraph graphCopy = new mxGraph(modelCopy);
    Object parentCopy = graphCopy.getDefaultParent();
    graphCopy.addCells(cells);
    mxAnalysisGraph aGraphCopy = new mxAnalysisGraph();
View Full Code Here


  public static void setDefaultGraphStyle(mxAnalysisGraph aGraph, boolean resetEdgeValues)
  {
    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++)
    {
      model.setStyle(vertices[i], basicVertexStyleString);
    }

    Object[] edges = aGraph.getChildEdges(parent);
    boolean isDirected = mxGraphProperties.isDirected(aGraph.getProperties(), mxGraphProperties.DEFAULT_DIRECTED);
    String edgeString = basicEdgeStyleString;

    if (isDirected)
    {
      edgeString = edgeString + basicArrowStyleString;
    }
    else
    {
      edgeString = edgeString + "endArrow=none";
    }

    for (int i = 0; i < edges.length; i++)
    {
      model.setStyle(edges[i], edgeString);
    }

    if (resetEdgeValues)
    {
      for (int i = 0; i < edges.length; i++)
      {
        model.setValue(edges[i], null);
      }

      for (int i = 0; i < edges.length; i++)
      {
        model.setValue(edges[i], aGraph.getGenerator().getNewEdgeValue(aGraph));
      }
    }
  };
View Full Code Here

   * (non-Javadoc)
   * @see com.mxgraph.layout.mxGraphLayout#move(java.lang.Object, double, double)
   */
  public void moveCell(Object cell, double x, double y)
  {
    mxIGraphModel model = graph.getModel();
    Object parent = model.getParent(cell);
    boolean horizontal = isHorizontal();

    if (cell instanceof mxICell && parent instanceof mxICell)
    {
      int i = 0;
      double last = 0;
      int childCount = model.getChildCount(parent);
      double value = (horizontal) ? x : y;
      mxCellState pstate = graph.getView().getState(parent);

      if (pstate != null)
      {
        value -= (horizontal) ? pstate.getX() : pstate.getY();
      }

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

        if (child != cell)
        {
          mxGeometry bounds = model.getGeometry(child);

          if (bounds != null)
          {
            double tmp = (horizontal) ? bounds.getX()
                + bounds.getWidth() / 2 : bounds.getY()
                + bounds.getHeight() / 2;

            if (last < value && tmp > value)
            {
              break;
            }

            last = tmp;
          }
        }
      }

      // Changes child order in parent
      int idx = ((mxICell) parent).getIndex((mxICell) cell);
      idx = Math.max(0, i - ((i > idx) ? 1 : 0));

      model.add(parent, cell, idx);
    }
  }
View Full Code Here

   * @return true if <b>vertex</b> is a cut vertex
   */
  public static boolean isCutVertex(mxAnalysisGraph aGraph, Object vertex)
  {
    mxGraph graph = aGraph.getGraph();
    mxIGraphModel model = graph.getModel();

    if (aGraph.getEdges(vertex, null, true, true, false, true).length >= 2)
    {
      Object[] cells = model.cloneCells(aGraph.getChildCells(graph.getDefaultParent(), true, true), true);
      mxGraphModel modelCopy = new mxGraphModel();
      mxGraph graphCopy = new mxGraph(modelCopy);
      graphCopy.addCells(cells);
      mxAnalysisGraph aGraphCopy = new mxAnalysisGraph();
      aGraphCopy.setGraph(graphCopy);
View Full Code Here

   * @return true if <b>edge</b> is a cut edge of <b>aGraph</b>
   */
  public static boolean isCutEdge(mxAnalysisGraph aGraph, Object edge)
  {
    mxGraph graph = aGraph.getGraph();
    mxIGraphModel model = graph.getModel();
    mxCostFunction costFunction = aGraph.getGenerator().getCostFunction();
    mxGraphView view = graph.getView();

    int srcValue = (int) costFunction.getCost(new mxCellState(view, aGraph.getTerminal(edge, true), null));
    int destValue = (int) costFunction.getCost(new mxCellState(view, aGraph.getTerminal(edge, false), null));

    if (aGraph.getTerminal(edge, false) != null || aGraph.getTerminal(edge, true) != null)
    {
      Object[] cells = model.cloneCells(aGraph.getChildCells(graph.getDefaultParent(), true, true), true);
      mxGraphModel modelCopy = new mxGraphModel();
      mxGraph graphCopy = new mxGraph(modelCopy);
      graphCopy.addCells(cells);
      mxAnalysisGraph aGraphCopy = new mxAnalysisGraph();
      aGraphCopy.setGraph(graphCopy);
View Full Code Here

  public void execute(Object parent)
  {
    if (parent != null)
    {
      boolean horizontal = isHorizontal();
      mxIGraphModel model = graph.getModel();
      mxGeometry pgeo = model.getGeometry(parent);

      // Handles special case where the parent is either a layer with no
      // geometry or the current root of the view in which case the size
      // of the graph's container will be used.
      if (pgeo == null && model.getParent(parent) == model.getRoot()
          || parent == graph.getView().getCurrentRoot())
      {
        mxRectangle tmp = getContainerSize();
        pgeo = new mxGeometry(0, 0, tmp.getWidth(), tmp.getHeight());
      }

      double fillValue = 0;

      if (pgeo != null)
      {
        fillValue = (horizontal) ? pgeo.getHeight() : pgeo.getWidth();
      }

      fillValue -= 2 * spacing + 2 * border;

      // Handles swimlane start size
      mxRectangle size = graph.getStartSize(parent);
      fillValue -= (horizontal) ? size.getHeight() : size.getWidth();
      double x0 = this.x0 + size.getWidth() + border;
      double y0 = this.y0 + size.getHeight() + border;

      model.beginUpdate();
      try
      {
        double tmp = 0;
        mxGeometry last = null;
        int childCount = model.getChildCount(parent);

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

          if (!isVertexIgnored(child) && isVertexMovable(child))
          {
            mxGeometry geo = model.getGeometry(child);

            if (geo != null)
            {
              geo = (mxGeometry) geo.clone();

              if (wrap != 0 && last != null)
              {

                if ((horizontal && last.getX()
                    + last.getWidth() + geo.getWidth() + 2
                    * spacing > wrap)
                    || (!horizontal && last.getY()
                        + last.getHeight()
                        + geo.getHeight() + 2 * spacing > wrap))
                {
                  last = null;

                  if (horizontal)
                  {
                    y0 += tmp + spacing;
                  }
                  else
                  {
                    x0 += tmp + spacing;
                  }

                  tmp = 0;
                }
              }

              tmp = Math.max(tmp, (horizontal) ? geo
                  .getHeight() : geo.getWidth());

              if (last != null)
              {
                if (horizontal)
                {
                  geo.setX(last.getX() + last.getWidth()
                      + spacing);
                }
                else
                {
                  geo.setY(last.getY() + last.getHeight()
                      + spacing);
                }
              }
              else
              {
                if (horizontal)
                {
                  geo.setX(x0);
                }
                else
                {
                  geo.setY(y0);
                }
              }

              if (horizontal)
              {
                geo.setY(y0);
              }
              else
              {
                geo.setX(x0);
              }

              if (fill && fillValue > 0)
              {
                if (horizontal)
                {
                  geo.setHeight(fillValue);
                }
                else
                {
                  geo.setWidth(fillValue);
                }
              }

              model.setGeometry(child, geo);
              last = geo;
            }
          }
        }

        if (resizeParent && pgeo != null && last != null
            && !graph.isCellCollapsed(parent))
        {
          pgeo = (mxGeometry) pgeo.clone();

          if (horizontal)
          {
            pgeo.setWidth(last.getX() + last.getWidth() + spacing);
          }
          else
          {
            pgeo
                .setHeight(last.getY() + last.getHeight()
                    + spacing);
          }

          model.setGeometry(parent, pgeo);
        }
      }
      finally
      {
        model.endUpdate();
      }
    }
  }
View Full Code Here

   * (non-Javadoc)
   * @see com.mxgraph.layout.mxGraphLayout#move(java.lang.Object, double, double)
   */
  public void moveCell(Object cell, double x, double y)
  {
    mxIGraphModel model = graph.getModel();
    Object parent = model.getParent(cell);

    if (cell instanceof mxICell && parent instanceof mxICell)
    {
      int i = 0;
      double last = 0;
      int childCount = model.getChildCount(parent);

      // Finds index of the closest swimlane
      // TODO: Take into account the orientation
      for (i = 0; i < childCount; i++)
      {
        Object child = model.getChildAt(parent, i);
        mxRectangle bounds = getVertexBounds(child);

        if (bounds != null)
        {
          double tmp = bounds.getX() + bounds.getWidth() / 2;

          if (last < x && tmp > x)
          {
            break;
          }

          last = tmp;
        }
      }

      // Changes child order in parent
      int idx = ((mxICell) parent).getIndex((mxICell) cell);
      idx = Math.max(0, i - ((i > idx) ? 1 : 0));

      model.add(parent, cell, idx);
    }
  }
View Full Code Here

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

    // Handles special case where the parent is either a layer with no
    // geometry or the current root of the view in which case the size
    // of the graph's container will be used.
    if (pgeo == null && model.getParent(parent) == model.getRoot()
        || parent == graph.getView().getCurrentRoot())
    {
      mxRectangle tmp = getContainerSize();
      pgeo = new mxGeometry(0, 0, tmp.getWidth(), tmp.getHeight());
    }

    if (pgeo != null)
    {
      int childCount = model.getChildCount(parent);
      List<Object> children = new ArrayList<Object>(childCount);

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

        if (!isVertexIgnored(child) && isVertexMovable(child))
        {
          children.add(child);
        }
      }

      int n = children.size();

      if (n > 0)
      {
        double x0 = border;
        double y0 = border;
        double other = (horizontal) ? pgeo.getHeight() : pgeo
            .getWidth();
        other -= 2 * border;

        mxRectangle size = graph.getStartSize(parent);

        other -= (horizontal) ? size.getHeight() : size.getWidth();
        x0 = x0 + size.getWidth();
        y0 = y0 + size.getHeight();

        double tmp = border + (n - 1) * spacing;
        double value = (horizontal) ? ((pgeo.getWidth() - x0 - tmp) / n)
            : ((pgeo.getHeight() - y0 - tmp) / n);

        // Avoids negative values, that is values where the sum of the
        // spacing plus the border is larger then the available space
        if (value > 0)
        {
          model.beginUpdate();
          try
          {
            for (int i = 0; i < n; i++)
            {
              Object child = children.get(i);
              mxGeometry geo = model.getGeometry(child);

              if (geo != null)
              {
                geo = (mxGeometry) geo.clone();
                geo.setX(x0);
                geo.setY(y0);

                if (horizontal)
                {
                  if (resizeVertices)
                  {
                    geo.setWidth(value);
                    geo.setHeight(other);
                  }

                  x0 += value + spacing;
                }
                else
                {
                  if (resizeVertices)
                  {
                    geo.setHeight(value);
                    geo.setWidth(other);
                  }

                  y0 += value + spacing;
                }

                model.setGeometry(child, geo);
              }
            }
          }
          finally
          {
            model.endUpdate();
          }
        }
      }
    }
  }
View Full Code Here

   *
   */
  protected Map<String, List<Object>> findParallels(Object parent)
  {
    Map<String, List<Object>> lookup = new Hashtable<String, List<Object>>();
    mxIGraphModel model = graph.getModel();
    int childCount = model.getChildCount(parent);

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

      if (!isEdgeIgnored(child))
      {
        String id = getEdgeId(child);

View Full Code Here

   *
   */
  protected void layout(List<Object> parallels)
  {
    Object edge = parallels.get(0);
    mxIGraphModel model = graph.getModel();
    mxGeometry src = model.getGeometry(model.getTerminal(edge, true));
    mxGeometry trg = model.getGeometry(model.getTerminal(edge, false));

    // Routes multiple loops
    if (src == trg)
    {
      double x0 = src.getX() + src.getWidth() + this.spacing;
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.