From 6655f2dc8e228c0485b598acae467f09a8684a05 Mon Sep 17 00:00:00 2001 From: VladimirEliTokarev Date: Wed, 5 Oct 2016 13:00:57 +0300 Subject: [PATCH] Added the usage of VotersBallot --- .../voting/gui/managment/TwoWayNode.java | 5 +++++ .../voting/gui/managment/VotersBallot.java | 19 +++++++++++++++++++ .../PicturesAnswersUpdater.java | 12 +++++++++++- .../SelectCandidateByPictureController.java | 14 +++++++++++++- .../SelectCandidateNameController.java | 14 +++++++++++++- .../StringsAnswersUpdater.java | 13 +++++++++++-- .../StraightChannelSectionController.java | 9 +++++++++ 7 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 voting-booth-gui/src/main/java/meerkat/voting/gui/managment/VotersBallot.java diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/managment/TwoWayNode.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/managment/TwoWayNode.java index 201bc16..58cf0b3 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/managment/TwoWayNode.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/managment/TwoWayNode.java @@ -17,6 +17,11 @@ public abstract class TwoWayNode { protected Scene currentScene; protected VotingBoothConfiguration config; + /** + * Object which contains the voters selections in different panels + */ + protected VotersBallot votersChoise; + /** * Sets which next TwoWayNode * @param nextObject the next TwoWayNode to which the flow will eventual arrive diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/managment/VotersBallot.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/managment/VotersBallot.java new file mode 100644 index 0000000..ec5e207 --- /dev/null +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/managment/VotersBallot.java @@ -0,0 +1,19 @@ +package meerkat.voting.gui.managment; + +import com.google.protobuf.ByteString; + +import java.util.List; + +/** + * Created by Vladimir Eliezer Tokarev on 10/5/2016. + * This class contains the voters selection in different panel + * those items are: + * 1. the channel of the voter + * 2. the name of the person the voter selected + * 3. the ByteString (that contains bytes of image) of the person the voter selected + */ +public class VotersBallot { + public List Votershannel; + public String VotersNameSelection; + public ByteString VotersImageSelection; +} 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 f6819b1..384000d 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 @@ -1,5 +1,6 @@ package meerkat.voting.gui.panels.select_candidate_by_picture; +import com.google.common.util.concurrent.FutureCallback; import com.google.protobuf.ByteString; import javafx.embed.swing.SwingFXUtils; import javafx.event.Event; @@ -31,6 +32,7 @@ class PicturesAnswersUpdater implements EventHandler{ private int columIndex; private List allAvailableAnswers; private ByteString answer; + private FutureCallback imageUpdate; PicturesAnswersUpdater(Stage primaryStage) { this.currentStage = primaryStage; @@ -40,6 +42,14 @@ class PicturesAnswersUpdater implements EventHandler{ this.allAvailableAnswers = new ArrayList<>(); } + /** + * Sets the call back object which will be called every time the voter choose different candidate picture + * @param imageUpdate the callback object itself + */ + public void SetImageUpdate(FutureCallback imageUpdate){ + this.imageUpdate = imageUpdate; + } + /** * Gets all the binaryDatas from the ballot ui question and puts them into the binaryDatas container * @@ -148,7 +158,7 @@ class PicturesAnswersUpdater implements EventHandler{ if (target.isSelected()) { String answerIndex = target.getId().split("-")[0]; - this.answer = this.allAvailableAnswers.get(Integer.parseInt(answerIndex) - 1); + this.imageUpdate.onSuccess(this.allAvailableAnswers.get(Integer.parseInt(answerIndex) - 1)); this.uncheckBoxes(target); } } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_by_picture/SelectCandidateByPictureController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_by_picture/SelectCandidateByPictureController.java index 12fea25..d7ac6e9 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_by_picture/SelectCandidateByPictureController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_by_picture/SelectCandidateByPictureController.java @@ -1,5 +1,7 @@ package meerkat.voting.gui.panels.select_candidate_by_picture; +import com.google.common.util.concurrent.FutureCallback; +import com.google.protobuf.ByteString; import javafx.fxml.FXML; import javafx.scene.input.MouseEvent; import meerkat.voting.gui.managment.TwoWayNode; @@ -8,7 +10,7 @@ import meerkat.voting.gui.managment.TwoWayNode; * Created by Vladimir Eliezer Tokarev on 8/27/2016. * SelectCandidateNameController handle the behavior of select by picture screen */ -public class SelectCandidateByPictureController extends TwoWayNode { +public class SelectCandidateByPictureController extends TwoWayNode implements FutureCallback { @FXML private void GetToSelectByName(MouseEvent mousePressed){ @@ -38,4 +40,14 @@ public class SelectCandidateByPictureController extends TwoWayNode { public void UpdateNode() { this.UpdateVoterOptions(); } + + @Override + public void onSuccess(ByteString result) { + this.votersChoise.VotersImageSelection = result; + } + + @Override + public void onFailure(Throwable t) { + // log about failure in updating proccess + } } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_name/SelectCandidateNameController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_name/SelectCandidateNameController.java index f2305d1..302dc57 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_name/SelectCandidateNameController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/select_candidate_name/SelectCandidateNameController.java @@ -1,5 +1,6 @@ package meerkat.voting.gui.panels.select_candidate_name; +import com.google.common.util.concurrent.FutureCallback; import javafx.fxml.FXML; import javafx.scene.input.MouseEvent; import meerkat.voting.gui.managment.TwoWayNode; @@ -8,7 +9,7 @@ import meerkat.voting.gui.managment.TwoWayNode; * Created by Vladimir Eliezer Tokarev on 8/27/2016. * SelectCandidateNameController handle the behavior of select by name screen */ -public class SelectCandidateNameController extends TwoWayNode { +public class SelectCandidateNameController extends TwoWayNode implements FutureCallback{ @FXML private void GetToSelectChannel(MouseEvent mousePressed){ this.currentStage.close(); @@ -31,10 +32,21 @@ public class SelectCandidateNameController extends TwoWayNode { private void UpdateVoterOptions(){ StringsAnswersUpdater updater = new StringsAnswersUpdater(this.currentStage); updater.UpdateAnswers(this.config.NameSelectionQuestion); + updater.SetUpdateAnswers(this); } @Override public void UpdateNode() { this.UpdateVoterOptions(); } + + @Override + public void onSuccess(String result) { + this.votersChoise.VotersNameSelection = result; + } + + @Override + public void onFailure(Throwable t) { + // Write log that the string answers updater failed to update the answer + } } 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 455232e..7e5c57c 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 @@ -1,5 +1,6 @@ package meerkat.voting.gui.panels.select_candidate_name; +import com.google.common.util.concurrent.FutureCallback; import com.google.protobuf.ByteString; import javafx.event.Event; import javafx.scene.Node; @@ -20,7 +21,7 @@ import java.util.Objects; class StringsAnswersUpdater implements javafx.event.EventHandler{ private Stage currentStage; private int rowAmount; - private String answer; + private FutureCallback updateAnswer; StringsAnswersUpdater(Stage primaryStage) { this.currentStage = primaryStage; @@ -29,6 +30,14 @@ class StringsAnswersUpdater implements javafx.event.EventHandler{ this.currentStage.getScene().getRoot().applyCss(); } + /** + * The update answers method will be called every time the user select different answer + * @param updateAnswer the method that will get the new answer every time + */ + public void SetUpdateAnswers(FutureCallback updateAnswer){ + this.updateAnswer = updateAnswer; + } + /** * Gets the container of the answers * @return GridPane object @@ -118,7 +127,7 @@ class StringsAnswersUpdater implements javafx.event.EventHandler{ if (target.isSelected()) { String answer = target.getId().split("-")[0]; - this.answer = answer; + this.updateAnswer.onSuccess(answer); this.uncheckBoxes(target); } } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/straight_channel_section/StraightChannelSectionController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/straight_channel_section/StraightChannelSectionController.java index 1bce65a..a4d3fd7 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/straight_channel_section/StraightChannelSectionController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/straight_channel_section/StraightChannelSectionController.java @@ -41,6 +41,13 @@ public class StraightChannelSectionController extends TwoWayNode { this.updateVisualChanel(); } + /** + * Updates the channel in the voters choise + */ + private void UpdateVotersChoise(){ + this.votersChoise.Votershannel = this.chanelValue; + } + /** * Updates the visual channel value */ @@ -59,6 +66,7 @@ public class StraightChannelSectionController extends TwoWayNode { this.chanelValue.set(this.pointer, Integer.parseInt(value)); this.pointer++; this.updateVisualChanel(); + this.UpdateVotersChoise(); if (this.pointer == 4) { this.lock = true; } @@ -73,6 +81,7 @@ public class StraightChannelSectionController extends TwoWayNode { this.currentStage.show(); this.pointer--; this.updateVisualChanel(); + this.UpdateVotersChoise(); this.lock = false; } }