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
|
|
@ -15,6 +15,9 @@ import javafx.scene.text.*;
|
|||
import javafx.geometry.Pos;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.stage.*; // Dateiöffnen / Speichern-Dialog
|
||||
import javafx.application.Platform;
|
||||
import javafx.scene.input.Clipboard;
|
||||
import javafx.scene.input.ClipboardContent;
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.net.URL;
|
||||
|
|
@ -23,11 +26,11 @@ import java.nio.file.*;
|
|||
import java.util.Collections;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.Iterator;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.regex.Pattern;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import javafx.collections.ObservableList;
|
||||
|
||||
|
|
@ -37,9 +40,13 @@ import javafx.collections.ObservableList;
|
|||
* durchgeführt werden.
|
||||
*
|
||||
* @author Thomas Schaller
|
||||
* @version v6.7 (9.12.2020)
|
||||
* @version 03.03.2023 (v7.0)
|
||||
* v7.1: Fehler bei Aktualisierung des Hilfefensters behoben, Splitpane statt HBox
|
||||
* v7.0: Mechanismus geändert, so dass die init-Methode des Algorithmus beim Wechesel eines Algorithmus
|
||||
* aufgerufen wird, um die für diesen Algorithmus passenden Anzeigeeinstellungen zu setzen.
|
||||
* v6.9: Hilfefenster ist in Simulationsfenster integriert
|
||||
*/
|
||||
public class SimulationTabMitController extends TabMitController {
|
||||
public class SimulationTabMitController extends TabMitController implements Hilfe {
|
||||
|
||||
@FXML
|
||||
private ComboBox<String> cbAlgorithmen;
|
||||
|
|
@ -61,22 +68,23 @@ public class SimulationTabMitController extends TabMitController {
|
|||
|
||||
private GraphAlgo aktAlgo = null;
|
||||
private ArrayList<String> algoNamen;
|
||||
private Hilfefenster hilfe;
|
||||
private Hilfe hilfe;
|
||||
|
||||
public SimulationTabMitController(Graph graph, GraphOptions options) {
|
||||
this.graph = graph;
|
||||
this.options = options;
|
||||
this.setOnClosed((ev)->afterClosing());
|
||||
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
this.algoNamen = new ArrayList<String>();
|
||||
try {
|
||||
File verzeichnis = new File("algorithmen");
|
||||
if(verzeichnis != null) {
|
||||
String[] entries = verzeichnis.list();
|
||||
for (String name : entries) {
|
||||
if (name.startsWith("GraphAlgo_") && name.endsWith(".class")){
|
||||
|
||||
File verzeichnis = new File("algorithmen");
|
||||
if(verzeichnis != null && verzeichnis.isDirectory()) {
|
||||
String[] entries = verzeichnis.list();
|
||||
for (String name : entries) {
|
||||
if (name.startsWith("GraphAlgo_") && name.endsWith(".class")){
|
||||
try{
|
||||
Class c = Class.forName("algorithmen."+name.split(Pattern.quote("."))[0]);
|
||||
GraphAlgo a = ((GraphAlgo)(c).getDeclaredConstructor().newInstance());
|
||||
int i = 0;
|
||||
|
|
@ -87,13 +95,23 @@ public class SimulationTabMitController extends TabMitController {
|
|||
|
||||
algoNamen.add(i, "algorithmen."+name.split(Pattern.quote("."))[0]);
|
||||
}
|
||||
} // end of for
|
||||
}
|
||||
verzeichnis = new File( "eigeneAlgorithmen" );
|
||||
if(verzeichnis != null) {
|
||||
String[] entries = verzeichnis.list();
|
||||
for (String name : entries) {
|
||||
if (name.startsWith("GraphAlgo_") && name.endsWith(".class")){
|
||||
catch(ExceptionInInitializerError e) {}
|
||||
catch(LinkageError e){}
|
||||
catch(ClassNotFoundException e) {}
|
||||
catch(NoSuchMethodException e) {}
|
||||
catch(InstantiationException e) {}
|
||||
catch(IllegalAccessException e) {}
|
||||
catch(InvocationTargetException e) {}
|
||||
|
||||
}
|
||||
} // end of for
|
||||
}
|
||||
verzeichnis = new File( "eigeneAlgorithmen" );
|
||||
if(verzeichnis != null && verzeichnis.isDirectory()) {
|
||||
String[] entries = verzeichnis.list();
|
||||
for (String name : entries) {
|
||||
if (name.startsWith("GraphAlgo_") && name.endsWith(".class")){
|
||||
try{
|
||||
Class c = Class.forName("eigeneAlgorithmen."+name.split(Pattern.quote("."))[0]);
|
||||
GraphAlgo a = ((GraphAlgo)(c).getDeclaredConstructor().newInstance());
|
||||
int i = 0;
|
||||
|
|
@ -104,12 +122,21 @@ public class SimulationTabMitController extends TabMitController {
|
|||
|
||||
algoNamen.add(i, "eigeneAlgorithmen."+name.split(Pattern.quote("."))[0]);
|
||||
}
|
||||
} // end of for
|
||||
}
|
||||
} catch(Exception e)
|
||||
{
|
||||
System.out.println("Exception " + e);
|
||||
}
|
||||
catch(ExceptionInInitializerError e) {}
|
||||
catch(LinkageError e){}
|
||||
catch(ClassNotFoundException e) {}
|
||||
catch(NoSuchMethodException e) {}
|
||||
catch(InstantiationException e) {}
|
||||
catch(IllegalAccessException e) {}
|
||||
catch(InvocationTargetException e) {}
|
||||
|
||||
}
|
||||
} // end of for
|
||||
}
|
||||
|
||||
cbAlgorithmen.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
|
||||
changeAlgorithm();
|
||||
});
|
||||
|
||||
viewer.setGraph(graph,options);
|
||||
this.hilfe = null;
|
||||
|
|
@ -120,44 +147,39 @@ public class SimulationTabMitController extends TabMitController {
|
|||
bStart.managedProperty().bind(bStart.visibleProperty());
|
||||
bBreak.managedProperty().bind(bBreak.visibleProperty());
|
||||
bBreak.setVisible(false);
|
||||
}
|
||||
|
||||
private void afterClosing() {
|
||||
if (hilfe != null) hilfe.close();
|
||||
}
|
||||
//------------- Hilfefunktion
|
||||
loescheAlles();
|
||||
zustaende = new ArrayList<List<String>>();
|
||||
aktuell = null;
|
||||
reviewAllowed = false;
|
||||
tvAblauf.getSelectionModel().selectedIndexProperty().addListener((obs,oldValue, newValue)->showState());
|
||||
|
||||
private void hilfefensterErzeugen() {
|
||||
try { // try-catch ist notwendig, um Fehler durch fehlende Dateien abzufangen.
|
||||
if(hilfe != null) hilfe.close();
|
||||
|
||||
hilfe = new Hilfefenster();
|
||||
FXMLLoader loader = new FXMLLoader(getClass().getResource("/view/hilfefenster.fxml"));
|
||||
loader.setController(hilfe);
|
||||
Scene scene = new Scene((VBox) loader.load());
|
||||
Image icon = new Image("/view/icon.png");
|
||||
hilfe.getIcons().add(icon);
|
||||
hilfe.setTitle("Hilfefenster");
|
||||
hilfe.setScene(scene);
|
||||
hilfe.setX(0);
|
||||
hilfe.setY(0);
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void showHilfe(boolean b) {
|
||||
if(b) {
|
||||
hilfefensterErzeugen();
|
||||
hilfe.show();
|
||||
if(aktAlgo != null && aktAlgo.isAlive()) {
|
||||
lAblauf.setVisible(true);
|
||||
tvAblauf.setVisible(true);
|
||||
bClipboard.setVisible(true);
|
||||
|
||||
hilfe = this;
|
||||
if(aktAlgo != null ) {
|
||||
aktAlgo.setGUIElemente(viewer,hilfe);
|
||||
hilfe.append("Unvollständiger Ablauf");
|
||||
if(aktAlgo.isAlive())
|
||||
hilfe.append("Unvollständiger Ablauf");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (hilfe != null) hilfe.close();
|
||||
lAblauf.setVisible(false);
|
||||
tvAblauf.setVisible(false);
|
||||
bClipboard.setVisible(false);
|
||||
if(aktAlgo != null && aktAlgo.isAlive()) aktAlgo.setGUIElemente(viewer, null);
|
||||
hilfe = null;
|
||||
loescheAlles();
|
||||
zustaende = new ArrayList<List<String>>();
|
||||
aktuell = null;
|
||||
reviewAllowed = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -166,48 +188,56 @@ public class SimulationTabMitController extends TabMitController {
|
|||
mReset(null);
|
||||
}
|
||||
|
||||
@FXML
|
||||
void mReset(ActionEvent event) {
|
||||
public void changeAlgorithm() {
|
||||
if(aktAlgo != null && aktAlgo.isAlive()) aktAlgo.stop();
|
||||
graph.initialisiereAlleKnoten();
|
||||
graph.initialisiereAlleKanten();
|
||||
update();
|
||||
//gp.setInfoText(gp.getGraph().toString());
|
||||
|
||||
bStep.setDisable(false);
|
||||
bStart.setDisable(false);
|
||||
bStart.setVisible(true);
|
||||
bBreak.setVisible(false);
|
||||
if (hilfe != null) hilfe.loescheAlles();
|
||||
this.aktAlgo = null;
|
||||
|
||||
if(cbAlgorithmen.getSelectionModel().getSelectedIndex() >= 0) {
|
||||
|
||||
try{
|
||||
ClassLoader parentClassLoader = MyClassLoader.class.getClassLoader();
|
||||
MyClassLoader classLoader = new MyClassLoader(parentClassLoader);
|
||||
Class c = classLoader.loadClass(algoNamen.get(cbAlgorithmen.getSelectionModel().getSelectedIndex()));
|
||||
|
||||
aktAlgo = ((GraphAlgo)(c).getDeclaredConstructor().newInstance());
|
||||
aktAlgo.setStartKnoten(viewer.getSelectedKnoten());
|
||||
aktAlgo.setGUIElemente(viewer, hilfe);
|
||||
aktAlgo.setSpeed(910-(int) (sSpeed.getValue()));
|
||||
aktAlgo.init();
|
||||
} catch( Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
void mReset(ActionEvent event) {
|
||||
|
||||
changeAlgorithm();
|
||||
}
|
||||
|
||||
@FXML
|
||||
void mStep(ActionEvent event) {
|
||||
|
||||
if (aktAlgo == null ) {
|
||||
if(cbAlgorithmen.getSelectionModel().getSelectedIndex() >= 0) {
|
||||
try{
|
||||
ClassLoader parentClassLoader = MyClassLoader.class.getClassLoader();
|
||||
MyClassLoader classLoader = new MyClassLoader(parentClassLoader);
|
||||
Class c = classLoader.loadClass(algoNamen.get(cbAlgorithmen.getSelectionModel().getSelectedIndex()));
|
||||
|
||||
aktAlgo = ((GraphAlgo)(c).getDeclaredConstructor().newInstance());
|
||||
aktAlgo.setStartKnoten(viewer.getSelectedKnoten());
|
||||
aktAlgo.setGUIElemente(viewer, hilfe);
|
||||
aktAlgo.setSpeed(910-(int) (sSpeed.getValue()));
|
||||
} catch( Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
aktAlgo.start();
|
||||
}
|
||||
if (aktAlgo == null) return;
|
||||
if (aktAlgo.getState() == Thread.State.NEW ) {
|
||||
aktAlgo.setStartKnoten(viewer.getSelectedKnoten());
|
||||
aktAlgo.start();
|
||||
} else {
|
||||
if(aktAlgo.isAlive()) {
|
||||
aktAlgo.setSpeed(910-(int) (sSpeed.getValue()));
|
||||
aktAlgo.setWaitforclick(false);
|
||||
//gp.setInfoText(aktAlgo.getInfo());
|
||||
|
||||
} else {
|
||||
//gp.setInfoText("Algorithmus ist beendet. "+aktAlgo.getInfo());
|
||||
bStep.setDisable(true);
|
||||
bStart.setDisable(true);
|
||||
bBreak.setDisable(true);
|
||||
|
|
@ -218,7 +248,6 @@ public class SimulationTabMitController extends TabMitController {
|
|||
} catch(Exception e) {}
|
||||
|
||||
if (!aktAlgo.isAlive()) {
|
||||
//gp.setInfoText("Algorithmus ist beendet"+aktAlgo.getInfo());
|
||||
bStep.setDisable(true);
|
||||
bStart.setDisable(true);
|
||||
bBreak.setDisable(true);
|
||||
|
|
@ -227,41 +256,19 @@ public class SimulationTabMitController extends TabMitController {
|
|||
|
||||
@FXML
|
||||
void mStart(ActionEvent event) {
|
||||
|
||||
if (aktAlgo == null ) {
|
||||
if(cbAlgorithmen.getSelectionModel().getSelectedIndex() >= 0) {
|
||||
try{
|
||||
ClassLoader parentClassLoader = MyClassLoader.class.getClassLoader();
|
||||
MyClassLoader classLoader = new MyClassLoader(parentClassLoader);
|
||||
Class c = classLoader.loadClass(algoNamen.get(cbAlgorithmen.getSelectionModel().getSelectedIndex()));
|
||||
|
||||
aktAlgo = ((GraphAlgo)(c).getDeclaredConstructor().newInstance());
|
||||
|
||||
aktAlgo.setStartKnoten(viewer.getSelectedKnoten());
|
||||
aktAlgo.setGUIElemente(viewer,hilfe);
|
||||
aktAlgo.setSpeed(910-(int) (sSpeed.getValue()));
|
||||
|
||||
} catch( Exception e) {
|
||||
System.out.println(e);
|
||||
}
|
||||
|
||||
aktAlgo.setStepping(false);
|
||||
aktAlgo.start();
|
||||
}
|
||||
if (aktAlgo == null) return;
|
||||
if (aktAlgo.getState() == Thread.State.NEW ) {
|
||||
aktAlgo.setStartKnoten(viewer.getSelectedKnoten());
|
||||
aktAlgo.setStepping(false);
|
||||
aktAlgo.start();
|
||||
} else {
|
||||
if(aktAlgo.isAlive()) {
|
||||
aktAlgo.setSpeed(910-(int) (sSpeed.getValue()));
|
||||
aktAlgo.setStepping(false);
|
||||
aktAlgo.setWaitforclick(false);
|
||||
//gp.setInfoText(aktAlgo.getInfo());
|
||||
|
||||
} else {
|
||||
//gp.setInfoText("Algorithmus ist beendet. "+aktAlgo.getInfo());
|
||||
|
||||
} // end of if-else
|
||||
}
|
||||
} // end of if-else
|
||||
|
||||
// gp.setInfoText(aktAlgo.getInfo());
|
||||
bStep.setDisable(true);
|
||||
bStart.setVisible(false);
|
||||
bBreak.setVisible(true);
|
||||
|
|
@ -277,4 +284,151 @@ public class SimulationTabMitController extends TabMitController {
|
|||
bStep.setDisable(false);
|
||||
}
|
||||
}
|
||||
|
||||
// --------- Hilfefenster --------------------------------------------
|
||||
@FXML
|
||||
private TreeView<String> tvAblauf;
|
||||
|
||||
@FXML
|
||||
private Label lAblauf;
|
||||
|
||||
@FXML
|
||||
private Button bClipboard;
|
||||
|
||||
private List<TreeItem<String>> stufen;
|
||||
private List<List<String>> zustaende;
|
||||
private TreeItem<String> last;
|
||||
private GraphPlotter gp;
|
||||
private List<String> aktuell;
|
||||
private boolean reviewAllowed;
|
||||
|
||||
public void setGraphPlotter(GraphPlotter gp) {
|
||||
this.gp = gp;
|
||||
}
|
||||
|
||||
public void loescheAlles() {
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
stufen = new ArrayList<TreeItem<String>>();
|
||||
zustaende = new ArrayList<List<String>>();
|
||||
TreeItem<String> root = new TreeItem<String>("Algorithmus");
|
||||
root.setExpanded(true);
|
||||
last = root;
|
||||
tvAblauf.setRoot(root);
|
||||
tvAblauf.setShowRoot(false);
|
||||
stufen.add(root);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void append(String text) {
|
||||
List<String> status = gp.getGraph().getStatus();
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
last = new TreeItem<String>(text);
|
||||
stufen.get(stufen.size()-1).getChildren().add(last);
|
||||
zustaende.add(status);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void indentMore() {
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(stufen.size() == 1) { // Hauptknoten
|
||||
TreeItem parent = stufen.get(0);
|
||||
List<TreeItem> children = parent.getChildren();
|
||||
for(int i=children.size()-1; i >= 0; i--) {
|
||||
TreeItem t = children.get(i);
|
||||
if(t.isExpanded()) {
|
||||
t.setExpanded(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
stufen.add(last);
|
||||
last.setExpanded(true);
|
||||
last.expandedProperty().addListener((b, o, n) -> showState());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void indentLess() {
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(stufen.size() > 1) stufen.remove(stufen.size()-1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setReviewAllowed(boolean a) {
|
||||
this.reviewAllowed = a;
|
||||
if(!reviewAllowed) tvAblauf.getSelectionModel().clearSelection();
|
||||
}
|
||||
|
||||
public void showState() {
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(reviewAllowed && tvAblauf.getSelectionModel().getSelectedIndex()>=0) {
|
||||
TreeItem s = tvAblauf.getSelectionModel().getSelectedItem();
|
||||
if(!s.isExpanded()) { // suche das letzte Kind
|
||||
while(s.getChildren().size()>0){
|
||||
List<TreeItem> c = s.getChildren();
|
||||
s = c.get(c.size()-1);
|
||||
}
|
||||
}
|
||||
gp.getGraph().setStatus(zustaende.get(calculateIndex(tvAblauf.getRoot(), s ,0)-1));
|
||||
gp.updateImage();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private int calculateIndex(TreeItem t, TreeItem search, int nr) {
|
||||
if(t == search) return nr;
|
||||
nr++;
|
||||
List<TreeItem> children = t.getChildren();
|
||||
for(TreeItem c : children) {
|
||||
int i = calculateIndex(c, search, nr);
|
||||
if(i>0) return i;
|
||||
nr = -i;
|
||||
}
|
||||
return -nr;
|
||||
}
|
||||
|
||||
@FXML
|
||||
void bCopyClicked(ActionEvent event) {
|
||||
final Clipboard clipboard = Clipboard.getSystemClipboard();
|
||||
final ClipboardContent content = new ClipboardContent();
|
||||
String s = "";
|
||||
for(Object c : tvAblauf.getRoot().getChildren()) {
|
||||
if(c instanceof TreeItem) {
|
||||
s += generateClipboardContent((TreeItem) c, "");
|
||||
}
|
||||
}
|
||||
|
||||
content.putString(s);
|
||||
|
||||
clipboard.setContent(content);
|
||||
}
|
||||
|
||||
private String generateClipboardContent(TreeItem t, String tab) {
|
||||
String s = tab+t.getValue();
|
||||
for(Object c : t.getChildren()) {
|
||||
if(c instanceof TreeItem) {
|
||||
s += generateClipboardContent((TreeItem) c, tab+" ");
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue