meerkat-java/voting-booth-gui/src/main/select_candidate_by_picture/SelectCandidateByPictureCon...

87 lines
2.6 KiB
Java

package main.select_candidate_by_picture;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
import main.TwoWayNode;
import meerkat.protobuf.Voting;
import java.awt.*;
import java.util.List;
/**
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
* SelectCandidateNameController handle the behavior of select by picture screen
*/
public class SelectCandidateByPictureController extends TwoWayNode {
private List<Voting.BallotQuestion> questions;
private List<Voting.BallotAnswer> answers;
private int QuestionId:
public void SetQuestions(List<Voting.BallotQuestion> questions) throws InterruptedException {
this.questions = questions;
this.GetAnswers();
}
public List<Voting.BallotAnswer> GetAnswers() throws InterruptedException {
return null;
}
@FXML
private void submitTheSelection(MouseEvent mousePressed){
BorderPane b = (BorderPane) mousePressed.getSource();
int id = Integer.parseInt(b.getId().split("_")[1]);
unColorAllOthers(id);
b.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
}
private List<Voting.BallotAnswer> getAnswers(String id){
String name = getCandidateName(id);
}
/**
* Gets the name of the candidate
* @param id
* @return
*/
private String getCandidateName(String id){
return ((Label)this.currentStage.getScene().lookup("#name"+id)).getText();
}
/**
* Uncolors all the not selected picttures of candidates
* @param id the id of the selected candidate
*/
private void unColorAllOthers(int id){
for (int i = 0 ; i < 3 ; i++ ){
BorderPane b = (BorderPane)currentStage.getScene().lookup("#picture_"+i);
if (i != id) {
b.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
}
}
}
@FXML
private void GetToSelectByName(MouseEvent mousePressed){
this.currentStage.close();
this.currentStage.setScene(this.previous);
this.currentStage.show();
}
@FXML
private void GetToBallotSummary(MouseEvent mousePressed){
this.currentStage.close();
this.currentStage.setScene(this.next);
this.currentStage.show();
}
}