Package com.mxgraph.model

Examples of com.mxgraph.model.mxIGraphModel


          editorPane.requestFocus();
          editorPane.select(start, ende);
        }
        else
        {
          mxIGraphModel model = graphComponent.getGraph().getModel();
          model.beginUpdate();
          try
          {
            graphComponent.stopEditing(false);
            graphComponent.getGraph().toggleCellStyleFlags(
                mxConstants.STYLE_FONTSTYLE,
                (bold) ? mxConstants.FONT_BOLD
                    : mxConstants.FONT_ITALIC);
          }
          finally
          {
            model.endUpdate();
          }
        }
      }
    }
View Full Code Here


   * list of mxPoints. Set the points to null to remove all
   * existing points for an edge.
   */
  public void setEdgePoints(Object edge, List<mxPoint> points)
  {
    mxIGraphModel model = graph.getModel();
    mxGeometry geometry = model.getGeometry(edge);

    if (geometry == null)
    {
      geometry = new mxGeometry();
      geometry.setRelative(true);
    }
    else
    {
      geometry = (mxGeometry) geometry.clone();
    }

    if (this.parent != null && points != null)
    {
      Object parent = graph.getModel().getParent(edge);

        mxPoint parentOffset = getParentOffset(parent);

        for (mxPoint point : points)
        {
          point.setX(point.getX() - parentOffset.getX());
          point.setY(point.getY() - parentOffset.getY());
        }

    }

    geometry.setPoints(points);
    model.setGeometry(edge, geometry);
  }
View Full Code Here

   * x - Integer that defines the x-coordinate of the new location.
   * y - Integer that defines the y-coordinate of the new location.
   */
  public mxRectangle setVertexLocation(Object vertex, double x, double y)
  {
    mxIGraphModel model = graph.getModel();
    mxGeometry geometry = model.getGeometry(vertex);
    mxRectangle result = null;

    if (geometry != null)
    {
      result = new mxRectangle(x, y, geometry.getWidth(),
          geometry.getHeight());

      mxGraphView graphView = graph.getView();

      // Checks for oversize labels and offset the result
      if (useBoundingBox)
      {
        mxCellState state = graphView.getState(vertex);

        if (state != null)
        {
          double scale = graph.getView().getScale();
          mxRectangle box = state.getBoundingBox();

          if (state.getBoundingBox().getX() < state.getX())
          {
            x += (state.getX() - box.getX()) / scale;
            result.setWidth(box.getWidth());
          }
          if (state.getBoundingBox().getY() < state.getY())
          {
            y += (state.getY() - box.getY()) / scale;
            result.setHeight(box.getHeight());
          }
        }
      }

      if (this.parent != null)
      {
        Object parent = model.getParent(vertex);

        if (parent != null && parent != this.parent)
        {
          mxPoint parentOffset = getParentOffset(parent);

          x = x - parentOffset.getX();
          y = y - parentOffset.getY();
        }
      }

      if (geometry.getX() != x || geometry.getY() != y)
      {
        geometry = (mxGeometry) geometry.clone();
        geometry.setX(x);
        geometry.setY(y);

        model.setGeometry(vertex, geometry);
      }
    }

    return result;
  }
View Full Code Here

    else
    {
      Object[] edges = graph.getEdges(cell, parent, incoming, outgoing, includeLoops, recurse);
      List<Object> result = new ArrayList<Object>(edges.length);

      mxIGraphModel model = graph.getModel();

      for (int i = 0; i < edges.length; i++)
      {
        Object source = model.getTerminal(edges[i], true);
        Object target = model.getTerminal(edges[i], false);

        if (((includeLoops && source == target) || ((source != target) && ((incoming && target == cell) || (outgoing && source == cell))))
            && model.isVisible(edges[i]))
        {
          result.add(edges[i]);
        }
      }
View Full Code Here

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

    // Gets all vertices and edges inside the parent
    List<Object> edges = new ArrayList<Object>();
    List<Object> vertices = new ArrayList<Object>();
    int childCount = model.getChildCount(parent);

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

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

  /**
   *
   */
  protected void placeLabels(Object[] v, Object[] e)
  {
    mxIGraphModel model = graph.getModel();

    // Moves the vertices to build a circle. Makes sure the
    // radius is large enough for the vertices to not
    // overlap
    model.beginUpdate();
    try
    {
      for (int i = 0; i < e.length; i++)
      {
        mxCellState edge = (mxCellState) e[i];

        if (edge != null && edge.getLabelBounds() != null)
        {
          for (int j = 0; j < v.length; j++)
          {
            mxCellState vertex = (mxCellState) v[j];

            if (vertex != null)
            {
              avoid(edge, vertex);
            }
          }
        }
      }
    }
    finally
    {
      model.endUpdate();
    }
  }
View Full Code Here

  /**
   *
   */
  protected void avoid(mxCellState edge, mxCellState vertex)
  {
    mxIGraphModel model = graph.getModel();
    Rectangle labRect = edge.getLabelBounds().getRectangle();
    Rectangle vRect = vertex.getRectangle();

    if (labRect.intersects(vRect))
    {
      int dy1 = -labRect.y - labRect.height + vRect.y;
      int dy2 = -labRect.y + vRect.y + vRect.height;

      int dy = (Math.abs(dy1) < Math.abs(dy2)) ? dy1 : dy2;

      int dx1 = -labRect.x - labRect.width + vRect.x;
      int dx2 = -labRect.x + vRect.x + vRect.width;

      int dx = (Math.abs(dx1) < Math.abs(dx2)) ? dx1 : dx2;

      if (Math.abs(dx) < Math.abs(dy))
      {
        dy = 0;
      }
      else
      {
        dx = 0;
      }

      mxGeometry g = model.getGeometry(edge.getCell());

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

        if (g.getOffset() != null)
        {
          g.getOffset().setX(g.getOffset().getX() + dx);
          g.getOffset().setY(g.getOffset().getY() + dy);
        }
        else
        {
          g.setOffset(new mxPoint(dx, dy));
        }

        model.setGeometry(edge.getCell(), g);
      }
    }
  }
View Full Code Here

   * @return true if the graph contains cycles regardless of edge direction
   */
  public static boolean isCyclicUndirected(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(graphCopy, aGraph.getGenerator(), aGraph.getProperties());
View Full Code Here

    if (isTree(aGraph))
    {
      mxGraphProperties.setDirected(aGraph.getProperties(), false);
      final ArrayList<Object> bFSList = new ArrayList<Object>();
      mxGraph graph = aGraph.getGraph();
      final mxIGraphModel model = graph.getModel();
      Object parent = graph.getDefaultParent();

      mxTraversal.bfs(aGraph, startVertex, new mxICellVisitor()
      {
        public boolean visit(Object vertex, Object edge)
        {
          bFSList.add(vertex);
          return false;
        }
      });

      for (int i = 0; i < bFSList.size(); i++)
      {
        Object parentVertex = bFSList.get(i);
        Object currEdges[] = aGraph.getEdges(parentVertex, parent, true, true, false, true);
        Object[] neighbors = aGraph.getOpposites(currEdges, parentVertex, true, true);

        for (int j = 0; j < neighbors.length; j++)
        {
          Object currVertex = neighbors[j];
          int childIndex = bFSList.indexOf(currVertex);

          if (childIndex > i)
          {
            //parentVertex is parent of currVertex, so the edge must be directed from parentVertex to currVertex
            // but we need to find the connecting edge first
            Object currEdge = getConnectingEdge(aGraph, parentVertex, currVertex);
            model.setTerminal(currEdge, parentVertex, true);
            model.setTerminal(currEdge, currVertex, false);
          }
        }
      }

      mxGraphProperties.setDirected(aGraph.getProperties(), true);
View Full Code Here

   * @param vertexTwo
   * @return an edge that directly connects <b>vertexOne</b> and <b>vertexTwo</b> regardless of direction, null if they are not connected directly
   */
  public static Object getConnectingEdge(mxAnalysisGraph aGraph, Object vertexOne, Object vertexTwo)
  {
    mxIGraphModel model = aGraph.getGraph().getModel();
    Object[] edges = aGraph.getEdges(vertexOne, null, true, true, false, true);

    for (int i = 0; i < edges.length; i++)
    {
      Object currEdge = edges[i];
      Object source = model.getTerminal(currEdge, true);
      Object target = model.getTerminal(currEdge, false);

      if (source.equals(vertexOne) && target.equals(vertexTwo))
      {
        return currEdge;

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.