From 352fb7a548ae4839b2f35ecf40e55e55ba521c1b Mon Sep 17 00:00:00 2001 From: VladimirEliTokarev Date: Mon, 3 Oct 2016 12:15:08 +0300 Subject: [PATCH] Now the text question represented in the select name panel --- .../BallotSummaryController.java | 4 +- .../cast_or_audit/CastOrAuditController.java | 2 +- .../SelectCandidateByPictureController.java | 4 +- .../SelectCandidateNameController.java | 4 +- .../StringsAnswersUpdater.java | 105 +++++++++++++++--- .../StraightChannelSectionController.java | 5 +- .../WelcomeSplashController.java | 3 +- .../resources/view/select_candidate_name.fxml | 98 +--------------- 8 files changed, 103 insertions(+), 122 deletions(-) diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/ballot_summary/BallotSummaryController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/ballot_summary/BallotSummaryController.java index ff32a50..cde28bb 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/ballot_summary/BallotSummaryController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/ballot_summary/BallotSummaryController.java @@ -12,16 +12,16 @@ public class BallotSummaryController extends TwoWayNode { @FXML private void GetToSelectByPicture(MouseEvent mousePressed){ this.currentStage.close(); - this.previous.UpdateNode(); this.currentStage.setScene(this.previous.GetCurrentScene()); + this.previous.UpdateNode(); this.currentStage.show(); } @FXML private void GetToCastOrAudit(MouseEvent mousePressed){ this.currentStage.close(); - this.next.UpdateNode(); this.currentStage.setScene(this.next.GetCurrentScene()); + this.next.UpdateNode(); this.currentStage.show(); } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/cast_or_audit/CastOrAuditController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/cast_or_audit/CastOrAuditController.java index 6fdc68c..61f7301 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/cast_or_audit/CastOrAuditController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/cast_or_audit/CastOrAuditController.java @@ -13,8 +13,8 @@ public class CastOrAuditController extends TwoWayNode { @FXML private void GetToVoteHaveBeenCast(MouseEvent mousePressed) { this.currentStage.close(); - this.next.UpdateNode(); this.currentStage.setScene(this.next.GetCurrentScene()); + this.next.UpdateNode(); this.currentStage.show(); } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_by_picture/SelectCandidateByPictureController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_by_picture/SelectCandidateByPictureController.java index 317278f..b94094e 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_by_picture/SelectCandidateByPictureController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_by_picture/SelectCandidateByPictureController.java @@ -13,16 +13,16 @@ public class SelectCandidateByPictureController extends TwoWayNode { @FXML private void GetToSelectByName(MouseEvent mousePressed){ this.currentStage.close(); - this.previous.UpdateNode(); this.currentStage.setScene(this.previous.GetCurrentScene()); + this.previous.UpdateNode(); this.currentStage.show(); } @FXML private void GetToBallotSummary(MouseEvent mousePressed){ this.currentStage.close(); - this.next.UpdateNode(); this.currentStage.setScene(this.next.GetCurrentScene()); + this.next.UpdateNode(); this.currentStage.show(); } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_name/SelectCandidateNameController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_name/SelectCandidateNameController.java index 7b0edec..dc97322 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_name/SelectCandidateNameController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_name/SelectCandidateNameController.java @@ -12,16 +12,16 @@ public class SelectCandidateNameController extends TwoWayNode { @FXML private void GetToSelectChannel(MouseEvent mousePressed){ this.currentStage.close(); - this.previous.UpdateNode(); this.currentStage.setScene(this.previous.GetCurrentScene()); + this.previous.UpdateNode(); this.currentStage.show(); } @FXML private void SelectCandidateByName(MouseEvent mousePressed) { this.currentStage.close(); - this.next.UpdateNode(); this.currentStage.setScene(this.next.GetCurrentScene()); + this.next.UpdateNode(); this.currentStage.show(); } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_name/StringsAnswersUpdater.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_name/StringsAnswersUpdater.java index 7ceb66e..cab03ac 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_name/StringsAnswersUpdater.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_name/StringsAnswersUpdater.java @@ -1,51 +1,128 @@ package meerkat.voting.gui.select_candidate_name; import com.google.protobuf.ByteString; +import javafx.event.Event; +import javafx.scene.Node; +import javafx.scene.control.CheckBox; import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.stage.Stage; import meerkat.protobuf.BallotQuestionUIElementOuterClass; +import java.util.Objects; + /** * Created by Vladimir Eliezer Tokarev on 10/2/2016. * This object gets the current stage and appends to the container of the names - * the different names that there are in the config object + * the different names that there are in the config object and saves the use answer */ -public class StringsAnswersUpdater { +class StringsAnswersUpdater implements javafx.event.EventHandler{ private Stage currentStage; private int rowAmount; + private String answer; - public StringsAnswersUpdater(Stage primaryStage) { + StringsAnswersUpdater(Stage primaryStage) { this.currentStage = primaryStage; this.rowAmount = 0; + // The lookup works only after the css have been randered + this.currentStage.getScene().getRoot().applyCss(); } + /** + * Gets the container of the answers + * @return GridPane object + */ private GridPane GetAnswersContainer(){ - return (GridPane) this.currentStage.getScene().lookup("#AnswersScrollPane"); + return (GridPane) this.currentStage.getScene().lookup("#AnswersGridPane"); } - private void AddAnswer(String answer){ - GridPane container = this.GetAnswersContainer(); + /** + * Remove all previous answers from the container + */ + private void RemoveAllAnswers(){ + this.GetAnswersContainer().getChildren().removeAll(); + } + + /** + * Creates answer element which is grid pane with the answer and check box + * @param answer string answer to show to the voter + * @return GridPane which contains string and check box + */ + private GridPane GetAnswerElement(String answer){ + GridPane gridPane = new GridPane(); Label label = new Label(); label.setText(answer); + label.setPrefSize(550, 30); + GridPane.setConstraints(label, 1, 1); + + CheckBox checkBox = new CheckBox(); + checkBox.setId(answer+"-checkBox"); + checkBox.setOnAction(this); + GridPane.setConstraints(checkBox, 10, 1); + + gridPane.getChildren().addAll(label, checkBox); + return gridPane; + } + + /** + * Adds the GridPane answer to the panel + * @param answer is the answer string to represent to the user + */ + private void AddAnswer(String answer){ + GridPane container = this.GetAnswersContainer(); + + GridPane newAnswer = this.GetAnswerElement(answer); container.addRow(0); this.rowAmount++; - container.add(label, 0, this.rowAmount); + container.add(newAnswer, 0, this.rowAmount); } - private void RemoveAllAnswers(){ - GridPane gridPane = this.GetAnswersContainer(); - gridPane.getChildren().removeAll(); - } - - public void AddAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) { + /** + * Gets all the answers from the ballot ui question and puts them into the answers container + * @param question + */ + void AddAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) { this.RemoveAllAnswers(); for (ByteString bytesAnswer : question.getAnswers().getAnswers().getAnswersList()){ - this.AddAnswer(bytesAnswer.toString()); + this.AddAnswer(bytesAnswer.toStringUtf8()); } this.currentStage.show(); } + + /** + * Unchecks all the check boxes that are not target box + * @param target + */ + private void uncheckBoxes(CheckBox target){ + GridPane answersContainer = this.GetAnswersContainer(); + for (Node child : answersContainer.getChildren()){ + GridPane answer = (GridPane)child; + CheckBox checkBox = (CheckBox) answer.getChildren().get(1); + if (!Objects.equals(checkBox.getId(), target.getId()) && checkBox.isSelected()){ + checkBox.fire(); + } + } + + } + + @Override + /** + * Saves the user chose + */ + public void handle(Event event) { + if (event.getSource() instanceof CheckBox) { + CheckBox target = ((CheckBox)event.getSource()); + + if (target.isSelected()) { + String answer = target.getId().split("-")[0]; + this.answer = answer; + System.out.println(answer); + this.uncheckBoxes(target); + } + } + } + } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/straight_channel_section/StraightChannelSectionController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/straight_channel_section/StraightChannelSectionController.java index 56d405c..84ffdc6 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/straight_channel_section/StraightChannelSectionController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/straight_channel_section/StraightChannelSectionController.java @@ -1,10 +1,7 @@ package meerkat.voting.gui.straight_channel_section; import javafx.fxml.FXML; -import javafx.scene.Parent; -import javafx.scene.Scene; import javafx.scene.input.MouseEvent; -import javafx.stage.Stage; import meerkat.voting.gui.TwoWayNode; /** @@ -16,8 +13,8 @@ public class StraightChannelSectionController extends TwoWayNode { @FXML private void ProceedToNameSelection(MouseEvent boutonPressed) { this.currentStage.close(); - this.next.UpdateNode(); this.currentStage.setScene(this.next.GetCurrentScene()); + this.next.UpdateNode(); this.currentStage.show(); } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/welcome_splash/WelcomeSplashController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/welcome_splash/WelcomeSplashController.java index 995e5fb..b4e93fc 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/welcome_splash/WelcomeSplashController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/welcome_splash/WelcomeSplashController.java @@ -1,7 +1,6 @@ package meerkat.voting.gui.welcome_splash; import javafx.fxml.FXML; -import javafx.scene.Scene; import javafx.scene.input.MouseEvent; import meerkat.voting.gui.TwoWayNode; @@ -14,8 +13,8 @@ public class WelcomeSplashController extends TwoWayNode { @FXML private void StartVotingProcess(MouseEvent mousePressed) { this.currentStage.close(); - this.next.UpdateNode(); this.currentStage.setScene(this.next.GetCurrentScene()); + this.next.UpdateNode(); this.currentStage.show(); } diff --git a/voting-booth-gui/src/main/resources/view/select_candidate_name.fxml b/voting-booth-gui/src/main/resources/view/select_candidate_name.fxml index 0bcb3fa..dd0d5f5 100644 --- a/voting-booth-gui/src/main/resources/view/select_candidate_name.fxml +++ b/voting-booth-gui/src/main/resources/view/select_candidate_name.fxml @@ -79,105 +79,13 @@ - + - + - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - -
+