Added the usage of VotersBallot

android-scanner
VladimirEliTokarev 2016-10-05 13:00:57 +03:00
parent af2622b05c
commit 6655f2dc8e
7 changed files with 81 additions and 5 deletions

View File

@ -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

View File

@ -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<Integer> Votershannel;
public String VotersNameSelection;
public ByteString VotersImageSelection;
}

View File

@ -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<ByteString> allAvailableAnswers;
private ByteString answer;
private FutureCallback<ByteString> 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<ByteString> 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);
}
}

View File

@ -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<ByteString> {
@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
}
}

View File

@ -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<String>{
@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
}
}

View File

@ -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<String> 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<String> 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);
}
}

View File

@ -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;
}
}