Removed the adding/removing logic from PSD controller
The only thing that the controller of the Polling Station Dashboard suppose to do is to handle events (not manage the llogic of adding or removing actual parts/panels to the main stage ) this is why this logic is now mainteined in saparated objects as Settings Visual Updater or Status Log Visual Updatervoting-station-gui
parent
f2dc2ec6d8
commit
c80aa8efc1
|
@ -9,7 +9,7 @@
|
|||
|
||||
<GridPane fx:id="StatusLogGridPane" prefHeight="615.0" prefWidth="400.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="polling_station_dashboard.statusLog.java.StatusLogController">
|
||||
<children>
|
||||
<BorderPane onMousePressed="#CloseStatusLog" prefHeight="200.0" prefWidth="200.0">
|
||||
<BorderPane prefHeight="200.0" prefWidth="200.0">
|
||||
<center>
|
||||
<Label text="Status Log" BorderPane.alignment="CENTER" />
|
||||
</center>
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package polling_station_dashboard.statusLog.java;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
|
@ -10,21 +9,8 @@ import javafx.stage.Stage;
|
|||
public class StatusLogController {
|
||||
|
||||
private Stage primaryStage;
|
||||
private StatusLogUpdate statusLogUpdater;
|
||||
|
||||
public void SetStatusLogUpdater(StatusLogUpdate updater){
|
||||
statusLogUpdater = updater;
|
||||
}
|
||||
|
||||
public void SetStage(Stage stage){
|
||||
primaryStage = stage;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void CloseStatusLog(){
|
||||
// UpdateStatusLog is called from open status log object which means that
|
||||
// the current UpdateStatusLog will close it
|
||||
statusLogUpdater.UpdateStatusLog();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,12 +16,10 @@ public class StatusLogLoader {
|
|||
|
||||
private Stage currentStage;
|
||||
private FXMLLoader fxmlLoader;
|
||||
private StatusLogUpdate statusLogUpdater;
|
||||
|
||||
public StatusLogLoader (Stage primaryStage, StatusLogUpdate updater) throws IOException
|
||||
public StatusLogLoader (Stage primaryStage) throws IOException
|
||||
{
|
||||
currentStage = primaryStage;
|
||||
statusLogUpdater = updater;
|
||||
fxmlLoader = new FXMLLoader(getClass().getResource(STATUS_LOG_FXML_PATH));
|
||||
}
|
||||
|
||||
|
@ -29,7 +27,6 @@ public class StatusLogLoader {
|
|||
GridPane StatusLog = fxmlLoader.load();
|
||||
StatusLogController controller = fxmlLoader.getController();
|
||||
controller.SetStage(currentStage);
|
||||
controller.SetStatusLogUpdater(statusLogUpdater);
|
||||
|
||||
return StatusLog;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<children>
|
||||
<BorderPane prefHeight="102.0" prefWidth="714.0">
|
||||
<right>
|
||||
<Button mnemonicParsing="false" prefHeight="50.0" prefWidth="112.0" text="Search" BorderPane.alignment="CENTER" />
|
||||
<Button mnemonicParsing="false" onMousePressed="#SearchTrigered" prefHeight="50.0" prefWidth="112.0" text="Search" BorderPane.alignment="CENTER" />
|
||||
</right>
|
||||
<bottom>
|
||||
<Separator prefWidth="200.0" BorderPane.alignment="CENTER" />
|
||||
|
@ -67,14 +67,14 @@
|
|||
<Separator orientation="VERTICAL" prefHeight="200.0" BorderPane.alignment="CENTER" />
|
||||
</right>
|
||||
</BorderPane>
|
||||
<Pane fx:id="StatusLog" layoutX="788.0" layoutY="12.0" prefHeight="544.0" prefWidth="42.0">
|
||||
<Pane fx:id="StatusLog" onMousePressed="#OnStatusLogPressed" layoutX="788.0" layoutY="12.0" prefHeight="544.0" prefWidth="42.0">
|
||||
<children>
|
||||
<Button fx:id="StatusLogButton" layoutX="-251.0" layoutY="250.0" mnemonicParsing="false" onMousePressed="#OnStatusLogPressed" prefHeight="43.0" prefWidth="545.0" rotate="-90.0" text="Status Log" />
|
||||
</children>
|
||||
</Pane>
|
||||
<Pane fx:id="Settings" layoutX="20" layoutY="557.0" prefHeight="34.0" prefWidth="830.0">
|
||||
<Pane fx:id="Settings" onMousePressed="#OnSettingsPressed" layoutX="20" layoutY="557.0" prefHeight="34.0" prefWidth="830.0">
|
||||
<children>
|
||||
<Button fx:id="SettingsButton" onMousePressed="#OnSettingsPressed" mnemonicParsing="false" prefHeight="34.0" prefWidth="790.0" text="Settings" />
|
||||
<Button fx:id="SettingsButton" mnemonicParsing="false" onMousePressed="#OnSettingsPressed" prefHeight="34.0" prefWidth="790.0" text="Settings" />
|
||||
</children>
|
||||
</Pane>
|
||||
</children>
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
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;
|
||||
|
@ -12,109 +9,43 @@ 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;
|
||||
public class PollingStationDashboardController {
|
||||
|
||||
private SettingsUpdate SettingsVisualUpdater;
|
||||
private StatusLogUpdate StatusLogVisualUpdater;
|
||||
private Stage currentStage;
|
||||
private GridPane statusLog;
|
||||
private GridPane settings;
|
||||
|
||||
private boolean statusLogOpened = false;
|
||||
private boolean settingsOpened = false;
|
||||
|
||||
public void SetStage(Stage primaryStage) {
|
||||
public void SetStage(Stage primaryStage)
|
||||
{
|
||||
this.currentStage = primaryStage;
|
||||
}
|
||||
|
||||
public void SetStatusLog(GridPane statusLog){
|
||||
this.statusLog = statusLog;
|
||||
public void SetSettingsVisualUpdater(SettingsUpdate settingsVisualUpdater)
|
||||
{
|
||||
this.SettingsVisualUpdater = settingsVisualUpdater;
|
||||
}
|
||||
|
||||
public void SetStatusLogVisualUpdater(StatusLogUpdate statusLogVisualUpdater)
|
||||
{
|
||||
this.StatusLogVisualUpdater = statusLogVisualUpdater;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void OnStatusLogPressed()
|
||||
{
|
||||
StatusLogVisualUpdater.UpdateStatusLog();
|
||||
}
|
||||
|
||||
|
||||
@FXML
|
||||
private void OnStatusLogPressed() {
|
||||
UpdateStatusLog();
|
||||
private void OnSettingsPressed()
|
||||
{
|
||||
SettingsVisualUpdater.UpdateSettings();
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
private void SearchTrigered(){
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@ import javafx.fxml.FXMLLoader;
|
|||
import javafx.scene.Parent;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.stage.Stage;
|
||||
import polling_station_dashboard.settings.java.SettingsVisualUpdater;
|
||||
import polling_station_dashboard.statusLog.java.StatusLogLoader;
|
||||
import polling_station_dashboard.settings.java.settingsLoader;
|
||||
import polling_station_dashboard.statusLog.java.StatusLogVisualUpdater;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -33,14 +35,25 @@ public class PollingStationDashboardLoader {
|
|||
currentStage.setScene(new Scene(root, 850, 615));
|
||||
currentStage.show();
|
||||
|
||||
// create the status log object
|
||||
StatusLogLoader statusLogLoader = new StatusLogLoader(currentStage, controller);
|
||||
controller.SetStage(currentStage);
|
||||
controller.SetStatusLog(statusLogLoader.GetStatusLogInstance());
|
||||
|
||||
// create the settings object
|
||||
settingsLoader settingsLoader = new settingsLoader(currentStage, controller);
|
||||
controller.SetSettings(settingsLoader.GetSettingsInstance());
|
||||
setSettingsUpdater(controller);
|
||||
setStatusLogUpdater(controller);
|
||||
|
||||
}
|
||||
|
||||
private void setSettingsUpdater(PollingStationDashboardController controller) throws IOException
|
||||
{
|
||||
settingsLoader settingsLoader = new settingsLoader(currentStage);
|
||||
SettingsVisualUpdater settingsVisualUpdater =
|
||||
new SettingsVisualUpdater(settingsLoader.GetSettingsInstance(), currentStage);
|
||||
controller.SetSettingsVisualUpdater(settingsVisualUpdater);
|
||||
}
|
||||
|
||||
private void setStatusLogUpdater(PollingStationDashboardController controller) throws IOException
|
||||
{
|
||||
StatusLogLoader statusLogLoader = new StatusLogLoader(currentStage);
|
||||
StatusLogVisualUpdater statusLogVisualUpdater =
|
||||
new StatusLogVisualUpdater(statusLogLoader.GetStatusLogInstance(), currentStage);
|
||||
controller.SetStatusLogVisualUpdater(statusLogVisualUpdater);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
<RowConstraints maxHeight="561.0" minHeight="10.0" prefHeight="561.0" vgrow="SOMETIMES" />
|
||||
</rowConstraints>
|
||||
<children>
|
||||
<GridPane onMousePressed="#CloseSettings" GridPane.rowIndex="1">
|
||||
<GridPane GridPane.rowIndex="1">
|
||||
<columnConstraints>
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="80.0" minWidth="10.0" prefWidth="53.0" />
|
||||
<ColumnConstraints hgrow="SOMETIMES" maxWidth="125.0" minWidth="10.0" prefWidth="117.0" />
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
package polling_station_dashboard.settings.java;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 12/06/2016.
|
||||
* This object manages the visual changes of the settings panel
|
||||
* which means that he opens and closes settings panel)
|
||||
*/
|
||||
public class SettingsVisualUpdater implements SettingsUpdate {
|
||||
|
||||
private GridPane settings;
|
||||
private static final int SETTINGS_HEIGHT_EXPANSION_VALUE = 60;
|
||||
private boolean settingsOpened = false;
|
||||
private Stage currentStage;
|
||||
|
||||
public SettingsVisualUpdater(GridPane settings, Stage primalStage)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.currentStage = primalStage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void UpdateSettings() {
|
||||
showSettingsButton(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);
|
||||
}
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
package polling_station_dashboard.settings.java;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
|
@ -10,20 +9,9 @@ import javafx.stage.Stage;
|
|||
public class settingsController {
|
||||
|
||||
private Stage currentStage;
|
||||
private SettingsUpdate settingsUpdater;
|
||||
|
||||
public void SetStage(Stage stage){
|
||||
this.currentStage = stage;
|
||||
}
|
||||
|
||||
public void SetSettingsUpdate(SettingsUpdate updater){
|
||||
this.settingsUpdater = updater;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void CloseSettings(){
|
||||
// UpdateStatusLog is called from open status log object which means that
|
||||
// the current UpdateStatusLog will close it
|
||||
this.settingsUpdater.UpdateSettings();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,12 +16,10 @@ public class settingsLoader {
|
|||
|
||||
private Stage currentStage;
|
||||
private FXMLLoader fxmlLoader;
|
||||
private SettingsUpdate settingsUpdater;
|
||||
|
||||
public settingsLoader(Stage primaryStage, SettingsUpdate updater) throws IOException
|
||||
public settingsLoader(Stage primaryStage) throws IOException
|
||||
{
|
||||
currentStage = primaryStage;
|
||||
settingsUpdater = updater;
|
||||
fxmlLoader = new FXMLLoader(getClass().getResource(SETTINGS_FXML_PATH));
|
||||
}
|
||||
|
||||
|
@ -29,7 +27,6 @@ public class settingsLoader {
|
|||
GridPane settings = fxmlLoader.load();
|
||||
settingsController controller = fxmlLoader.getController();
|
||||
controller.SetStage(currentStage);
|
||||
controller.SetSettingsUpdate(settingsUpdater);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
package polling_station_dashboard.statusLog.java;
|
||||
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.layout.GridPane;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 12/06/2016.
|
||||
* This object manages the visual changes of the status log panel
|
||||
* which means that he opens and closes status log panel)
|
||||
*/
|
||||
public class StatusLogVisualUpdater implements StatusLogUpdate {
|
||||
|
||||
private static final int STATUS_LOG_WIDTH_EXPANSION_VALUE = 400;
|
||||
private boolean statusLogOpened = false;
|
||||
private Stage currentStage;
|
||||
private GridPane statusLog;
|
||||
|
||||
|
||||
public StatusLogVisualUpdater(GridPane statusLog, Stage primalStage)
|
||||
{
|
||||
this.statusLog = statusLog;
|
||||
this.currentStage = primalStage;
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue