Now the text question represented in the select name panel

android-scanner
VladimirEliTokarev 2016-10-03 12:15:08 +03:00
parent 4e071c83ce
commit 352fb7a548
8 changed files with 103 additions and 122 deletions

View File

@ -12,16 +12,16 @@ public class BallotSummaryController extends TwoWayNode {
@FXML
private void GetToSelectByPicture(MouseEvent mousePressed){
this.currentStage.close();
this.previous.UpdateNode();
this.currentStage.setScene(this.previous.GetCurrentScene());
this.previous.UpdateNode();
this.currentStage.show();
}
@FXML
private void GetToCastOrAudit(MouseEvent mousePressed){
this.currentStage.close();
this.next.UpdateNode();
this.currentStage.setScene(this.next.GetCurrentScene());
this.next.UpdateNode();
this.currentStage.show();
}

View File

@ -13,8 +13,8 @@ public class CastOrAuditController extends TwoWayNode {
@FXML
private void GetToVoteHaveBeenCast(MouseEvent mousePressed) {
this.currentStage.close();
this.next.UpdateNode();
this.currentStage.setScene(this.next.GetCurrentScene());
this.next.UpdateNode();
this.currentStage.show();
}

View File

@ -13,16 +13,16 @@ public class SelectCandidateByPictureController extends TwoWayNode {
@FXML
private void GetToSelectByName(MouseEvent mousePressed){
this.currentStage.close();
this.previous.UpdateNode();
this.currentStage.setScene(this.previous.GetCurrentScene());
this.previous.UpdateNode();
this.currentStage.show();
}
@FXML
private void GetToBallotSummary(MouseEvent mousePressed){
this.currentStage.close();
this.next.UpdateNode();
this.currentStage.setScene(this.next.GetCurrentScene());
this.next.UpdateNode();
this.currentStage.show();
}

View File

@ -12,16 +12,16 @@ public class SelectCandidateNameController extends TwoWayNode {
@FXML
private void GetToSelectChannel(MouseEvent mousePressed){
this.currentStage.close();
this.previous.UpdateNode();
this.currentStage.setScene(this.previous.GetCurrentScene());
this.previous.UpdateNode();
this.currentStage.show();
}
@FXML
private void SelectCandidateByName(MouseEvent mousePressed) {
this.currentStage.close();
this.next.UpdateNode();
this.currentStage.setScene(this.next.GetCurrentScene());
this.next.UpdateNode();
this.currentStage.show();
}

View File

@ -1,51 +1,128 @@
package meerkat.voting.gui.select_candidate_name;
import com.google.protobuf.ByteString;
import javafx.event.Event;
import javafx.scene.Node;
import javafx.scene.control.CheckBox;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import meerkat.protobuf.BallotQuestionUIElementOuterClass;
import java.util.Objects;
/**
* Created by Vladimir Eliezer Tokarev on 10/2/2016.
* This object gets the current stage and appends to the container of the names
* the different names that there are in the config object
* the different names that there are in the config object and saves the use answer
*/
public class StringsAnswersUpdater {
class StringsAnswersUpdater implements javafx.event.EventHandler{
private Stage currentStage;
private int rowAmount;
private String answer;
public StringsAnswersUpdater(Stage primaryStage) {
StringsAnswersUpdater(Stage primaryStage) {
this.currentStage = primaryStage;
this.rowAmount = 0;
// The lookup works only after the css have been randered
this.currentStage.getScene().getRoot().applyCss();
}
/**
* Gets the container of the answers
* @return GridPane object
*/
private GridPane GetAnswersContainer(){
return (GridPane) this.currentStage.getScene().lookup("#AnswersScrollPane");
return (GridPane) this.currentStage.getScene().lookup("#AnswersGridPane");
}
private void AddAnswer(String answer){
GridPane container = this.GetAnswersContainer();
/**
* Remove all previous answers from the container
*/
private void RemoveAllAnswers(){
this.GetAnswersContainer().getChildren().removeAll();
}
/**
* Creates answer element which is grid pane with the answer and check box
* @param answer string answer to show to the voter
* @return GridPane which contains string and check box
*/
private GridPane GetAnswerElement(String answer){
GridPane gridPane = new GridPane();
Label label = new Label();
label.setText(answer);
label.setPrefSize(550, 30);
GridPane.setConstraints(label, 1, 1);
CheckBox checkBox = new CheckBox();
checkBox.setId(answer+"-checkBox");
checkBox.setOnAction(this);
GridPane.setConstraints(checkBox, 10, 1);
gridPane.getChildren().addAll(label, checkBox);
return gridPane;
}
/**
* Adds the GridPane answer to the panel
* @param answer is the answer string to represent to the user
*/
private void AddAnswer(String answer){
GridPane container = this.GetAnswersContainer();
GridPane newAnswer = this.GetAnswerElement(answer);
container.addRow(0);
this.rowAmount++;
container.add(label, 0, this.rowAmount);
container.add(newAnswer, 0, this.rowAmount);
}
private void RemoveAllAnswers(){
GridPane gridPane = this.GetAnswersContainer();
gridPane.getChildren().removeAll();
}
public void AddAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
/**
* Gets all the answers from the ballot ui question and puts them into the answers container
* @param question
*/
void AddAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
this.RemoveAllAnswers();
for (ByteString bytesAnswer : question.getAnswers().getAnswers().getAnswersList()){
this.AddAnswer(bytesAnswer.toString());
this.AddAnswer(bytesAnswer.toStringUtf8());
}
this.currentStage.show();
}
/**
* Unchecks all the check boxes that are not target box
* @param target
*/
private void uncheckBoxes(CheckBox target){
GridPane answersContainer = this.GetAnswersContainer();
for (Node child : answersContainer.getChildren()){
GridPane answer = (GridPane)child;
CheckBox checkBox = (CheckBox) answer.getChildren().get(1);
if (!Objects.equals(checkBox.getId(), target.getId()) && checkBox.isSelected()){
checkBox.fire();
}
}
}
@Override
/**
* Saves the user chose
*/
public void handle(Event event) {
if (event.getSource() instanceof CheckBox) {
CheckBox target = ((CheckBox)event.getSource());
if (target.isSelected()) {
String answer = target.getId().split("-")[0];
this.answer = answer;
System.out.println(answer);
this.uncheckBoxes(target);
}
}
}
}

View File

@ -1,10 +1,7 @@
package meerkat.voting.gui.straight_channel_section;
import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import meerkat.voting.gui.TwoWayNode;
/**
@ -16,8 +13,8 @@ public class StraightChannelSectionController extends TwoWayNode {
@FXML
private void ProceedToNameSelection(MouseEvent boutonPressed) {
this.currentStage.close();
this.next.UpdateNode();
this.currentStage.setScene(this.next.GetCurrentScene());
this.next.UpdateNode();
this.currentStage.show();
}

View File

@ -1,7 +1,6 @@
package meerkat.voting.gui.welcome_splash;
import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import meerkat.voting.gui.TwoWayNode;
@ -14,8 +13,8 @@ public class WelcomeSplashController extends TwoWayNode {
@FXML
private void StartVotingProcess(MouseEvent mousePressed) {
this.currentStage.close();
this.next.UpdateNode();
this.currentStage.setScene(this.next.GetCurrentScene());
this.next.UpdateNode();
this.currentStage.show();
}

View File

@ -79,105 +79,13 @@
</GridPane>
<ScrollPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="200.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="592.0" prefWidth="582.0">
<children>
<Pane layoutX="-1.0" layoutY="-14.0" prefHeight="200.0" prefWidth="585.0">
<Pane layoutX="9.0" layoutY="-5.0" prefHeight="191.0" prefWidth="575.0">
<children>
<BorderPane layoutY="18.0" prefHeight="182.0" prefWidth="587.0">
<bottom>
<GridPane fx:id="#AnswersScrollPane" prefHeight="159.0" prefWidth="596.0" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="143.0" minWidth="10.0" prefWidth="66.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="462.0" minWidth="10.0" prefWidth="452.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="190.0" minWidth="10.0" prefWidth="67.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
<center>
<GridPane BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<bottom>
<Label text="Name of Candidate" BorderPane.alignment="CENTER">
<font>
<Font name="System Bold" size="15.0" />
</font>
<padding>
<Insets right="300.0" />
</padding>
</Label>
</bottom>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
<top>
<Label text="Name of Party" BorderPane.alignment="CENTER">
<padding>
<Insets right="358.0" />
</padding>
</Label>
</top>
</BorderPane>
</children>
</GridPane>
</center>
</BorderPane>
<GridPane GridPane.columnIndex="1" GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<BorderPane prefHeight="26.0" prefWidth="462.0">
<bottom>
<Label text="Name Of Candidate" BorderPane.alignment="CENTER">
<font>
<Font name="System Bold" size="15.0" />
</font>
<BorderPane.margin>
<Insets right="300.0" />
</BorderPane.margin>
</Label>
</bottom>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
<top>
<Label text="Name of Party" BorderPane.alignment="CENTER">
<padding>
<Insets right="360.0" />
</padding>
</Label>
</top>
</BorderPane>
</children>
</GridPane>
<BorderPane prefHeight="53.0" prefWidth="437.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
<left>
<Label text="Write In" BorderPane.alignment="CENTER">
<font>
<Font name="System Bold" size="15.0" />
</font>
<padding>
<Insets left="10.0" />
</padding>
</Label>
</left>
</BorderPane>
</children>
<GridPane fx:id="AnswersGridPane" prefHeight="291.0" prefWidth="585.0" BorderPane.alignment="CENTER">
</GridPane>
</bottom>
</BorderPane>