diff --git a/Graph/.idea/workspace.xml b/Graph/.idea/workspace.xml
index 144e264..48bd106 100644
--- a/Graph/.idea/workspace.xml
+++ b/Graph/.idea/workspace.xml
@@ -12,99 +12,141 @@
-
-
+
+
-
-
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
-
-
+
-
-
+
+
-
-
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
+
+
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
@@ -127,10 +169,48 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -144,19 +224,17 @@
-
-
-
-
+
+
+
+
+
-
-
-
@@ -173,30 +251,66 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
@@ -213,10 +327,20 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
@@ -228,9 +352,11 @@
+
+
@@ -248,12 +374,19 @@
1530258857287
-
+
+
+
+
+
+
+
+
-
+
@@ -261,32 +394,32 @@
-
+
-
+
-
-
-
+
+
+
-
+
-
-
+
+
@@ -295,171 +428,298 @@
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
-
-
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
+
+
+
+
-
-
+
+
+
+
+
-
+
-
-
+
+
-
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
-
-
-
+
+
+
+
+
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Graph/out/production/Graph/Meny/MainFrame/Launcher.class b/Graph/out/production/Graph/Meny/MainFrame/Launcher.class
new file mode 100644
index 0000000..13c8d33
Binary files /dev/null and b/Graph/out/production/Graph/Meny/MainFrame/Launcher.class differ
diff --git a/Graph/out/production/Graph/Meny/MainFrame/Panels/ControllPanel.class b/Graph/out/production/Graph/Meny/MainFrame/Panels/ControllPanel.class
new file mode 100644
index 0000000..a60fe6c
Binary files /dev/null and b/Graph/out/production/Graph/Meny/MainFrame/Panels/ControllPanel.class differ
diff --git a/Graph/out/production/Graph/Meny/MainFrame/Panels/EditPanel.class b/Graph/out/production/Graph/Meny/MainFrame/Panels/EditPanel.class
new file mode 100644
index 0000000..98d9290
Binary files /dev/null and b/Graph/out/production/Graph/Meny/MainFrame/Panels/EditPanel.class differ
diff --git a/Graph/out/production/Graph/Meny/MainFrame/Panels/MainWindow.class b/Graph/out/production/Graph/Meny/MainFrame/Panels/MainWindow.class
new file mode 100644
index 0000000..876c71c
Binary files /dev/null and b/Graph/out/production/Graph/Meny/MainFrame/Panels/MainWindow.class differ
diff --git a/Graph/out/production/Graph/Meny/MainFrame/Panels/View.class b/Graph/out/production/Graph/Meny/MainFrame/Panels/View.class
new file mode 100644
index 0000000..861131f
Binary files /dev/null and b/Graph/out/production/Graph/Meny/MainFrame/Panels/View.class differ
diff --git a/Graph/out/production/Graph/Meny/MainFrame/SwingGraphics.class b/Graph/out/production/Graph/Meny/MainFrame/SwingGraphics.class
new file mode 100644
index 0000000..c78249b
Binary files /dev/null and b/Graph/out/production/Graph/Meny/MainFrame/SwingGraphics.class differ
diff --git a/Graph/out/production/Graph/Meny/controller/Algorithm.class b/Graph/out/production/Graph/Meny/controller/Algorithm.class
new file mode 100644
index 0000000..45f5b58
Binary files /dev/null and b/Graph/out/production/Graph/Meny/controller/Algorithm.class differ
diff --git a/Graph/out/production/Graph/Meny/controller/ChangeListener.class b/Graph/out/production/Graph/Meny/controller/ChangeListener.class
new file mode 100644
index 0000000..0d7c568
Binary files /dev/null and b/Graph/out/production/Graph/Meny/controller/ChangeListener.class differ
diff --git a/Graph/out/production/Graph/Meny/controller/FindBridge.class b/Graph/out/production/Graph/Meny/controller/FindBridge.class
new file mode 100644
index 0000000..b9d720e
Binary files /dev/null and b/Graph/out/production/Graph/Meny/controller/FindBridge.class differ
diff --git a/Graph/out/production/Graph/Meny/model/Edge.class b/Graph/out/production/Graph/Meny/model/Edge.class
new file mode 100644
index 0000000..50cd7eb
Binary files /dev/null and b/Graph/out/production/Graph/Meny/model/Edge.class differ
diff --git a/Graph/out/production/Graph/Meny/model/Graph.class b/Graph/out/production/Graph/Meny/model/Graph.class
new file mode 100644
index 0000000..c01a7da
Binary files /dev/null and b/Graph/out/production/Graph/Meny/model/Graph.class differ
diff --git a/Graph/out/production/Graph/Meny/model/Node.class b/Graph/out/production/Graph/Meny/model/Node.class
new file mode 100644
index 0000000..c5aa1fd
Binary files /dev/null and b/Graph/out/production/Graph/Meny/model/Node.class differ
diff --git a/Graph/out/production/Graph/Meny/model/NodeFactory.class b/Graph/out/production/Graph/Meny/model/NodeFactory.class
new file mode 100644
index 0000000..f5649c2
Binary files /dev/null and b/Graph/out/production/Graph/Meny/model/NodeFactory.class differ
diff --git a/Graph/out/production/Graph/Meny/model/SimpleNode.class b/Graph/out/production/Graph/Meny/model/SimpleNode.class
new file mode 100644
index 0000000..43073aa
Binary files /dev/null and b/Graph/out/production/Graph/Meny/model/SimpleNode.class differ
diff --git a/Graph/out/production/Graph/Meny/view/DrawEdge.class b/Graph/out/production/Graph/Meny/view/DrawEdge.class
new file mode 100644
index 0000000..59e39da
Binary files /dev/null and b/Graph/out/production/Graph/Meny/view/DrawEdge.class differ
diff --git a/Graph/out/production/Graph/Meny/view/DrawGraph.class b/Graph/out/production/Graph/Meny/view/DrawGraph.class
new file mode 100644
index 0000000..b2cfa10
Binary files /dev/null and b/Graph/out/production/Graph/Meny/view/DrawGraph.class differ
diff --git a/Graph/out/production/Graph/Meny/view/DrawNode.class b/Graph/out/production/Graph/Meny/view/DrawNode.class
new file mode 100644
index 0000000..024569b
Binary files /dev/null and b/Graph/out/production/Graph/Meny/view/DrawNode.class differ
diff --git a/Graph/out/production/Graph/Meny/view/Graphics.class b/Graph/out/production/Graph/Meny/view/Graphics.class
new file mode 100644
index 0000000..68eb863
Binary files /dev/null and b/Graph/out/production/Graph/Meny/view/Graphics.class differ
diff --git a/Graph/out/production/Graph/Meny/view/SimpleFigures/Circle.class b/Graph/out/production/Graph/Meny/view/SimpleFigures/Circle.class
new file mode 100644
index 0000000..c233756
Binary files /dev/null and b/Graph/out/production/Graph/Meny/view/SimpleFigures/Circle.class differ
diff --git a/Graph/out/production/Graph/Meny/view/SimpleFigures/Line.class b/Graph/out/production/Graph/Meny/view/SimpleFigures/Line.class
new file mode 100644
index 0000000..5107707
Binary files /dev/null and b/Graph/out/production/Graph/Meny/view/SimpleFigures/Line.class differ
diff --git a/Graph/out/production/Graph/Meny/view/SimpleFigures/Point.class b/Graph/out/production/Graph/Meny/view/SimpleFigures/Point.class
new file mode 100644
index 0000000..a1f141f
Binary files /dev/null and b/Graph/out/production/Graph/Meny/view/SimpleFigures/Point.class differ
diff --git a/Graph/src/DrawClass.java b/Graph/src/DrawClass.java
deleted file mode 100644
index 2cb9573..0000000
--- a/Graph/src/DrawClass.java
+++ /dev/null
@@ -1,68 +0,0 @@
-import Graphpcg.*;
-
-import javax.swing.JFrame;
-
-import com.mxgraph.swing.mxGraphComponent;
-import com.mxgraph.view.mxGraph;
-
-import java.util.ArrayList;
-import java.util.Random;
-
-
-public class DrawClass extends JFrame {
-
- public DrawClass(Graph NodesGraph) {
-
- super("Hello, World!");
-
- Random rnd = new Random(System.currentTimeMillis());
- mxGraph graph = new mxGraph();
- Object parent = graph.getDefaultParent();
-
- graph.getModel().beginUpdate();
- ArrayList nodes = NodesGraph.getNodes();
- int i = 1;
- try
- {
- for(SimpleNode node: nodes) {
-
- Object obj = graph.insertVertex(parent, null, node.getName(),
- (rnd.nextInt(500 - 100 + 1)),
- (rnd.nextInt(500 - 100 + 1)),
- 60,60,"shape=ellipse;perimeter=ellipsePerimeter");
- node.setPictrue(obj);
- ++i;
- }
- for(SimpleNode node: nodes) {
-
- for(Edge edge: node.getEdgesList()) {
-
- if(node.equals(edge.getSourceNode()))
- graph.insertEdge(parent, null, "", node.getPictrue(),edge.getDestNode().getPictrue());
- }
- }
- }
- finally
- {
- graph.getModel().endUpdate();
- }
-
- mxGraphComponent graphComponent = new mxGraphComponent(graph);
- getContentPane().add(graphComponent);
-}
-
- public static void main(String[] args)
- {
-
- Graph NodeGraph = new Graph(SimpleNode::new);
- NodeGraph.addNode("First");
- NodeGraph.addNode("Second");
- NodeGraph.addNode("Third");
- NodeGraph.ConnectNodes("First","Second");
- NodeGraph.ConnectNodes("First","Third");
- DrawClass frame = new DrawClass(NodeGraph);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(1200, 800);
- frame.setVisible(true);
- }
-}
diff --git a/Graph/src/Meny/MainFrame/Launcher.java b/Graph/src/Meny/MainFrame/Launcher.java
new file mode 100644
index 0000000..399e301
--- /dev/null
+++ b/Graph/src/Meny/MainFrame/Launcher.java
@@ -0,0 +1,79 @@
+package Meny.MainFrame;
+
+import Meny.MainFrame.Panels.ControllPanel;
+import Meny.MainFrame.Panels.EditPanel;
+import Meny.MainFrame.Panels.MainWindow;
+import Meny.controller.FindBridge;
+import Meny.model.*;
+import Meny.view.DrawGraph;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class Launcher extends JFrame {
+
+ private MainWindow mainWindow;
+
+ public static void main(String[] args) {
+ SwingUtilities.invokeLater(() -> new Launcher().setVisible(true));
+ }
+
+ private Launcher() {
+
+ mainWindow = new MainWindow();
+ mainWindow.setSize(new Dimension(800, 600));
+ mainWindow.setMaximumSize(new Dimension(600, 600));
+ setSize(new Dimension(800, 600));
+ setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ setLayout(new BorderLayout());
+ setContentPane(mainWindow);
+ pack();
+ setLocationRelativeTo(null);
+ init();
+ }
+
+ private void init() {
+
+ mainWindow.setNameForControlPanel("Find Bridges Algorithm");
+ Graph NodeGraph = new Graph<>(SimpleNode::new);
+// NodeGraph.addNode("Могилев");
+// NodeGraph.addNode("Минск");
+// NodeGraph.addNode("Витебск");
+// NodeGraph.addNode("Гомель");
+//
+// NodeGraph.addNode("Санкт-Петербург");
+// NodeGraph.addNode("Москва");
+// NodeGraph.addNode("Архангельск");
+//
+// NodeGraph.addNode("New-York");
+// NodeGraph.addNode("LosAngeles");
+//
+//
+// NodeGraph.ConnectNodes("Могилев","Минск");
+// NodeGraph.ConnectNodes("Могилев","Гомель");
+// NodeGraph.ConnectNodes("Могилев","Витебск");
+// NodeGraph.ConnectNodes("Минск","Витебск");
+// NodeGraph.ConnectNodes("Минск","New-York");
+// NodeGraph.ConnectNodes("LosAngeles","New-York");
+// NodeGraph.ConnectNodes("Санкт-Петербург","Витебск");
+// NodeGraph.ConnectNodes("Санкт-Петербург","Москва");
+// NodeGraph.ConnectNodes("Санкт-Петербург","Архангельск");
+// NodeGraph.ConnectNodes("Москва","Архангельск");
+ FindBridge findBridge = new FindBridge(NodeGraph);
+ EditPanel edit = mainWindow.getEditPanel();
+ findBridge.setDrawClass(mainWindow);
+ findBridge.setFrame(this);
+ mainWindow.getEditPanel().setGraph(NodeGraph);
+ findBridge.setEditor(mainWindow.getEditPanel());
+ edit.addBuildButtonListener(e -> findBridge.buildGraph(edit.getTextArea()));
+ edit.addEditNodeButtonListener(e -> findBridge.AddNode(edit.getEditNode(), edit.getConnection()));
+ edit.addRemoveNodeButtonListener(e -> findBridge.DeleteNode(edit.getEditNode()));
+ edit.addEditConnectionButtonListener(e -> findBridge.addConnection(edit.getFirstSelected(), edit.getSeconsSelected()));
+ edit.addRemoveConnectionButtonListener(e -> findBridge.deleteConnection(edit.getFirstSelected(), edit.getDeleteSelected()));
+
+ ControllPanel control = mainWindow.getControllPanel();
+
+ control.addAlgButtonListener(e -> findBridge.FindBridges(control.getRun_by_step()));
+ control.addManualButtonListener(e-> findBridge.ManualStep());
+ }
+}
diff --git a/Graph/src/Meny/MainFrame/Panels/ControllPanel.java b/Graph/src/Meny/MainFrame/Panels/ControllPanel.java
new file mode 100644
index 0000000..4a2b80d
--- /dev/null
+++ b/Graph/src/Meny/MainFrame/Panels/ControllPanel.java
@@ -0,0 +1,70 @@
+package Meny.MainFrame.Panels;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionListener;
+
+public class ControllPanel extends JPanel {
+
+ private final JButton run_algorithm = new JButton("Start algorithm");
+ private final JButton run_manual = new JButton("Start manually");
+ private JCheckBox run_by_step = new JCheckBox("Step by step solution");
+ private JLabel algorithm_name = new JLabel();
+ private GridBagLayout layout = new GridBagLayout();
+ private GridBagConstraints constraints = new GridBagConstraints();
+
+ public ControllPanel() {
+
+ super(null);
+ initConstrains();
+ setLayout(layout);
+ add(algorithm_name, constraints);
+ add(run_algorithm, constraints);
+ add(run_manual, constraints);
+ add(run_by_step,constraints);
+ }
+
+ public ControllPanel(String name) {
+
+ super(null);
+ initConstrains();
+ setLayout(layout);
+ setAlgorithmName(name);
+ add(algorithm_name, constraints);
+ add(run_algorithm, constraints);
+ add(run_manual, constraints);
+ add(run_by_step,constraints);
+ }
+
+ private void initConstrains() {
+
+ constraints.anchor = GridBagConstraints.NORTH;
+ constraints.fill = GridBagConstraints.BOTH;
+ constraints.gridheight = 1;
+ constraints.gridwidth = GridBagConstraints.REMAINDER;
+ constraints.gridx = GridBagConstraints.RELATIVE;
+ constraints.gridy = GridBagConstraints.RELATIVE;
+ constraints.insets = new Insets(1, 2, 3, 4);
+ constraints.ipadx = 0;
+ constraints.ipady = 0;
+ constraints.weightx = 0.0;
+ constraints.weighty = 0.0;
+ }
+
+ public void addAlgButtonListener(ActionListener listener) {
+ run_algorithm.addActionListener(listener);
+ }
+
+ public void addManualButtonListener(ActionListener listener) {
+ run_manual.addActionListener(listener);
+ }
+
+ public boolean getRun_by_step() {
+ return run_by_step.isSelected();
+ }
+
+ void setAlgorithmName(String name) {
+
+ algorithm_name.setText(name);
+ }
+}
diff --git a/Graph/src/Meny/MainFrame/Panels/EditPanel.java b/Graph/src/Meny/MainFrame/Panels/EditPanel.java
new file mode 100644
index 0000000..92965fd
--- /dev/null
+++ b/Graph/src/Meny/MainFrame/Panels/EditPanel.java
@@ -0,0 +1,137 @@
+package Meny.MainFrame.Panels;
+
+import Meny.controller.ChangeListener;
+import Meny.model.Edge;
+import Meny.model.Graph;
+import Meny.model.Node;
+import Meny.model.SimpleNode;
+import com.sun.org.apache.bcel.internal.generic.SIPUSH;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+
+public class EditPanel extends JPanel {
+
+ private JLabel name_label = new JLabel("Redact Area");
+ private JTextArea list_area = new JTextArea();
+ private JTextField sourse_node_name = new JTextField();
+ private JTextField connection = new JTextField();
+ private JComboBox sourse_list = new JComboBox<>();
+ private JComboBox other_sourse_list = new JComboBox<>();
+ private JComboBox dest_list = new JComboBox<>();
+
+ private JButton build_graph_button = new JButton("Build Graph");
+ private JButton edit_node_button = new JButton("Add Node");
+ private JButton remove_node_button = new JButton("Delete Node");
+
+ private JButton addConnectionButton = new JButton("Add Edge");
+ private JButton removeConnectionButton = new JButton("Delete Edge");
+
+ private GridBagLayout layout = new GridBagLayout();
+ private GridBagConstraints constraints = new GridBagConstraints();
+
+ private Graph graph;
+
+ public EditPanel() {
+
+ super(null);
+ initConstrains();
+ setLayout(layout);
+ name_label.setMaximumSize(new Dimension(Integer.MAX_VALUE, name_label.getMinimumSize().height));
+ add(name_label, constraints);
+ list_area.setPreferredSize(new Dimension(220, 200));
+ add(list_area, constraints);
+ add(build_graph_button, constraints);
+ add(new JLabel("Isert:Source node name"),constraints);
+ add(sourse_node_name, constraints);
+ add(new JLabel("Isert:List of neighbors nodes"),constraints);
+ add(connection, constraints);
+ add(edit_node_button, constraints);
+ add(remove_node_button, constraints);
+ add(new JLabel("Source node name"),constraints);
+ add(sourse_list, constraints);
+ add(new JLabel("Dest node name"),constraints);
+ add(other_sourse_list, constraints);
+ add(new JLabel("List of neighbors nodes"),constraints);
+ add(dest_list, constraints);
+ add(addConnectionButton, constraints);
+ add(removeConnectionButton,constraints);
+ }
+
+ public String[] getTextArea() {
+ if(!list_area.getText().isEmpty())
+ return list_area.getText().split("\\n");
+ return null;
+ }
+
+ public String getEditNode() {return sourse_node_name.getText();}
+
+ public String[] getConnection() {
+ if(!connection.getText().isEmpty())
+ return connection.getText().split("\\W");
+ return null;
+ }
+
+ public String getFirstSelected() {return sourse_list.getSelectedItem().toString();}
+
+ public String getDeleteSelected() {return dest_list.getSelectedItem().toString();}
+
+ public String getSeconsSelected() {return other_sourse_list.getSelectedItem().toString();}
+
+ public void setGraph(Graph g) {
+ graph = g;
+ sourse_list.removeAllItems();
+ other_sourse_list.removeAllItems();
+ ArrayList nodes = graph.getNodes();
+ for (SimpleNode node :nodes) {
+ sourse_list.addItem(node.getName());
+ other_sourse_list.addItem(node.getName());
+ }
+ ChangeListener listener = new ChangeListener(this);
+ sourse_list.addItemListener(listener);
+ }
+
+ public void updateBox() {
+ String s = getFirstSelected();
+ dest_list.removeAllItems();
+ SimpleNode node = (SimpleNode)graph.findByName(s);
+ for(Edge ed:node.getEdgesList()) {
+ dest_list.addItem(ed.getDestNode().getName());
+ }
+ }
+
+ private void initConstrains() {
+ constraints.anchor = GridBagConstraints.WEST;
+ constraints.fill = GridBagConstraints.BOTH;
+ constraints.gridheight = 1;
+ constraints.gridwidth = 1;
+ constraints.gridx = 0;
+ constraints.gridy = GridBagConstraints.RELATIVE;
+ constraints.insets = new Insets(2, 2, 2, 2);
+ constraints.ipadx = 0;
+ constraints.ipady = 0;
+ constraints.weightx = 0.0;
+ constraints.weighty = 0.0;
+ }
+
+ public void addBuildButtonListener(ActionListener listener) {
+ build_graph_button.addActionListener(listener);
+ }
+
+ public void addEditNodeButtonListener(ActionListener listener) {
+ edit_node_button.addActionListener(listener);
+ }
+
+ public void addRemoveNodeButtonListener(ActionListener listener) {
+ remove_node_button.addActionListener(listener);
+ }
+
+ public void addEditConnectionButtonListener(ActionListener listener) {
+ addConnectionButton.addActionListener(listener);
+ }
+ public void addRemoveConnectionButtonListener(ActionListener listener) {
+ removeConnectionButton.addActionListener(listener);
+ }
+}
diff --git a/Graph/src/Meny/MainFrame/Panels/MainWindow.java b/Graph/src/Meny/MainFrame/Panels/MainWindow.java
new file mode 100644
index 0000000..db4c43e
--- /dev/null
+++ b/Graph/src/Meny/MainFrame/Panels/MainWindow.java
@@ -0,0 +1,90 @@
+package Meny.MainFrame.Panels;
+
+import javax.swing.*;
+import java.awt.*;
+import Meny.model.*;
+
+public class MainWindow extends JPanel {
+
+ private ControllPanel controll_panel = new ControllPanel();
+ private EditPanel edit_panel = new EditPanel();
+ private View visual_panel;
+ private GridBagLayout layout = new GridBagLayout();
+ private GridBagConstraints constraints = new GridBagConstraints();
+
+ public MainWindow() {
+
+ super(null);
+ initConstrains();
+ visual_panel = new View();
+ setLayout(layout);
+ setPanelSize(edit_panel, new Dimension(240,600));
+ setPanelSize(controll_panel, new Dimension(360,120));
+ visual_panel.setPreferredSize(new Dimension(600,600));
+ // visual_panel.setVisible(true);
+ // setElementSize(1,1);
+ add(edit_panel, constraints);
+ setElementPos(0,1);
+ // setElementSize(1,1);
+ add(controll_panel,constraints);
+ setElementPos(1,0);
+ setElementSize(3,3);
+ add(visual_panel,constraints);
+ }
+
+ public ControllPanel getControllPanel() {
+ return controll_panel;
+ }
+
+ public void setView(View view){
+ visual_panel = view;
+ visual_panel.setVisible(true);
+ setElementPos(1,0);
+ add(visual_panel,constraints);
+ }
+ private void initConstrains() {
+ constraints.anchor = GridBagConstraints.WEST;
+ constraints.fill = GridBagConstraints.HORIZONTAL;
+ constraints.gridheight = 1;
+ constraints.gridwidth = 1;
+ //constraints.gridwidth = GridBagConstraints.REMAINDER;
+ constraints.gridx = 0;
+ constraints.gridy = 0;
+ constraints.insets = new Insets(2, 2, 2, 2);
+ constraints.ipadx = 0;
+ constraints.ipady = 0;
+ constraints.weightx = 1;
+ constraints.weighty = 1;
+ }
+
+ private void setElementPos(int x, int y) {
+
+ constraints.gridx = x;
+ constraints.gridy = y;
+ }
+
+ private void setElementSize(int height, int width) {
+
+ constraints.gridheight = height;
+ constraints.gridwidth = width;
+ }
+
+ public View getVisualPanel() {
+ return visual_panel;
+ }
+
+ public EditPanel getEditPanel() { return edit_panel;}
+
+ public void setNameForControlPanel(String name) {
+
+ controll_panel.setName(name);
+ }
+
+ private void setPanelSize(JPanel panel , Dimension size) {
+ panel.setPreferredSize(size);
+ }
+
+ private void setPanelMinimumSize(JPanel panel , Dimension size) {
+ panel.setMinimumSize(size);
+ }
+}
diff --git a/Graph/src/Meny/MainFrame/Panels/View.java b/Graph/src/Meny/MainFrame/Panels/View.java
new file mode 100644
index 0000000..88d0c4f
--- /dev/null
+++ b/Graph/src/Meny/MainFrame/Panels/View.java
@@ -0,0 +1,76 @@
+package Meny.MainFrame.Panels;
+
+import Meny.model.SimpleNode;
+import Meny.view.*;
+import Meny.view.SimpleFigures.*;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.Graphics;
+import java.util.ArrayList;
+
+public class View extends JPanel {
+
+ private ArrayList lines;
+ private ArrayList circles;
+
+ private Line superline;
+ private Circle superCircle;
+
+ public View() {
+ super(null);
+ lines = new ArrayList<>();
+ circles = new ArrayList<>();
+
+ superline = new Line(50,20,40,100);
+ superCircle = new Circle(40,30,40,40);
+ }
+
+ public void addComponents(ArrayList nodes, ArrayList edges){
+ makeNodesList(nodes);
+ makeEdgeList(edges);
+ repaint();
+ }
+
+ private void makeNodesList(ArrayList nodes) {
+ circles.clear();
+ for(DrawNode node: nodes) {
+ Circle crcl = new Circle(node.getxPos(),node.getyPos(),70);
+ double cx = crcl.getCenterX();
+ double cy = crcl.getCenterY();
+ crcl.name = node.getName();
+ crcl.setColor(node.getColor());
+ circles.add(crcl);
+ }
+ }
+
+ private void makeEdgeList(ArrayList edges) {
+ lines.clear();
+ for(DrawEdge edge: edges) {
+ Line ln = new Line(edge.getStart(),edge.getEnd());
+ ln.setColor(edge.getColor());
+ lines.add(ln);
+ }
+
+ }
+
+ @Override
+ public void paintComponent(Graphics g) {
+
+ Graphics2D g2 = (Graphics2D)g;
+ g2.setStroke(new BasicStroke(3.0f));
+ for(Circle crcl: circles) {
+ g2.setColor(crcl.getColor());
+ g2.draw(crcl);
+ g2.setColor(Color.BLACK);
+ g2.drawString(crcl.name,(int)crcl.getCenterX()-20,(int)crcl.getCenterY());
+ }
+ g2.setStroke(new BasicStroke(2.0f));
+ for(Line ln: lines) {
+ g2.setColor(ln.getColor());
+ g2.draw(ln);
+ g2.setColor(Color.BLACK);
+ }
+ }
+
+}
diff --git a/Graph/src/Meny/MainFrame/Panels/VisualPanel.java b/Graph/src/Meny/MainFrame/Panels/VisualPanel.java
new file mode 100644
index 0000000..f5d7769
--- /dev/null
+++ b/Graph/src/Meny/MainFrame/Panels/VisualPanel.java
@@ -0,0 +1,120 @@
+//package Meny.MainFrame.Panels;
+//
+//import Meny.controller.Algorithmpcg.*;
+//import Meny.model.Edge;
+//import Meny.model.*;
+//
+//import java.util.HashMap;
+//import java.util.Map;
+//
+//import com.mxgraph.util.mxConstants;
+//import com.mxgraph.swing.mxGraphComponent;
+//import com.mxgraph.view.mxStylesheet;
+//import com.mxgraph.view.mxGraph;
+//
+//import javax.swing.*;
+//import java.util.ArrayList;
+//
+//public class VisualPanel extends JPanel {
+//
+// private mxGraph graph;
+// private Object parent;
+//
+// public VisualPanel() {
+//
+// super(null);
+// //getContentPane().add(graphComponent);
+// }
+//
+// public void setGraph(Graph NodesGraph) {
+//
+// graph = new mxGraph();
+// parent = graph.getDefaultParent();
+//
+// graph.getModel().beginUpdate();
+// ArrayList nodes = NodesGraph.getNodes();
+//
+// int i = 1;
+//
+//
+// //value for rotation
+// double k = 360.0 / nodes.size();
+// double PI = 3.14;
+//
+// double Rot = 10;
+//
+// double x = 300; // координаты центра во кргу которого рисуем
+// double y = 250;
+//
+// double x0 = 300;// координаты первой вершины
+// double y0 = 50;
+//
+// double NX;
+// double NY;
+//
+//
+// try {
+// for (SimpleNode node : nodes) {
+// Rot += k;
+// NX = x + (x0 - x) * Math.cos(Rot * PI / 180) - (y0 - y) * Math.sin(Rot * PI / 180);
+// NY = y + (y0 - y) * Math.cos(Rot * PI / 180) + (x0 - x) * Math.sin(Rot * PI / 180) + 13;
+//
+//
+// Object obj = graph.insertVertex(parent, null, node.getName(),
+// (NX),
+// (NY),
+// 60, 60, "shape=ellipse;perimeter=ellipsePerimeter");
+// node.setPictrue(obj);
+// ++i;
+// }
+//
+// /*Стиль для обычного моста*/
+// Map StyleForEdge = new HashMap();
+// StyleForEdge.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR);
+// StyleForEdge.put(mxConstants.STYLE_STROKECOLOR, "#6482B9"); // default is #6482B9
+// mxStylesheet edgeStyle1 = new mxStylesheet();
+// edgeStyle1.setDefaultEdgeStyle(StyleForEdge);
+// graph.setStylesheet(edgeStyle1);
+// /**/
+//
+// for (SimpleNode node : nodes) {
+// for (Edge edge : node.getEdgesList()) {
+// if (node == edge.getDestNode())
+// graph.insertEdge(parent, null, "", node.getPictrue(), edge.getSourceNode().getPictrue());
+// }
+// }
+// } finally {
+// graph.getModel().endUpdate();
+// }
+//
+// mxGraphComponent graphComponent = new mxGraphComponent(graph);
+// add(graphComponent);
+// }
+//
+// public void DrawBriedge(Graph NodesGraph) {
+//
+// Map StyleForBridge = new HashMap();
+// StyleForBridge.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_CONNECTOR);
+// StyleForBridge.put(mxConstants.STYLE_STROKECOLOR, "#ff0000"); // default is #6482B9
+// mxStylesheet edgeStyle = new mxStylesheet();
+// edgeStyle.setDefaultEdgeStyle(StyleForBridge);
+// graph.setStylesheet(edgeStyle);
+//
+//
+// FindBridge a = new FindBridge(NodesGraph);
+// ArrayList Bridges = a.FindBridges();
+// try {
+// for (int i = 0; i < Bridges.size(); i++) {
+// graph.insertEdge(parent, null, "", Bridges.get(i).getSourceNode().getPictrue(), Bridges.get(i).getDestNode().getPictrue());
+//
+// }
+// } finally {
+//
+// }
+//
+// graph.getModel().endUpdate();
+// mxGraphComponent graphComponent = new mxGraphComponent(graph);
+// //getContentPane().add(graphComponent);
+// add(graphComponent);
+// }
+//}
diff --git a/Graph/src/Meny/MainFrame/SwingGraphics.java b/Graph/src/Meny/MainFrame/SwingGraphics.java
new file mode 100644
index 0000000..9ceba34
--- /dev/null
+++ b/Graph/src/Meny/MainFrame/SwingGraphics.java
@@ -0,0 +1,54 @@
+package Meny.MainFrame;
+
+import javax.swing.*;
+import java.awt.*;
+
+import Meny.MainFrame.Panels.View;
+import Meny.view.Graphics;
+
+public class SwingGraphics implements Graphics {
+
+ private final JPanel mainFrame;
+ private final java.awt.Graphics graphics;
+
+ public SwingGraphics(JPanel panel, java.awt.Graphics graphics) {
+ this.mainFrame = panel;
+ this.graphics = graphics;
+ System.out.println(graphics);
+ }
+
+ @Override
+ @SuppressWarnings("SuspiciousNameCombination")
+ public void drawOval(int x, int y, int width, int height, int rgb) {
+
+ Color color = new Color((rgb));
+ System.out.println(mainFrame.getGraphics());
+ View view = new View();
+ view.setPreferredSize(new Dimension(50,50));
+// mainFrame.getGraphics().setColor(Color.BLACK);
+// mainFrame.getGraphics().fillOval(y, x, width, height);
+// Graphics2D g2 = (Graphics2D)graphics;
+// g2.setColor(color);
+// g2.drawLine(0,0,500,500);
+ graphics.setColor(color);
+ // graphics.fillOval(y, x, width, height);
+ graphics.drawRect(50,50,100,100);
+ mainFrame.add(view);
+ view.paintComponents(graphics);
+ }
+
+ @Override
+ public void drawText(int x, int y, String text, int rgb) {
+ char[] symbols = text.toCharArray();
+ graphics.setColor(new Color(rgb));
+ graphics.drawChars(symbols, 0, symbols.length, x, y);
+ }
+
+ @Override
+ public void drawLine(int startX, int startY, int endX, int endY, int rgb) {
+
+ graphics.setColor(new Color(rgb));
+ graphics.drawLine(startX, startY, endX, endY);
+ }
+
+}
diff --git a/Graph/src/Meny/controller/Algorithm.java b/Graph/src/Meny/controller/Algorithm.java
new file mode 100644
index 0000000..ccd8591
--- /dev/null
+++ b/Graph/src/Meny/controller/Algorithm.java
@@ -0,0 +1,14 @@
+package Meny.controller;
+
+import Meny.model.*;
+
+import javax.swing.*;
+import java.util.ArrayList;
+
+public abstract class Algorithm {
+ protected Graph NewGraph;
+ public Graph GetGraph(){return NewGraph;};
+ public void setGraph(Graph A){NewGraph = A;}
+
+ void FindBridge(Graph A){};
+}
diff --git a/Graph/src/Meny/controller/ChangeListener.java b/Graph/src/Meny/controller/ChangeListener.java
new file mode 100644
index 0000000..b4f19e1
--- /dev/null
+++ b/Graph/src/Meny/controller/ChangeListener.java
@@ -0,0 +1,23 @@
+package Meny.controller;
+
+import Meny.MainFrame.Panels.EditPanel;
+
+import javax.swing.*;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+public class ChangeListener implements ItemListener {
+
+ private EditPanel panel;
+ public ChangeListener(EditPanel panel){
+ this.panel = panel;
+ }
+ @Override
+ public void itemStateChanged(ItemEvent event) {
+ JComboBox cb = (JComboBox) event.getSource();
+
+ Object item = event.getItem();
+ if(event.getStateChange() == ItemEvent.SELECTED)
+ panel.updateBox();
+ }
+}
diff --git a/Graph/src/Meny/controller/FindBridge.java b/Graph/src/Meny/controller/FindBridge.java
new file mode 100644
index 0000000..4de7a16
--- /dev/null
+++ b/Graph/src/Meny/controller/FindBridge.java
@@ -0,0 +1,284 @@
+package Meny.controller;
+import Meny.MainFrame.Panels.EditPanel;
+import Meny.MainFrame.Panels.MainWindow;
+import Meny.MainFrame.Panels.View;
+import Meny.model.Edge;
+import Meny.model.*;
+import Meny.view.DrawGraph;
+
+import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.util.ArrayList;
+
+public class FindBridge extends Algorithm {
+
+ /*value required for the algorithm*/
+ private int time = 0;
+ private int S[] ;
+ private int Up[] ;
+ private boolean Res[] ;
+ private EditPanel editor;
+ private DrawGraph drawGraph;
+ private Timer timer;
+ private int flag = -1;
+ private int step;
+ /**/
+
+ private ArrayList nodes ;
+ private ArrayList edgesOfBridge;
+ private ArrayList WayOfbridge;
+ private ArrayList tmpNodes = new ArrayList<>();
+
+ public ArrayList GetWat()
+ {
+ return WayOfbridge;
+ }
+
+ public FindBridge(Graph N)
+ {
+ WayOfbridge = new ArrayList<>();
+ NewGraph = N;
+ nodes = N.getNodes();
+ edgesOfBridge = new ArrayList<>() ;
+ }
+
+ @Override
+ public void setGraph(Graph A) {
+
+ NewGraph = A;
+ nodes = NewGraph.getNodes();
+ if(drawGraph != null)
+ drawGraph.setGraph(A);
+ }
+
+ public void setDrawClass(MainWindow panel) {
+ drawGraph = new DrawGraph(NewGraph);
+ drawGraph.setView(panel);
+ }
+
+ private boolean isBridge(Edge edge,ArrayList list) {
+ String one = edge.getDestNode().getName();
+ String two = edge.getSourceNode().getName();
+ for(int i=0;i graph = new Graph<>(SimpleNode::new);
+ if(list == null)
+ return;
+// if(graph == null) {
+// Graph graph = new Graph<>(SimpleNode::new);
+// setGraph(graph);
+// }
+ ArrayList nodes = new ArrayList<>();
+ for(int i=0; i temp = new ArrayList<>();
+ for (int j = items.length - 1; j >= 0; --j) {
+ if (!graph.checkNode(items[j])) {
+ graph.addNode(items[j]);
+ }
+ if (j == 0) {
+ for (String str : temp) {
+ graph.ConnectNodes(items[0], str);
+ }
+ } else
+ temp.add(items[j]);
+ }
+ temp.clear();
+ }
+ setGraph(graph);
+ editor.setGraph(NewGraph);
+ drawGraph.drawGraph();
+ }
+
+ public void AddNode(String s,String[] list) {
+ if(list == null)
+ return;
+ if(!NewGraph.checkNode(s)){
+ NewGraph.addNode(s);
+ }
+ for(String name:list) {
+ System.out.println(name);
+ if(!NewGraph.checkNode(name)){
+ NewGraph.addNode(name);
+ }
+ NewGraph.ConnectNodes(s,name);
+ }
+ editor.setGraph(NewGraph);
+ drawGraph.drawGraph();
+ }
+ public void DeleteNode(String s) {
+ if(NewGraph.checkNode(s)){
+ NewGraph.deleteNode(s);
+ }
+ editor.setGraph(NewGraph);
+ drawGraph.drawGraph();
+ }
+
+ public void addConnection(String first, String second) {
+ if((NewGraph.checkNode(first))&&(NewGraph.checkNode(second))) {
+ SimpleNode firstNode = (SimpleNode)NewGraph.findByName(first);
+ firstNode.addEdge(NewGraph.findByName(second));
+ }
+ drawGraph.drawGraph();
+ }
+
+ public void deleteConnection(String first, String second){
+ if((NewGraph.checkNode(first))&&(NewGraph.checkNode(second))) {
+ SimpleNode firstNode = (SimpleNode)NewGraph.findByName(first);
+ firstNode.deleteConnection(second);
+ }
+ drawGraph.drawGraph();
+ }
+
+ public void setEditor(EditPanel editor) {
+ this.editor = editor;
+ }
+ public void setFrame(JFrame frame) {
+ drawGraph.setFrame(frame);
+ }
+ public ArrayList FindBridges(boolean step_by_step)
+ {
+ edgesOfBridge.clear();
+ WayOfbridge.clear();
+ NewGraph.clearBridges();
+ int kolNodes = GetGraph().getNodes().size();//bred
+ S = new int[kolNodes]; // Star
+ Up = new int[kolNodes]; // End
+ Res = new boolean[kolNodes]; // Most or no
+
+ for(int i = 0;i < kolNodes;i++)
+ {
+ if (S[i] == 0)
+ {
+ DPS(i,0);
+ }
+ }
+
+ flag = 0;
+ if(step_by_step) {
+ timer = new Timer(500,e-> updateNode());
+ timer.setRepeats(true);
+ timer.start();
+ System.out.println(edgesOfBridge);
+ System.out.println(WayOfbridge);
+ }
+ else {
+ for(Edge ed:edgesOfBridge)
+ ed.setBridge(true);
+ drawGraph.drawGraph();
+ }
+ return edgesOfBridge;
+ }
+
+ public void updateNode() {
+ for(SimpleNode node:tmpNodes) {
+ node.setChoosen(false);
+ }
+ tmpNodes.clear();
+ if(WayOfbridge.size() != 0) {
+ if (flag == 0) {
+ tmpNodes.add(WayOfbridge.get(0).getDestNode());
+ tmpNodes.get(0).setChoosen(true);
+ tmpNodes.add(WayOfbridge.get(0).getSourceNode());
+ tmpNodes.get(1).setChoosen(true);
+ if (isBridge(WayOfbridge.get(0),edgesOfBridge))
+ ++flag;
+ WayOfbridge.remove(0);
+ }
+ else {
+ flag = 0;
+ edgesOfBridge.get(step).setBridge(true);
+ System.out.println("status");
+ }
+ drawGraph.drawGraph();
+ return;
+ }
+ if((timer!=null)&&(timer.isRunning())) {
+ timer.stop();
+ }
+ for(SimpleNode node:tmpNodes) {
+ node.setChoosen(false);
+ }
+ tmpNodes.clear();
+ flag = -1;
+ }
+
+ void setDefaults() {
+ for (SimpleNode node: nodes) {
+ node.setChoosen(false);
+ }
+ NewGraph.clearBridges();
+ }
+
+ public void ManualStep() {
+ if(flag == -1) {
+ FindBridges(false);
+ setDefaults();
+ }
+ updateNode();
+ }
+
+ public void DPS(int v,int p)
+ {
+ Res[v] = true;
+ S[v] = Up[v] = time++;
+
+ SimpleNode elem;
+ for(Edge TMP: nodes.get(v).getEdgesList()) {
+
+ if(nodes.get(v) != TMP.getDestNode())
+ {
+ elem = TMP.getDestNode();
+ }
+ else
+ {
+ elem = TMP.getSourceNode();
+ }
+ //int to = NewGraph.GetPosOfNode(elem);
+ int to = nodes.indexOf(elem);
+ if (to == p) continue;
+ if (Res[to]) {
+ Up[v] = Math.min(Up[v], S[to]);
+
+ } else {
+ WayOfbridge.add(TMP);
+ DPS(to, v);
+ WayOfbridge.add(TMP);
+ Up[v] = Math.min(Up[v], Up[to]);
+ if (Up[to] > S[v]) {
+
+ for(Edge elemEdge:nodes.get(v).getEdgesList())
+ {
+ if (nodes.get(v) == elemEdge.getDestNode())
+ {
+ if (nodes.get(to) == elemEdge.getSourceNode())
+ {
+ edgesOfBridge.add(elemEdge);
+ }
+ }
+
+ else
+ {
+ if (nodes.get(to) == elemEdge.getDestNode())
+ {
+ edgesOfBridge.add(elemEdge);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/Graph/src/Graphpcg/Edge.java b/Graph/src/Meny/model/Edge.java
similarity index 51%
rename from Graph/src/Graphpcg/Edge.java
rename to Graph/src/Meny/model/Edge.java
index 61b1257..480b071 100644
--- a/Graph/src/Graphpcg/Edge.java
+++ b/Graph/src/Meny/model/Edge.java
@@ -1,15 +1,33 @@
-package Graphpcg;
+package Meny.model;
+
+import Meny.model.SimpleNode;
+import Meny.view.DrawEdge;
public class Edge {
private SimpleNode sourceNode; //исходный узел
private SimpleNode destNode; //конечный узел
+ private boolean isBrtide = false;
+
+ DrawEdge picture;
Edge(SimpleNode sourceNode, SimpleNode destNode) {
this.sourceNode = sourceNode;
this.destNode = destNode;
}
+ public void setStatus(boolean status) {
+ isBrtide = status;
+ }
+
+ public void setBridge(boolean status) {
+ isBrtide = status;
+ for (Edge edge : destNode.getEdgesList()) {
+ if (edge.destNode.getName().equals(sourceNode.getName()))
+ edge.setStatus(true);
+ }
+ }
+ public boolean getStatus() { return isBrtide;}
public SimpleNode getSourceNode() {
return sourceNode;
}
@@ -28,4 +46,12 @@ public void setDestNode(SimpleNode destNode){
this.destNode = destNode;
}
}
+
+ public void setPicture(DrawEdge picture) {
+ this.picture = picture;
+ }
+
+ public DrawEdge getPicture() {
+ return picture;
+ }
}
diff --git a/Graph/src/Graphpcg/Graph.java b/Graph/src/Meny/model/Graph.java
similarity index 69%
rename from Graph/src/Graphpcg/Graph.java
rename to Graph/src/Meny/model/Graph.java
index 26c5828..821a05f 100644
--- a/Graph/src/Graphpcg/Graph.java
+++ b/Graph/src/Meny/model/Graph.java
@@ -1,4 +1,4 @@
-package Graphpcg;
+package Meny.model;
import java.util.ArrayList;
@@ -11,6 +11,7 @@ public class Graph {
public Graph(NodeFactory factory) {
this.factory = factory;
}
+
public void addNode(String name) {
T node = factory.createNode(name);
nodes.add(node);
@@ -36,7 +37,35 @@ public void ConnectNodes(String first, String second) {
if ((sourceNode != null) && (destNode != null))
sourceNode.addEdge(destNode);
//else
- // throw exeption;
+ // throw exeption;
+ }
+
+ public boolean checkNode(String name) {
+ for(T node: nodes){
+ if(node.getName().equals(name))
+ return true;
+ }
+ return false;
+ }
+
+ public void deleteNode(String name) {
+ for(int i =0;i getEdgesList();
}
diff --git a/Graph/src/Graphpcg/NodeFactory.java b/Graph/src/Meny/model/NodeFactory.java
similarity index 80%
rename from Graph/src/Graphpcg/NodeFactory.java
rename to Graph/src/Meny/model/NodeFactory.java
index 008d030..fcc0773 100644
--- a/Graph/src/Graphpcg/NodeFactory.java
+++ b/Graph/src/Meny/model/NodeFactory.java
@@ -1,4 +1,4 @@
-package Graphpcg;
+package Meny.model;
public interface NodeFactory {
T createNode(String name);
diff --git a/Graph/src/Graphpcg/SimpleNode.java b/Graph/src/Meny/model/SimpleNode.java
similarity index 63%
rename from Graph/src/Graphpcg/SimpleNode.java
rename to Graph/src/Meny/model/SimpleNode.java
index 09752b6..c0f9a5b 100644
--- a/Graph/src/Graphpcg/SimpleNode.java
+++ b/Graph/src/Meny/model/SimpleNode.java
@@ -1,4 +1,6 @@
-package Graphpcg;
+package Meny.model;
+
+import Meny.view.DrawNode;
import java.util.ArrayList;
@@ -40,17 +42,23 @@ public SimpleNode(String name)
}
private ArrayList edges_list;
- private Object pictrue;
+ private DrawNode pictrue;
+ private boolean isChoosen;
public ArrayList getEdgesList() {
return edges_list;
}
- public void setPictrue(Object pictrue) {
+ public void setPictrue(DrawNode pictrue) {
this.pictrue = pictrue;
}
- public Object getPictrue() {
+ public boolean getChoosen(){return isChoosen;}
+
+ public void setChoosen(boolean choosen) {
+ isChoosen = choosen;
+ }
+ public DrawNode getPictrue() {
return pictrue;
}
@@ -70,25 +78,38 @@ public ArrayList GetList()
@Override
public void addEdge(Node dest_node)
{
- /*
- 1. Проверка на принадлежность
- 2. Т.к. не ориентированный, то а -> а не имеет смысла
- */
-
-// if (CheckNode(n) == false && this != n)
-// {
-// relateNode.add(n);
-// }
- Edge edge = new Edge(this, (SimpleNode)dest_node);
- edges_list.add(edge);
- ((SimpleNode) dest_node).addEdge(edge);
+ if(!checkConnection(dest_node)) {
+ Edge edge = new Edge(this, (SimpleNode) dest_node);
+ edges_list.add(edge);
+ ((SimpleNode) dest_node).addEdge(edge);
+ }
}
+ @Override
+ public void deleteConnection(String name) {
+ for(int i =0;i nodesd;
+ private ArrayList edgesd;
+ private MainWindow view;
+
+ public DrawGraph(Graph graph) {
+ nodesd = new ArrayList<>();
+ edgesd = new ArrayList<>();
+ setGraph(graph);
+ }
+
+ public void setGraph(Graph graph) {
+ this.graph = graph;
+ }
+
+ public Graph getGraph() {
+ return graph;
+ }
+
+ public void setView(MainWindow view) {
+ this.view = view;
+ }
+
+ public void setFrame(JFrame frame) {
+ this.frame = frame;
+ }
+
+ public void drawGraph() {
+
+ nodesd.clear();
+ edgesd.clear();
+ ArrayList nodes = graph.getNodes();
+ int i = 1;
+
+
+ //value for rotation
+ double k = 360.0 / nodes.size();
+ double PI = 3.14;
+
+ double Rot = 10;
+
+ double x = 300; // координаты центра во кргу которого рисуем
+ double y = 250;
+
+ double x0 = 300;// координаты первой вершины
+ double y0 = 50;
+
+ double NX;
+ double NY;
+
+ for (SimpleNode node : nodes) {
+
+ Rot += k;
+ NX = x + (x0 - x) * Math.cos(Rot * PI / 180) - (y0 - y) * Math.sin(Rot * PI / 180);
+ NY = y + (y0 - y) * Math.cos(Rot * PI / 180) + (x0 - x) * Math.sin(Rot * PI / 180) + 13;
+
+ DrawNode drawNode = new DrawNode(node.getName(), NX, NY);
+ if(node.getChoosen())
+ drawNode.setColor(Color.BLUE);
+ else
+ drawNode.setColor(Color.BLACK);
+ nodesd.add(drawNode);
+ node.setPictrue(drawNode);
+ ++i;
+ }
+ // view.addComponents(nodesd,edgesd);
+ for (SimpleNode node : nodes) {
+ for (Edge edge : node.getEdgesList()) {
+ if (node == edge.getSourceNode()) {
+ DrawEdge drawEdge = new DrawEdge(node.getPictrue(), edge.getDestNode().getPictrue());
+ if(edge.getStatus())
+ drawEdge.setColor(Color.RED);
+ else
+ drawEdge.setColor(Color.BLACK);
+ edgesd.add(drawEdge);
+ edge.setPicture(drawEdge);
+ }
+ }
+ }
+ frame.repaint();
+ view.getVisualPanel().addComponents(nodesd,edgesd);
+ }
+}
diff --git a/Graph/src/Meny/view/DrawNode.java b/Graph/src/Meny/view/DrawNode.java
new file mode 100644
index 0000000..d41e983
--- /dev/null
+++ b/Graph/src/Meny/view/DrawNode.java
@@ -0,0 +1,60 @@
+package Meny.view;
+
+import java.awt.*;
+import java.awt.Graphics;
+
+public class DrawNode {
+
+ private double xPos;
+ private double yPos;
+ private Meny.view.Graphics graphics;
+ private final String text;
+
+ private Color color;
+
+ public DrawNode(String text, double xPos, double yPos) {
+ setPos(xPos,yPos);
+ this.text = text;
+ setGraphics(graphics);
+ color = new Color(Color.BLACK.getRGB());
+ draw(color);
+ }
+
+ public void setPos(double xPos, double yPos) {
+ this.xPos = xPos;
+ this.yPos = yPos;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+ public int getxPos() {
+ return (int)xPos;
+ }
+
+ public int getyPos() {
+ return (int)yPos;
+ }
+
+ public void draw(Color color) {
+ // graphics.drawOval((int)xPos,(int)yPos,80,80,color.getRGB());
+ setText(text);
+ // drawBackGround(Color.WHITE);
+ }
+
+ public void setText(String text) {
+ // graphics.drawText((int)xPos,(int)yPos,text,color.getRGB());
+ }
+
+ public String getName(){
+ return text;
+ }
+
+ void setGraphics(Meny.view.Graphics graphics) {
+ this.graphics = graphics;
+ }
+}
diff --git a/Graph/src/Meny/view/Graphics.java b/Graph/src/Meny/view/Graphics.java
new file mode 100644
index 0000000..6f6ea05
--- /dev/null
+++ b/Graph/src/Meny/view/Graphics.java
@@ -0,0 +1,8 @@
+package Meny.view;
+
+public interface Graphics {
+
+ void drawOval(int x, int y, int width, int height, int rgb);
+ void drawText(int x, int y, String text, int rgb);
+ void drawLine(int startX, int startY, int endX, int endY, int rgb);
+}
diff --git a/Graph/src/Meny/view/SimpleFigures/Circle.java b/Graph/src/Meny/view/SimpleFigures/Circle.java
new file mode 100644
index 0000000..fd6547b
--- /dev/null
+++ b/Graph/src/Meny/view/SimpleFigures/Circle.java
@@ -0,0 +1,81 @@
+package Meny.view.SimpleFigures;
+
+import java.awt.*;
+import java.awt.geom.Ellipse2D;
+import java.awt.geom.Rectangle2D;
+
+public class Circle extends Ellipse2D {
+
+ private Point center;
+ private int height = 0;
+ private int width = 0;
+
+ private Color color;
+
+ public String name;
+
+ public Circle() {
+ center = new Point();
+ }
+
+ public Circle(double x, double y) {
+ center = new Point(x,y);
+ }
+
+ public Circle(double x, double y,int height, int width) {
+ center = new Point(x,y);
+ this.height = height;
+ this.width = width;
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ public Circle(double x, double y, int ray) {
+ center = new Point(x,y);
+ this.height = ray;
+ this.width = ray;
+ }
+
+ @Override
+ public double getX() {
+ return center.getX();
+ }
+
+ @Override
+ public double getY() {
+ return center.getY();
+ }
+
+ @Override
+ public double getWidth() {
+ return width;
+ }
+
+ @Override
+ public double getHeight() {
+ return height;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ if((center != null) && (height != 0) && (width != 0))
+ return true;
+ return false;
+ }
+
+ @Override
+ public void setFrame(double v, double v1, double v2, double v3) {
+
+ }
+
+ @Override
+ public Rectangle2D getBounds2D() {
+ return null;
+ }
+}
diff --git a/Graph/src/Meny/view/SimpleFigures/Line.java b/Graph/src/Meny/view/SimpleFigures/Line.java
new file mode 100644
index 0000000..ea559b2
--- /dev/null
+++ b/Graph/src/Meny/view/SimpleFigures/Line.java
@@ -0,0 +1,79 @@
+package Meny.view.SimpleFigures;
+
+import java.awt.*;
+import java.awt.geom.Line2D;
+import java.awt.geom.Rectangle2D;
+
+public class Line extends Line2D {
+
+
+ private Point p1;
+ private Point p2;
+ private Color color;
+
+ public Line() {
+ p1 = new Point();
+ p2 = new Point();
+ }
+
+ public Line(Point p1, Point p2) {
+ this.p1 = p1;
+ this.p2 = p2;
+ }
+
+ public Line(double p1x, double p1y, double p2x, double p2y) {
+
+ p1 = new Point(p1x,p1y);
+ p2 = new Point(p2x,p2y);
+ }
+
+ public Color getColor() {
+ return color;
+ }
+
+ public void setColor(Color color) {
+ this.color = color;
+ }
+
+ @Override
+ public double getX1() {
+ return p1.getX();
+ }
+
+ @Override
+ public double getY1() {
+ return p1.getY();
+ }
+
+ @Override
+ public Point getP1() {
+ return p1;
+ }
+
+ @Override
+ public double getX2() {
+ return p2.getX();
+ }
+
+ @Override
+ public double getY2() {
+ return p2.getY();
+ }
+
+ @Override
+ public Point getP2() {
+ return p2;
+ }
+
+ @Override
+ public void setLine(double v, double v1, double v2, double v3) {
+
+ p1.setLocation(v, v1);
+ p1.setLocation(v2,v3);
+ }
+
+ @Override
+ public Rectangle2D getBounds2D() {
+ return null;
+ }
+}
diff --git a/Graph/src/Meny/view/SimpleFigures/Point.java b/Graph/src/Meny/view/SimpleFigures/Point.java
new file mode 100644
index 0000000..f363279
--- /dev/null
+++ b/Graph/src/Meny/view/SimpleFigures/Point.java
@@ -0,0 +1,44 @@
+package Meny.view.SimpleFigures;
+
+import java.awt.geom.Point2D;
+
+public class Point extends Point2D {
+ private double x;
+ private double y;
+
+ public Point(double x, double y) {
+ setLocation(x,y);
+ }
+
+ public Point() {}
+
+ @Override
+ public double getX() {
+ return x;
+ }
+
+ @Override
+ public double getY() {
+ return y;
+ }
+
+ @Override
+ public void setLocation(double v, double v1) {
+ x = v;
+ y = v1;
+ }
+
+ public void setX(double x) {
+ this.x = x;
+ }
+
+ public void setY(double y) {
+ this.y = y;
+ }
+
+ public boolean isequal(Point other) {
+ if((this!= null)&&(x == other.x)&&(y == other.y))
+ return true;
+ return false;
+ }
+}
diff --git a/Graph/src/com/company/Main.java b/Graph/src/com/company/Main.java
deleted file mode 100644
index d9d1a8b..0000000
--- a/Graph/src/com/company/Main.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.company;
-
-public class Main {
-
- public static void main(String[] args) {
- // write your code here
- }
-}
diff --git a/README.md b/README.md
deleted file mode 100644
index ed0ddc9..0000000
--- a/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# JavaPractice
-
-## link for Java JDK 8: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
-## link for IDE if you need it (IntelliJ Idea): https://www.jetbrains.com/idea/download/#section=linux
-
-Каждый работает в своей ветке. Пуш производить в свою ветку, потом дулать пул реквест
-Пул делать только из ветки мастера
diff --git a/jgraphx.jar b/jgraphx.jar
deleted file mode 100644
index b9bf1c0..0000000
Binary files a/jgraphx.jar and /dev/null differ
diff --git a/src/com/company/Main.java b/src/com/company/Main.java
deleted file mode 100644
index d9d1a8b..0000000
--- a/src/com/company/Main.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.company;
-
-public class Main {
-
- public static void main(String[] args) {
- // write your code here
- }
-}