2020-04-05 19:11:50 +00:00
|
|
|
package de.wwwu.awolf.view.controller;
|
|
|
|
|
2020-04-05 20:27:56 +00:00
|
|
|
import de.wwwu.awolf.model.dao.Line;
|
|
|
|
import de.wwwu.awolf.model.dao.LineModel;
|
2020-04-05 19:11:50 +00:00
|
|
|
import de.wwwu.awolf.presenter.algorithms.Algorithm;
|
|
|
|
import de.wwwu.awolf.view.services.ButtonClickService;
|
2020-04-06 11:07:10 +00:00
|
|
|
import java.util.HashMap;
|
2020-04-05 19:11:50 +00:00
|
|
|
import java.util.Map;
|
|
|
|
import javafx.beans.property.BooleanProperty;
|
2020-04-06 11:07:10 +00:00
|
|
|
import javafx.beans.property.SimpleObjectProperty;
|
2020-04-05 19:11:50 +00:00
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.geometry.Insets;
|
|
|
|
import javafx.geometry.Pos;
|
|
|
|
import javafx.scene.chart.LineChart;
|
|
|
|
import javafx.scene.chart.XYChart;
|
|
|
|
import javafx.scene.control.Button;
|
|
|
|
import javafx.scene.control.Label;
|
|
|
|
import javafx.scene.control.TextField;
|
|
|
|
import javafx.scene.layout.BorderPane;
|
|
|
|
import javafx.scene.layout.VBox;
|
2020-04-06 11:07:10 +00:00
|
|
|
import javax.annotation.Nullable;
|
2020-04-05 19:11:50 +00:00
|
|
|
|
|
|
|
public class AlgorithmTabController {
|
|
|
|
|
|
|
|
private final XYChart.Series<Double, Double> dataSerie;
|
|
|
|
private final XYChart.Series<Double, Double> lineSerie;
|
|
|
|
@FXML
|
2020-04-05 20:27:56 +00:00
|
|
|
private LineChart<Double, Double> chart;
|
2020-04-05 19:11:50 +00:00
|
|
|
@FXML
|
2020-04-05 20:27:56 +00:00
|
|
|
private VBox vBox;
|
2020-04-05 19:11:50 +00:00
|
|
|
@FXML
|
2020-04-05 20:27:56 +00:00
|
|
|
private Button startButton;
|
|
|
|
|
2020-04-05 19:11:50 +00:00
|
|
|
private Algorithm.Type algorithmType;
|
2020-04-06 11:07:10 +00:00
|
|
|
private Map<String, SimpleObjectProperty<String>> properties;
|
2020-04-05 19:11:50 +00:00
|
|
|
private LineModel model;
|
|
|
|
|
|
|
|
public AlgorithmTabController() {
|
|
|
|
dataSerie = new XYChart.Series<>();
|
|
|
|
dataSerie.setName("Datapoints");
|
|
|
|
lineSerie = new XYChart.Series<>();
|
|
|
|
lineSerie.setName("Estimated Line");
|
|
|
|
}
|
|
|
|
|
|
|
|
public LineModel getModel() {
|
|
|
|
return model;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setModel(LineModel model) {
|
|
|
|
this.model = model;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init() {
|
|
|
|
// add GUI elements to maintain the parameters
|
2020-04-05 20:27:56 +00:00
|
|
|
if (properties != null) {
|
|
|
|
properties.forEach((key, value) -> {
|
|
|
|
//Pane component for the layout
|
|
|
|
BorderPane borderPane = new BorderPane();
|
|
|
|
borderPane.setPadding(new Insets(10, 0, 10, 0));
|
|
|
|
|
|
|
|
//text field for the input
|
2020-04-06 11:07:10 +00:00
|
|
|
TextField textField = new TextField(String.valueOf(value.get()));
|
|
|
|
textField.textProperty().bindBidirectional(value);
|
2020-04-05 20:27:56 +00:00
|
|
|
|
|
|
|
//label
|
|
|
|
Label label = new Label(key);
|
|
|
|
label.setAlignment(Pos.BASELINE_LEFT);
|
|
|
|
label.setLabelFor(textField);
|
|
|
|
label.setPadding(new Insets(2, 10, 0, 0));
|
|
|
|
|
|
|
|
//add components
|
|
|
|
borderPane.setLeft(label);
|
|
|
|
borderPane.setRight(textField);
|
|
|
|
vBox.getChildren().add(borderPane);
|
|
|
|
});
|
|
|
|
}
|
2020-04-05 19:11:50 +00:00
|
|
|
|
|
|
|
BooleanProperty booleanProperty = startButton.disableProperty();
|
|
|
|
startButton.setOnAction(event -> {
|
2020-04-06 11:07:10 +00:00
|
|
|
ButtonClickService buttonClickService = new ButtonClickService(algorithmType, getProperties(), booleanProperty);
|
2020-04-05 19:11:50 +00:00
|
|
|
buttonClickService.start();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
updatePlot(this.model, null);
|
|
|
|
chart.getData().add(dataSerie);
|
|
|
|
chart.getData().add(lineSerie);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updatePlot(final LineModel model, final Line pLine) {
|
|
|
|
dataSerie.getData().clear();
|
|
|
|
model.getLines()
|
|
|
|
.forEach(
|
|
|
|
line -> dataSerie.getData().add(new XYChart.Data<>(line.getM(), line.getB())));
|
|
|
|
|
|
|
|
if (pLine != null) {
|
|
|
|
lineSerie.getData().clear();
|
|
|
|
Double x1 = pLine.calculateX1(model.getMin());
|
|
|
|
Double y1 = pLine.calculateY1(model.getMin());
|
|
|
|
Double x2 = pLine.calculateX2(model.getMax());
|
|
|
|
Double y2 = pLine.calculateY2(model.getMax());
|
|
|
|
|
|
|
|
lineSerie.getData().add(new XYChart.Data<>(x1, y1));
|
|
|
|
lineSerie.getData().add(new XYChart.Data<>(x2, y2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Algorithm.Type getAlgorithmType() {
|
|
|
|
return algorithmType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAlgorithmType(Algorithm.Type algorithmType) {
|
|
|
|
this.algorithmType = algorithmType;
|
|
|
|
}
|
|
|
|
|
2020-04-06 11:07:10 +00:00
|
|
|
@Nullable
|
|
|
|
public Map<String, String> getProperties() {
|
|
|
|
if (properties == null) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
HashMap<String, String> props = new HashMap<>();
|
|
|
|
properties.forEach((key, value) -> {
|
|
|
|
props.put(key, value.get());
|
|
|
|
});
|
|
|
|
return props;
|
|
|
|
}
|
2020-04-05 19:11:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-06 11:07:10 +00:00
|
|
|
public void setProperties(Map<String, String> props) {
|
|
|
|
if (props != null && !props.isEmpty()) {
|
|
|
|
properties = new HashMap<>();
|
|
|
|
props.forEach((key, value) -> {
|
|
|
|
properties.put(key, new SimpleObjectProperty<>(value));
|
|
|
|
});
|
|
|
|
}
|
2020-04-05 19:11:50 +00:00
|
|
|
}
|
|
|
|
|
2020-04-05 20:27:56 +00:00
|
|
|
public Button getStartButton() {
|
|
|
|
return startButton;
|
|
|
|
}
|
2020-04-05 19:11:50 +00:00
|
|
|
}
|