channel single question
parent
646824de44
commit
f813cf49ee
|
@ -28,61 +28,81 @@ public class ChannelChoiceController {
|
||||||
List<Voting.BallotQuestion> questions = new ArrayList<>();
|
List<Voting.BallotQuestion> questions = new ArrayList<>();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
ChannelChoiceUICommand command = (ChannelChoiceUICommand) VistaNavigator.getCurrentCommand();
|
ChannelChoiceUICommand command = (ChannelChoiceUICommand) VistaNavigator.getCurrentCommand();
|
||||||
|
String questionText;
|
||||||
|
|
||||||
@FXML ToggleGroup answerGroup;
|
@FXML ToggleGroup answerGroup;
|
||||||
@FXML private Text question;
|
@FXML private Text question;
|
||||||
|
@FXML private Text warningMsg;
|
||||||
@FXML private Pane questionPane;
|
@FXML private Pane questionPane;
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void nextQuestion() {
|
public void initialize() {
|
||||||
if (questions.size()==0) {
|
// Voting.UIElementDataType.TEXT
|
||||||
questions = command.getQuestions();
|
questions = command.getQuestions();
|
||||||
answerGroup = new ToggleGroup();
|
answerGroup = new ToggleGroup();
|
||||||
}
|
int choiceType = questions.get(index).getQuestion().getTypeValue();
|
||||||
if (answerGroup.getSelectedToggle()!=null) {
|
System.out.println(choiceType);
|
||||||
String s = answerGroup.getSelectedToggle().getUserData().toString();
|
switch (choiceType) {
|
||||||
answers.add(UIUtils.translateStringAnswerToProtoBufMessageAnswer(s));
|
case 0: showQuestion(); //0==TEXT
|
||||||
index++;
|
break;
|
||||||
}
|
case 1: showCodeSelection();
|
||||||
if (index < questions.size()) {
|
break;
|
||||||
showQuestion();
|
// : showError();
|
||||||
} else {
|
|
||||||
//return answers to main threads
|
|
||||||
nextPane();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @FXML
|
||||||
|
// private void nextQuestion() {
|
||||||
|
// if (questions.size()==0) {
|
||||||
|
// questions = command.getQuestions();
|
||||||
|
// answerGroup = new ToggleGroup();
|
||||||
|
// }
|
||||||
|
// if (answerGroup.getSelectedToggle()!=null) {
|
||||||
|
// String s = answerGroup.getSelectedToggle().getUserData().toString();
|
||||||
|
// answers.add(UIUtils.translateStringAnswerToProtoBufMessageAnswer(s));
|
||||||
|
// index++;
|
||||||
|
// }
|
||||||
|
// if (index < questions.size()) {
|
||||||
|
// showQuestion();
|
||||||
|
// } else {
|
||||||
|
// //return answers to main threads
|
||||||
|
// nextPane();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
private void showCodeSelection() {
|
||||||
|
questionText = "Here we show code pad.";
|
||||||
|
question.setText(questionText);
|
||||||
|
}
|
||||||
|
|
||||||
private void showQuestion() {
|
private void showQuestion() {
|
||||||
Voting.BallotQuestion ballotQuestion = questions.get(index);
|
Voting.BallotQuestion ballotQuestion = questions.get(index);
|
||||||
question.setText("This is question n. "+index);
|
questionText = "Please answer this question before voting:";
|
||||||
|
question.setText(questionText);
|
||||||
answerGroup.getToggles().clear();
|
answerGroup.getToggles().clear();
|
||||||
VBox vbox = VistaNavigator.uiThread.showQuestionInFX(ballotQuestion, answerGroup);
|
VBox vbox = VistaNavigator.uiThread.showQuestionInFX(ballotQuestion, answerGroup);
|
||||||
questionPane.getChildren().clear();
|
questionPane.getChildren().clear();
|
||||||
questionPane.getChildren().addAll(vbox);
|
questionPane.getChildren().addAll(vbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
private void showError() {
|
||||||
private void goBack() throws VoterCancelThrowable{
|
questionText = "There was an error reading the channel, please go back to polling station.";
|
||||||
if (index == 0) {
|
question.setText(questionText);
|
||||||
doCancel();
|
|
||||||
} else {
|
|
||||||
--index;
|
|
||||||
answers.remove(index);
|
|
||||||
nextQuestion();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void doCancel() throws VoterCancelThrowable{
|
|
||||||
VoterCancelThrowable e = new VoterCancelThrowable();
|
|
||||||
command.getCallback().onFailure(e);
|
|
||||||
//see what is done in the original (basically need to call the callback of the command onFailure()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void nextPane() {
|
private void nextPane() {
|
||||||
VistaNavigator.loadVista(VistaNavigator.LOADING);
|
if (answerGroup.getSelectedToggle()!=null) {
|
||||||
VistaNavigator.uiThread.answerChannelChoiceScreen(command, answers);
|
String s = answerGroup.getSelectedToggle().getUserData().toString();
|
||||||
|
answers.add(UIUtils.translateStringAnswerToProtoBufMessageAnswer(s));
|
||||||
|
} else {
|
||||||
|
warningMsg.setText("(Please give an answer to continue)");
|
||||||
|
}
|
||||||
|
if (answers.size()!=0) {
|
||||||
|
VistaNavigator.loadVista(VistaNavigator.LOADING);
|
||||||
|
VistaNavigator.uiThread.answerChannelChoiceScreen(command, answers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,11 @@
|
||||||
<?import javafx.scene.layout.Pane?>
|
<?import javafx.scene.layout.Pane?>
|
||||||
<?import javafx.scene.text.Text?>
|
<?import javafx.scene.text.Text?>
|
||||||
|
|
||||||
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="meerkat.voting.gui.controllersFX.ChannelChoiceController">
|
<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="meerkat.voting.gui.controllersFX.ChannelChoiceController">
|
||||||
<children>
|
<children>
|
||||||
<Button layoutX="469.0" layoutY="343.0" mnemonicParsing="false" onMousePressed="#nextQuestion" text="Next" />
|
<Button layoutX="469.0" layoutY="343.0" mnemonicParsing="false" onMousePressed="#nextPane" prefHeight="39.0" prefWidth="109.0" text="Next" />
|
||||||
<Text fx:id="question" layoutX="84.0" layoutY="89.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Click 'Next' to see the first question." wrappingWidth="431.3046875" />
|
<Text fx:id="question" layoutX="84.0" layoutY="89.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Channel selection:" wrappingWidth="431.3046875" />
|
||||||
<Pane fx:id="questionPane" layoutX="84.0" layoutY="97.0" prefHeight="234.0" prefWidth="422.0" />
|
<Pane fx:id="questionPane" layoutX="84.0" layoutY="97.0" prefHeight="234.0" prefWidth="422.0" />
|
||||||
<Button layoutX="275.0" layoutY="343.0" mnemonicParsing="false" onMousePressed="#doCancel" text="Cancel" />
|
<Text fx:id="warningMsg" fill="#ee0909" layoutX="82.0" layoutY="64.0" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="431.3046875" />
|
||||||
<Button layoutX="84.0" layoutY="343.0" mnemonicParsing="false" onMousePressed="#goBack" text="Back" />
|
|
||||||
</children>
|
</children>
|
||||||
</Pane>
|
</Pane>
|
||||||
|
|
Loading…
Reference in New Issue