2024-07-02 19:13:30 +00:00
|
|
|
|
package OurApplication;
|
2024-06-15 19:55:30 +00:00
|
|
|
|
|
2024-07-07 21:39:17 +00:00
|
|
|
|
import graph.*;
|
2024-07-02 19:13:30 +00:00
|
|
|
|
import visualisation.ParameterArea;
|
|
|
|
|
|
|
|
|
|
import javax.swing.*;
|
2024-07-07 10:58:33 +00:00
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
2024-06-15 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This class provides an example for using visualization.ParameterArea.
|
2024-07-02 19:13:30 +00:00
|
|
|
|
* @see ParameterArea
|
|
|
|
|
* @author MSch<EFBFBD>fer
|
2024-06-15 19:55:30 +00:00
|
|
|
|
* DHBW Stuttgart/Campus Horb AI2008<br>
|
|
|
|
|
* <br>
|
|
|
|
|
*/
|
2024-07-02 19:13:30 +00:00
|
|
|
|
public class OurParameterArea extends ParameterArea{
|
2024-06-15 19:55:30 +00:00
|
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
2024-07-07 10:58:33 +00:00
|
|
|
|
|
2024-07-07 21:39:17 +00:00
|
|
|
|
private DirectedGraph<VertexMarking, EdgeMarking> customGraph;
|
|
|
|
|
|
2024-07-07 10:58:33 +00:00
|
|
|
|
private JRadioButton button1;
|
|
|
|
|
private JRadioButton button2;
|
|
|
|
|
private JRadioButton button3;
|
|
|
|
|
private JRadioButton button4;
|
2024-07-07 18:34:38 +00:00
|
|
|
|
private JRadioButton button5;
|
2024-07-07 10:58:33 +00:00
|
|
|
|
|
2024-07-07 21:39:17 +00:00
|
|
|
|
private JButton buttonAddGraph;
|
|
|
|
|
private JTextField textField1;
|
|
|
|
|
private JTextField textField2;
|
|
|
|
|
|
|
|
|
|
|
2024-07-07 10:58:33 +00:00
|
|
|
|
private int selectedExample;
|
|
|
|
|
|
|
|
|
|
|
2024-06-15 19:55:30 +00:00
|
|
|
|
/** TextField containing maximum sum up value. */
|
|
|
|
|
protected JTextField maxValue;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Standard constructor.
|
|
|
|
|
* Creates SumUpParameterArea with an empty JTextField.
|
|
|
|
|
*/
|
2024-07-02 19:13:30 +00:00
|
|
|
|
public OurParameterArea() {
|
2024-06-15 19:55:30 +00:00
|
|
|
|
super();
|
2024-07-07 10:58:33 +00:00
|
|
|
|
selectedExample = 1; // Standardmäßig Beispiel 1
|
2024-07-07 21:39:17 +00:00
|
|
|
|
this.customGraph = new DirectedGraph<>();
|
2024-07-07 10:58:33 +00:00
|
|
|
|
|
2024-06-15 19:55:30 +00:00
|
|
|
|
setBorder(BorderFactory.createTitledBorder("ParameterArea"));
|
|
|
|
|
|
2024-07-07 10:58:33 +00:00
|
|
|
|
// Layout-Manager setzen, um die Buttons vertikal anzuordnen
|
|
|
|
|
setLayout(new GridLayout(4, 1, 5, 5)); // 4 Zeilen, 1 Spalte, 5 Pixel Abstand
|
|
|
|
|
|
|
|
|
|
// Buttons erstellen
|
|
|
|
|
button1 = new JRadioButton("Beispiel 1", true);
|
|
|
|
|
button2 = new JRadioButton("Beispiel 2");
|
|
|
|
|
button3 = new JRadioButton("Beispiel 3");
|
|
|
|
|
button4 = new JRadioButton("Beispiel 4");
|
2024-07-07 18:34:38 +00:00
|
|
|
|
button5 = new JRadioButton("Eigener Graph");
|
|
|
|
|
|
2024-07-07 21:39:17 +00:00
|
|
|
|
buttonAddGraph = new JButton("Graph einfügen");
|
|
|
|
|
// Eingabefelder
|
|
|
|
|
textField1 = new JTextField("Knoten");
|
|
|
|
|
textField2 = new JTextField("Kanten");
|
|
|
|
|
|
2024-07-07 10:58:33 +00:00
|
|
|
|
|
|
|
|
|
// ButtonGroup erstellen und Buttons hinzufügen, um die gegenseitige Ausschließung zu gewährleisten
|
|
|
|
|
ButtonGroup group = new ButtonGroup();
|
|
|
|
|
group.add(button1);
|
|
|
|
|
group.add(button2);
|
|
|
|
|
group.add(button3);
|
|
|
|
|
group.add(button4);
|
2024-07-07 18:34:38 +00:00
|
|
|
|
group.add(button5);
|
2024-07-07 10:58:33 +00:00
|
|
|
|
|
|
|
|
|
// ActionListener hinzufügen
|
2024-07-07 21:39:17 +00:00
|
|
|
|
button1.addActionListener(e -> selectedExample = 1);
|
2024-07-07 10:58:33 +00:00
|
|
|
|
|
2024-07-07 21:39:17 +00:00
|
|
|
|
button2.addActionListener(e -> selectedExample = 2);
|
2024-07-07 10:58:33 +00:00
|
|
|
|
|
2024-07-07 21:39:17 +00:00
|
|
|
|
button3.addActionListener(e -> selectedExample = 3);
|
|
|
|
|
|
|
|
|
|
button4.addActionListener(e -> selectedExample = 4);
|
|
|
|
|
|
|
|
|
|
button5.addActionListener(e -> selectedExample = 5);
|
2024-07-07 10:58:33 +00:00
|
|
|
|
|
|
|
|
|
|
2024-07-07 21:39:17 +00:00
|
|
|
|
buttonAddGraph.addActionListener(e -> {
|
|
|
|
|
String input1 = textField1.getText();
|
|
|
|
|
String input2 = textField2.getText();
|
|
|
|
|
this.customGraph = createGraph(input1, input2);
|
2024-07-07 18:34:38 +00:00
|
|
|
|
});
|
|
|
|
|
|
2024-07-07 21:39:17 +00:00
|
|
|
|
// Buttons zum Panel hinzufügen
|
|
|
|
|
add(button1);
|
|
|
|
|
add(button2);
|
|
|
|
|
add(button3);
|
|
|
|
|
add(button4);
|
|
|
|
|
add(button5);
|
|
|
|
|
|
|
|
|
|
add(buttonAddGraph);
|
|
|
|
|
add(textField1);
|
|
|
|
|
add(textField2);
|
2024-07-07 10:58:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DirectedGraph<VertexMarking, EdgeMarking> getSelectedGraph() {
|
|
|
|
|
ExampleGraphs temp = new ExampleGraphs();
|
|
|
|
|
switch (selectedExample) {
|
|
|
|
|
case 2:
|
|
|
|
|
return temp.example2();
|
|
|
|
|
case 3:
|
|
|
|
|
return temp.example3();
|
|
|
|
|
case 4:
|
|
|
|
|
return temp.example4();
|
2024-07-07 18:34:38 +00:00
|
|
|
|
case 5:
|
2024-07-07 21:39:17 +00:00
|
|
|
|
return this.customGraph;
|
2024-07-07 10:58:33 +00:00
|
|
|
|
case 1:
|
|
|
|
|
default:
|
|
|
|
|
return temp.example1();
|
|
|
|
|
}
|
2024-07-02 22:46:21 +00:00
|
|
|
|
}
|
2024-07-07 10:58:33 +00:00
|
|
|
|
|
2024-07-07 21:39:17 +00:00
|
|
|
|
|
|
|
|
|
// Vertex Eingabe: A-23-23;A-23-23
|
|
|
|
|
// Edge Eingabe: A-B-15;A-B-15
|
|
|
|
|
public DirectedGraph<VertexMarking, EdgeMarking> createGraph(String vertices, String edges) {
|
|
|
|
|
DirectedGraph<VertexMarking, EdgeMarking> 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<VertexMarking> start = null;
|
|
|
|
|
MarkedVertex<VertexMarking> end = null;
|
|
|
|
|
for (String i: allEdges) {
|
|
|
|
|
String[] current = i.split("-");
|
|
|
|
|
for (MarkedVertex<VertexMarking> 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;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-15 19:55:30 +00:00
|
|
|
|
}
|