diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/ChannelChoiceController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/ChannelChoiceController.java index 08e4d2c..bea9cf1 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/ChannelChoiceController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/ChannelChoiceController.java @@ -28,61 +28,81 @@ public class ChannelChoiceController { List questions = new ArrayList<>(); int index = 0; ChannelChoiceUICommand command = (ChannelChoiceUICommand) VistaNavigator.getCurrentCommand(); + String questionText; @FXML ToggleGroup answerGroup; @FXML private Text question; + @FXML private Text warningMsg; @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(); + public void initialize() { +// Voting.UIElementDataType.TEXT + questions = command.getQuestions(); + answerGroup = new ToggleGroup(); + int choiceType = questions.get(index).getQuestion().getTypeValue(); + System.out.println(choiceType); + switch (choiceType) { + case 0: showQuestion(); //0==TEXT + break; + case 1: showCodeSelection(); + break; +// : showError(); } } +// @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 showCodeSelection() { + questionText = "Here we show code pad."; + question.setText(questionText); + } + private void showQuestion() { Voting.BallotQuestion ballotQuestion = questions.get(index); - question.setText("This is question n. "+index); + questionText = "Please answer this question before voting:"; + question.setText(questionText); 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(); - } + private void showError() { + questionText = "There was an error reading the channel, please go back to polling station."; + question.setText(questionText); + } @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.answerChannelChoiceScreen(command, answers); + if (answerGroup.getSelectedToggle()!=null) { + String s = answerGroup.getSelectedToggle().getUserData().toString(); + answers.add(UIUtils.translateStringAnswerToProtoBufMessageAnswer(s)); + } else { + warningMsg.setText("(Please give an answer to continue)"); + } + if (answers.size()!=0) { + VistaNavigator.loadVista(VistaNavigator.LOADING); + VistaNavigator.uiThread.answerChannelChoiceScreen(command, answers); + } } diff --git a/voting-booth-gui/src/main/resources/views/channel_choice.fxml b/voting-booth-gui/src/main/resources/views/channel_choice.fxml index 55981b5..3830fa6 100644 --- a/voting-booth-gui/src/main/resources/views/channel_choice.fxml +++ b/voting-booth-gui/src/main/resources/views/channel_choice.fxml @@ -4,12 +4,11 @@ - + -