Package com.mxgraph.model

Examples of com.mxgraph.model.mxCell


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

    for (int i = 0; i < vertexCount; i++)
    {
      mxCell currVertex = (mxCell) vertices[i];
      int edgeCount = currVertex.getEdgeCount();
      mxCell currEdge = new mxCell();
      ArrayList<mxCell> neighborVertexes = new ArrayList<mxCell>();

      for (int j = 0; j < edgeCount; j++)
      {
        currEdge = (mxCell) currVertex.getEdgeAt(j);

        mxCell source = (mxCell) currEdge.getSource();
        mxCell destination = (mxCell) currEdge.getTarget();

        if (!source.equals(currVertex))
        {
          neighborVertexes.add(j, source);
        }
        else
        {
          neighborVertexes.add(j, destination);
        }

      }

      oldConnections.add(i, neighborVertexes);
    }

    //delete all edges and make a complementary model
    Object[] edges = aGraph.getChildEdges(parent);
    graph.removeCells(edges);

    for (int i = 0; i < vertexCount; i++)
    {
      ArrayList<mxCell> oldNeighbors = new ArrayList<mxCell>();
      oldNeighbors = oldConnections.get(i);
      mxCell currVertex = (mxCell) vertices[i];

      for (int j = 0; j < vertexCount; j++)
      {
        mxCell targetVertex = (mxCell) vertices[j];
        boolean shouldConnect = true; // the decision if the two current vertexes should be connected

        if (oldNeighbors.contains(targetVertex))
        {
          shouldConnect = false;
        }
        else if (targetVertex.equals(currVertex))
        {
          shouldConnect = false;
        }
        else if (areConnected(aGraph, currVertex, targetVertex))
        {
View Full Code Here


            {
              @Override
              // simple visitor that prints current vertex
              public boolean visit(Object vertex, Object edge)
              {
                mxCell v = (mxCell) vertex;
                mxCell e = (mxCell) edge;

                if (e != null)
                {
                  System.out.println("Vertex: " + v.getValue() + " edge: " + e.getValue());
                }
                else
                {
                  System.out.println("Vertex: " + v.getValue() + " edge: N/A");
                }

                return false;
              }
            });
           
            mxGraphProperties.setDirected(aGraph.getProperties(), oldDir);
          }
          else if (graphType2 == GraphType.DFS_DIR)
          {
            boolean oldDir = mxGraphProperties.isDirected(aGraph.getProperties(), mxGraphProperties.DEFAULT_DIRECTED);
            mxGraphProperties.setDirected(aGraph.getProperties(), true);
            System.out.println("DFS test");

            mxTraversal.dfs(aGraph, startVertex, new mxICellVisitor()
            {
              @Override
              // simple visitor that prints current vertex
              public boolean visit(Object vertex, Object edge)
              {
                mxCell v = (mxCell) vertex;
                mxCell e = (mxCell) edge;

                if (e != null)
                {
                  System.out.println("Vertex: " + v.getValue() + " edge: " + e.getValue());
                }
                else
                {
                  System.out.println("Vertex: " + v.getValue() + " edge: N/A");
                }

                return false;
              }
            });

            mxGraphProperties.setDirected(aGraph.getProperties(), oldDir);
          }
          else if (graphType2 == GraphType.BFS_UNDIR)
          {
            boolean oldDir = mxGraphProperties.isDirected(aGraph.getProperties(), mxGraphProperties.DEFAULT_DIRECTED);
            mxGraphProperties.setDirected(aGraph.getProperties(), false);
            System.out.println("BFS test");

            mxTraversal.bfs(aGraph, startVertex, new mxICellVisitor()
            {
              @Override
              // simple visitor that prints current vertex
              public boolean visit(Object vertex, Object edge)
              {
                mxCell v = (mxCell) vertex;
                mxCell e = (mxCell) edge;

                if (e != null)
                {
                  System.out.println("Vertex: " + v.getValue() + " edge: " + e.getValue());
                }
                else
                {
                  System.out.println("Vertex: " + v.getValue() + " edge: N/A");
                }

                return false;
              }
            });
           
            mxGraphProperties.setDirected(aGraph.getProperties(), oldDir);
          }
          else if (graphType2 == GraphType.DFS_UNDIR)
          {
            boolean oldDir = mxGraphProperties.isDirected(aGraph.getProperties(), mxGraphProperties.DEFAULT_DIRECTED);
            mxGraphProperties.setDirected(aGraph.getProperties(), false);
            System.out.println("DFS test");

            mxTraversal.dfs(aGraph, startVertex, new mxICellVisitor()
            {
              @Override
              // simple visitor that prints current vertex
              public boolean visit(Object vertex, Object edge)
              {
                mxCell v = (mxCell) vertex;
                mxCell e = (mxCell) edge;

                if (e != null)
                {
                  System.out.println("Vertex: " + v.getValue() + " edge: " + e.getValue());
                }
                else
                {
                  System.out.println("Vertex: " + v.getValue() + " edge: N/A");
                }

                return false;
              }
            });

            mxGraphProperties.setDirected(aGraph.getProperties(), oldDir);
          }
          else if (graphType2 == GraphType.MAKE_TREE_DIRECTED)
          {
            try
            {
              graph.getModel().beginUpdate();
              mxGraphStructure.makeTreeDirected(aGraph, startVertex);
              graph.getModel().endUpdate();
              graph.getModel().beginUpdate();
              mxCompactTreeLayout layout = new mxCompactTreeLayout(graph);
              layout.setHorizontal(false);
              layout.execute(graph.getDefaultParent());
              graph.getModel().endUpdate();
            }
            catch (StructuralException e1)
            {
              System.out.println(e1);
            }
          }
          else if (graphType2 == GraphType.INDEGREE)
          {
            int indegree = mxGraphStructure.indegree(aGraph, startVertex);
            System.out.println("Indegree of " + aGraph.getGraph().getModel().getValue(startVertex) + " is " + indegree);
          }
          else if (graphType2 == GraphType.OUTDEGREE)
          {
            int outdegree = mxGraphStructure.outdegree(aGraph, startVertex);
            System.out.println("Outdegree of " + aGraph.getGraph().getModel().getValue(startVertex) + " is " + outdegree);
          }
          else if (graphType2 == GraphType.IS_CUT_VERTEX)
          {
            boolean isCutVertex = mxGraphStructure.isCutVertex(aGraph, startVertex);

            if (isCutVertex)
            {
              System.out.println("Vertex " + aGraph.getGraph().getModel().getValue(startVertex) + " is a cut vertex.");
            }
            else
            {
              System.out.println("Vertex " + aGraph.getGraph().getModel().getValue(startVertex) + " is not a cut vertex.");
            }
          }
          setVisible(false);
        }
      });
      closeButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          insertGraph = false;
          setVisible(false);
        }
      });

      getContentPane().add(panelBorder, BorderLayout.CENTER);
      getContentPane().add(buttonPanel, BorderLayout.SOUTH);
      pack();
      setResizable(false);
      // setLocationRelativeTo(parent);
    }
    else if ((graphType2 == GraphType.DIJKSTRA) || (graphType2 == GraphType.BELLMAN_FORD))
    {
      JPanel panel = new JPanel(new GridLayout(2, 2, 4, 4));
      panel.add(new JLabel("Starting vertex"));
      panel.add(startVertexValueField);
      panel.add(new JLabel("End vertex"));
      panel.add(endVertexValueField);
      JPanel panelBorder = new JPanel();
      panelBorder.setBorder(new EmptyBorder(10, 10, 10, 10));
      panelBorder.add(panel);

      JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
      panel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.GRAY),
          BorderFactory.createEmptyBorder(16, 8, 8, 8)));

      JButton applyButton = new JButton("Start");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        double distance = 0;

        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int startValue = Integer.parseInt(startVertexValueField.getText());
          int endValue = Integer.parseInt(endVertexValueField.getText());
          Object startVertex = mxGraphStructure.getVertexWithValue(aGraph, startValue);
          Object endVertex = mxGraphStructure.getVertexWithValue(aGraph, endValue);

          if (graphType2 == GraphType.DIJKSTRA)
          {
            System.out.println("Dijkstra test");

            try
            {
              mxTraversal.dijkstra(aGraph, startVertex, endVertex, new mxICellVisitor()
              {
                @Override
                // simple visitor that prints current vertex
                public boolean visit(Object vertex, Object edge)
                {
                  mxCell v = (mxCell) vertex;
                  mxCell e = (mxCell) edge;
                  String eVal = "N/A";

                  if (e != null)
                  {
                    if (e.getValue() == null)
                    {
                      eVal = "1.0";
                    }
                    else
                    {
                      eVal = e.getValue().toString();
                    }
                  }

                  if (!eVal.equals("N/A"))
                  {
View Full Code Here

  /**
   * Constructs a new cell codec.
   */
  public mxCellCodec()
  {
    this(new mxCell(), null, new String[] { "parent", "source", "target" },
        null);
  }
View Full Code Here

   */
  public Node afterEncode(mxCodec enc, Object obj, Node node)
  {
    if (obj instanceof mxCell)
    {
      mxCell cell = (mxCell) obj;

      if (cell.getValue() instanceof Node)
      {
        // Wraps the graphical annotation up in the
        // user object (inversion) by putting the
        // result of the default encoding into
        // a clone of the user object (node type 1)
        // and returning this cloned user object.
        Element tmp = (Element) node;
        node = enc.getDocument().importNode((Node) cell.getValue(),
            true);
        node.appendChild(tmp);

        // Moves the id attribute to the outermost
        // XML node, namely the node which denotes
View Full Code Here

  {
    Element inner = (Element) node;

    if (obj instanceof mxCell)
    {
      mxCell cell = (mxCell) obj;
      String classname = getName();
      String nodeName = node.getNodeName();
     
      // Handles aliased names
      if (!nodeName.equals(classname))
      {
        String tmp = mxCodecRegistry.aliases.get(nodeName);
       
        if (tmp != null)
        {
          nodeName = tmp;
        }
      }

      if (!nodeName.equals(classname))
      {
        // Passes the inner graphical annotation node to the
        // object codec for further processing of the cell.
        Node tmp = inner.getElementsByTagName(classname).item(0);

        if (tmp != null && tmp.getParentNode() == node)
        {
          inner = (Element) tmp;

          // Removes annotation and whitespace from node
          Node tmp2 = tmp.getPreviousSibling();

          while (tmp2 != null && tmp2.getNodeType() == Node.TEXT_NODE)
          {
            Node tmp3 = tmp2.getPreviousSibling();

            if (tmp2.getTextContent().trim().length() == 0)
            {
              tmp2.getParentNode().removeChild(tmp2);
            }

            tmp2 = tmp3;
          }

          // Removes more whitespace
          tmp2 = tmp.getNextSibling();

          while (tmp2 != null && tmp2.getNodeType() == Node.TEXT_NODE)
          {
            Node tmp3 = tmp2.getPreviousSibling();

            if (tmp2.getTextContent().trim().length() == 0)
            {
              tmp2.getParentNode().removeChild(tmp2);
            }

            tmp2 = tmp3;
          }

          tmp.getParentNode().removeChild(tmp);
        }
        else
        {
          inner = null;
        }

        // Creates the user object out of the XML node
        Element value = (Element) node.cloneNode(true);
        cell.setValue(value);
        String id = value.getAttribute("id");

        if (id != null)
        {
          cell.setId(id);
          value.removeAttribute("id");
        }
      }
      else
      {
        cell.setId(((Element) node).getAttribute("id"));
      }

      // Preprocesses and removes all Id-references
      // in order to use the correct encoder (this)
      // for the known references to cells (all).
View Full Code Here

    for (Object vertex : vertexes)
    {
      List<mxGraphMlNode> Gmlnodes = gmlGraph.getNodes();

      mxCell v = (mxCell) vertex;
      String id = v.getId();

      mxGraphMlNode gmlNode = new mxGraphMlNode(id, null);
      addNodeData(gmlNode, v);
      Gmlnodes.add(gmlNode);
      gmlGraph.setNodes(Gmlnodes);
View Full Code Here

      Object parent, mxGraph graph)
  {
    Object[] edges = graph.getChildEdges(parent);
    for (Object edge : edges)
    {
      mxCell e = (mxCell) edge;
      mxCell source = (mxCell) e.getSource();
      mxCell target = (mxCell) e.getTarget();

      String sourceName = "";
      String targetName = "";
      String sourcePort = "";
      String targetPort = "";
      sourceName = source != null ? source.getId() : "";
      targetName = target != null ? target.getId() : "";

      //Get the graph view that contains the states
      mxGraphView view = graph.getView();
      mxPoint sourceConstraint = null;
      mxPoint targetConstraint = null;
View Full Code Here

   * @param node Gml Node
   * @return The inserted Vertex cell.
   */
  private mxCell addNode(mxGraph graph, Object parent, mxGraphMlNode node)
  {
    mxCell v1;
    String id = node.getNodeId();

    mxGraphMlData data = dataNodeKey(node);

    if (data != null && data.getDataShapeNode() != null)
View Full Code Here

    {
      style = edge.getEdgeStyle();
    }

    //Insert new edge.
    mxCell e = (mxCell) graph.insertEdge(parent, null, label, source,
        target, style);
    graph.setConnectionConstraint(e, source, true,
        new mxConnectionConstraint(fromConstraint, false));
    graph.setConnectionConstraint(e, target, false,
        new mxConnectionConstraint(toConstraint, false));
View Full Code Here

    Object parent = graph.getDefaultParent();

    graph.getModel().beginUpdate();
    try
    {
      mxCell v1 = (mxCell) graph.insertVertex(parent, null, "Hello", 20,
          20, 100, 100, "");
      v1.setConnectable(false);
      mxGeometry geo = graph.getModel().getGeometry(v1);
      // The size of the rectangle when the minus sign is clicked
      geo.setAlternateBounds(new mxRectangle(20, 20, 100, 50));

      mxGeometry geo1 = new mxGeometry(0, 0.5, PORT_DIAMETER,
          PORT_DIAMETER);
      // Because the origin is at upper left corner, need to translate to
      // position the center of port correctly
      geo1.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS));
      geo1.setRelative(true);

      mxCell port1 = new mxCell(null, geo1,
          "shape=ellipse;perimter=ellipsePerimeter");
      port1.setVertex(true);

      mxGeometry geo2 = new mxGeometry(1.0, 0.5, PORT_DIAMETER,
          PORT_DIAMETER);
      geo2.setOffset(new mxPoint(-PORT_RADIUS, -PORT_RADIUS));
      geo2.setRelative(true);

      mxCell port2 = new mxCell(null, geo2,
          "shape=ellipse;perimter=ellipsePerimeter");
      port2.setVertex(true);

      graph.addCell(port1, v1);
      graph.addCell(port2, v1);

      Object v2 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30);
View Full Code Here

TOP

Related Classes of com.mxgraph.model.mxCell

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.