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 9062d30..7b0edec 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 @@ -29,8 +29,8 @@ public class SelectCandidateNameController extends TwoWayNode { * Updates the voter options according to the VotingBoothConfiguration */ private void UpdateVoterOptions(){ - - + StringsAnswersUpdater updater = new StringsAnswersUpdater(this.currentStage); + updater.AddAnswers(this.config.NameSelectionQuestion); } @Override 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 new file mode 100644 index 0000000..7ceb66e --- /dev/null +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/select_candidate_name/StringsAnswersUpdater.java @@ -0,0 +1,51 @@ +package meerkat.voting.gui.select_candidate_name; + +import com.google.protobuf.ByteString; +import javafx.scene.control.Label; +import javafx.scene.layout.GridPane; +import javafx.stage.Stage; +import meerkat.protobuf.BallotQuestionUIElementOuterClass; + + +/** + * 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 + */ +public class StringsAnswersUpdater { + private Stage currentStage; + private int rowAmount; + + public StringsAnswersUpdater(Stage primaryStage) { + this.currentStage = primaryStage; + this.rowAmount = 0; + } + + private GridPane GetAnswersContainer(){ + return (GridPane) this.currentStage.getScene().lookup("#AnswersScrollPane"); + } + + private void AddAnswer(String answer){ + GridPane container = this.GetAnswersContainer(); + + Label label = new Label(); + label.setText(answer); + container.addRow(0); + + this.rowAmount++; + container.add(label, 0, this.rowAmount); + } + + private void RemoveAllAnswers(){ + GridPane gridPane = this.GetAnswersContainer(); + gridPane.getChildren().removeAll(); + } + + public void AddAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) { + this.RemoveAllAnswers(); + for (ByteString bytesAnswer : question.getAnswers().getAnswers().getAnswersList()){ + this.AddAnswer(bytesAnswer.toString()); + } + 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 616b281..0bcb3fa 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 @@ -85,7 +85,7 @@ - +