diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6b60723..a5bdb32 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,22 +5,29 @@ + + + - - - - + + + + + + + + diff --git a/OurApplication/OurApplication.java b/OurApplication/OurApplication.java index 1a62e6f..32fb11d 100644 --- a/OurApplication/OurApplication.java +++ b/OurApplication/OurApplication.java @@ -6,6 +6,7 @@ import visualisation.HybridWindow; import visualizationElements.Vertex; import javax.swing.*; +import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.Random; @@ -53,7 +54,7 @@ public class OurApplication { - LogElementList logList=new LogElementList(); + LogElementList logList = new LogElementList<>(); OurParameterArea parameterArea = new OurParameterArea(); OurMethodButtons methodButtons = new OurMethodButtons(); OurDrawArea drawArea = new OurDrawArea(logList,"GraphVisualization"); @@ -76,5 +77,4 @@ public class OurApplication { frame.setVisible(true); } - } diff --git a/OurApplication/OurParameterArea.java b/OurApplication/OurParameterArea.java index db4c1d8..8813c8e 100644 --- a/OurApplication/OurParameterArea.java +++ b/OurApplication/OurParameterArea.java @@ -1,9 +1,6 @@ package OurApplication; -import graph.DirectedGraph; -import graph.EdgeMarking; -import graph.ExampleGraphs; -import graph.VertexMarking; +import graph.*; import visualisation.ParameterArea; import javax.swing.*; @@ -22,13 +19,19 @@ public class OurParameterArea extends ParameterArea{ private static final long serialVersionUID = 1L; + private DirectedGraph customGraph; + private JRadioButton button1; private JRadioButton button2; private JRadioButton button3; private JRadioButton button4; private JRadioButton button5; - private ExampleGraphs temp; + private JButton buttonAddGraph; + private JTextField textField1; + private JTextField textField2; + + private int selectedExample; @@ -41,8 +44,8 @@ public class OurParameterArea extends ParameterArea{ */ public OurParameterArea() { super(); - temp = new ExampleGraphs(); selectedExample = 1; // Standardmäßig Beispiel 1 + this.customGraph = new DirectedGraph<>(); setBorder(BorderFactory.createTitledBorder("ParameterArea")); @@ -56,6 +59,11 @@ public class OurParameterArea extends ParameterArea{ button4 = new JRadioButton("Beispiel 4"); button5 = new JRadioButton("Eigener Graph"); + buttonAddGraph = new JButton("Graph einfügen"); + // Eingabefelder + textField1 = new JTextField("Knoten"); + textField2 = new JTextField("Kanten"); + // ButtonGroup erstellen und Buttons hinzufügen, um die gegenseitige Ausschließung zu gewährleisten ButtonGroup group = new ButtonGroup(); @@ -66,47 +74,33 @@ public class OurParameterArea extends ParameterArea{ group.add(button5); // ActionListener hinzufügen - button1.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectedExample = 1; - } + button1.addActionListener(e -> selectedExample = 1); + + button2.addActionListener(e -> selectedExample = 2); + + button3.addActionListener(e -> selectedExample = 3); + + button4.addActionListener(e -> selectedExample = 4); + + button5.addActionListener(e -> selectedExample = 5); + + + buttonAddGraph.addActionListener(e -> { + String input1 = textField1.getText(); + String input2 = textField2.getText(); + this.customGraph = createGraph(input1, input2); }); - button2.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectedExample = 2; - } - }); + // Buttons zum Panel hinzufügen + add(button1); + add(button2); + add(button3); + add(button4); + add(button5); - button3.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectedExample = 3; - } - }); - - button4.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectedExample = 4; - } - }); - - button5.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - selectedExample = 5; - } - }); - - // Buttons zum Panel hinzufügen - add(button1); - add(button2); - add(button3); - add(button4); - add(button5); + add(buttonAddGraph); + add(textField1); + add(textField2); } public DirectedGraph getSelectedGraph() { @@ -119,11 +113,43 @@ public class OurParameterArea extends ParameterArea{ case 4: return temp.example4(); case 5: - return new DirectedGraph<>(); + return this.customGraph; case 1: default: return temp.example1(); } } + + // Vertex Eingabe: A-23-23;A-23-23 + // Edge Eingabe: A-B-15;A-B-15 + public DirectedGraph createGraph(String vertices, String edges) { + DirectedGraph newGraph = new DirectedGraph<>(); + + + String[] allVertices = vertices.split(";"); + String[] allEdges = edges.split(";"); + + for (String i: allVertices) { + String[] current = i.split("-"); + newGraph.addVertex(new MarkedVertex<>(Integer.parseInt(current[1]), Integer.parseInt(current[2]), current[0], null, Color.BLACK)); + } + + MarkedVertex start = null; + MarkedVertex end = null; + for (String i: allEdges) { + String[] current = i.split("-"); + for (MarkedVertex j: newGraph.getAllVertexes()) { + if (j.getName() == current[0]) { + start = j; + } else if (j.getName() == current[1]) { + end = j; + } + } + newGraph.addEdge(new MarkedEdge<>(i, start, end, new EdgeWeightMarking(Integer.parseInt(current[2])))); + } + + return newGraph; + } + } diff --git a/graph/DirectedGraph.java b/graph/DirectedGraph.java index 6c3ced1..719eee9 100644 --- a/graph/DirectedGraph.java +++ b/graph/DirectedGraph.java @@ -254,7 +254,9 @@ public class DirectedGraph exten // Logging textDescription = "Visit " + nextVertex.getElement().getName(); System.out.println(textDescription); - nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); + if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) { + nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); + } this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); @@ -305,7 +307,9 @@ public class DirectedGraph exten // Logging textDescription = "Add " + i.getName() + " with " + dist + " weight to queue."; System.out.println(textDescription); - i.getScreenVertex().setColor(Color.YELLOW); + if (i.getScreenVertex().getColor() != Color.RED) { + i.getScreenVertex().setColor(Color.YELLOW); + } this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); // Nehme nächsten Knoten in die Queue auf @@ -387,7 +391,9 @@ public class DirectedGraph exten // Logging textDescription = "Visit " + nextVertex.getElement().getName(); System.out.println(textDescription); - nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); + if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) { + nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); + } this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); // Wenn Weg gefunden, brich ab @@ -442,7 +448,9 @@ public class DirectedGraph exten // Logging textDescription = "Add " + i.getName() + " with " + dist + " weight to queue."; System.out.println(textDescription); - i.getScreenVertex().setColor(Color.YELLOW); + if (i.getScreenVertex().getColor() != Color.RED) { + i.getScreenVertex().setColor(Color.YELLOW); + } this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); // Nehme nächsten Knoten in die Queue auf diff --git a/graph/EdgeMarking.java b/graph/EdgeMarking.java index 2a13ad3..5243cb6 100644 --- a/graph/EdgeMarking.java +++ b/graph/EdgeMarking.java @@ -1,19 +1,4 @@ package graph; public abstract class EdgeMarking extends Marking{ -} - -class EdgeWeightMarking extends EdgeMarking{ - private int weight; - - EdgeWeightMarking(int weight){ - this.weight = weight; - } - - public void setWeight(int weight){ - this.weight=weight; - } - public int getWeight(){ - return this.weight; - } -} +} \ No newline at end of file diff --git a/graph/EdgeWeightMarking.java b/graph/EdgeWeightMarking.java new file mode 100644 index 0000000..b1f4362 --- /dev/null +++ b/graph/EdgeWeightMarking.java @@ -0,0 +1,17 @@ +package graph; + +public class EdgeWeightMarking extends EdgeMarking { + private int weight; + + public EdgeWeightMarking(int weight){ + this.weight = weight; + } + + public void setWeight(int weight){ + this.weight=weight; + } + public int getWeight(){ + return this.weight; + } +} + diff --git a/graph/UndirectedGraph.java b/graph/UndirectedGraph.java index c7bb47d..efbfa4d 100644 --- a/graph/UndirectedGraph.java +++ b/graph/UndirectedGraph.java @@ -189,7 +189,9 @@ public class UndirectedGraph ext // Logging textDescription = "Visit " + nextVertex.getElement().getName(); System.out.println(textDescription); - nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); + if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) { + nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); + } this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); @@ -240,7 +242,9 @@ public class UndirectedGraph ext // Logging textDescription = "Add " + i.getName() + " with " + dist + " weight to queue."; System.out.println(textDescription); - i.getScreenVertex().setColor(Color.YELLOW); + if (i.getScreenVertex().getColor() != Color.RED) { + i.getScreenVertex().setColor(Color.YELLOW); + } this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); // Nehme nächsten Knoten in die Queue auf @@ -321,7 +325,9 @@ public class UndirectedGraph ext // Logging textDescription = "Visit " + nextVertex.getElement().getName(); System.out.println(textDescription); - nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); + if (nextVertex.getElement().getScreenVertex().getColor() != Color.RED) { + nextVertex.getElement().getScreenVertex().setColor(Color.BLUE); + } this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); @@ -377,7 +383,9 @@ public class UndirectedGraph ext // Logging textDescription = "Add " + i.getName() + " with " + dist + " weight to queue."; System.out.println(textDescription); - i.getScreenVertex().setColor(Color.YELLOW); + if (i.getScreenVertex().getColor() != Color.RED) { + i.getScreenVertex().setColor(Color.YELLOW); + } this.logList.add(new OurLogElement(step, textDescription, 0, this.getScreenGraphCopy())); // Nehme nächsten Knoten in die Queue auf diff --git a/out/production/ProjektGraph/OurApplication/OurApplication.class b/out/production/ProjektGraph/OurApplication/OurApplication.class index 75fc353..481d405 100644 Binary files a/out/production/ProjektGraph/OurApplication/OurApplication.class and b/out/production/ProjektGraph/OurApplication/OurApplication.class differ diff --git a/out/production/ProjektGraph/OurApplication/OurParameterArea.class b/out/production/ProjektGraph/OurApplication/OurParameterArea.class index 9984749..e1a26bf 100644 Binary files a/out/production/ProjektGraph/OurApplication/OurParameterArea.class and b/out/production/ProjektGraph/OurApplication/OurParameterArea.class differ diff --git a/out/production/ProjektGraph/graph/EdgeWeightMarking.class b/out/production/ProjektGraph/graph/EdgeWeightMarking.class index 8f06a71..749074e 100644 Binary files a/out/production/ProjektGraph/graph/EdgeWeightMarking.class and b/out/production/ProjektGraph/graph/EdgeWeightMarking.class differ