From b8418156b13c11704bc4388d5ee68659e1d3ef5a Mon Sep 17 00:00:00 2001 From: Laura Radaelli Date: Thu, 12 Jan 2017 12:32:59 +0200 Subject: [PATCH] got to Cast or Audit screen --- .../meerkat/voting/gui/ui/GraphicalUI.java | 33 ++++--- .../controllersFX/CastOrAuditController.java | 59 ++++++++++++ .../ChannelChoiceController.java | 15 +-- .../gui/ui/controllersFX/VistaNavigator.java | 1 + .../ui/controllersFX/VotingController.java | 91 +++++++++++++++++++ .../src/main/resources/views/castOrAudit.fxml | 14 +++ .../src/main/resources/views/voting.fxml | 15 +++ 7 files changed, 201 insertions(+), 27 deletions(-) create mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/CastOrAuditController.java create mode 100644 voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VotingController.java create mode 100644 voting-booth/src/main/resources/views/castOrAudit.fxml create mode 100644 voting-booth/src/main/resources/views/voting.fxml 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 19d0b81..71c13da 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 @@ -10,6 +10,7 @@ import javafx.scene.layout.VBox; import javafx.scene.text.Font; import javafx.scene.text.FontPosture; import javafx.scene.text.Text; +import meerkat.protobuf.Voting; import meerkat.protobuf.Voting.BallotAnswer; import meerkat.protobuf.Voting.BallotQuestion; import meerkat.protobuf.Voting.UIElement; @@ -171,6 +172,21 @@ public class GraphicalUI implements VotingBoothUI, Runnable { callback.onSuccess(null); } + public void answerChannelChoiceScreen(ChannelChoiceUICommand command, List answers) { + command.getCallback().onSuccess(answers); + } + + + public void answerVotingScreen(RaceVotingUICommand command, List answers) { + command.getCallback().onSuccess(answers); + } + + public void answerCastOrAuditScreen(CastOrAuditUICommand command, VotingBoothUI.FinalizeBallotChoice fChoice) { + ControllerCallback callback = command.getCallback(); + assert (callback instanceof CastOrAuditCallback); + ((CastOrAuditCallback)callback).onSuccess(fChoice); + } + /** * marks that the waiting, for something else to have happened, is finished */ @@ -241,20 +257,9 @@ public class GraphicalUI implements VotingBoothUI, Runnable { */ private void doAskVotingQuestions (RaceVotingUICommand command) { logger.debug("UI: doAskVotingQuestions"); - System.out.println("Showing questions for race voting:\n"); - try { - List answers = askVoterForAnswers(command.getQuestions()); - command.getCallback().onSuccess(answers); - } - catch (VoterCancelThrowable e) { - command.getCallback().onFailure(e); - } - catch (IOException e) { - String errorMessage = "Asking voting questions failed due to IOException: " + e; - logger.error (errorMessage); - System.err.println(errorMessage); - command.getCallback().onFailure(e); - } + UIUtils.assertQuestionsAreValid(command.getQuestions(), logger); + VistaNavigator.setCurrentCommand(command); + VistaNavigator.loadVista(VistaNavigator.VOTING); } /** diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/CastOrAuditController.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/CastOrAuditController.java new file mode 100644 index 0000000..e98d0f0 --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/CastOrAuditController.java @@ -0,0 +1,59 @@ +package meerkat.voting.gui.ui.controllersFX; + +import javafx.fxml.FXML; +import javafx.scene.control.ToggleGroup; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; +import meerkat.protobuf.Voting; +import meerkat.voting.controller.callbacks.CastOrAuditCallback; +import meerkat.voting.controller.callbacks.ControllerCallback; +import meerkat.voting.controller.callbacks.VoterCancelThrowable; +import meerkat.voting.gui.ui.UIUtils; +import meerkat.voting.gui.ui.VotingBoothUI; +import meerkat.voting.gui.ui.uicommands.CastOrAuditUICommand; +import meerkat.voting.gui.ui.uicommands.RaceVotingUICommand; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +//import meerkat.voting.gui.ui.UIUtils; + +/** + * Created by Vladimir Eliezer Tokarev on 8/27/2016. + * ChannelChoiceController handle the behavior of select channel section screen + */ +public class CastOrAuditController { + + CastOrAuditUICommand command = (CastOrAuditUICommand) VistaNavigator.getCurrentCommand(); + VotingBoothUI.FinalizeBallotChoice fChoice; + + + @FXML + private void cast() { + fChoice = VotingBoothUI.FinalizeBallotChoice.CAST; + } + + @FXML + private void audit() { + fChoice = VotingBoothUI.FinalizeBallotChoice.AUDIT; + } + + private void nextPane() { + VistaNavigator.loadVista(VistaNavigator.LOADING); + VistaNavigator.uiThread.answerCastOrAuditScreen(command, fChoice); + } + + +// +// @FXML +// private void doCancel() throws VoterCancelThrowable{ +// String errorMessage = "doCastOrAudit: some error with reading input from console. details: " + e; +// logger.error(errorMessage); +// command.getCallback().onFailure(e); +// //see what is done in the original (basically need to call the callback of the command onFailure() +// } + + +} 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 index 1b2ac08..647e795 100644 --- 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 @@ -60,7 +60,7 @@ public class ChannelChoiceController { private void showQuestion() { Voting.BallotQuestion ballotQuestion = questions.get(index); - question.setText("This question n. "+index); + question.setText("This is question n. "+index); answerGroup.getToggles().clear(); VBox vbox = VistaNavigator.uiThread.showQuestionInFX(ballotQuestion, answerGroup); questionPane.getChildren().clear(); @@ -88,19 +88,8 @@ public class ChannelChoiceController { private void nextPane() { VistaNavigator.loadVista(VistaNavigator.LOADING); - command.getCallback().onSuccess(answers); + VistaNavigator.uiThread.answerChannelChoiceScreen(command, answers); } - /** - * 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)."); - } } 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 index 6ee6644..2874eb7 100644 --- 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 @@ -30,6 +30,7 @@ public class VistaNavigator { public static final String WELCOME_SCREEN = "/views/welcome_screen.fxml"; public static final String VISTA_2 = "/views/vista2.fxml"; public static final String CHANNEL_CHOICE = "/views/channel_choice.fxml"; + public static final String VOTING = "/views/voting.fxml"; /** The main application layout controller. */ private static MainController mainController; diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VotingController.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VotingController.java new file mode 100644 index 0000000..365d4a4 --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VotingController.java @@ -0,0 +1,91 @@ +package meerkat.voting.gui.ui.controllersFX; + +import javafx.fxml.FXML; +import javafx.scene.control.ToggleGroup; +import javafx.scene.layout.Pane; +import javafx.scene.layout.VBox; +import javafx.scene.text.Text; +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.RaceVotingUICommand; + +import java.util.ArrayList; +import java.util.List; + +//import meerkat.voting.gui.ui.UIUtils; + +/** + * Created by Vladimir Eliezer Tokarev on 8/27/2016. + * ChannelChoiceController handle the behavior of select channel section screen + */ +public class VotingController { + +// private List chanelValue; +// private int pointer; +// private boolean lock; + + List answers = new ArrayList<>(); + List questions = new ArrayList<>(); + int index = 0; + RaceVotingUICommand command = (RaceVotingUICommand) VistaNavigator.getCurrentCommand(); + + @FXML ToggleGroup answerGroup; + @FXML private Text question; + @FXML private Pane questionPane; + + @FXML + private void nextQuestion() { + if (questions.size()==0) { + questions = command.getQuestions(); + answerGroup = new ToggleGroup(); + } + if (answerGroup.getSelectedToggle()!=null) { + String s = answerGroup.getSelectedToggle().getUserData().toString(); + answers.add(UIUtils.translateStringAnswerToProtoBufMessageAnswer(s)); + index++; + } + if (index < questions.size()) { + showQuestion(); + } else { + //return answers to main threads + nextPane(); + } + } + + private void showQuestion() { + Voting.BallotQuestion ballotQuestion = questions.get(index); + question.setText("This is question n. "+index); + answerGroup.getToggles().clear(); + VBox vbox = VistaNavigator.uiThread.showQuestionInFX(ballotQuestion, answerGroup); + questionPane.getChildren().clear(); + questionPane.getChildren().addAll(vbox); + } + + @FXML + private void goBack() throws VoterCancelThrowable{ + if (index == 0) { + doCancel(); + } else { + --index; + answers.remove(index); + nextQuestion(); + } + } + + @FXML + private void doCancel() throws VoterCancelThrowable{ + VoterCancelThrowable e = new VoterCancelThrowable(); + command.getCallback().onFailure(e); + //see what is done in the original (basically need to call the callback of the command onFailure() + } + + + private void nextPane() { + VistaNavigator.loadVista(VistaNavigator.LOADING); + VistaNavigator.uiThread.answerVotingScreen(command, answers); + } + + +} diff --git a/voting-booth/src/main/resources/views/castOrAudit.fxml b/voting-booth/src/main/resources/views/castOrAudit.fxml new file mode 100644 index 0000000..eeaf57c --- /dev/null +++ b/voting-booth/src/main/resources/views/castOrAudit.fxml @@ -0,0 +1,14 @@ + + + + + + + + + + +