Error Handling
This commit is contained in:
parent
4b59b88688
commit
2213a4385d
@ -4,6 +4,7 @@ import graph.*;
|
||||
import logging.Algorithm;
|
||||
import logging.LogElementList;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@ -46,6 +47,7 @@ public class OurAlgorithm extends Algorithm {
|
||||
*/
|
||||
public LogElementList<OurLogElement> run() {
|
||||
|
||||
try{
|
||||
this.setCurrentGraph(((OurParameterArea) this.getParameterArea()).getSelectedGraph());
|
||||
|
||||
MarkedVertex<VertexMarking> start = null;
|
||||
@ -67,7 +69,25 @@ public class OurAlgorithm extends Algorithm {
|
||||
} else {
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,8 @@ public class OurDrawArea extends DrawArea {
|
||||
// Get the current log element from the log list
|
||||
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);
|
||||
|
||||
// Draw markings on edges
|
||||
@ -57,5 +58,6 @@ public class OurDrawArea extends DrawArea {
|
||||
(screenEdge.getSource().getYpos() + screenEdge.getDestination().getYpos()) / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public class OurParameterArea extends ParameterArea {
|
||||
|
||||
// Input text fields
|
||||
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()));
|
||||
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) {
|
||||
DirectedGraph<VertexMarking, EdgeMarking> newGraph = new DirectedGraph<>();
|
||||
|
||||
try{
|
||||
String[] allVertices = vertices.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]))));
|
||||
}
|
||||
//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;
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user