diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_by_picture/PicturesAnswersUpdater.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_by_picture/PicturesAnswersUpdater.java index 74c72a5..7126bf1 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_by_picture/PicturesAnswersUpdater.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_by_picture/PicturesAnswersUpdater.java @@ -19,6 +19,7 @@ import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Objects; @@ -57,7 +58,12 @@ class PicturesAnswersUpdater implements EventHandler{ */ void UpdateAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) { this.RemoveAllAnswers(); - for (ByteString bytesAnswer : question.getAnswers().getAnswers().getAnswersList()) { + List answers = new ArrayList<>(question.getAnswers().getAnswers().getAnswersList()); + + if (question.getRandomizeListOrder()) { + Collections.shuffle(answers); + } + for (ByteString bytesAnswer : answers){ try { this.allAvailableAnswers.add(bytesAnswer); this.AddAnswer(bytesAnswer); diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_name/StringsAnswersUpdater.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_name/StringsAnswersUpdater.java index f4b4cfa..d98f780 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_name/StringsAnswersUpdater.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_name/StringsAnswersUpdater.java @@ -10,6 +10,9 @@ import javafx.scene.layout.GridPane; import javafx.stage.Stage; import meerkat.protobuf.BallotQuestionUIElementOuterClass; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import java.util.Objects; @@ -91,11 +94,18 @@ class StringsAnswersUpdater implements javafx.event.EventHandler{ /** * Gets all the answers from the ballot ui question and puts them into the answers container - * @param question + * Checks if the answers should be randomized, if they are then randomize them + * @param question the questions that have all the information to be reporesneted */ void UpdateAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) { this.RemoveAllAnswers(); - for (ByteString bytesAnswer : question.getAnswers().getAnswers().getAnswersList()){ + + List answers = new ArrayList<>(question.getAnswers().getAnswers().getAnswersList()); + + if (question.getRandomizeListOrder()){ + Collections.shuffle(answers); + } + for (ByteString bytesAnswer : answers){ this.AddAnswer(bytesAnswer.toStringUtf8()); } this.currentStage.show(); @@ -103,7 +113,7 @@ class StringsAnswersUpdater implements javafx.event.EventHandler{ /** * Unchecks all the check boxes that are not target box - * @param target + * @param target the check box which wont be unchecked */ private void uncheckBoxes(CheckBox target){ GridPane answersContainer = this.GetAnswersContainer();