2016-05-28 10:50:22 -04:00
|
|
|
package polling_station_dashboard.java;
|
|
|
|
|
2016-06-04 06:01:06 -04:00
|
|
|
import javafx.fxml.FXML;
|
2016-06-04 08:11:18 -04:00
|
|
|
import javafx.scene.control.Button;
|
|
|
|
import javafx.scene.layout.GridPane;
|
2016-06-04 06:01:06 -04:00
|
|
|
import javafx.scene.layout.Pane;
|
2016-05-28 11:00:40 -04:00
|
|
|
import javafx.stage.Stage;
|
2016-06-11 07:53:57 -04:00
|
|
|
import polling_station_dashboard.statusLog.java.StatusLogUpdate;
|
2016-06-04 09:05:12 -04:00
|
|
|
import polling_station_dashboard.settings.java.SettingsUpdate;
|
2016-05-28 11:00:40 -04:00
|
|
|
|
2016-05-28 10:50:22 -04:00
|
|
|
/**
|
|
|
|
* Created by Vladimir Eliezer Tokarev on 28/05/2016.
|
2016-06-04 08:11:18 -04:00
|
|
|
* PollingStationDashboardController controls the behavior of the polling station dashboard
|
2016-05-28 10:50:22 -04:00
|
|
|
*/
|
2016-06-04 09:05:12 -04:00
|
|
|
public class PollingStationDashboardController implements StatusLogUpdate, SettingsUpdate {
|
2016-05-28 11:00:40 -04:00
|
|
|
|
2016-06-04 09:48:47 -04:00
|
|
|
private static final int STATUS_LOG_WIDTH_EXPANSION_VALUE = 400;
|
|
|
|
private static final int SETTINGS_HEIGHT_EXPANSION_VALUE = 60;
|
|
|
|
|
2016-05-28 11:00:40 -04:00
|
|
|
private Stage currentStage;
|
2016-06-04 08:11:18 -04:00
|
|
|
private GridPane statusLog;
|
2016-06-04 09:48:47 -04:00
|
|
|
private GridPane settings;
|
2016-05-28 11:00:40 -04:00
|
|
|
|
2016-06-04 06:01:06 -04:00
|
|
|
private boolean statusLogOpened = false;
|
2016-06-04 09:48:47 -04:00
|
|
|
private boolean settingsOpened = false;
|
2016-06-04 06:01:06 -04:00
|
|
|
|
2016-06-04 08:11:18 -04:00
|
|
|
public void SetStage(Stage primaryStage) {
|
2016-05-28 11:00:40 -04:00
|
|
|
this.currentStage = primaryStage;
|
|
|
|
}
|
2016-06-04 06:01:06 -04:00
|
|
|
|
2016-06-04 08:11:18 -04:00
|
|
|
public void SetStatusLog(GridPane statusLog){
|
|
|
|
this.statusLog = statusLog;
|
|
|
|
}
|
|
|
|
|
2016-06-04 09:48:47 -04:00
|
|
|
|
|
|
|
@FXML
|
|
|
|
private void OnStatusLogPressed() {
|
|
|
|
UpdateStatusLog();
|
|
|
|
}
|
|
|
|
|
2016-06-04 08:11:18 -04:00
|
|
|
@Override
|
|
|
|
public void UpdateStatusLog(){
|
|
|
|
showStatusLogButton(statusLogOpened);
|
2016-06-04 06:01:06 -04:00
|
|
|
if (!statusLogOpened) {
|
2016-06-04 09:48:47 -04:00
|
|
|
SetStatusLogSize(STATUS_LOG_WIDTH_EXPANSION_VALUE);
|
2016-06-04 08:11:18 -04:00
|
|
|
addStatusLog();
|
2016-06-04 06:01:06 -04:00
|
|
|
}
|
|
|
|
else {
|
2016-06-04 09:48:47 -04:00
|
|
|
SetStatusLogSize(-STATUS_LOG_WIDTH_EXPANSION_VALUE);
|
2016-06-04 08:11:18 -04:00
|
|
|
removeStatusLog();
|
2016-06-04 06:01:06 -04:00
|
|
|
}
|
|
|
|
statusLogOpened = !statusLogOpened;
|
|
|
|
}
|
|
|
|
|
2016-06-04 08:11:18 -04:00
|
|
|
private void showStatusLogButton(boolean showOrNot){
|
|
|
|
Button statusLogButton = (Button) currentStage.getScene().lookup("#StatusLogButton");
|
|
|
|
statusLogButton.setVisible(showOrNot);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addStatusLog() {
|
2016-06-11 07:53:57 -04:00
|
|
|
Pane statusLog = (Pane) currentStage.getScene().lookup("#statusLog");
|
2016-06-04 09:48:47 -04:00
|
|
|
statusLog.getChildren().add(this.statusLog);
|
2016-06-04 08:11:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
private void removeStatusLog(){
|
2016-06-11 07:53:57 -04:00
|
|
|
Pane statusLog = (Pane) currentStage.getScene().lookup("#statusLog");
|
2016-06-04 09:48:47 -04:00
|
|
|
statusLog.getChildren().remove(this.statusLog);
|
2016-06-04 08:11:18 -04:00
|
|
|
}
|
|
|
|
|
2016-06-04 06:01:06 -04:00
|
|
|
private void SetStatusLogSize(int expansionWidth) {
|
|
|
|
currentStage.setWidth(currentStage.getWidth() + expansionWidth);
|
2016-06-11 07:53:57 -04:00
|
|
|
Pane statusLog = (Pane) currentStage.getScene().lookup("#statusLog");
|
2016-06-04 09:48:47 -04:00
|
|
|
statusLog.setPrefWidth(expansionWidth);
|
2016-06-04 06:01:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@FXML
|
2016-06-04 09:48:47 -04:00
|
|
|
private void OnSettingsPressed() {
|
|
|
|
UpdateSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetSettings(GridPane settings){
|
|
|
|
this.settings = settings;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void UpdateSettings() {
|
|
|
|
showSettingsButton(settingsOpened);
|
|
|
|
System.out.println(settingsOpened);
|
|
|
|
if (!settingsOpened) {
|
|
|
|
SetSettingsSize(SETTINGS_HEIGHT_EXPANSION_VALUE);
|
|
|
|
addSettings();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
SetSettingsSize(-SETTINGS_HEIGHT_EXPANSION_VALUE);
|
|
|
|
removeSettings();
|
|
|
|
}
|
|
|
|
settingsOpened = !settingsOpened;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void SetSettingsSize(int expansionHeight) {
|
|
|
|
currentStage.setHeight(currentStage.getHeight() + expansionHeight);
|
|
|
|
Pane statusLog = (Pane) currentStage.getScene().lookup("#Settings");
|
|
|
|
statusLog.setPrefHeight(expansionHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showSettingsButton(boolean showOrNot){
|
|
|
|
Button settings = (Button) currentStage.getScene().lookup("#SettingsButton");
|
|
|
|
settings.setVisible(showOrNot);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void addSettings() {
|
|
|
|
Pane settingsPane = (Pane) currentStage.getScene().lookup("#Settings");
|
|
|
|
settingsPane.getChildren().add(settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeSettings(){
|
|
|
|
Pane settingsPane = (Pane) currentStage.getScene().lookup("#Settings");
|
|
|
|
settingsPane.getChildren().remove(settings);
|
2016-06-04 06:01:06 -04:00
|
|
|
}
|
2016-05-28 10:50:22 -04:00
|
|
|
}
|