meerkat-java/voting-station-gui/src/polling_station_dashboard/java/PollingStationDashboardCont...

121 lines
3.7 KiB
Java
Raw Normal View History

package polling_station_dashboard.java;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import polling_station_dashboard.StatusLog.java.StatusLogUpdate;
import polling_station_dashboard.settings.java.SettingsUpdate;
/**
* Created by Vladimir Eliezer Tokarev on 28/05/2016.
* PollingStationDashboardController controls the behavior of the polling station dashboard
*/
public class PollingStationDashboardController implements StatusLogUpdate, SettingsUpdate {
private static final int STATUS_LOG_WIDTH_EXPANSION_VALUE = 400;
private static final int SETTINGS_HEIGHT_EXPANSION_VALUE = 60;
private Stage currentStage;
private GridPane statusLog;
private GridPane settings;
private boolean statusLogOpened = false;
private boolean settingsOpened = false;
public void SetStage(Stage primaryStage) {
this.currentStage = primaryStage;
}
public void SetStatusLog(GridPane statusLog){
this.statusLog = statusLog;
}
@FXML
private void OnStatusLogPressed() {
UpdateStatusLog();
}
@Override
public void UpdateStatusLog(){
showStatusLogButton(statusLogOpened);
if (!statusLogOpened) {
SetStatusLogSize(STATUS_LOG_WIDTH_EXPANSION_VALUE);
addStatusLog();
}
else {
SetStatusLogSize(-STATUS_LOG_WIDTH_EXPANSION_VALUE);
removeStatusLog();
}
statusLogOpened = !statusLogOpened;
}
private void showStatusLogButton(boolean showOrNot){
Button statusLogButton = (Button) currentStage.getScene().lookup("#StatusLogButton");
statusLogButton.setVisible(showOrNot);
}
private void addStatusLog() {
Pane statusLog = (Pane) currentStage.getScene().lookup("#StatusLog");
statusLog.getChildren().add(this.statusLog);
}
private void removeStatusLog(){
Pane statusLog = (Pane) currentStage.getScene().lookup("#StatusLog");
statusLog.getChildren().remove(this.statusLog);
}
private void SetStatusLogSize(int expansionWidth) {
currentStage.setWidth(currentStage.getWidth() + expansionWidth);
Pane statusLog = (Pane) currentStage.getScene().lookup("#StatusLog");
statusLog.setPrefWidth(expansionWidth);
}
@FXML
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);
}
}