mirror of
https://codeberg.org/qg-info-unterricht/zpg-graphentester.git
synced 2026-03-25 04:58:24 +01:00
Sync with upstream
This commit is contained in:
parent
39a2f13410
commit
66e8fa72bf
135 changed files with 38902 additions and 37757 deletions
|
|
@ -8,25 +8,24 @@ import javafx.scene.control.Alert;
|
|||
import javafx.scene.control.Alert.AlertType;
|
||||
import javafx.scene.control.ButtonType;
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.control.TextInputDialog;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
*
|
||||
* description
|
||||
* Abstrakte Oberklasse für alle zu simulierende Algorithmen
|
||||
* Diese müssen die Methode getBezeichnung(): String und fuehreAlgorithmusAus() überschreiben.
|
||||
*
|
||||
* @version 1.0 from 26.04.2019
|
||||
* @author
|
||||
* @version 6.7 (Dez. 2020)
|
||||
* @author Thomas Schaller
|
||||
*/
|
||||
|
||||
public abstract class GraphAlgo extends Thread {
|
||||
|
||||
// Anfang Attribute
|
||||
private boolean stepping;
|
||||
private boolean waitforrepaint;
|
||||
private boolean waitforclick;
|
||||
protected boolean inArbeit;
|
||||
private GraphPlotter gp;
|
||||
private boolean stepping; // Einzelschrittmodus
|
||||
private boolean waitforrepaint; // wird gerade gezeichnet (=> nicht nochmal zeichnen beauftragen)
|
||||
private boolean waitforclick; // wird auf Klick für nächsten Step gewartet
|
||||
protected boolean inArbeit;
|
||||
protected GraphPlotter gp;
|
||||
private Knoten startKnoten;
|
||||
private int speed =100;
|
||||
private Hilfe hilfe;
|
||||
|
|
@ -35,6 +34,9 @@ public abstract class GraphAlgo extends Thread {
|
|||
// Ende Attribute
|
||||
|
||||
// Anfang Methoden
|
||||
/**
|
||||
* Erzeugt neues Algorithmus-Objekt
|
||||
*/
|
||||
public GraphAlgo() {
|
||||
stepping = true;
|
||||
waitforrepaint = false;
|
||||
|
|
@ -43,6 +45,11 @@ public abstract class GraphAlgo extends Thread {
|
|||
setDaemon(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die Referenz auf die GraphAnzeige und das Hilfefenster
|
||||
* @param graphPlotter
|
||||
* @param hilfe
|
||||
*/
|
||||
public void setGUIElemente(GraphPlotter graphPlotter, Hilfe hilfe) {
|
||||
gp = graphPlotter;
|
||||
g = gp.getGraph();
|
||||
|
|
@ -50,15 +57,31 @@ public abstract class GraphAlgo extends Thread {
|
|||
if (hilfe != null) hilfe.setGraphPlotter(gp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt Referenz auf den Graphen
|
||||
* @param g Graph auf den der Algorithmus angewendet wird
|
||||
*/
|
||||
public void setGraph(Graph g) {
|
||||
this.g = g;
|
||||
gp = null;
|
||||
hilfe = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt Referenz auf den Graphen zurück
|
||||
* @return g Graph, auf den der Algorithmus angewendet wird
|
||||
*/
|
||||
public Graph getGraph() {
|
||||
return g;
|
||||
}
|
||||
|
||||
/**
|
||||
* Muss vom Algorithmus aufgerufen werden, um einen Haltepunkt zu setzen
|
||||
*/
|
||||
public void step() {
|
||||
if(gp == null) return;
|
||||
try{
|
||||
//System.out.println("Step");
|
||||
gp.updateImage();
|
||||
aktuellerZustand = g.getStatus();
|
||||
waitforclick = true;
|
||||
|
|
@ -68,6 +91,7 @@ public abstract class GraphAlgo extends Thread {
|
|||
Thread.sleep(10);
|
||||
i++;
|
||||
}
|
||||
|
||||
if (hilfe != null) hilfe.setReviewAllowed(false);
|
||||
g.setStatus(aktuellerZustand);
|
||||
aktuellerZustand = null;
|
||||
|
|
@ -77,30 +101,41 @@ public abstract class GraphAlgo extends Thread {
|
|||
}
|
||||
}
|
||||
|
||||
public boolean getWaitforrepaint() {
|
||||
return waitforrepaint;
|
||||
}
|
||||
|
||||
public void setWaitforrepaint(boolean waitforrepaintNeu) {
|
||||
waitforrepaint = waitforrepaintNeu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wird gerade auf einen Buttonklick für den nächsten Step gewartet?
|
||||
* @return true/false
|
||||
*/
|
||||
public boolean getWaitforclick() {
|
||||
return waitforclick;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt, ob gewartet wird. Damit kann übermittelt werden, dass der Button gedrückt wurde
|
||||
* @param wairforclickNeu Soll weiter gewartet werden?
|
||||
*/
|
||||
public void setWaitforclick(boolean waitforclickNeu) {
|
||||
waitforclick = waitforclickNeu;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt, ob im Einzelschrittmodus ausgeführt werden soll
|
||||
* @param stepping true/false
|
||||
*/
|
||||
public void setStepping(boolean stepping) {
|
||||
this.stepping = stepping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setzt die Wartezeit im automatischen Modus
|
||||
* @param delay Wartezeit
|
||||
*/
|
||||
public void setSpeed(int delay) {
|
||||
this.speed = delay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ausführung des Algorithmus
|
||||
*/
|
||||
public void run()
|
||||
{
|
||||
if(!inArbeit && gp != null)
|
||||
|
|
@ -110,9 +145,10 @@ public abstract class GraphAlgo extends Thread {
|
|||
try{
|
||||
if (hilfe != null) hilfe.setReviewAllowed(false);
|
||||
fuehreAlgorithmusAus();
|
||||
gp.updateImage();
|
||||
// System.out.println("Algorithmus beendet");
|
||||
} catch( ThreadDeath e){
|
||||
// System.out.println("Algorithmus vorzeitig beendet.");
|
||||
// System.out.println("Algorithmus vorzeitig beendet."+e);
|
||||
}
|
||||
if (hilfe != null) hilfe.setReviewAllowed(true);
|
||||
inArbeit = false;
|
||||
|
|
@ -125,10 +161,18 @@ public abstract class GraphAlgo extends Thread {
|
|||
}
|
||||
// Ende Methoden
|
||||
|
||||
/**
|
||||
* Setzen des Startknotens
|
||||
* @param k Startknoten
|
||||
*/
|
||||
public void setStartKnoten(Knoten k) {
|
||||
startKnoten = k;
|
||||
}
|
||||
|
||||
/**
|
||||
* Abfragen des Startknotens für den Algorithmus
|
||||
* @return gesetzter Startknoten oder Knoten Nr. 0
|
||||
*/
|
||||
public Knoten getStartKnoten() {
|
||||
if (startKnoten != null) {
|
||||
return startKnoten;
|
||||
|
|
@ -137,24 +181,22 @@ public abstract class GraphAlgo extends Thread {
|
|||
} // end of if-else
|
||||
}
|
||||
|
||||
/**
|
||||
* Methode für den eigentlichen Algorithmus
|
||||
*/
|
||||
public abstract void fuehreAlgorithmusAus();
|
||||
|
||||
/**
|
||||
* Name des Algorithmus für die Dropdown-Auswahl
|
||||
*/
|
||||
public abstract String getBezeichnung();
|
||||
|
||||
public void eingabe() {
|
||||
Platform.runLater(() -> {
|
||||
TextInputDialog dialog = new TextInputDialog(); // create an instance
|
||||
|
||||
dialog.setTitle("Title");
|
||||
// other formatting etc
|
||||
|
||||
Optional<String> result = dialog.showAndWait();
|
||||
// this shows the dialog, waits until it is closed, and stores the result
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffnet ein Anzeigefenster mit einer Meldung. Die
|
||||
* Meldung wird ggf. auch im Hilfefenster angezeigt.
|
||||
* Ist für die Verwendung im Algorithmus gedacht.
|
||||
* @param s Meldung
|
||||
*/
|
||||
public void melde(String s) {
|
||||
info(s);
|
||||
Platform.runLater(() -> {
|
||||
|
|
@ -165,22 +207,53 @@ public abstract class GraphAlgo extends Thread {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Text in das Hilfefenster einfügen
|
||||
* Ist für die Verwendung im Algorithmus gedacht.
|
||||
* @param s Hilfetext
|
||||
*/
|
||||
public void info(String s) {
|
||||
if(hilfe != null) hilfe.append(s+"\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Löscht das Hilfefenster
|
||||
*/
|
||||
public void resetInfo() {
|
||||
if(hilfe != null) hilfe.loescheAlles();
|
||||
}
|
||||
|
||||
/**
|
||||
* Rückt im Hilfefenster eine Ebene tiefer ein.
|
||||
* Ist für die Verwendung im Algorithmus gedacht.
|
||||
*/
|
||||
public void infoIndentMore() {
|
||||
if(hilfe != null) hilfe.indentMore();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rückt im Hilfefenster eine Ebene aus.
|
||||
* Ist für die Verwendung im Algorithmus gedacht.
|
||||
*/
|
||||
public void infoIndentLess() {
|
||||
if(hilfe != null) hilfe.indentLess();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialisiert den Graphen
|
||||
*/
|
||||
public void init() {
|
||||
gp.getGraphOptions().knotenKurztext = new String[]{"Wert"};
|
||||
gp.getGraphOptions().knotenLangtext = new String[]{"Infotext","Wert","Markiert","Besucht"};
|
||||
if(g.isGewichtet()) {
|
||||
gp.getGraphOptions().kanteKurztext = new String[]{"Gewicht"};
|
||||
gp.getGraphOptions().kanteLangtext = new String[]{"Gewicht","Markiert","Gelöscht"};
|
||||
} else {
|
||||
gp.getGraphOptions().kanteKurztext = new String[]{};
|
||||
gp.getGraphOptions().kanteLangtext = new String[]{"Markiert","Gelöscht"};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue