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 Updater
voting-station-gui
Vladimir ELazar Tokarev 2016-06-12 13:18:01 +03:00
parent f2dc2ec6d8
commit c80aa8efc1
11 changed files with 174 additions and 139 deletions

View File

@ -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"> <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> <children>
<BorderPane onMousePressed="#CloseStatusLog" prefHeight="200.0" prefWidth="200.0"> <BorderPane prefHeight="200.0" prefWidth="200.0">
<center> <center>
<Label text="Status Log" BorderPane.alignment="CENTER" /> <Label text="Status Log" BorderPane.alignment="CENTER" />
</center> </center>

View File

@ -1,6 +1,5 @@
package polling_station_dashboard.statusLog.java; package polling_station_dashboard.statusLog.java;
import javafx.fxml.FXML;
import javafx.stage.Stage; import javafx.stage.Stage;
/** /**
@ -10,21 +9,8 @@ import javafx.stage.Stage;
public class StatusLogController { public class StatusLogController {
private Stage primaryStage; private Stage primaryStage;
private StatusLogUpdate statusLogUpdater;
public void SetStatusLogUpdater(StatusLogUpdate updater){
statusLogUpdater = updater;
}
public void SetStage(Stage stage){ public void SetStage(Stage stage){
primaryStage = 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();
}
} }

View File

@ -16,12 +16,10 @@ public class StatusLogLoader {
private Stage currentStage; private Stage currentStage;
private FXMLLoader fxmlLoader; private FXMLLoader fxmlLoader;
private StatusLogUpdate statusLogUpdater;
public StatusLogLoader (Stage primaryStage, StatusLogUpdate updater) throws IOException public StatusLogLoader (Stage primaryStage) throws IOException
{ {
currentStage = primaryStage; currentStage = primaryStage;
statusLogUpdater = updater;
fxmlLoader = new FXMLLoader(getClass().getResource(STATUS_LOG_FXML_PATH)); fxmlLoader = new FXMLLoader(getClass().getResource(STATUS_LOG_FXML_PATH));
} }
@ -29,7 +27,6 @@ public class StatusLogLoader {
GridPane StatusLog = fxmlLoader.load(); GridPane StatusLog = fxmlLoader.load();
StatusLogController controller = fxmlLoader.getController(); StatusLogController controller = fxmlLoader.getController();
controller.SetStage(currentStage); controller.SetStage(currentStage);
controller.SetStatusLogUpdater(statusLogUpdater);
return StatusLog; return StatusLog;
} }

View File

@ -25,7 +25,7 @@
<children> <children>
<BorderPane prefHeight="102.0" prefWidth="714.0"> <BorderPane prefHeight="102.0" prefWidth="714.0">
<right> <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> </right>
<bottom> <bottom>
<Separator prefWidth="200.0" BorderPane.alignment="CENTER" /> <Separator prefWidth="200.0" BorderPane.alignment="CENTER" />
@ -67,14 +67,14 @@
<Separator orientation="VERTICAL" prefHeight="200.0" BorderPane.alignment="CENTER" /> <Separator orientation="VERTICAL" prefHeight="200.0" BorderPane.alignment="CENTER" />
</right> </right>
</BorderPane> </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> <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" /> <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> </children>
</Pane> </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> <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> </children>
</Pane> </Pane>
</children> </children>

View File

@ -1,9 +1,6 @@
package polling_station_dashboard.java; package polling_station_dashboard.java;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.Stage; import javafx.stage.Stage;
import polling_station_dashboard.statusLog.java.StatusLogUpdate; import polling_station_dashboard.statusLog.java.StatusLogUpdate;
import polling_station_dashboard.settings.java.SettingsUpdate; 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. * Created by Vladimir Eliezer Tokarev on 28/05/2016.
* PollingStationDashboardController controls the behavior of the polling station dashboard * PollingStationDashboardController controls the behavior of the polling station dashboard
*/ */
public class PollingStationDashboardController implements StatusLogUpdate, SettingsUpdate { public class PollingStationDashboardController {
private static final int STATUS_LOG_WIDTH_EXPANSION_VALUE = 400;
private static final int SETTINGS_HEIGHT_EXPANSION_VALUE = 60;
private SettingsUpdate SettingsVisualUpdater;
private StatusLogUpdate StatusLogVisualUpdater;
private Stage currentStage; private Stage currentStage;
private GridPane statusLog;
private GridPane settings;
private boolean statusLogOpened = false; public void SetStage(Stage primaryStage)
private boolean settingsOpened = false; {
public void SetStage(Stage primaryStage) {
this.currentStage = primaryStage; this.currentStage = primaryStage;
} }
public void SetStatusLog(GridPane statusLog){ public void SetSettingsVisualUpdater(SettingsUpdate settingsVisualUpdater)
this.statusLog = statusLog; {
this.SettingsVisualUpdater = settingsVisualUpdater;
}
public void SetStatusLogVisualUpdater(StatusLogUpdate statusLogVisualUpdater)
{
this.StatusLogVisualUpdater = statusLogVisualUpdater;
}
@FXML
private void OnStatusLogPressed()
{
StatusLogVisualUpdater.UpdateStatusLog();
} }
@FXML @FXML
private void OnStatusLogPressed() { private void OnSettingsPressed()
UpdateStatusLog(); {
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 @FXML
private void OnSettingsPressed() { private void SearchTrigered(){
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);
} }
} }

View File

@ -4,8 +4,10 @@ import javafx.fxml.FXMLLoader;
import javafx.scene.Parent; import javafx.scene.Parent;
import javafx.scene.Scene; import javafx.scene.Scene;
import javafx.stage.Stage; import javafx.stage.Stage;
import polling_station_dashboard.settings.java.SettingsVisualUpdater;
import polling_station_dashboard.statusLog.java.StatusLogLoader; import polling_station_dashboard.statusLog.java.StatusLogLoader;
import polling_station_dashboard.settings.java.settingsLoader; import polling_station_dashboard.settings.java.settingsLoader;
import polling_station_dashboard.statusLog.java.StatusLogVisualUpdater;
import java.io.IOException; import java.io.IOException;
@ -33,14 +35,25 @@ public class PollingStationDashboardLoader {
currentStage.setScene(new Scene(root, 850, 615)); currentStage.setScene(new Scene(root, 850, 615));
currentStage.show(); currentStage.show();
// create the status log object
StatusLogLoader statusLogLoader = new StatusLogLoader(currentStage, controller);
controller.SetStage(currentStage); controller.SetStage(currentStage);
controller.SetStatusLog(statusLogLoader.GetStatusLogInstance()); setSettingsUpdater(controller);
setStatusLogUpdater(controller);
// create the settings object
settingsLoader settingsLoader = new settingsLoader(currentStage, controller);
controller.SetSettings(settingsLoader.GetSettingsInstance());
} }
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);
}
} }

View File

@ -19,7 +19,7 @@
<RowConstraints maxHeight="561.0" minHeight="10.0" prefHeight="561.0" vgrow="SOMETIMES" /> <RowConstraints maxHeight="561.0" minHeight="10.0" prefHeight="561.0" vgrow="SOMETIMES" />
</rowConstraints> </rowConstraints>
<children> <children>
<GridPane onMousePressed="#CloseSettings" GridPane.rowIndex="1"> <GridPane GridPane.rowIndex="1">
<columnConstraints> <columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="80.0" minWidth="10.0" prefWidth="53.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="80.0" minWidth="10.0" prefWidth="53.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="125.0" minWidth="10.0" prefWidth="117.0" /> <ColumnConstraints hgrow="SOMETIMES" maxWidth="125.0" minWidth="10.0" prefWidth="117.0" />

View File

@ -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);
}
}

View File

@ -1,6 +1,5 @@
package polling_station_dashboard.settings.java; package polling_station_dashboard.settings.java;
import javafx.fxml.FXML;
import javafx.stage.Stage; import javafx.stage.Stage;
/** /**
@ -10,20 +9,9 @@ import javafx.stage.Stage;
public class settingsController { public class settingsController {
private Stage currentStage; private Stage currentStage;
private SettingsUpdate settingsUpdater;
public void SetStage(Stage stage){ public void SetStage(Stage stage){
this.currentStage = 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();
}
} }

View File

@ -16,12 +16,10 @@ public class settingsLoader {
private Stage currentStage; private Stage currentStage;
private FXMLLoader fxmlLoader; private FXMLLoader fxmlLoader;
private SettingsUpdate settingsUpdater;
public settingsLoader(Stage primaryStage, SettingsUpdate updater) throws IOException public settingsLoader(Stage primaryStage) throws IOException
{ {
currentStage = primaryStage; currentStage = primaryStage;
settingsUpdater = updater;
fxmlLoader = new FXMLLoader(getClass().getResource(SETTINGS_FXML_PATH)); fxmlLoader = new FXMLLoader(getClass().getResource(SETTINGS_FXML_PATH));
} }
@ -29,7 +27,6 @@ public class settingsLoader {
GridPane settings = fxmlLoader.load(); GridPane settings = fxmlLoader.load();
settingsController controller = fxmlLoader.getController(); settingsController controller = fxmlLoader.getController();
controller.SetStage(currentStage); controller.SetStage(currentStage);
controller.SetSettingsUpdate(settingsUpdater);
return settings; return settings;
} }

View File

@ -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);
}
}