Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
566 changes: 413 additions & 153 deletions Graph/.idea/workspace.xml

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Graph/out/production/Graph/Meny/model/Edge.class
Binary file not shown.
Binary file added Graph/out/production/Graph/Meny/model/Graph.class
Binary file not shown.
Binary file added Graph/out/production/Graph/Meny/model/Node.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Graph/out/production/Graph/Meny/view/Graphics.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
68 changes: 0 additions & 68 deletions Graph/src/DrawClass.java

This file was deleted.

79 changes: 79 additions & 0 deletions Graph/src/Meny/MainFrame/Launcher.java
Original file line number Diff line number Diff line change
@@ -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<SimpleNode> 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());
}
}
70 changes: 70 additions & 0 deletions Graph/src/Meny/MainFrame/Panels/ControllPanel.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
137 changes: 137 additions & 0 deletions Graph/src/Meny/MainFrame/Panels/EditPanel.java
Original file line number Diff line number Diff line change
@@ -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<String> sourse_list = new JComboBox<>();
private JComboBox<String> other_sourse_list = new JComboBox<>();
private JComboBox<String> 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<SimpleNode> 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);
}
}
Loading