210 lines
6.3 KiB
Java
210 lines
6.3 KiB
Java
package de.wwwu.awolf.view;
|
|
|
|
|
|
import de.wwwu.awolf.model.Line;
|
|
import de.wwwu.awolf.presenter.Presenter;
|
|
import de.wwwu.awolf.presenter.algorithms.Algorithm;
|
|
import de.wwwu.awolf.presenter.data.DataHandler;
|
|
import de.wwwu.awolf.presenter.util.Logging;
|
|
import de.wwwu.awolf.view.controller.AlgorithmTabController;
|
|
import de.wwwu.awolf.view.services.DataService;
|
|
import javafx.application.Platform;
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.FXMLLoader;
|
|
import javafx.scene.Parent;
|
|
import javafx.scene.control.*;
|
|
import javafx.stage.FileChooser;
|
|
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* Implementierung verschiedener Algorithmen zur Berechnung von Ausgleichsgeraden.
|
|
*
|
|
* @Author: Armin Wolf
|
|
* @Email: a_wolf28@uni-muenster.de
|
|
* @Date: 28.05.2017.
|
|
*/
|
|
public class ViewController {
|
|
|
|
private static final String TITLE = "Beta JavaFX";
|
|
private Parent pane;
|
|
|
|
@FXML
|
|
private TabPane tabPane;
|
|
@FXML
|
|
private MenuBar menuBar;
|
|
private Map<Algorithm.Type, AlgorithmTabController> algorithmTabControllers;
|
|
|
|
public Map<Algorithm.Type, AlgorithmTabController> getAlgorithmTabControllers() {
|
|
return algorithmTabControllers;
|
|
}
|
|
|
|
public ViewController() {
|
|
super();
|
|
this.algorithmTabControllers = new EnumMap<>(Algorithm.Type.class);
|
|
}
|
|
|
|
public void initGui() {
|
|
initMenuBar();
|
|
initTabbedPane();
|
|
}
|
|
|
|
private void initTabbedPane() {
|
|
//TODO
|
|
Map<String, String> props = new HashMap<>();
|
|
props.put("sfsdf", "dsadasd");
|
|
props.put("dfd", "dsadasd");
|
|
props.put("sdfdsfg", "dsadasd");
|
|
props.put("dsfsdfsdf", "dsadasd");
|
|
|
|
|
|
try {
|
|
for (Algorithm.Type value : Algorithm.Type.values()) {
|
|
FXMLLoader loader = new FXMLLoader();
|
|
loader.setLocation(AlgorithmTabController.class.getResource("/views/AlgorithmTab.fxml"));
|
|
Parent parent = loader.load();
|
|
AlgorithmTabController controller = loader.getController();
|
|
controller.setAlgorithmType(value);
|
|
controller.setProperties(props);
|
|
controller.setModel(Presenter.getInstance().getModel());
|
|
controller.init();
|
|
this.algorithmTabControllers.put(value, controller);
|
|
Tab tab = new Tab(value.getName(), parent);
|
|
tab.setId(value.name());
|
|
tabPane.getTabs().add(tab);
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
Logging.logError("Error while reading AlgorithmTab.fxml", e);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void initMenuBar() {
|
|
// Create menus
|
|
Menu fileMenu = new Menu("File");
|
|
Menu toolsMenu = new Menu("Tools");
|
|
Menu helpMenu = new Menu("Help");
|
|
|
|
// Create MenuItems
|
|
//export the data
|
|
MenuItem exportItem = new MenuItem("Export");
|
|
exportItem.setOnAction(actionEvent -> {
|
|
FileChooser fileChooser = new FileChooser();
|
|
File file = fileChooser.showOpenDialog(null);
|
|
if (file != null && file.canWrite() && file.canRead()) {
|
|
new DataService(DataHandler.ActionType.EXPORT, file).start();
|
|
}
|
|
});
|
|
|
|
//start an import of data
|
|
MenuItem importItem = new MenuItem("Import");
|
|
importItem.setOnAction(actionEvent -> {
|
|
FileChooser fileChooser = new FileChooser();
|
|
File file = fileChooser.showOpenDialog(null);
|
|
if (file != null && file.canWrite() && file.canRead()) {
|
|
new DataService(DataHandler.ActionType.IMPORT, file).start();
|
|
}
|
|
});
|
|
|
|
//exit menu item should stop the application
|
|
MenuItem exitItem = new MenuItem("Exit");
|
|
exitItem.setOnAction(actionEvent -> {
|
|
Platform.exit();
|
|
System.exit(0);
|
|
});
|
|
|
|
// about the application
|
|
MenuItem aboutItem = new MenuItem("About");
|
|
|
|
MenuItem generationItem = new MenuItem("Generate");
|
|
generationItem.setOnAction(actionEvent -> {
|
|
new DataService(DataHandler.ActionType.GENERATE, DataHandler.DataType.LINE, 1000).start();
|
|
});
|
|
MenuItem evaluationItem = new MenuItem("Evaluate");
|
|
|
|
// Add menuItems to the Menus
|
|
fileMenu.getItems().addAll(importItem, exportItem, exitItem);
|
|
toolsMenu.getItems().addAll(generationItem, evaluationItem);
|
|
helpMenu.getItems().addAll(aboutItem);
|
|
|
|
// Add Menus to the MenuBar
|
|
menuBar.getMenus().addAll(fileMenu, toolsMenu, helpMenu);
|
|
|
|
}
|
|
|
|
|
|
/*******************************************************************************************************************
|
|
* visualisierungs methoden
|
|
******************************************************************************************************************/
|
|
|
|
|
|
/**
|
|
* Visualisiert das Ergebnis des LMS-Schätzers
|
|
*
|
|
* @param line Line
|
|
*/
|
|
public void visualizeLMS(final Line line) {
|
|
// plotLMS = new PlotPanel();
|
|
// lmsPanel.setPlotPanel(plotLMS);
|
|
// createPlot(line.getM(), line.getB(), plotLMS, lmsPanel, "LMS");
|
|
}
|
|
|
|
/**
|
|
* Visualisiert das Ergebnis des RM-Schätzers
|
|
*
|
|
* @param line Line
|
|
*/
|
|
public void visualizeRM(final Line line) {
|
|
// plotRM = new PlotPanel();
|
|
// rmPanel.setPlotPanel(plotRM);
|
|
// createPlot(line.getM(), line.getB(), plotRM, rmPanel, "RM");
|
|
}
|
|
|
|
|
|
/**
|
|
* Visualisiert das Ergebnis des TS-Schätzers
|
|
*
|
|
* @param line Line
|
|
*/
|
|
public void visualizeTS(final Line line) {
|
|
// plotTS = new PlotPanel();
|
|
// tsPanel.setPlotPanel(plotTS);
|
|
// createPlot(line.getM(), line.getB(), plotTS, tsPanel, "TS");
|
|
}
|
|
|
|
/**
|
|
* Fügt der Evaluations-Tabelle eine Zeile mit Daten hinzu
|
|
*
|
|
* @param tableEntries Data of the Table
|
|
*/
|
|
public void appendEvalResult(Map<Algorithm.Type, Map<String, String>> tableEntries) {
|
|
|
|
}
|
|
|
|
/**
|
|
* Fügt der Evaluations-Tabelle eine Zeile mit Daten hinzu
|
|
*
|
|
* @param res Daten der Spalte
|
|
*/
|
|
public void appendEvalResults(Map<Algorithm.Type, Map<String, String>> res) {
|
|
appendEvalResult(res);
|
|
}
|
|
|
|
/**
|
|
* Funktionalitäten werden aktiviert.
|
|
*/
|
|
public void enableFunctionality() {
|
|
}
|
|
|
|
/**
|
|
* Funktionalitäten werden deaktiviert.
|
|
*/
|
|
public void disableFunctionality() {
|
|
}
|
|
|
|
}
|