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
|
|
@ -3,6 +3,11 @@ package control;
|
|||
import imp.*;
|
||||
import graph.*;
|
||||
import algorithmen.*;
|
||||
import java.io.FileReader;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.FileWriter;
|
||||
|
||||
import javafx.fxml.*;
|
||||
import javafx.scene.control.*;
|
||||
|
|
@ -18,6 +23,7 @@ import java.io.File;
|
|||
import java.nio.file.*;
|
||||
import javafx.stage.FileChooser.ExtensionFilter;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.geometry.Rectangle2D;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -26,11 +32,14 @@ import javafx.collections.ObservableList;
|
|||
* Die Klasse Controller stellt den Controller des Hauptfensters / Menu dar.
|
||||
*
|
||||
* @author Thomas Schaller
|
||||
* @version v6.7 (9.12.2020)
|
||||
* @version 03.03.2023 (v7.1)
|
||||
* v7.0: Die aktuelle Bildschirmposition und der angezeigte Graph werden in config.csv abgelegt.
|
||||
* v7.1: Verzeichnisauswahl für Laden/Speichern verbessert
|
||||
*/
|
||||
|
||||
public class Controller {
|
||||
private String version = "6.8 (Februar 2021)";
|
||||
private String version = "7.0 (Februar 2023)";
|
||||
private String pfad; // Pfad der aktuell angezeigten Datei
|
||||
|
||||
@FXML
|
||||
private TabPane tpRekursionen;
|
||||
|
|
@ -74,8 +83,10 @@ public class Controller {
|
|||
private FileChooser dateidialog;
|
||||
private Graph graph;
|
||||
private GraphOptions options;
|
||||
private Stage stage;
|
||||
|
||||
public void initialize() {
|
||||
|
||||
dateidialog = new FileChooser();
|
||||
dateidialog.setInitialDirectory(new File("beispielgraphen"));
|
||||
|
||||
|
|
@ -85,6 +96,60 @@ public class Controller {
|
|||
tpRekursionen.getSelectionModel().selectedItemProperty().
|
||||
addListener((value, tabOld, tabNew) -> changeTab(tabOld, tabNew));
|
||||
|
||||
BufferedReader in =null;
|
||||
try{
|
||||
in = new BufferedReader(new FileReader("config.csv"));
|
||||
String fullScreen = in.readLine();
|
||||
String posSize = in.readLine();
|
||||
String[] ps = posSize.split(",");
|
||||
Rectangle2D ss = Screen.getPrimary().getBounds();
|
||||
|
||||
stage.setX(Double.parseDouble(ps[0]));
|
||||
stage.setY(Double.parseDouble(ps[1]));
|
||||
stage.setWidth(Math.min(Double.parseDouble(ps[2]), ss.getWidth()-Double.parseDouble(ps[0])));
|
||||
stage.setHeight(Math.min(Double.parseDouble(ps[3]), ss.getHeight()-Double.parseDouble(ps[1])));
|
||||
String[] fs = fullScreen.split(",");
|
||||
if(fs[0].equals("true")) stage.setFullScreen(true);
|
||||
if(fs[1].equals("true")) stage.setMaximized(true);
|
||||
pfad = in.readLine();
|
||||
File f = new File(pfad);
|
||||
f.getCanonicalPath();
|
||||
if(!pfad.isBlank() && f.exists()){
|
||||
graphLaden(pfad);
|
||||
dateidialog.setInitialDirectory((f.getAbsoluteFile()).getParentFile());
|
||||
} else {
|
||||
pfad = "";
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
pfad = "";
|
||||
dateidialog.setInitialDirectory(new File("beispielgraphen"));
|
||||
}
|
||||
finally{
|
||||
try{if(in != null) in.close();} catch(IOException e) {}
|
||||
showTitle();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void saveAktConfig() {
|
||||
PrintWriter pWriter = null;
|
||||
String s = "config.csv";
|
||||
try {
|
||||
pWriter = new PrintWriter(new FileWriter(s));
|
||||
pWriter.println(stage.isFullScreen()+","+stage.isMaximized());
|
||||
stage.setFullScreen(false);
|
||||
stage.setMaximized(false);
|
||||
pWriter.println(stage.getX()+","+stage.getY()+","+stage.getWidth()+","+ stage.getHeight());
|
||||
pWriter.println(pfad);
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
} finally {
|
||||
if (pWriter != null) {
|
||||
pWriter.flush();
|
||||
pWriter.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void changeTab(Tab tabOld, Tab tabNew) {
|
||||
|
|
@ -113,20 +178,26 @@ public class Controller {
|
|||
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.println(e);
|
||||
// System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void setStage(Stage s){
|
||||
stage = s;
|
||||
}
|
||||
|
||||
@FXML
|
||||
void mNeuerGraph(ActionEvent event) {
|
||||
while(tpRekursionen.getTabs().size()>1) tpRekursionen.getTabs().remove(1);
|
||||
|
||||
TabMitController tc = (TabMitController) (tpRekursionen.getTabs().get(0));
|
||||
options = new GraphOptions();
|
||||
|
||||
graph = new Graph();
|
||||
options = new GraphOptions(graph);
|
||||
tc.setGraph(graph, options);
|
||||
pfad = "";
|
||||
|
||||
showTitle();
|
||||
menuChangeAnsicht();
|
||||
}
|
||||
|
||||
|
|
@ -154,7 +225,7 @@ public class Controller {
|
|||
tpRekursionen.getSelectionModel().select(newtab);
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.println(e);
|
||||
//System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,7 +244,7 @@ public class Controller {
|
|||
tpRekursionen.getSelectionModel().select(newtab);
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.println(e);
|
||||
// System.out.println(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,10 +304,11 @@ public class Controller {
|
|||
|
||||
@FXML
|
||||
public void mBeenden(ActionEvent event) {
|
||||
saveAktConfig();
|
||||
schliesseTabs();
|
||||
((Stage)tpRekursionen.getScene().getWindow()).close();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
void menuChangeAnsicht() {
|
||||
TabMitController tc = (TabMitController) (tpRekursionen.getSelectionModel().getSelectedItem());
|
||||
|
|
@ -322,43 +394,74 @@ public class Controller {
|
|||
|
||||
@FXML
|
||||
void mOeffnen(ActionEvent event) {
|
||||
dateidialog.getExtensionFilters().clear();
|
||||
dateidialog.getExtensionFilters().add(new ExtensionFilter("Graph-Datei (*.csv)", "*.csv"));
|
||||
|
||||
File file = dateidialog.showOpenDialog(null);
|
||||
if (file != null) {
|
||||
graphLaden(file.getAbsolutePath());
|
||||
dateidialog.setInitialDirectory(file.getAbsoluteFile().getParentFile());
|
||||
}
|
||||
}
|
||||
|
||||
void graphLaden(String dateiname) {
|
||||
void graphLaden(String p) {
|
||||
|
||||
while(tpRekursionen.getTabs().size()>2) tpRekursionen.getTabs().remove(1);
|
||||
|
||||
TabMitController tc = (TabMitController) (tpRekursionen.getTabs().get(0));
|
||||
options = new GraphOptions();
|
||||
|
||||
Table csvParser = new Table(dateiname,"",',','"');
|
||||
options.ladeGraph(csvParser);
|
||||
graph = new Graph();
|
||||
graph.ladeGraph(csvParser);
|
||||
File f = new File(p);
|
||||
if(f.exists() ){
|
||||
pfad = p;
|
||||
|
||||
Table csvParser = new Table(pfad,"",',','"');
|
||||
|
||||
graph = new Graph();
|
||||
graph.ladeGraph(csvParser);
|
||||
|
||||
options = new GraphOptions(graph);
|
||||
options.ladeGraph(csvParser);
|
||||
|
||||
tc.setGraph(graph, options);
|
||||
if(tpRekursionen.getTabs().size()>1){
|
||||
tc = (TabMitController) (tpRekursionen.getTabs().get(1));
|
||||
tc.setGraph(graph, options);
|
||||
}
|
||||
|
||||
if(tpRekursionen.getTabs().size()>1){
|
||||
tc = (TabMitController) (tpRekursionen.getTabs().get(1));
|
||||
tc.setGraph(graph, options);
|
||||
}
|
||||
}
|
||||
|
||||
menuChangeAnsicht();
|
||||
showTitle();
|
||||
|
||||
}
|
||||
|
||||
public void showTitle() {
|
||||
|
||||
if(stage!=null) {
|
||||
if(pfad == null || pfad.equals("")) {
|
||||
stage.setTitle("GraphTester by Thomas Schaller - Version "+version);
|
||||
} else {
|
||||
String[] arr = pfad.split("[/\\\\]");
|
||||
String dateiname = arr[arr.length-1];
|
||||
stage.setTitle("GraphTester by Thomas Schaller - Version "+version+" - "+dateiname);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@FXML
|
||||
void mSchliessen(ActionEvent event) {
|
||||
mNeuerGraph(event);
|
||||
mNeuerGraph(event);
|
||||
}
|
||||
|
||||
@FXML
|
||||
void mSpeichern(ActionEvent event) {
|
||||
dateidialog.getExtensionFilters().clear();
|
||||
dateidialog.getExtensionFilters().add(new ExtensionFilter("Graph-Datei (*.csv)", "*.csv"));
|
||||
dateidialog.getExtensionFilters().clear();
|
||||
dateidialog.getExtensionFilters().add(new ExtensionFilter("Graph-Datei (*.csv)", "*.csv"));
|
||||
if(!pfad.isBlank())
|
||||
dateidialog.setInitialFileName(new File(pfad).getName());
|
||||
else
|
||||
dateidialog.setInitialFileName("");
|
||||
|
||||
File file = dateidialog.showSaveDialog(null);
|
||||
if (file != null) {
|
||||
try{
|
||||
|
|
@ -371,7 +474,9 @@ public class Controller {
|
|||
String name = dateiName.substring(dateiName.lastIndexOf("\\")+1);
|
||||
if(name.contains(".")) dateiName = dateiName.substring(0, dateiName.lastIndexOf("."));
|
||||
Files.write(Paths.get(file.getAbsolutePath()), text.getBytes());
|
||||
|
||||
pfad = file.getAbsolutePath();
|
||||
dateidialog.setInitialDirectory(file.getAbsoluteFile().getParentFile());
|
||||
showTitle();
|
||||
} catch(Exception e) {
|
||||
|
||||
}
|
||||
|
|
@ -381,21 +486,22 @@ public class Controller {
|
|||
|
||||
@FXML
|
||||
void mBildExportieren(ActionEvent event) {
|
||||
dateidialog.getExtensionFilters().clear();
|
||||
dateidialog.getExtensionFilters().add(new ExtensionFilter("Bild des Graphen", "*.png","*.gif"));
|
||||
File file = dateidialog.showSaveDialog(null);
|
||||
dateidialog.getExtensionFilters().clear();
|
||||
dateidialog.getExtensionFilters().add(new ExtensionFilter("Bild des Graphen", "*.png","*.gif"));
|
||||
File file = dateidialog.showSaveDialog(null);
|
||||
if (file != null) {
|
||||
try{
|
||||
TabMitController tc = (TabMitController) (tpRekursionen.getSelectionModel().getSelectedItem());
|
||||
Picture p = tc.getViewer().updateImage();
|
||||
String dateiName = file.getAbsolutePath();
|
||||
p.save(dateiName);
|
||||
p.save(dateiName);
|
||||
|
||||
} catch(Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
void mUeber(ActionEvent event) {
|
||||
Alert alert = new Alert(AlertType.INFORMATION);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue