Examples of mxCircleLayout


Examples of com.mxgraph.layout.mxCircleLayout

          }
        };
      }
      else if (ident.equals("circleLayout"))
      {
        layout = new mxCircleLayout(graph);
      }
    }

    return layout;
  }
View Full Code Here

Examples of com.mxgraph.layout.mxCircleLayout

          }
        };
      }
      else if (ident.equals("circleLayout"))
      {
        layout = new mxCircleLayout(graph);
      }
    }

    return layout;
  }
View Full Code Here

Examples of com.mxgraph.layout.mxCircleLayout

            configAnalysisGraph(graph, generator, props);

            generator.getNullGraph(aGraph, nodeCount);

            mxGraphStructure.setDefaultGraphStyle(aGraph, false);
            mxCircleLayout layout = new mxCircleLayout(graph);
            layout.execute(graph.getDefaultParent());
          }
          else if (graphType2 == GraphType.SIMPLE_RANDOM_TREE)
          {
            graph.getModel().beginUpdate();

            mxGraphGenerator generator = new mxGraphGenerator(mxGraphGenerator.getGeneratorFunction(graph, false, 0, 10),
                new mxDoubleValCostFunction());
            Map<String, Object> props = new HashMap<String, Object>();
            mxGraphProperties.setDirected(props, false);
            configAnalysisGraph(graph, generator, props);

            generator.getSimpleRandomTree(aGraph, nodeCount);

            mxGraphProperties.setDirected(props, true);
            mxGraphStructure.setDefaultGraphStyle(aGraph, false);
            setVisible(false);
            mxCompactTreeLayout layout = new mxCompactTreeLayout(graph, false);
            layout.execute(graph.getDefaultParent());
            graph.getModel().endUpdate();
          }

          graph.getModel().endUpdate();
          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.COMPLETE)
    {
      JPanel panel = new JPanel(new GridLayout(5, 1, 4, 4));
      panel.add(new JLabel("Number of nodes"));
      panel.add(numNodesField);
      panel.add(arrowsBox = new JCheckBox("Directed", false));
      panel.add(weightedBox = new JCheckBox("Weighted", false));
      panel.add(new JLabel("Min. weight"));
      panel.add(minWeightField);
      panel.add(new JLabel("Max. weight"));
      panel.add(maxWeightField);

      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int vertexNumParam = Integer.parseInt(numNodesField.getText());
          int minWeightParam = Integer.parseInt(minWeightField.getText());
          int maxWeightParam = Integer.parseInt(maxWeightField.getText());
          graph.getModel().beginUpdate();

          graph.selectAll();
          graph.removeCells();
          mxGraphGenerator generator = new mxGraphGenerator(mxGraphGenerator.getGeneratorFunction(graph, weighted,
              minWeightParam, maxWeightParam), new mxDoubleValCostFunction());
          Map<String, Object> props = new HashMap<String, Object>();
          mxGraphProperties.setDirected(props, arrows);
          configAnalysisGraph(graph, generator, props);

          generator.getCompleteGraph(aGraph, vertexNumParam);

          mxGraphStructure.setDefaultGraphStyle(aGraph, false);
          setVisible(false);
          mxCircleLayout layout = new mxCircleLayout(graph);
          layout.execute(graph.getDefaultParent());
          graph.getModel().endUpdate();
        }
      });
      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.FULL_WINDMILL || graphType2 == GraphType.FRIENDSHIP_WINDMILL)
    {
      JPanel panel = new JPanel(new GridLayout(6, 1, 4, 4));
      panel.add(new JLabel("Number of branches"));
      panel.add(numBranchesField);
      panel.add(new JLabel("Number of vertexes per branch"));
      panel.add(numVertexesInBranchField);
      panel.add(arrowsBox = new JCheckBox("Directed", false));
      panel.add(weightedBox = new JCheckBox("Weighted", false));
      panel.add(new JLabel("Min. weight"));
      panel.add(minWeightField);
      panel.add(new JLabel("Max. weight"));
      panel.add(maxWeightField);

      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          graph.selectAll();
          graph.removeCells();
          int minWeightParam = Integer.parseInt(minWeightField.getText());
          int maxWeightParam = Integer.parseInt(maxWeightField.getText());
          int numBranchesParam = Integer.parseInt(numBranchesField.getText());
          int numVertexesInBranchParam = Integer.parseInt(numVertexesInBranchField.getText());
          Map<String, Object> props = new HashMap<String, Object>();
          mxGraphProperties.setDirected(props, arrows);
          mxGraphGenerator generator = new mxGraphGenerator(mxGraphGenerator.getGeneratorFunction(graph, weighted,
              minWeightParam, maxWeightParam), new mxDoubleValCostFunction());
          configAnalysisGraph(graph, generator, props);

          if (graphType2 == GraphType.FRIENDSHIP_WINDMILL)
          {
            generator.getFriendshipWindmillGraph(aGraph, numBranchesParam, numVertexesInBranchParam);
          }
          else if (graphType2 == GraphType.FULL_WINDMILL)
          {
            generator.getWindmillGraph(aGraph, numBranchesParam, numVertexesInBranchParam);
          }

          generator.setWindmillGraphLayout(aGraph, numBranchesParam, numVertexesInBranchParam, 1000);
          mxGraphStructure.setDefaultGraphStyle(aGraph, false);
          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.WHEEL) || (graphType2 == GraphType.STAR) || (graphType2 == GraphType.PATH))
    {
      JPanel panel = new JPanel(new GridLayout(5, 1, 4, 4));
      panel.add(new JLabel("Number of nodes"));
      panel.add(numNodesField);
      panel.add(arrowsBox = new JCheckBox("Directed", false));
      panel.add(weightedBox = new JCheckBox("Weighted", false));
      panel.add(new JLabel("Min. weight"));
      panel.add(minWeightField);
      panel.add(new JLabel("Max. weight"));
      panel.add(maxWeightField);

      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int numNodesParam = Integer.parseInt(numNodesField.getText());
          int minWeightParam = Integer.parseInt(minWeightField.getText());
          int maxWeightParam = Integer.parseInt(maxWeightField.getText());
          Map<String, Object> props = new HashMap<String, Object>();
          mxGraphProperties.setDirected(props, arrows);
          mxGraphGenerator generator = new mxGraphGenerator(mxGraphGenerator.getGeneratorFunction(graph, weighted,
              minWeightParam, maxWeightParam), new mxDoubleValCostFunction());
          configAnalysisGraph(graph, generator, props);
          graph.getModel().beginUpdate();
          graph.selectAll();
          graph.removeCells();

          if (graphType2 == GraphType.WHEEL)
          {
            generator.getWheelGraph(aGraph, numNodesParam);
            generator.setStarGraphLayout(aGraph, 400);
          }
          else if (graphType2 == GraphType.STAR)
          {
            generator.getStarGraph(aGraph, numNodesParam);
            generator.setStarGraphLayout(aGraph, 400);
          }
          else if (graphType2 == GraphType.PATH)
          {
            generator.getPathGraph(aGraph, numNodesParam);
            generator.setPathGraphSpacing(aGraph, 80);
          }

          mxGraphStructure.setDefaultGraphStyle(aGraph, false);
          setVisible(false);
          graph.getModel().endUpdate();
        }
      });

      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.PETERSEN)
    {
      JPanel panel = new JPanel(new GridLayout(4, 1, 4, 4));
      panel.add(arrowsBox = new JCheckBox("Directed", false));
      panel.add(weightedBox = new JCheckBox("Weighted", false));
      panel.add(new JLabel("Min. weight"));
      panel.add(minWeightField);
      panel.add(new JLabel("Max. weight"));
      panel.add(maxWeightField);

      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int minWeightParam = Integer.parseInt(minWeightField.getText());
          int maxWeightParam = Integer.parseInt(maxWeightField.getText());
          Map<String, Object> props = new HashMap<String, Object>();
          mxGraphProperties.setDirected(props, arrows);
          mxGraphGenerator generator = new mxGraphGenerator(mxGraphGenerator.getGeneratorFunction(graph, weighted,
              minWeightParam, maxWeightParam), new mxDoubleValCostFunction());
          configAnalysisGraph(graph, generator, props);
          graph.getModel().beginUpdate();
          graph.selectAll();
          graph.removeCells();

          generator.getPetersenGraph(aGraph);
          mxGraphStructure.setDefaultGraphStyle(aGraph, false);
          setVisible(false);
          mxCircleLayout layout = new mxCircleLayout(graph);
          layout.execute(graph.getDefaultParent());

          graph.getModel().endUpdate();
        }
      });
      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.GRID)
    {
      JPanel panel = new JPanel(new GridLayout(3, 2, 4, 4));
      panel.add(new JLabel("Number of rows"));
      panel.add(numRowsField);
      panel.add(new JLabel("Number of columns"));
      panel.add(numColumnsField);
      panel.add(new JLabel("Grid spacing"));
      panel.add(gridSpacingField);
      panel.add(arrowsBox = new JCheckBox("Directed", false));
      panel.add(weightedBox = new JCheckBox("Weighted", false));
      panel.add(new JLabel("Min. weight"));
      panel.add(minWeightField);
      panel.add(new JLabel("Max. weight"));
      panel.add(maxWeightField);

      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int yDim = Integer.parseInt(numRowsField.getText());
          int xDim = Integer.parseInt(numColumnsField.getText());
          int minWeightParam = Integer.parseInt(minWeightField.getText());
          int maxWeightParam = Integer.parseInt(maxWeightField.getText());
          float spacing = Float.parseFloat(gridSpacingField.getText());
          graph.getModel().beginUpdate();
          graph.selectAll();
          graph.removeCells();

          mxGraphGenerator generator = new mxGraphGenerator(mxGraphGenerator.getGeneratorFunction(graph, weighted,
              minWeightParam, maxWeightParam), new mxDoubleValCostFunction());
          Map<String, Object> props = new HashMap<String, Object>();
          mxGraphProperties.setDirected(props, arrows);
          configAnalysisGraph(graph, generator, props);

          generator.getGridGraph(aGraph, xDim, yDim);
          generator.setGridGraphSpacing(aGraph, spacing, spacing, xDim, yDim);

          mxGraphStructure.setDefaultGraphStyle(aGraph, false);
          setVisible(false);
          graph.getModel().endUpdate();
        }
      });

      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.KNIGHT) || (graphType2 == GraphType.KING))
    {
      JPanel panel = new JPanel(new GridLayout(5, 2, 4, 4));
      panel.add(new JLabel("Number of rows"));
      panel.add(numRowsField);
      panel.add(new JLabel("Number of columns"));
      panel.add(numColumnsField);
      panel.add(new JLabel("Grid spacing"));
      panel.add(gridSpacingField);

      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int yDim = Integer.parseInt(numRowsField.getText());
          int xDim = Integer.parseInt(numColumnsField.getText());
          float spacing = Float.parseFloat(gridSpacingField.getText());

          mxGraphGenerator generator = new mxGraphGenerator(null, new mxDoubleValCostFunction());
          Map<String, Object> props = new HashMap<String, Object>();
          mxGraphProperties.setDirected(props, arrows);
          configAnalysisGraph(graph, generator, props);
          graph.getModel().beginUpdate();
          graph.selectAll();
          graph.removeCells();

          if (graphType2 == GraphType.KNIGHT)
          {
            generator.getKnightGraph(aGraph, xDim, yDim);
          }
          else if (graphType2 == GraphType.KING)
          {
            generator.getKingGraph(aGraph, xDim, yDim);
          }

          generator.setGridGraphSpacing(aGraph, spacing, spacing, xDim, yDim);
          mxGraphStructure.setDefaultGraphStyle(aGraph, false);
          setVisible(false);
          graph.getModel().endUpdate();
        }
      });
      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.KNIGHT_TOUR)
    {
      JPanel panel = new JPanel(new GridLayout(4, 2, 4, 4));
      panel.add(new JLabel("Starting node"));
      panel.add(startVertexValueField);
      panel.add(new JLabel("X dimension of chessboard"));
      panel.add(numColumnsField);
      panel.add(new JLabel("Y dimension of chessboard"));
      panel.add(numRowsField);
      panel.add(new JLabel("Grid spacing"));
      panel.add(gridSpacingField);

      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int yDim = Integer.parseInt(numRowsField.getText());
          int xDim = Integer.parseInt(numColumnsField.getText());
          int value = Integer.parseInt(startVertexValueField.getText());
          float spacing = Float.parseFloat(gridSpacingField.getText());
          mxGraphGenerator generator = new mxGraphGenerator(null, new mxDoubleValCostFunction());
          Map<String, Object> props = new HashMap<String, Object>();
          mxGraphProperties.setDirected(props, true);
          configAnalysisGraph(graph, generator, props);
          graph.getModel().beginUpdate();
          graph.selectAll();
          graph.removeCells();

          try
          {
            generator.getKnightTour(aGraph, xDim, yDim, value);
          }
          catch (StructuralException e1)
          {
            System.out.println(e1);
          }

          generator.setGridGraphSpacing(aGraph, spacing, spacing, xDim, yDim);
          mxGraphStructure.setDefaultGraphStyle(aGraph, false);
          setVisible(false);
          graph.getModel().endUpdate();
        }
      });
      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.BIPARTITE) || (graphType2 == GraphType.COMPLETE_BIPARTITE))
    {
      JPanel panel = new JPanel(new GridLayout(3, 2, 4, 4));
      panel.add(new JLabel("Number of vertexes in group 1"));
      panel.add(numVertexesLeftField);
      panel.add(new JLabel("Number of vertexes in group 2"));
      panel.add(numVertexesRightField);
      panel.add(new JLabel("Group spacing"));
      panel.add(groupSpacingField);
      panel.add(arrowsBox = new JCheckBox("Directed", false));
      panel.add(weightedBox = new JCheckBox("Weighted", false));
      panel.add(new JLabel("Min. weight"));
      panel.add(minWeightField);
      panel.add(new JLabel("Max. weight"));
      panel.add(maxWeightField);

      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int leftNodeCount = Integer.parseInt(numVertexesLeftField.getText());
          int rightNodeCount = Integer.parseInt(numVertexesRightField.getText());
          float spacing = Float.parseFloat(groupSpacingField.getText());
          int minWeightParam = Integer.parseInt(minWeightField.getText());
          int maxWeightParam = Integer.parseInt(maxWeightField.getText());
          mxGraphGenerator generator = new mxGraphGenerator(mxGraphGenerator.getGeneratorFunction(graph, weighted,
              minWeightParam, maxWeightParam), new mxDoubleValCostFunction());
          Map<String, Object> props = new HashMap<String, Object>();
          mxGraphProperties.setDirected(props, arrows);
          configAnalysisGraph(graph, generator, props);
          graph.getModel().beginUpdate();
          graph.selectAll();
          graph.removeCells();

          if (graphType2 == GraphType.BIPARTITE)
          {
            generator.getBipartiteGraph(aGraph, leftNodeCount, rightNodeCount);
          }
          else if (graphType2 == GraphType.COMPLETE_BIPARTITE)
          {
            generator.getCompleteBipartiteGraph(aGraph, leftNodeCount, rightNodeCount);
          }

          generator.setBipartiteGraphSpacing(aGraph, leftNodeCount, rightNodeCount, spacing, spacing * 2);
          mxGraphStructure.setDefaultGraphStyle(aGraph, false);
          setVisible(false);
          graph.getModel().endUpdate();
        }
      });

      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.SIMPLE_RANDOM)
    {
      JPanel panel = new JPanel(new GridLayout(15, 2, 4, 4));
      panel.add(new JLabel("Number of nodes"));
      panel.add(numNodesField);
      panel.add(new JLabel("Number of edges"));
      panel.add(numEdgesField);
      panel.add(arrowsBox = new JCheckBox("Directed", false));
      panel.add(weightedBox = new JCheckBox("Weighted", false));
      panel.add(new JLabel("Min. weight"));
      panel.add(minWeightField);
      panel.add(new JLabel("Max. weight"));
      panel.add(maxWeightField);
      panel.add(selfLoopBox = new JCheckBox("Allow self-loops", false));
      panel.add(multipleEdgeBox = new JCheckBox("Allow multiple edges", false));
      panel.add(forceConnectedBox = new JCheckBox("Always connected (edge count may be inaccurate)", false));
      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int nodeCount = Integer.parseInt(numNodesField.getText());
          int edgeCount = Integer.parseInt(numEdgesField.getText());
          int minWeightParam = Integer.parseInt(minWeightField.getText());
          int maxWeightParam = Integer.parseInt(maxWeightField.getText());
          Map<String, Object> props = new HashMap<String, Object>();
          mxGraphProperties.setDirected(props, arrows);
          mxGraphGenerator generator = new mxGraphGenerator(mxGraphGenerator.getGeneratorFunction(graph, weighted,
              minWeightParam, maxWeightParam), new mxDoubleValCostFunction());
          configAnalysisGraph(graph, generator, props);
          graph.getModel().beginUpdate();
          graph.selectAll();
          graph.removeCells();

          generator.getSimpleRandomGraph(aGraph, nodeCount, edgeCount, allowSelfLoops, allowMultipleEdges, forceConnected);

          mxGraphStructure.setDefaultGraphStyle(aGraph, false);
          mxOrganicLayout layout = new mxOrganicLayout(graph);
          layout.execute(graph.getDefaultParent());
          graph.getModel().endUpdate();
          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);
    }
    else if (graphType2 == GraphType.RESET_STYLE)
    {
      JPanel panel = new JPanel(new GridLayout(4, 2, 4, 4));
      panel.add(arrowsBox = new JCheckBox("Directed", false));
      panel.add(weightedBox = new JCheckBox("Weighted", false));
      panel.add(new JLabel("Min. weight"));
      panel.add(minWeightField);
      panel.add(new JLabel("Max. weight"));
      panel.add(maxWeightField);
      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("Generate");
      JButton closeButton = new JButton("Cancel");
      buttonPanel.add(closeButton);
      buttonPanel.add(applyButton);
      getRootPane().setDefaultButton(applyButton);

      applyButton.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int minWeightParam = Integer.parseInt(minWeightField.getText());
          int maxWeightParam = Integer.parseInt(maxWeightField.getText());
          Map<String, Object> props = aGraph.getProperties();
          mxGraphProperties.setDirected(props, arrows);
          mxGraphGenerator generator = new mxGraphGenerator(mxGraphGenerator.getGeneratorFunction(graph, weighted,
              minWeightParam, maxWeightParam), new mxDoubleValCostFunction());
          configAnalysisGraph(graph, generator, props);
          graph.getModel().beginUpdate();

          mxGraphStructure.setDefaultGraphStyle(aGraph, true);

          graph.getModel().endUpdate();
          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.BFS_DIR) || (graphType2 == GraphType.DFS_DIR) || (graphType2 == GraphType.BFS_UNDIR)
        || (graphType2 == GraphType.DFS_UNDIR) || (graphType2 == GraphType.MAKE_TREE_DIRECTED)
        || (graphType2 == GraphType.INDEGREE) || (graphType2 == GraphType.OUTDEGREE) || (graphType2 == GraphType.IS_CUT_VERTEX))
    {
      JPanel panel = new JPanel(new GridLayout(1, 2, 4, 4));
      panel.add(new JLabel("Starting vertex"));
      panel.add(startVertexValueField);
      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()
      {
        public void actionPerformed(ActionEvent e)
        {
          applyValues();
          int value = Integer.parseInt(startVertexValueField.getText());
          Object startVertex = mxGraphStructure.getVertexWithValue(aGraph, value);

          if(startVertex == null)
          {
            System.out.println("The specified vertex is not in the graph.");
          }
          else if (graphType2 == GraphType.BFS_DIR)
          {
            boolean oldDir = mxGraphProperties.isDirected(aGraph.getProperties(), mxGraphProperties.DEFAULT_DIRECTED);
            mxGraphProperties.setDirected(aGraph.getProperties(), true);
            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_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);
View Full Code Here

Examples of com.mxgraph.layout.mxCircleLayout

    @Override
    public Object getLayout(IGraphView view) {
      if (view instanceof JGraphView) {
        JGraphView jgraphview = (JGraphView) view;
        mxCircleLayout layout = new mxCircleLayout(jgraphview.getGraph());
        layout.setDisableEdgeStyle(false);
        if (super.settings.get(RADIUS) instanceof Double) {
          layout.setRadius((Double)super.settings.get(RADIUS));       
        }

        return layout;
      }     
      return null;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.