From 5113c2235b75118e9658eaa5f5751843a0023e39 Mon Sep 17 00:00:00 2001 From: Laura Radaelli Date: Fri, 16 Dec 2016 22:10:23 +0200 Subject: [PATCH] fx gui with MainController and Navigator (incomplete) --- .../StraightChannelSectionController.java | 2 +- .../WelcomeSplashController.java | 2 +- .../voting/VotingBoothToyGraphicalRun.java | 6 +- .../meerkat/voting/gui/ui/GraphicalFX.java | 114 ------------- .../meerkat/voting/gui/ui/GraphicalUI.java | 37 ++--- .../java/meerkat/voting/gui/ui/MainFX.java | 83 +++++++++ .../StraightChannelSectionController.java | 109 ------------ .../controllerFX/WelcomeSplashController.java | 39 ----- .../ChannelChoiceController.java | 157 ++++++++++++++++++ .../controllersFX/StartSessionController.java | 26 +++ .../ui/controllersFX/Vista2Controller.java | 24 +++ .../gui/ui/controllersFX/VistaNavigator.java | 100 +++++++++++ .../channel_choice.fxml} | 2 +- .../src/main/resources/views/loading.fxml | 11 ++ .../src/main/resources/views/main.fxml | 12 ++ .../starting_session.fxml} | 4 +- .../src/main/resources/views/vista.css | 28 ++++ .../src/main/resources/views/vista1.fxml | 11 ++ .../src/main/resources/views/vista2.fxml | 11 ++ 19 files changed, 479 insertions(+), 299 deletions(-) delete mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalFX.java create mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/MainFX.java delete mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/StraightChannelSectionController.java delete mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/WelcomeSplashController.java create mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/ChannelChoiceController.java create mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/StartSessionController.java create mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/Vista2Controller.java create mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VistaNavigator.java rename voting-booth/src/main/resources/{graphical_fxml/straight_channel_section.fxml => views/channel_choice.fxml} (99%) create mode 100644 voting-booth/src/main/resources/views/loading.fxml create mode 100644 voting-booth/src/main/resources/views/main.fxml rename voting-booth/src/main/resources/{graphical_fxml/welcome_splash_screen.fxml => views/starting_session.fxml} (96%) create mode 100644 voting-booth/src/main/resources/views/vista.css create mode 100644 voting-booth/src/main/resources/views/vista1.fxml create mode 100644 voting-booth/src/main/resources/views/vista2.fxml diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/straight_channel_section/StraightChannelSectionController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/straight_channel_section/StraightChannelSectionController.java index ed2e9c1..bf8244a 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/straight_channel_section/StraightChannelSectionController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/straight_channel_section/StraightChannelSectionController.java @@ -13,7 +13,7 @@ import java.util.List; /** * Created by Vladimir Eliezer Tokarev on 8/27/2016. - * StraightChannelSectionController handle the behavior of select channel section screen + * ChannelChoiceController handle the behavior of select channel section screen */ public class StraightChannelSectionController extends TwoWayNode { diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/welcome_splash/WelcomeSplashController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/welcome_splash/WelcomeSplashController.java index dc5a999..ac91ab4 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/welcome_splash/WelcomeSplashController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/welcome_splash/WelcomeSplashController.java @@ -9,7 +9,7 @@ import org.slf4j.LoggerFactory; /** * Created by Vladimir Eliezer Tokarev on 8/27/2016. - * WelcomeSplashController handle the behavior of welcome splash class + * StartSessionController handle the behavior of welcome splash class */ public class WelcomeSplashController extends TwoWayNode { diff --git a/voting-booth/src/main/java/meerkat/voting/VotingBoothToyGraphicalRun.java b/voting-booth/src/main/java/meerkat/voting/VotingBoothToyGraphicalRun.java index 89c1cda..6d72d6f 100644 --- a/voting-booth/src/main/java/meerkat/voting/VotingBoothToyGraphicalRun.java +++ b/voting-booth/src/main/java/meerkat/voting/VotingBoothToyGraphicalRun.java @@ -1,17 +1,13 @@ package meerkat.voting; import com.google.protobuf.ByteString; -import com.sun.corba.se.impl.orbutil.graph.Graph; import meerkat.crypto.DigitalSignature; import meerkat.crypto.Encryption; import meerkat.protobuf.Voting; import meerkat.voting.controller.VotingBoothImpl; import meerkat.voting.encryptor.VBCryptoManager; import meerkat.voting.encryptor.VBCryptoManagerImpl; -import meerkat.voting.gui.ui.GraphicalFX; -import javafx.application.Application; import meerkat.voting.gui.ui.GraphicalUI; -import meerkat.voting.gui.ui.SystemConsoleUI; import meerkat.voting.output.SystemConsoleOutputDevice; import meerkat.voting.storage.StorageManager; import meerkat.voting.storage.StorageManagerMockup; @@ -26,7 +22,7 @@ import java.util.*; public class VotingBoothToyGraphicalRun { // public static void main(String[] args) { -// Application.launch(GraphicalFX.class, args); +// Application.launch(MainFX.class, args); // } diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalFX.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalFX.java deleted file mode 100644 index 36fb88b..0000000 --- a/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalFX.java +++ /dev/null @@ -1,114 +0,0 @@ -package meerkat.voting.gui.ui; - -/** - * Created by Laura on 12/12/2016. - */ - -import javafx.application.Application; -import javafx.scene.Scene; -import javafx.scene.layout.StackPane; -import javafx.stage.Stage; -import meerkat.voting.gui.ui.uicommands.StartSessionUICommand; -import meerkat.voting.gui.ui.uicommands.UICommand; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import javafx.scene.Parent; -import javafx.fxml.FXMLLoader; - -import java.io.IOException; -import java.io.File; - -public class GraphicalFX extends Application { - - private static final Logger logger = LoggerFactory.getLogger(GraphicalUI.class); - private static GraphicalUI parent; - private Stage activeStage; - private static UICommand currentCommand; - - public static void setParent(GraphicalUI ui) { - if (GraphicalFX.parent==null) { - GraphicalFX.parent = ui; - } - logger.warn("Trying to assign again the parent of GraphicalFX."); - } - - @Override - public void init() throws Exception { -// System.out.println("init() of Hello World FX"); - parent.setGraphicalFx(this); - } - -// public static void main(String[] args) { -// launch(args); -// } - -// @Override -// public void start(Stage primaryStage) { -// primaryStage.setTitle("Hello World!"); -// Button btn = new Button(); -// btn.setText("Say 'Hello World'"); -// btn.setOnAction(new EventHandler() { -// -// @Override -// public void handle(ActionEvent event) { -// System.out.println("Hello World!"); -// System.out.println(parent.testPrint()); -// } -// }); -// -// StackPane root = new StackPane(); -// root.getChildren().add(btn); -// Scene scene = new Scene(root, 300, 250); -// -// primaryStage.setScene(scene); -// primaryStage.show(); -// } - - @Override - public void start(Stage primaryStage) { - this.activeStage=primaryStage; - -// Parent root = new StackPane(); -// Scene scene = new Scene(root, 300, 275); -// primaryStage.setScene(scene); -// primaryStage.show(); - - Parent root = null; - try { - root = FXMLLoader.load(getClass().getResource("/graphical_fxml/welcome_splash_screen.fxml")); - } catch (IOException e) { - e.printStackTrace(); - } - - Scene scene = new Scene(root, 300, 275); - - this.activeStage.setScene(scene); - this.activeStage.show(); - } - - public void showWelcomeScreen(UICommand command) { - GraphicalFX.currentCommand = command; - System.out.println("in FX showWelcomeScreen"); - } - - public void answerWelcomeScreen() { - GraphicalFX.parent.answerWelcomeScreen((StartSessionUICommand) GraphicalFX.currentCommand); - } - - public void showChannelChoiceScreen(UICommand command) { - GraphicalFX.currentCommand = command; - System.out.println("in FX showChannelChoiceScreen"); - Parent root = null; - try { - root = FXMLLoader.load(getClass().getResource("/graphical_fxml/welcome_splash_screen.fxml")); - } catch (IOException e) { - e.printStackTrace(); - } - - Scene scene = new Scene(root, 300, 275); - - this.activeStage.setScene(scene); - this.activeStage.show(); - } - -} diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalUI.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalUI.java index 8350c24..a8dcbc8 100644 --- a/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalUI.java +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalUI.java @@ -2,26 +2,23 @@ package meerkat.voting.gui.ui; import com.google.common.util.concurrent.FutureCallback; import javafx.application.Application; -import javafx.stage.Stage; import meerkat.protobuf.Voting.BallotAnswer; import meerkat.protobuf.Voting.BallotQuestion; import meerkat.protobuf.Voting.UIElement; import meerkat.protobuf.Voting.UIElementDataType; import meerkat.voting.controller.callbacks.*; +import meerkat.voting.gui.ui.controllersFX.VistaNavigator; import meerkat.voting.gui.ui.uicommands.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Timer; -import static java.lang.System.in; - /** * an asynchronous thread implementation of the VotingBoothUI interface @@ -37,15 +34,14 @@ public class GraphicalUI implements VotingBoothUI, Runnable { private volatile boolean shutDownHasBeenCalled; - private GraphicalFX ui; + private MainFX ui; public GraphicalUI() { final int tickDurationInMillisec = 10; // period between view update calls logger.info("A graphical UI console is constructed"); cmdPend = new CommandPend<>(); -// bufferedReader = new BufferedReader(new InputStreamReader(in)); - GraphicalFX.setParent(this); + VistaNavigator.setUIThread(this); startWaitingTime = null; Timer timer = new Timer(); @@ -60,11 +56,11 @@ public class GraphicalUI implements VotingBoothUI, Runnable { @Override public void run () { logger.info("UI starts running"); - // Application.launch(GraphicalFX.class); + // Application.launch(MainFX.class); new Thread() { @Override public void run() { - Application.launch(GraphicalFX.class); + Application.launch(MainFX.class); } }.start(); try { @@ -157,13 +153,13 @@ public class GraphicalUI implements VotingBoothUI, Runnable { */ private void doShowWelcomeScreen(StartSessionUICommand command) { logger.debug("UI entered doShowWelcomeScreen"); - this.ui.showWelcomeScreen(command); + VistaNavigator.setCurrentCommand(command); // waitForEnter(null); // ControllerCallback callback = command.getCallback(); // callback.onSuccess(null); } - protected void answerWelcomeScreen(StartSessionUICommand command) { + public void answerWelcomeScreen(StartSessionUICommand command) { ControllerCallback callback = command.getCallback(); callback.onSuccess(null); } @@ -216,20 +212,7 @@ public class GraphicalUI implements VotingBoothUI, Runnable { */ private void doAskChannelChoiceQuestions (ChannelChoiceUICommand command) { logger.debug("UI: doAskChannelChoiceQuestions"); - System.out.println("Showing questions for choosing channel:\n"); - try { - List answers = askVoterForAnswers(command.getQuestions()); - command.getCallback().onSuccess(answers); - } - catch (VoterCancelThrowable e) { - command.getCallback().onFailure(e); - } - catch (IOException e) { - String errorMessage = "Channel choice failed due to IOException: " + e; - logger.error (errorMessage); - System.err.println(errorMessage); - command.getCallback().onFailure(e); - } + VistaNavigator.getMainController().showChannelChoiceScreen(command, logger); } /** @@ -503,8 +486,8 @@ public class GraphicalUI implements VotingBoothUI, Runnable { return "testPrint called"; } - public void setGraphicalFx(GraphicalFX graphicalFX) { - this.ui = graphicalFX; + public void setGraphicalFx(MainFX mainFX) { + this.ui = mainFX; } } diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/MainFX.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/MainFX.java new file mode 100644 index 0000000..7fd2465 --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/MainFX.java @@ -0,0 +1,83 @@ +package meerkat.voting.gui.ui; + +/** + * Created by Laura on 12/12/2016. + */ + +import javafx.application.Application; +import javafx.scene.Scene; +import javafx.scene.layout.Pane; +import javafx.stage.Stage; +import meerkat.voting.gui.ui.controllersFX.MainController; +import meerkat.voting.gui.ui.controllersFX.VistaNavigator; +import meerkat.voting.gui.ui.uicommands.StartSessionUICommand; +import meerkat.voting.gui.ui.uicommands.UICommand; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javafx.scene.Parent; +import javafx.fxml.FXMLLoader; + +import java.io.IOException; + +public class MainFX extends Application { + + private static final Logger logger = LoggerFactory.getLogger(GraphicalUI.class); + +// @Override +// public void init() throws Exception { +// parent.setGraphicalFx(this); +// } + +// public static void main(String[] args) { +// launch(args); +// } + + @Override + public void start(Stage stage) throws Exception{ + stage.setTitle("Vista Viewer"); + stage.setScene( + createScene( + loadMainPane() + ) + ); + stage.show(); + } + + /** + * Loads the main fxml layout. + * Sets up the vista switching VistaNavigator. + * Loads the first vista into the fxml layout. + * + * @return the loaded pane. + * @throws IOException if the pane could not be loaded. + */ + private Pane loadMainPane() throws IOException { + FXMLLoader loader = new FXMLLoader(getClass().getResource(VistaNavigator.MAIN)); + + Pane mainPane = (Pane) loader.load(); + + MainController mainController = loader.getController(); + mainController.setCurrentCommand(null); + + VistaNavigator.setMainController(mainController); + VistaNavigator.loadVista(VistaNavigator.VISTA_1); + + return mainPane; + } + + /** + * Creates the main application scene. + * + * @param mainPane the main application layout. + * + * @return the created scene. + */ + private Scene createScene(Pane mainPane) { + Scene scene = new Scene(mainPane); +// scene.getStylesheets().setAll( +// getClass().getResource("/views/vista.css").toExternalForm() +// ); + return scene; + } + +} diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/StraightChannelSectionController.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/StraightChannelSectionController.java deleted file mode 100644 index 425be45..0000000 --- a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/StraightChannelSectionController.java +++ /dev/null @@ -1,109 +0,0 @@ -package meerkat.voting.gui.ui.controllerFX; - -import javafx.fxml.FXML; -import javafx.scene.control.Button; -import javafx.scene.control.TextField; -import javafx.scene.input.MouseEvent; -import meerkat.voting.gui.managment.TwoWayNode; -import meerkat.voting.gui.ui.GraphicalFX; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by Vladimir Eliezer Tokarev on 8/27/2016. - * StraightChannelSectionController handle the behavior of select channel section screen - */ -public class StraightChannelSectionController { - - private List chanelValue; - private int pointer; - private boolean lock; - - @FXML - public void answerWelcomeScreen() { - GraphicalFX.parent.answerWelcomeScreen((StartSessionUICommand) GraphicalFX.currentCommand); - } - - private void ProceedToNameSelection(MouseEvent boutonPressed) { - this.currentStage.close(); - this.currentStage.setScene(this.next.GetCurrentScene()); - this.next.UpdateNode(); - this.currentStage.show(); - this.logger.debug("Created the proceess to name selection object loader."); - } - - @Override - /** - * Creates the array of the canel value - */ - public void UpdateNode() { - this.pointer = 0; - this.lock = false; - - // created the channel value list - // every value in the list represents one of the cells values - this.chanelValue = new ArrayList<>(); - this.chanelValue.add(0); - this.chanelValue.add(0); - this.chanelValue.add(0); - this.chanelValue.add(0); - this.logger.debug("Created and filled with zeros the channel value."); - - this.updateVisualChanel(); - this.UpdateVotersChoise(); - } - - /** - * Updates the channel in the voters choise - */ - private void UpdateVotersChoise(){ - this.votersBallot.VoterChannel = this.chanelValue; - } - - /** - * Updates the visual channel value - */ - private void updateVisualChanel(){ - for (int i = 0 ; i < 4 ; i ++ ){ - String id = "#textarea_"+i; - TextField textField = ((TextField)this.currentStage.getScene().lookup(id)); - textField.setText(String.valueOf(this.chanelValue.get(i))); - } -// this.logger.debug("Updated the visual representation of the channel (its visual value)."); - } - - @FXML - private void numberPressed(MouseEvent mousePressed){ - if (!this.lock) { - String value = ((Button) mousePressed.getSource()).getId().split("_")[1]; - this.chanelValue.set(this.pointer, Integer.parseInt(value)); - this.pointer++; - this.updateVisualChanel(); - this.UpdateVotersChoise(); - if (this.pointer == 4) { - this.lock = true; - } -// this.logger.debug("The " + value +" button have been pressed, then this value was pushed to channel value."); - } - } - - @FXML - private void clearLastNumber(MouseEvent mousePressed){ - if (this.pointer >= 1) { - int lastValueLocation = this.pointer - 1; - int lastValue = this.chanelValue.get(lastValueLocation); - this.chanelValue.set(lastValueLocation, 0); - this.currentStage.show(); - this.pointer--; - this.updateVisualChanel(); - this.UpdateVotersChoise(); - this.lock = false; -// this.logger.debug("The last value was removed from channel value (the value was " + lastValue + " )."); - } - } - - -} diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/WelcomeSplashController.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/WelcomeSplashController.java deleted file mode 100644 index b259c0e..0000000 --- a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/WelcomeSplashController.java +++ /dev/null @@ -1,39 +0,0 @@ -package meerkat.voting.gui.ui.controllerFX; - -import javafx.fxml.FXML; -import javafx.scene.control.Label; -import javafx.scene.input.MouseEvent; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Created by Vladimir Eliezer Tokarev on 8/27/2016. - * WelcomeSplashController handle the behavior of welcome splash class - */ -public class WelcomeSplashController { - - private final Logger logger = LoggerFactory.getLogger(WelcomeSplashController.class); - private final String INVALID_CONFIGURATION_ERROR_TEXT = "The given configuration is invalid please run this voting booth with different configuraiton."; - - @FXML - private Label ErrorPanel; - - @FXML - private void StartVotingProcess(MouseEvent mousePressed) { -// this.currentStage.close(); -// this.currentStage.setScene(this.next.GetCurrentScene()); -// this.next.UpdateNode(); -// this.currentStage.show(); -// this.logger.debug("Jumping to the select channel object."); - } - - /** - * Represents the given string to user in ErrorLabel - * @param message is the error string to represent to the user - */ - private void RepresentErrorToVoter(String message) { -// ErrorPanel.setText(message); -// this.currentStage.show(); - } - -} diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/ChannelChoiceController.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/ChannelChoiceController.java new file mode 100644 index 0000000..63f2c98 --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/ChannelChoiceController.java @@ -0,0 +1,157 @@ +package meerkat.voting.gui.ui.controllersFX; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.input.MouseEvent; +import meerkat.protobuf.Voting; +import meerkat.voting.controller.callbacks.VoterCancelThrowable; +import meerkat.voting.gui.ui.UIUtils; +import meerkat.voting.gui.ui.uicommands.ChannelChoiceUICommand; +import meerkat.voting.gui.ui.uicommands.UICommand; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by Vladimir Eliezer Tokarev on 8/27/2016. + * ChannelChoiceController handle the behavior of select channel section screen + */ +public class ChannelChoiceController { + + private List chanelValue; + private int pointer; + private boolean lock; + + @FXML + public void answerWelcomeScreen() { +// MainFX.parent.answerWelcomeScreen((StartSessionUICommand) MainFX.currentCommand); + } + + private void nextPane() { + ChannelChoiceUICommand command = (ChannelChoiceUICommand) VistaNavigator.getCurrentCommand(); + System.out.println("Showing questions for choosing channel:\n"); + try { + List answers = askVoterForAnswers(command.getQuestions()); + VistaNavigator.getCurrentCommand().getCallback().onSuccess(answers); + } + catch (VoterCancelThrowable e) { + VistaNavigator.getCurrentCommand().getCallback().onFailure(e); + } + catch (IOException e) { +// String errorMessage = "Channel choice failed due to IOException: " + e; +// logger.error (errorMessage); +// System.err.println(errorMessage); + VistaNavigator.getCurrentCommand().getCallback().onFailure(e); + } + + //askVoterForAnswers: + List answers = new ArrayList<>(); + int index = 0; + while (index < questions.size()) { + Voting.BallotQuestion question = questions.get(index); + System.out.println("Question number " + index); + showQuestionInConsole(question); + + System.out.println("UI screen: Enter your answer. You can also type '(b)ack' or '(c)ancel' or '(s)kip"); + String s = readInputLine(); + + if ((s.equals("cancel") || s.equals("c")) || (index == 0 && (s.equals("back") || s.equals("b")))) { + throw new VoterCancelThrowable(); + } + else if (s.equals("back") || s.equals("b")) { + --index; + answers.remove(index); + } + else if (s.equals("skip") || s.equals("s")) { + answers.add(UIUtils.translateStringAnswerToProtoBufMessageAnswer("")); + ++index; + } + else { + answers.add(UIUtils.translateStringAnswerToProtoBufMessageAnswer(s)); + ++index; + } + } + return answers; + } + + private void ProceedToNameSelection(MouseEvent boutonPressed) { +// this.currentStage.close(); +// this.currentStage.setScene(this.next.GetCurrentScene()); +// this.next.UpdateNode(); +// this.currentStage.show(); +// this.logger.debug("Created the proceess to name selection object loader."); + } + +// @Override + /** + * Creates the array of the canel value + */ + public void UpdateNode() { + this.pointer = 0; + this.lock = false; + + // created the channel value list + // every value in the list represents one of the cells values + this.chanelValue = new ArrayList<>(); + this.chanelValue.add(0); + this.chanelValue.add(0); + this.chanelValue.add(0); + this.chanelValue.add(0); +// this.logger.debug("Created and filled with zeros the channel value."); + + this.updateVisualChanel(); +// this.UpdateVotersChoise(); + } + + /** + * Updates the channel in the voters choise + */ +// private void UpdateVotersChoise(){ +// this.votersBallot.VoterChannel = this.chanelValue; +// } + + /** + * Updates the visual channel value + */ + private void updateVisualChanel(){ + for (int i = 0 ; i < 4 ; i ++ ){ + String id = "#textarea_"+i; +// TextField textField = ((TextField)this.currentStage.getScene().lookup(id)); +// textField.setText(String.valueOf(this.chanelValue.get(i))); + } +// this.logger.debug("Updated the visual representation of the channel (its visual value)."); + } + + @FXML + private void numberPressed(MouseEvent mousePressed){ + if (!this.lock) { + String value = ((Button) mousePressed.getSource()).getId().split("_")[1]; + this.chanelValue.set(this.pointer, Integer.parseInt(value)); + this.pointer++; + this.updateVisualChanel(); +// this.UpdateVotersChoise(); + if (this.pointer == 4) { + this.lock = true; + } +// this.logger.debug("The " + value +" button have been pressed, then this value was pushed to channel value."); + } + } + + @FXML + private void clearLastNumber(MouseEvent mousePressed){ + if (this.pointer >= 1) { + int lastValueLocation = this.pointer - 1; + int lastValue = this.chanelValue.get(lastValueLocation); + this.chanelValue.set(lastValueLocation, 0); +// this.currentStage.show(); + this.pointer--; + this.updateVisualChanel(); +// this.UpdateVotersChoise(); + this.lock = false; +// this.logger.debug("The last value was removed from channel value (the value was " + lastValue + " )."); + } + } + + +} diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/StartSessionController.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/StartSessionController.java new file mode 100644 index 0000000..0fe0cdb --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/StartSessionController.java @@ -0,0 +1,26 @@ +package meerkat.voting.gui.ui.controllersFX; + +import javafx.fxml.FXML; +import meerkat.voting.gui.ui.uicommands.StartSessionUICommand; + +/** + * Created by Vladimir Eliezer Tokarev on 8/27/2016. + * StartSessionController handle the behavior of welcome splash class + */ +public class StartSessionController { + + /** + * Event handler fired when the user requests a new vista. + * + */ + @FXML +// void nextPane() { +// VistaNavigator.loadVista(VistaNavigator.VISTA_2); +// } + + void nextPane() { + VistaNavigator.loadVista(VistaNavigator.LOADING); + VistaNavigator.uiThread.answerWelcomeScreen((StartSessionUICommand) VistaNavigator.getCurrentCommand()); + } + +} diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/Vista2Controller.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/Vista2Controller.java new file mode 100644 index 0000000..a5493ff --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/Vista2Controller.java @@ -0,0 +1,24 @@ +package meerkat.voting.gui.ui.controllersFX; + +/** + * Created by Laura on 12/16/2016. + */ +import javafx.event.ActionEvent; +import javafx.fxml.FXML; + +/** + * Controller class for the second vista. + */ +public class Vista2Controller { + + /** + * Event handler fired when the user requests a previous vista. + * + * @param event the event that triggered the handler. + */ + @FXML + void previousPane(ActionEvent event) { + VistaNavigator.loadVista(VistaNavigator.VISTA_1); + } + +} \ No newline at end of file diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VistaNavigator.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VistaNavigator.java new file mode 100644 index 0000000..48586f6 --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VistaNavigator.java @@ -0,0 +1,100 @@ +package meerkat.voting.gui.ui.controllersFX; + +/** + * Created by Laura on 12/16/2016. + */ +import javafx.fxml.FXMLLoader; +import meerkat.voting.gui.ui.GraphicalUI; +import meerkat.voting.gui.ui.uicommands.UICommand; + +import java.io.IOException; + +/** + * Utility class for controlling navigation between vistas. + * + * All methods on the navigator are static to facilitate + * simple access from anywhere in the application. + */ +public class VistaNavigator { + + /** + * Convenience constants for fxml layouts managed by the navigator. + */ + public static final String MAIN = "/views/main.fxml"; + public static final String LOADING = "/views/loading.fxml"; + public static final String VISTA_1 = "/views/starting_session.fxml"; + public static final String VISTA_2 = "/views/vista2.fxml"; + public static final String CHANNEL_CHOICE = "/views/channel_choice.fxml"; + + /** The main application layout controller. */ + private static MainController mainController; + public static GraphicalUI uiThread; + + + /** + * Stores the main controller for later use in navigation tasks. + * + * @param mainController the main application layout controller. + */ + public static void setMainController(MainController mainController) { + VistaNavigator.mainController = mainController; + } + + public static MainController getMainController() { + return VistaNavigator.mainController; + } + + /** + * Stores the thread that controls the UI. + * + * @param ui the thread that launched the fx application. + */ + public static void setUIThread(GraphicalUI ui) { + VistaNavigator.uiThread = ui; + } + + /** + * Stores the command that is requested to be executed. + * + * @param command the command that needs to be executed. + */ + public static void setCurrentCommand(UICommand command) { + VistaNavigator.mainController.setCurrentCommand(command); + } + + /** + * Returns the command that is requested to be executed. + */ + public static UICommand getCurrentCommand() { + return VistaNavigator.mainController.getCurrentCommand(); + } + + /** + * Loads the vista specified by the fxml file into the + * vistaHolder pane of the main application layout. + * + * Previously loaded vista for the same fxml file are not cached. + * The fxml is loaded anew and a new vista node hierarchy generated + * every time this method is invoked. + * + * A more sophisticated load function could potentially add some + * enhancements or optimizations, for example: + * cache FXMLLoaders + * cache loaded vista nodes, so they can be recalled or reused + * allow a user to specify vista node reuse or new creation + * allow back and forward history like a browser + * + * @param fxml the fxml file to be loaded. + */ + public static void loadVista(String fxml) { + try { + mainController.setVista( + FXMLLoader.load(VistaNavigator.class.getResource(fxml) + ) + ); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} \ No newline at end of file diff --git a/voting-booth/src/main/resources/graphical_fxml/straight_channel_section.fxml b/voting-booth/src/main/resources/views/channel_choice.fxml similarity index 99% rename from voting-booth/src/main/resources/graphical_fxml/straight_channel_section.fxml rename to voting-booth/src/main/resources/views/channel_choice.fxml index 01f0781..d01bd92 100644 --- a/voting-booth/src/main/resources/graphical_fxml/straight_channel_section.fxml +++ b/voting-booth/src/main/resources/views/channel_choice.fxml @@ -6,7 +6,7 @@ - + diff --git a/voting-booth/src/main/resources/views/loading.fxml b/voting-booth/src/main/resources/views/loading.fxml new file mode 100644 index 0000000..e10a718 --- /dev/null +++ b/voting-booth/src/main/resources/views/loading.fxml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/voting-booth/src/main/resources/views/main.fxml b/voting-booth/src/main/resources/views/main.fxml new file mode 100644 index 0000000..251c641 --- /dev/null +++ b/voting-booth/src/main/resources/views/main.fxml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/voting-booth/src/main/resources/graphical_fxml/welcome_splash_screen.fxml b/voting-booth/src/main/resources/views/starting_session.fxml similarity index 96% rename from voting-booth/src/main/resources/graphical_fxml/welcome_splash_screen.fxml rename to voting-booth/src/main/resources/views/starting_session.fxml index 67dbad7..3064e3c 100644 --- a/voting-booth/src/main/resources/graphical_fxml/welcome_splash_screen.fxml +++ b/voting-booth/src/main/resources/views/starting_session.fxml @@ -5,7 +5,7 @@ - + @@ -61,7 +61,7 @@
-