Package com.mxgraph.view

Examples of com.mxgraph.view.mxGraphView


      Arrays.fill(weight[i], Double.MAX_VALUE);
    }

    boolean isDirected = mxGraphProperties.isDirected(aGraph.getProperties(), mxGraphProperties.DEFAULT_DIRECTED);
    mxCostFunction costFunction = aGraph.getGenerator().getCostFunction();
    mxGraphView view = aGraph.getGraph().getView();

    for (Object currEdge : edges)
    {
      Object source = aGraph.getTerminal(currEdge, true);
      Object target = aGraph.getTerminal(currEdge, false);

      weight[indexMap.get(source)][indexMap.get(target)] = costFunction.getCost(view.getState(currEdge));

      if (!isDirected)
      {
        weight[indexMap.get(target)][indexMap.get(source)] = costFunction.getCost(view.getState(currEdge));
      }
    }

    for (int i = 0; i < nodes.length; i++)
    {
View Full Code Here


    }

    if (startVertex != targetVertex)
    {
      mxCostFunction cf = aGraph.getGenerator().getCostFunction();
      mxGraphView view = aGraph.getGraph().getView();
      ArrayList<Object> currPath = new ArrayList<Object>();
      currPath.add(startVertex);

      while (startVertex != targetVertex)
      {
View Full Code Here

    {
      cells = new Object[] { graph.getModel().getRoot() };
    }

    // Gets the current state of the view
    mxGraphView view = graph.getView();

    // Keeps the existing translation as the cells might
    // be aligned to the grid in a different way in a graph
    // that has a translation other than zero
    boolean eventsEnabled = view.isEventsEnabled();

    // Disables firing of scale events so that there is no
    // repaint or update of the original graph
    view.setEventsEnabled(false);

    // Uses the view to create temporary cell states for each cell
    mxTemporaryCellStates temp = new mxTemporaryCellStates(view, scale,
        cells);

    try
    {
      if (clip == null)
      {
        clip = graph.getPaintBounds(cells);
      }

      if (clip != null && clip.getWidth() > 0 && clip.getHeight() > 0)
      {
        Rectangle rect = clip.getRectangle();
        canvas = factory.createCanvas(rect.width + 1, rect.height + 1);

        if (canvas != null)
        {
          double previousScale = canvas.getScale();
          Point previousTranslate = canvas.getTranslate();

          try
          {
            canvas.setTranslate(-rect.x, -rect.y);
            canvas.setScale(view.getScale());

            for (int i = 0; i < cells.length; i++)
            {
              graph.drawCell(canvas, cells[i]);
            }
          }
          finally
          {
            canvas.setScale(previousScale);
            canvas.setTranslate(previousTranslate.x,
                previousTranslate.y);
          }
        }
      }
    }
    finally
    {
      temp.destroy();
      view.setEventsEnabled(eventsEnabled);
    }

    return canvas;
  }
View Full Code Here

   */
  protected void traverse(Object vertex, boolean directed, Object edge,
      Set<Object> allVertices, Set<Object> currentComp,
      List<Set<Object>> hierarchyVertices, Set<Object> filledVertexSet)
  {
    mxGraphView view = graph.getView();
    mxIGraphModel model = graph.getModel();

    if (vertex != null && allVertices != null)
    {
      // Has this vertex been seen before in any traversal
      // And if the filled vertex set is populated, only
      // process vertices in that it contains
      if (!allVertices.contains(vertex)
          && (filledVertexSet == null ? true : filledVertexSet
              .contains(vertex)))
      {
        currentComp.add(vertex);
        allVertices.add(vertex);

        if (filledVertexSet != null)
        {
          filledVertexSet.remove(vertex);
        }

        int edgeCount = model.getEdgeCount(vertex);

        if (edgeCount > 0)
        {
          for (int i = 0; i < edgeCount; i++)
          {
            Object e = model.getEdgeAt(vertex, i);
            boolean isSource = view.getVisibleTerminal(e, true) == vertex;

            if (!directed || isSource)
            {
              Object next = view.getVisibleTerminal(e, !isSource);
              traverse(next, directed, e, allVertices,
                  currentComp, hierarchyVertices,
                  filledVertexSet);
            }
          }
View Full Code Here

            }

            System.out.println("Path info:");

            mxCostFunction costFunction = aGraph.getGenerator().getCostFunction();
            mxGraphView view = aGraph.getGraph().getView();

            for (int i = 0; i < vertexNum; i++)
            {
              System.out.print("[");

              for (int j = 0; j < vertexNum; j++)
              {
                if (paths[i][j] != null)
                {
                  System.out.print(" " + costFunction.getCost(view.getState(paths[i][j])));
                }
                else
                {
                  System.out.print(" -");
                }
              }

              System.out.println(" ]");
            }

            try
            {
              Object[] path = mxTraversal.getWFIPath(aGraph, FWIresult, vertices[0], vertices[vertexNum - 1]);
              System.out.print("The path from " + costFunction.getCost(view.getState(vertices[0])) + " to "
                  + costFunction.getCost((view.getState(vertices[vertexNum - 1]))) + " is:");

              for (int i = 0; i < path.length; i++)
              {
                System.out.print(" " + costFunction.getCost(view.getState(path[i])));
              }

              System.out.println();
            }
            catch (StructuralException e1)
View Full Code Here

   * 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

      mxICostFunction cf, int steps, boolean directed)
  {
    // Sets up a pqueue and a hashtable to store the predecessor for each
    // cell in tha graph traversal. The pqueue is initialized
    // with the from element at prio 0.
    mxGraphView view = graph.getView();
    mxFibonacciHeap q = createPriorityQueue();
    Hashtable<Object, Object> pred = new Hashtable<Object, Object>();
    q.decreaseKey(q.getNode(from, true), 0); // Inserts automatically

    // The main loop of the dijkstra algorithm is based on the pqueue being
    // updated with the actual shortest distance to the source vertex.
    for (int j = 0; j < steps; j++)
    {
      mxFibonacciHeap.Node node = q.removeMin();
      double prio = node.getKey();
      Object obj = node.getUserObject();

      // Exits the loop if the target node or vertex has been reached
      if (obj == to)
      {
        break;
      }

      // Gets all outgoing edges of the closest cell to the source
      Object[] e = (directed) ? graph.getOutgoingEdges(obj) : graph
          .getConnections(obj);

      if (e != null)
      {
        for (int i = 0; i < e.length; i++)
        {
          Object[] opp = graph.getOpposites(new Object[] { e[i] },
              obj);

          if (opp != null && opp.length > 0)
          {
            Object neighbour = opp[0];

            // Updates the priority in the pqueue for the opposite node
            // to be the distance of this step plus the cost to
            // traverese the edge to the neighbour. Note that the
            // priority queue will make sure that in the next step the
            // node with the smallest prio will be traversed.
            if (neighbour != null && neighbour != obj
                && neighbour != from)
            {
              double newPrio = prio
                  + ((cf != null) ? cf.getCost(view
                      .getState(e[i])) : 1);
              node = q.getNode(neighbour, true);
              double oldPrio = node.getKey();

              if (newPrio < oldPrio)
              {
                pred.put(neighbour, e[i]);
                q.decreaseKey(node, newPrio);
              }
            }
          }
        }
      }

      if (q.isEmpty())
      {
        break;
      }
    }

    // Constructs a path array by walking backwards through the predessecor
    // map and filling up a list of edges, which is subsequently returned.
    ArrayList<Object> list = new ArrayList<Object>(2 * steps);
    Object obj = to;
    Object edge = pred.get(obj);

    if (edge != null)
    {
      list.add(obj);

      while (edge != null)
      {
        list.add(0, edge);

        boolean isSource = view.getVisibleTerminal(edge, true) == obj;
        obj = view.getVisibleTerminal(edge, !isSource);
        list.add(0, obj);

        edge = pred.get(obj);
      }
    }
View Full Code Here

    // increasing length and tries adding to the MST. Only edges are added
    // that do not form cycles in the graph, that is, where the source
    // and target are in different sets in the union find structure.
    // Whenever an edge is added to the MST, the two different sets are
    // unified.
    mxGraphView view = graph.getView();
    mxUnionFind uf = createUnionFind(v);
    ArrayList<Object> result = new ArrayList<Object>(e.length);
    mxCellState[] edgeStates = sort(view.getCellStates(e), cf);

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

      Object source = view.getVisibleTerminal(edge, true);
      Object target = view.getVisibleTerminal(edge, false);

      mxUnionFind.Node setA = uf.find(uf.getNode(source));
      mxUnionFind.Node setB = uf.find(uf.getNode(target));

      if (setA == null || setB == null || setA != setB)
View Full Code Here

   * @see #createUnionFind(Object[])
   */
  public mxUnionFind getConnectionComponents(mxGraph graph, Object[] v,
      Object[] e)
  {
    mxGraphView view = graph.getView();
    mxUnionFind uf = createUnionFind(v);

    for (int i = 0; i < e.length; i++)
    {
      Object source = view.getVisibleTerminal(e[i], true);
      Object target = view.getVisibleTerminal(e[i], false);

      uf.union(uf.find(uf.getNode(source)), uf.find(uf.getNode(target)));
    }

    return uf;
View Full Code Here

          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

TOP

Related Classes of com.mxgraph.view.mxGraphView

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.