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 @FXML
private void GetToSelectByPicture(MouseEvent mousePressed){ private void GetToSelectByPicture(MouseEvent mousePressed){
this.currentStage.close(); this.currentStage.close();
this.previous.UpdateNode();
this.currentStage.setScene(this.previous.GetCurrentScene()); this.currentStage.setScene(this.previous.GetCurrentScene());
this.previous.UpdateNode();
this.currentStage.show(); this.currentStage.show();
} }
@FXML @FXML
private void GetToCastOrAudit(MouseEvent mousePressed){ private void GetToCastOrAudit(MouseEvent mousePressed){
this.currentStage.close(); this.currentStage.close();
this.next.UpdateNode();
this.currentStage.setScene(this.next.GetCurrentScene()); this.currentStage.setScene(this.next.GetCurrentScene());
this.next.UpdateNode();
this.currentStage.show(); this.currentStage.show();
} }

View File

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

View File

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

View File

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

View File

@ -1,51 +1,128 @@
package meerkat.voting.gui.select_candidate_name; package meerkat.voting.gui.select_candidate_name;
import com.google.protobuf.ByteString; 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.control.Label;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.stage.Stage; import javafx.stage.Stage;
import meerkat.protobuf.BallotQuestionUIElementOuterClass; import meerkat.protobuf.BallotQuestionUIElementOuterClass;
import java.util.Objects;
/** /**
* Created by Vladimir Eliezer Tokarev on 10/2/2016. * Created by Vladimir Eliezer Tokarev on 10/2/2016.
* This object gets the current stage and appends to the container of the names * 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 Stage currentStage;
private int rowAmount; private int rowAmount;
private String answer;
public StringsAnswersUpdater(Stage primaryStage) { StringsAnswersUpdater(Stage primaryStage) {
this.currentStage = primaryStage; this.currentStage = primaryStage;
this.rowAmount = 0; 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(){ 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 label = new Label();
label.setText(answer); 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); container.addRow(0);
this.rowAmount++; this.rowAmount++;
container.add(label, 0, this.rowAmount); container.add(newAnswer, 0, this.rowAmount);
} }
private void RemoveAllAnswers(){ /**
GridPane gridPane = this.GetAnswersContainer(); * Gets all the answers from the ballot ui question and puts them into the answers container
gridPane.getChildren().removeAll(); * @param question
} */
void AddAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
public void AddAnswers(BallotQuestionUIElementOuterClass.BallotQuestionUIElement question) {
this.RemoveAllAnswers(); this.RemoveAllAnswers();
for (ByteString bytesAnswer : question.getAnswers().getAnswers().getAnswersList()){ for (ByteString bytesAnswer : question.getAnswers().getAnswers().getAnswersList()){
this.AddAnswer(bytesAnswer.toString()); this.AddAnswer(bytesAnswer.toStringUtf8());
} }
this.currentStage.show(); 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; package meerkat.voting.gui.straight_channel_section;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent; import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import meerkat.voting.gui.TwoWayNode; import meerkat.voting.gui.TwoWayNode;
/** /**
@ -16,8 +13,8 @@ public class StraightChannelSectionController extends TwoWayNode {
@FXML @FXML
private void ProceedToNameSelection(MouseEvent boutonPressed) { private void ProceedToNameSelection(MouseEvent boutonPressed) {
this.currentStage.close(); this.currentStage.close();
this.next.UpdateNode();
this.currentStage.setScene(this.next.GetCurrentScene()); this.currentStage.setScene(this.next.GetCurrentScene());
this.next.UpdateNode();
this.currentStage.show(); this.currentStage.show();
} }

View File

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

View File

@ -79,105 +79,13 @@
</GridPane> </GridPane>
<ScrollPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1"> <ScrollPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
<content> <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> <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> <children>
<BorderPane layoutY="18.0" prefHeight="182.0" prefWidth="587.0"> <BorderPane layoutY="18.0" prefHeight="182.0" prefWidth="587.0">
<bottom> <bottom>
<GridPane fx:id="#AnswersScrollPane" prefHeight="159.0" prefWidth="596.0" BorderPane.alignment="CENTER"> <GridPane fx:id="AnswersGridPane" prefHeight="291.0" prefWidth="585.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> </GridPane>
</bottom> </bottom>
</BorderPane> </BorderPane>