Added the description of the picture of the candidate
							parent
							
								
									fbc1707b37
								
							
						
					
					
						commit
						c5dcb9f06e
					
				
							
								
								
									
										
											BIN
										
									
								
								VotersBallot.png
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								VotersBallot.png
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 1002 B After Width: | Height: | Size: 985 B  | 
| 
						 | 
					@ -4,11 +4,18 @@ package meerkat;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
option java_package = "meerkat.protobuf";
 | 
					option java_package = "meerkat.protobuf";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Message that represent single answer for given question
 | 
				
			||||||
 | 
					message UIAnswer{
 | 
				
			||||||
 | 
					    bytes answer=1;
 | 
				
			||||||
 | 
					    string description=2;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Message object which is number of bytes
 | 
					// Message object which is number of bytes
 | 
				
			||||||
message ListOfAnswers{
 | 
					message ListOfAnswers{
 | 
				
			||||||
	repeated bytes answers = 1;
 | 
						repeated UIAnswer answers = 1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Message object which contains the type of the answers and their data in bytes
 | 
					// Message object which contains the type of the answers and their data in bytes
 | 
				
			||||||
message UIAnswers {
 | 
					message UIAnswers {
 | 
				
			||||||
	int32 AnswersType = 1;
 | 
						int32 AnswersType = 1;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -29,7 +29,7 @@ public class Main extends Application {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private VotingBoothConfiguration GetConfig() throws IOException, JSONException {
 | 
					    private VotingBoothConfiguration GetConfig() throws IOException, JSONException {
 | 
				
			||||||
        VotingBoothConfigurationCreator creator = new VotingBoothConfigurationCreator();
 | 
					        VotingBoothConfigurationCreator creator = new VotingBoothConfigurationCreator();
 | 
				
			||||||
        return creator.CreateConfiguration("/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/configuration/VotingBoothConfiguration.json");
 | 
					        return creator.CreateConfiguration("/configuration/VotingBoothConfiguration.json");
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,5 @@
 | 
				
			||||||
package meerkat.voting.gui.configuration;
 | 
					package meerkat.voting.gui.configuration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.protobuf.ByteString;
 | 
					 | 
				
			||||||
import javafx.embed.swing.SwingFXUtils;
 | 
					import javafx.embed.swing.SwingFXUtils;
 | 
				
			||||||
import meerkat.protobuf.BallotQuestionUIElementOuterClass;
 | 
					import meerkat.protobuf.BallotQuestionUIElementOuterClass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -35,18 +34,24 @@ public class VotingBoothConfiguration {
 | 
				
			||||||
            return false;
 | 
					            return false;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Check that all the given answers are valid bte strings that can be converted into strings
 | 
					        // Check that all the given answers are valid bte strings that can be converted into strings
 | 
				
			||||||
        for (ByteString answer: NameSelectionQuestion.getAnswers().getAnswers().getAnswersList()){
 | 
					        for (BallotQuestionUIElementOuterClass.UIAnswer answer: NameSelectionQuestion.getAnswers().getAnswers().getAnswersList()){
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                String strAnswer = answer.toStringUtf8();
 | 
					                answer.getAnswer().toStringUtf8();
 | 
				
			||||||
 | 
					                if (answer.getDescription() == null) {
 | 
				
			||||||
 | 
					                    return false;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            } catch (Exception e){
 | 
					            } catch (Exception e){
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        // Check that all given byteStrings that are pictures can be converted into pictures
 | 
					        // Check that all given byteStrings that are pictures can be converted into pictures
 | 
				
			||||||
        for (ByteString answer :NameSelectionByPictureQuestion.getAnswers().getAnswers().getAnswersList()){
 | 
					        for (BallotQuestionUIElementOuterClass.UIAnswer answer :NameSelectionByPictureQuestion.getAnswers().getAnswers().getAnswersList()){
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                BufferedImage bufferedImage = ImageIO.read(answer.newInput());
 | 
					                BufferedImage bufferedImage = ImageIO.read(answer.getAnswer().newInput());
 | 
				
			||||||
                SwingFXUtils.toFXImage(bufferedImage, null);
 | 
					                SwingFXUtils.toFXImage(bufferedImage, null);
 | 
				
			||||||
 | 
					                if (answer.getDescription() == null){
 | 
				
			||||||
 | 
					                    return false;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            } catch (Exception e) {
 | 
					            } catch (Exception e) {
 | 
				
			||||||
                return false;
 | 
					                return false;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,6 +2,7 @@ package meerkat.voting.gui.configuration;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.protobuf.ByteString;
 | 
					import com.google.protobuf.ByteString;
 | 
				
			||||||
import meerkat.protobuf.BallotQuestionUIElementOuterClass;
 | 
					import meerkat.protobuf.BallotQuestionUIElementOuterClass;
 | 
				
			||||||
 | 
					import org.factcenter.qilin.util.Pair;
 | 
				
			||||||
import org.json.JSONArray;
 | 
					import org.json.JSONArray;
 | 
				
			||||||
import org.json.JSONException;
 | 
					import org.json.JSONException;
 | 
				
			||||||
import org.json.JSONObject;
 | 
					import org.json.JSONObject;
 | 
				
			||||||
| 
						 | 
					@ -69,7 +70,7 @@ public class VotingBoothConfigurationCreator {
 | 
				
			||||||
     * @throws JSONException will be thrown if the parsing will fail
 | 
					     * @throws JSONException will be thrown if the parsing will fail
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private JSONArray getJsonFromPath(String path) throws FileNotFoundException, JSONException {
 | 
					    private JSONArray getJsonFromPath(String path) throws FileNotFoundException, JSONException {
 | 
				
			||||||
        String content = new Scanner(new File(path)).useDelimiter("\\Z").next();
 | 
					        String content = new Scanner(new File(getClass().getResource(path).getPath())).useDelimiter("\\Z").next();
 | 
				
			||||||
        JSONObject jsonObject = new JSONObject(content);
 | 
					        JSONObject jsonObject = new JSONObject(content);
 | 
				
			||||||
        this.logger.debug("Created json object from from configuration path.");
 | 
					        this.logger.debug("Created json object from from configuration path.");
 | 
				
			||||||
        return (JSONArray)jsonObject.get("questions");
 | 
					        return (JSONArray)jsonObject.get("questions");
 | 
				
			||||||
| 
						 | 
					@ -86,30 +87,32 @@ public class VotingBoothConfigurationCreator {
 | 
				
			||||||
        // Question part
 | 
					        // Question part
 | 
				
			||||||
        JSONObject question = object.getJSONObject("question");
 | 
					        JSONObject question = object.getJSONObject("question");
 | 
				
			||||||
        int questionType = question.getInt("type");
 | 
					        int questionType = question.getInt("type");
 | 
				
			||||||
        ByteString questionValue = this.convertToByteStringBasedOnType(questionType, question.getString("questionValue"));
 | 
					        ByteString questionValue = ByteString.copyFromUtf8(question.getString("questionValue"));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Answers Part
 | 
					        // Convert and add json objects which have field answer and description into list of UIAnswers
 | 
				
			||||||
        JSONObject answers = object.getJSONObject("answers");
 | 
					        JSONObject answers = object.getJSONObject("answers");
 | 
				
			||||||
        int answersType = answers.getInt("type");
 | 
					        int answersType = answers.getInt("type");
 | 
				
			||||||
        JSONArray answersValues = answers.getJSONArray("answersValue");
 | 
					        JSONArray answersValues = answers.getJSONArray("answersValue");
 | 
				
			||||||
        List<ByteString> byteStrings = new ArrayList<>();
 | 
					        List<Pair<ByteString, String>> answersPairs= new ArrayList<>();
 | 
				
			||||||
        for (int i  = 0 ; i < answersValues.length(); i ++){
 | 
					        for (int i  = 0 ; i < answersValues.length(); i ++){
 | 
				
			||||||
            byteStrings.add(this.convertToByteStringBasedOnType(answersType, answersValues.getString(i)));
 | 
					            ByteString answer = this.convertToByteStringBasedOnType(answersType, answersValues.getJSONObject(i));
 | 
				
			||||||
 | 
					            String description = answersValues.getJSONObject(i).getString("description");
 | 
				
			||||||
 | 
					            answersPairs.add(new Pair<>(answer, description));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Create the UIQuestion and set the values parsed from jason
 | 
					        // Create the UIQuestion and set the values parsed from jason
 | 
				
			||||||
        BallotQuestionUIElementOuterClass.UIQuestion uiQuestion = BallotQuestionUIElementOuterClass.UIQuestion.newBuilder()
 | 
					        BallotQuestionUIElementOuterClass.UIQuestion uiQuestion = BallotQuestionUIElementOuterClass.UIQuestion.newBuilder()
 | 
				
			||||||
                .setQuestionType(questionType)
 | 
					                .setQuestionType(questionType)
 | 
				
			||||||
                .setQuestion(BallotQuestionUIElementOuterClass.Question.newBuilder()
 | 
					                .setQuestion(BallotQuestionUIElementOuterClass.Question.newBuilder()
 | 
				
			||||||
                        .setQuestion(questionValue))
 | 
					                .setQuestion(questionValue))
 | 
				
			||||||
                .build();
 | 
					                .build();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Create UIAnswers and set the values parsed from jason
 | 
					        // Create UIAnswers and set the values parsed from jason
 | 
				
			||||||
        BallotQuestionUIElementOuterClass.UIAnswers.Builder uiAnswersBuilder = BallotQuestionUIElementOuterClass.UIAnswers.newBuilder()
 | 
					        BallotQuestionUIElementOuterClass.UIAnswers.Builder uiAnswersBuilder = BallotQuestionUIElementOuterClass.UIAnswers.newBuilder()
 | 
				
			||||||
                .setAnswersType(answersType);
 | 
					                .setAnswersType(answersType);
 | 
				
			||||||
        BallotQuestionUIElementOuterClass.ListOfAnswers.Builder listOfAnswers = BallotQuestionUIElementOuterClass.ListOfAnswers.newBuilder();
 | 
					        BallotQuestionUIElementOuterClass.ListOfAnswers.Builder listOfAnswers = BallotQuestionUIElementOuterClass.ListOfAnswers.newBuilder();
 | 
				
			||||||
        for(ByteString byteString : byteStrings){
 | 
					        for(Pair<ByteString, String> pair: answersPairs){
 | 
				
			||||||
            listOfAnswers.addAnswers(byteString);
 | 
					            listOfAnswers.addAnswers(ConvertPairIntoUIAnswer(pair));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        uiAnswersBuilder.setAnswers(listOfAnswers);
 | 
					        uiAnswersBuilder.setAnswers(listOfAnswers);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -121,19 +124,31 @@ public class VotingBoothConfigurationCreator {
 | 
				
			||||||
                .build();
 | 
					                .build();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * Converts given pair<ByteString, String> into UIAnswer
 | 
				
			||||||
 | 
					     * @param pair A pair of byteString which is the answer and string which is the description of the answer
 | 
				
			||||||
 | 
					     * @return UIAnswer
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    private BallotQuestionUIElementOuterClass.UIAnswer ConvertPairIntoUIAnswer(Pair<ByteString, String> pair) {
 | 
				
			||||||
 | 
					        return BallotQuestionUIElementOuterClass.UIAnswer.newBuilder()
 | 
				
			||||||
 | 
					                .setAnswer(pair.a)
 | 
				
			||||||
 | 
					                .setDescription(pair.b)
 | 
				
			||||||
 | 
					                .build();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Tries to get convert the given question to ByteString else throws excetion
 | 
					     * Tries to get convert the given question to ByteString else throws excetion
 | 
				
			||||||
     * @param questionType the type of the question (can be 0 - text, 1 - audio, 2 - image)
 | 
					     * @param questionType the type of the question (can be 0 - text, 1 - audio, 2 - image)
 | 
				
			||||||
     * @param questionValue the values itseld (in case the type is 1 or 2 the question value will be a path to the file)
 | 
					     * @param value jsonObject which contains the value and its description
 | 
				
			||||||
     * @return ByteString which is or the value or the file in given path
 | 
					     * @return ByteString which is or the value or the file in given path
 | 
				
			||||||
     * @throws IOException will be thrown if the given type is unsupported
 | 
					     * @throws IOException will be thrown if the given type is unsupported
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private ByteString convertToByteStringBasedOnType(int questionType, String questionValue) throws IOException {
 | 
					    private ByteString convertToByteStringBasedOnType(int questionType, JSONObject value) throws IOException, JSONException {
 | 
				
			||||||
        if (questionType == BallotQuestionUIElementOuterClass.ValueType.TEXT_TYPE.getNumber()) {
 | 
					        if (questionType == BallotQuestionUIElementOuterClass.ValueType.TEXT_TYPE.getNumber()) {
 | 
				
			||||||
            return ByteString.copyFromUtf8(questionValue);
 | 
					            return ByteString.copyFromUtf8(value.getString("answer"));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if (questionType == BallotQuestionUIElementOuterClass.ValueType.IMAGE_TYPE.getNumber()) {
 | 
					        if (questionType == BallotQuestionUIElementOuterClass.ValueType.IMAGE_TYPE.getNumber()) {
 | 
				
			||||||
            return ByteString.copyFrom(getFileBytes(questionValue));
 | 
					            return ByteString.copyFrom(getFileBytes(value.getString("answer")));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else {
 | 
					        else {
 | 
				
			||||||
            throw new IOException(UNSUPPORTED_VALUE_TYPE_ERROR_MESSAGE);
 | 
					            throw new IOException(UNSUPPORTED_VALUE_TYPE_ERROR_MESSAGE);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
package meerkat.voting.gui.managment;
 | 
					package meerkat.voting.gui.managment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.protobuf.ByteString;
 | 
					import meerkat.protobuf.BallotQuestionUIElementOuterClass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ import java.util.List;
 | 
				
			||||||
public class VotersBallot {
 | 
					public class VotersBallot {
 | 
				
			||||||
    public List<Integer> VoterChannel;
 | 
					    public List<Integer> VoterChannel;
 | 
				
			||||||
    public String VotersNameSelection;
 | 
					    public String VotersNameSelection;
 | 
				
			||||||
    public ByteString VotersImageSelection;
 | 
					    public BallotQuestionUIElementOuterClass.UIAnswer VotersImageSelection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public String toString(){
 | 
					    public String toString(){
 | 
				
			||||||
        return this.VotersNameSelection +"---"+ this.VoterChannel.get(0) + "" +  this.VoterChannel.get(1) +
 | 
					        return this.VotersNameSelection +"---"+ this.VoterChannel.get(0) + "" +  this.VoterChannel.get(1) +
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -46,7 +46,7 @@ class VotersChoicesAdder {
 | 
				
			||||||
        this.RemoveAllAnswers();
 | 
					        this.RemoveAllAnswers();
 | 
				
			||||||
        this.addAnswer(this.getChannelChoice(this.votersBallot.VoterChannel));
 | 
					        this.addAnswer(this.getChannelChoice(this.votersBallot.VoterChannel));
 | 
				
			||||||
        this.addAnswer(this.getNameChoice(this.votersBallot.VotersNameSelection));
 | 
					        this.addAnswer(this.getNameChoice(this.votersBallot.VotersNameSelection));
 | 
				
			||||||
        this.addAnswer(this.getImageChoice(this.votersBallot.VotersImageSelection));
 | 
					        this.addAnswer(this.getImageChoice(this.votersBallot.VotersImageSelection.getAnswer()));
 | 
				
			||||||
        Label error = new Label();
 | 
					        Label error = new Label();
 | 
				
			||||||
        error.setPrefSize(250,30);
 | 
					        error.setPrefSize(250,30);
 | 
				
			||||||
        this.addAnswer(error);
 | 
					        this.addAnswer(error);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,13 +1,13 @@
 | 
				
			||||||
package meerkat.voting.gui.panels.select_candidate_by_picture;
 | 
					package meerkat.voting.gui.panels.select_candidate_by_picture;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.common.util.concurrent.FutureCallback;
 | 
					import com.google.common.util.concurrent.FutureCallback;
 | 
				
			||||||
import com.google.protobuf.ByteString;
 | 
					 | 
				
			||||||
import javafx.embed.swing.SwingFXUtils;
 | 
					import javafx.embed.swing.SwingFXUtils;
 | 
				
			||||||
import javafx.event.Event;
 | 
					import javafx.event.Event;
 | 
				
			||||||
import javafx.event.EventHandler;
 | 
					import javafx.event.EventHandler;
 | 
				
			||||||
import javafx.geometry.Insets;
 | 
					import javafx.geometry.Insets;
 | 
				
			||||||
import javafx.scene.Node;
 | 
					import javafx.scene.Node;
 | 
				
			||||||
import javafx.scene.control.CheckBox;
 | 
					import javafx.scene.control.CheckBox;
 | 
				
			||||||
 | 
					import javafx.scene.control.Label;
 | 
				
			||||||
import javafx.scene.image.Image;
 | 
					import javafx.scene.image.Image;
 | 
				
			||||||
import javafx.scene.image.ImageView;
 | 
					import javafx.scene.image.ImageView;
 | 
				
			||||||
import javafx.scene.layout.BorderPane;
 | 
					import javafx.scene.layout.BorderPane;
 | 
				
			||||||
| 
						 | 
					@ -36,8 +36,8 @@ class PicturesAnswersUpdater implements EventHandler{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private Stage currentStage;
 | 
					    private Stage currentStage;
 | 
				
			||||||
    private int columIndex;
 | 
					    private int columIndex;
 | 
				
			||||||
    private List<ByteString> allAvailableAnswers;
 | 
					    private List<BallotQuestionUIElementOuterClass.UIAnswer> allAvailableAnswers;
 | 
				
			||||||
    private FutureCallback<ByteString> imageUpdate;
 | 
					    private FutureCallback<BallotQuestionUIElementOuterClass.UIAnswer> imageUpdate;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    PicturesAnswersUpdater(Stage primaryStage) {
 | 
					    PicturesAnswersUpdater(Stage primaryStage) {
 | 
				
			||||||
        this.currentStage = primaryStage;
 | 
					        this.currentStage = primaryStage;
 | 
				
			||||||
| 
						 | 
					@ -52,7 +52,7 @@ class PicturesAnswersUpdater implements EventHandler{
 | 
				
			||||||
     * Sets the call back object which will be called every time the voter choose different candidate picture
 | 
					     * Sets the call back object which will be called every time the voter choose different candidate picture
 | 
				
			||||||
     * @param imageUpdate the callback object itself
 | 
					     * @param imageUpdate the callback object itself
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public void SetImageUpdate(FutureCallback<ByteString> imageUpdate){
 | 
					    public void SetImageUpdate(FutureCallback<BallotQuestionUIElementOuterClass.UIAnswer> imageUpdate){
 | 
				
			||||||
        this.imageUpdate = imageUpdate;
 | 
					        this.imageUpdate = imageUpdate;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,15 +63,15 @@ class PicturesAnswersUpdater implements EventHandler{
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void UpdateAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
 | 
					    void UpdateAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
 | 
				
			||||||
        this.RemoveAllAnswers();
 | 
					        this.RemoveAllAnswers();
 | 
				
			||||||
        List<ByteString> answers = new ArrayList<>(question.getAnswers().getAnswers().getAnswersList());
 | 
					        List<BallotQuestionUIElementOuterClass.UIAnswer> answers = new ArrayList<>(question.getAnswers().getAnswers().getAnswersList());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (question.getRandomizeListOrder()) {
 | 
					        if (question.getRandomizeListOrder()) {
 | 
				
			||||||
            Collections.shuffle(answers);
 | 
					            Collections.shuffle(answers);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        for (ByteString bytesAnswer : answers){
 | 
					        for (BallotQuestionUIElementOuterClass.UIAnswer answer: answers){
 | 
				
			||||||
            try {
 | 
					            try {
 | 
				
			||||||
                this.allAvailableAnswers.add(bytesAnswer);
 | 
					                this.allAvailableAnswers.add(answer);
 | 
				
			||||||
                this.AddAnswer(bytesAnswer);
 | 
					                this.AddAnswer(answer);
 | 
				
			||||||
            } catch (IOException e) {
 | 
					            } catch (IOException e) {
 | 
				
			||||||
                e.printStackTrace();
 | 
					                e.printStackTrace();
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					@ -100,19 +100,23 @@ class PicturesAnswersUpdater implements EventHandler{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Creates binaryData element which is grid pane with the binaryData and check box
 | 
					     * Creates binaryData element which is grid pane with the binaryData and check box
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param binaryData string binaryData to show to the voter
 | 
					     * @param answer object which have the answer and its description
 | 
				
			||||||
     * @param location the location of the picture
 | 
					     * @param location the location of the picture
 | 
				
			||||||
     * @return GridPane which contains string and check box
 | 
					     * @return GridPane which contains string and check box
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private GridPane GetAnswerElement(ByteString binaryData, int location) throws IOException {
 | 
					    private GridPane GetAnswerElement(BallotQuestionUIElementOuterClass.UIAnswer answer, int location) throws IOException {
 | 
				
			||||||
        GridPane gridPane = new GridPane();
 | 
					        GridPane gridPane = new GridPane();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        BufferedImage bufferedImage = ImageIO.read(binaryData.newInput());
 | 
					        BufferedImage bufferedImage = ImageIO.read(answer.getAnswer().newInput());
 | 
				
			||||||
        Image image = SwingFXUtils.toFXImage(bufferedImage, null);
 | 
					        Image image = SwingFXUtils.toFXImage(bufferedImage, null);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        ImageView imageView = new ImageView();
 | 
					        ImageView imageView = new ImageView();
 | 
				
			||||||
        imageView.setImage(image);
 | 
					        imageView.setImage(image);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Label description = new Label(answer.getDescription());
 | 
				
			||||||
 | 
					        BorderPane descriptionBorderPane = new BorderPane();
 | 
				
			||||||
 | 
					        descriptionBorderPane.setCenter(description);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        BorderPane borderPane = new BorderPane();
 | 
					        BorderPane borderPane = new BorderPane();
 | 
				
			||||||
        CheckBox checkBox = new CheckBox();
 | 
					        CheckBox checkBox = new CheckBox();
 | 
				
			||||||
        checkBox.setId(location+"-checkbox");
 | 
					        checkBox.setId(location+"-checkbox");
 | 
				
			||||||
| 
						 | 
					@ -120,7 +124,8 @@ class PicturesAnswersUpdater implements EventHandler{
 | 
				
			||||||
        borderPane.setCenter(checkBox);
 | 
					        borderPane.setCenter(checkBox);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        gridPane.add(imageView, 2 , 1);
 | 
					        gridPane.add(imageView, 2 , 1);
 | 
				
			||||||
        gridPane.add(borderPane, 2, 2);
 | 
					        gridPane.add(descriptionBorderPane, 2, 2);
 | 
				
			||||||
 | 
					        gridPane.add(borderPane, 2, 3);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        gridPane.setPrefSize(100, 100);
 | 
					        gridPane.setPrefSize(100, 100);
 | 
				
			||||||
        gridPane.setPadding(new Insets(10));
 | 
					        gridPane.setPadding(new Insets(10));
 | 
				
			||||||
| 
						 | 
					@ -132,13 +137,13 @@ class PicturesAnswersUpdater implements EventHandler{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Adds the GridPane binaryData to the panel
 | 
					     * Adds the GridPane binaryData to the panel
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param binaryData the binaryData string to represent to the user
 | 
					     * @param answer the binaryData string to represent to the user
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private void AddAnswer(ByteString binaryData) throws IOException {
 | 
					    private void AddAnswer(BallotQuestionUIElementOuterClass.UIAnswer answer) throws IOException {
 | 
				
			||||||
        GridPane container = this.GetAnswersContainer();
 | 
					        GridPane container = this.GetAnswersContainer();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        this.columIndex++;
 | 
					        this.columIndex++;
 | 
				
			||||||
        GridPane newAnswer = this.GetAnswerElement(binaryData, this.columIndex);
 | 
					        GridPane newAnswer = this.GetAnswerElement(answer, this.columIndex);
 | 
				
			||||||
        container.addColumn(1);
 | 
					        container.addColumn(1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        container.add(newAnswer, this.columIndex, 0);
 | 
					        container.add(newAnswer, this.columIndex, 0);
 | 
				
			||||||
| 
						 | 
					@ -154,7 +159,7 @@ class PicturesAnswersUpdater implements EventHandler{
 | 
				
			||||||
        GridPane answersContainer = this.GetAnswersContainer();
 | 
					        GridPane answersContainer = this.GetAnswersContainer();
 | 
				
			||||||
        for (Node child : answersContainer.getChildren()){
 | 
					        for (Node child : answersContainer.getChildren()){
 | 
				
			||||||
            GridPane answer = (GridPane)child;
 | 
					            GridPane answer = (GridPane)child;
 | 
				
			||||||
            BorderPane  borderPane = (BorderPane) answer.getChildren().get(1);
 | 
					            BorderPane  borderPane = (BorderPane) answer.getChildren().get(2);
 | 
				
			||||||
            CheckBox checkBox = (CheckBox)borderPane.getCenter();
 | 
					            CheckBox checkBox = (CheckBox)borderPane.getCenter();
 | 
				
			||||||
            if (!Objects.equals(checkBox.getId(), target.getId()) && checkBox.isSelected()){
 | 
					            if (!Objects.equals(checkBox.getId(), target.getId()) && checkBox.isSelected()){
 | 
				
			||||||
                checkBox.fire();
 | 
					                checkBox.fire();
 | 
				
			||||||
| 
						 | 
					@ -173,6 +178,7 @@ class PicturesAnswersUpdater implements EventHandler{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (target.isSelected()) {
 | 
					            if (target.isSelected()) {
 | 
				
			||||||
                String answerIndex = target.getId().split("-")[0];
 | 
					                String answerIndex = target.getId().split("-")[0];
 | 
				
			||||||
 | 
					                System.out.println(answerIndex);
 | 
				
			||||||
                this.imageUpdate.onSuccess(this.allAvailableAnswers.get(Integer.parseInt(answerIndex) - 1));
 | 
					                this.imageUpdate.onSuccess(this.allAvailableAnswers.get(Integer.parseInt(answerIndex) - 1));
 | 
				
			||||||
                this.uncheckBoxes(target);
 | 
					                this.uncheckBoxes(target);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,9 +1,9 @@
 | 
				
			||||||
package meerkat.voting.gui.panels.select_candidate_by_picture;
 | 
					package meerkat.voting.gui.panels.select_candidate_by_picture;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.common.util.concurrent.FutureCallback;
 | 
					import com.google.common.util.concurrent.FutureCallback;
 | 
				
			||||||
import com.google.protobuf.ByteString;
 | 
					 | 
				
			||||||
import javafx.fxml.FXML;
 | 
					import javafx.fxml.FXML;
 | 
				
			||||||
import javafx.scene.input.MouseEvent;
 | 
					import javafx.scene.input.MouseEvent;
 | 
				
			||||||
 | 
					import meerkat.protobuf.BallotQuestionUIElementOuterClass;
 | 
				
			||||||
import meerkat.voting.gui.managment.TwoWayNode;
 | 
					import meerkat.voting.gui.managment.TwoWayNode;
 | 
				
			||||||
import org.slf4j.Logger;
 | 
					import org.slf4j.Logger;
 | 
				
			||||||
import org.slf4j.LoggerFactory;
 | 
					import org.slf4j.LoggerFactory;
 | 
				
			||||||
| 
						 | 
					@ -12,7 +12,7 @@ import org.slf4j.LoggerFactory;
 | 
				
			||||||
 * Created by Vladimir Eliezer Tokarev on 8/27/2016.
 | 
					 * Created by Vladimir Eliezer Tokarev on 8/27/2016.
 | 
				
			||||||
 * SelectCandidateNameController handle the behavior of select by picture screen
 | 
					 * SelectCandidateNameController handle the behavior of select by picture screen
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
public class SelectCandidateByPictureController extends TwoWayNode implements FutureCallback<ByteString> {
 | 
					public class SelectCandidateByPictureController extends TwoWayNode implements FutureCallback<BallotQuestionUIElementOuterClass.UIAnswer> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private final Logger logger = LoggerFactory.getLogger(SelectCandidateByPictureController.class);
 | 
					    private final Logger logger = LoggerFactory.getLogger(SelectCandidateByPictureController.class);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,7 +50,7 @@ public class SelectCandidateByPictureController extends TwoWayNode implements Fu
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public void onSuccess(ByteString result) {
 | 
					    public void onSuccess(BallotQuestionUIElementOuterClass.UIAnswer result) {
 | 
				
			||||||
        this.votersBallot.VotersImageSelection = result;
 | 
					        this.votersBallot.VotersImageSelection = result;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,6 @@
 | 
				
			||||||
package meerkat.voting.gui.panels.select_candidate_name;
 | 
					package meerkat.voting.gui.panels.select_candidate_name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.google.common.util.concurrent.FutureCallback;
 | 
					import com.google.common.util.concurrent.FutureCallback;
 | 
				
			||||||
import com.google.protobuf.ByteString;
 | 
					 | 
				
			||||||
import javafx.event.Event;
 | 
					import javafx.event.Event;
 | 
				
			||||||
import javafx.scene.Node;
 | 
					import javafx.scene.Node;
 | 
				
			||||||
import javafx.scene.control.CheckBox;
 | 
					import javafx.scene.control.CheckBox;
 | 
				
			||||||
| 
						 | 
					@ -108,13 +107,14 @@ class StringsAnswersUpdater implements javafx.event.EventHandler{
 | 
				
			||||||
    void UpdateAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
 | 
					    void UpdateAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
 | 
				
			||||||
        this.RemoveAllAnswers();
 | 
					        this.RemoveAllAnswers();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        List<ByteString> answers = new ArrayList<>(question.getAnswers().getAnswers().getAnswersList());
 | 
					        List<BallotQuestionUIElementOuterClass.UIAnswer> answers =
 | 
				
			||||||
 | 
					                new ArrayList<>(question.getAnswers().getAnswers().getAnswersList());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (question.getRandomizeListOrder()){
 | 
					        if (question.getRandomizeListOrder()){
 | 
				
			||||||
            Collections.shuffle(answers);
 | 
					            Collections.shuffle(answers);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        for (ByteString bytesAnswer : answers){
 | 
					        for (BallotQuestionUIElementOuterClass.UIAnswer answer: answers){
 | 
				
			||||||
            this.AddAnswer(bytesAnswer.toStringUtf8());
 | 
					            this.AddAnswer(answer.getAnswer().toStringUtf8());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        this.currentStage.show();
 | 
					        this.currentStage.show();
 | 
				
			||||||
        this.logger.debug("Removed all the old answers and add all the news ones.");
 | 
					        this.logger.debug("Removed all the old answers and add all the news ones.");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,9 +9,18 @@
 | 
				
			||||||
      "answers": {
 | 
					      "answers": {
 | 
				
			||||||
        "type": 0,
 | 
					        "type": 0,
 | 
				
			||||||
        "answersValue": [
 | 
					        "answersValue": [
 | 
				
			||||||
          "George Boosh",
 | 
					          {
 | 
				
			||||||
          "Antonio Banderass",
 | 
					            "answer": "George Boosh",
 | 
				
			||||||
          "Michael Jakson"
 | 
					            "description": "The dude with the crazy stare"
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            "answer": "Antonio Banderass",
 | 
				
			||||||
 | 
					            "description": "the Espanic actor"
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            "answer": "Michael Jakson",
 | 
				
			||||||
 | 
					            "description": "the first black white singer"
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
| 
						 | 
					@ -24,9 +33,18 @@
 | 
				
			||||||
      "answers": {
 | 
					      "answers": {
 | 
				
			||||||
        "type": 2,
 | 
					        "type": 2,
 | 
				
			||||||
        "answersValue": [
 | 
					        "answersValue": [
 | 
				
			||||||
          "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/GeorgeBush.png",
 | 
					          {
 | 
				
			||||||
          "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/MichaelJackson.png",
 | 
					            "answer": "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/GeorgeBush.png",
 | 
				
			||||||
          "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/AntonioBanderass.png"
 | 
					            "description": "George Boosh image."
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            "answer": "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/MichaelJackson.png",
 | 
				
			||||||
 | 
					             "description": "Michael Jakson image."
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            "answer": "/F:/vova/meerkat/meerkat-java/voting-booth-gui/src/main/resources/images/AntonioBanderass.png",
 | 
				
			||||||
 | 
					            "description": "Antonio Banderass image."
 | 
				
			||||||
 | 
					          }
 | 
				
			||||||
        ]
 | 
					        ]
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue