Error Handling

This commit is contained in:
i23007 2024-07-09 01:55:13 +02:00
parent 4b59b88688
commit 2213a4385d
6 changed files with 85 additions and 45 deletions

View File

@ -4,6 +4,7 @@ import graph.*;
import logging.Algorithm; import logging.Algorithm;
import logging.LogElementList; import logging.LogElementList;
import javax.swing.*;
import java.util.Objects; import java.util.Objects;
@ -46,6 +47,7 @@ public class OurAlgorithm extends Algorithm {
*/ */
public LogElementList<OurLogElement> run() { public LogElementList<OurLogElement> run() {
try{
this.setCurrentGraph(((OurParameterArea) this.getParameterArea()).getSelectedGraph()); this.setCurrentGraph(((OurParameterArea) this.getParameterArea()).getSelectedGraph());
MarkedVertex<VertexMarking> start = null; MarkedVertex<VertexMarking> start = null;
@ -67,7 +69,25 @@ public class OurAlgorithm extends Algorithm {
} else { } else {
this.currentGraph.getShortestPathAStar(start, end); this.currentGraph.getShortestPathAStar(start, end);
} }
//Fehlerbehandlung
}catch(Throwable e){
JFrame info = new JFrame();
JPanel contentpane = new JPanel();
info.setContentPane(contentpane);
JOptionPane.showMessageDialog(
contentpane,
"Bitte geben SIe einen gültige Graphen an. Hilfestellung für das Erstellen von Knoten und Kanten:\n" +
"Knoten: Name;X-Coordinate;Y-Coordinate\nKanten: StartKnoten;Endknoten;Gewichtung\n" +
"Hinweis: ein Koten benötigt den Namen 'Startknoten', ein anderer 'Endknoten'\n" +
"(Festlegen der Start und Endknoten für die Algorithmen)",
"Eingabefehler",
JOptionPane.INFORMATION_MESSAGE,
null
);
LogElementList<OurLogElement> emptyLogList = new LogElementList<>();
emptyLogList.add(new OurLogElement());
return emptyLogList;
}
return this.currentGraph.getLogList(); return this.currentGraph.getLogList();
} }

View File

@ -47,7 +47,8 @@ public class OurDrawArea extends DrawArea {
// Get the current log element from the log list // Get the current log element from the log list
OurLogElement logElement = (OurLogElement) logList.get(); OurLogElement logElement = (OurLogElement) logList.get();
// Draw the graph associated with the log element // Draw the graph associated with the log element, if available
if (logElement.getGraph() != null) {
logElement.getGraph().draw(g); logElement.getGraph().draw(g);
// Draw markings on edges // Draw markings on edges
@ -57,5 +58,6 @@ public class OurDrawArea extends DrawArea {
(screenEdge.getSource().getYpos() + screenEdge.getDestination().getYpos()) / 2); (screenEdge.getSource().getYpos() + screenEdge.getDestination().getYpos()) / 2);
} }
} }
}
} }

View File

@ -66,7 +66,7 @@ public class OurParameterArea extends ParameterArea {
// Input text fields // Input text fields
textField1 = new JTextField("A-100-100;Ende-200-200;Start-100-200;D-200-100"); textField1 = new JTextField("A-100-100;Ende-200-200;Start-100-200;D-200-100");
textField2 = new JTextField("A-Ende-15;Start-D-10;D-A-3;A-Ende-15;Start-D-10;D-A-3"); textField2 = new JTextField("A-Ende-15;Start-D-10;D-A-3");
textField1.setPreferredSize(new Dimension(button5.getWidth(), button5.getHeight())); textField1.setPreferredSize(new Dimension(button5.getWidth(), button5.getHeight()));
textField2.setPreferredSize(new Dimension(button5.getWidth(), button5.getHeight())); textField2.setPreferredSize(new Dimension(button5.getWidth(), button5.getHeight()));
@ -135,6 +135,7 @@ public class OurParameterArea extends ParameterArea {
public DirectedGraph<VertexMarking, EdgeMarking> createGraph(String vertices, String edges) { public DirectedGraph<VertexMarking, EdgeMarking> createGraph(String vertices, String edges) {
DirectedGraph<VertexMarking, EdgeMarking> newGraph = new DirectedGraph<>(); DirectedGraph<VertexMarking, EdgeMarking> newGraph = new DirectedGraph<>();
try{
String[] allVertices = vertices.split(";"); String[] allVertices = vertices.split(";");
String[] allEdges = edges.split(";"); String[] allEdges = edges.split(";");
@ -159,6 +160,23 @@ public class OurParameterArea extends ParameterArea {
} }
newGraph.addEdge(new MarkedEdge<>(i, start, end, new EdgeWeightMarking(Integer.parseInt(current[2])))); newGraph.addEdge(new MarkedEdge<>(i, start, end, new EdgeWeightMarking(Integer.parseInt(current[2]))));
} }
//Fehlerbehandlung
}catch(Throwable e){
JFrame info = new JFrame();
JPanel contentpane = new JPanel();
info.setContentPane(contentpane);
JOptionPane.showMessageDialog(
contentpane,
"Fehler bei der Eingabe des Graphen. Beispieleingabe für Knoten und Kanten:\n" +
"Knoten: Name;X-Coordinate;Y-Coordinate\nKanten: StartKnoten;Endknoten;Gewichtung\n" +
"Hinweis: ein Koten benötigt den Namen 'Startknoten', ein anderer 'Endknoten'\n" +
"(Festlegen der Start und Endknoten für die Algorithmen)",
"Eingabefehler",
JOptionPane.INFORMATION_MESSAGE,
null
);
}
return newGraph; return newGraph;
} }