channel single question
parent
646824de44
commit
f813cf49ee
|
@ -28,61 +28,81 @@ public class ChannelChoiceController {
|
|||
List<Voting.BallotQuestion> questions = new ArrayList<>();
|
||||
int index = 0;
|
||||
ChannelChoiceUICommand command = (ChannelChoiceUICommand) VistaNavigator.getCurrentCommand();
|
||||
String questionText;
|
||||
|
||||
@FXML ToggleGroup answerGroup;
|
||||
@FXML private Text question;
|
||||
@FXML private Text warningMsg;
|
||||
@FXML private Pane questionPane;
|
||||
|
||||
@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();
|
||||
public void initialize() {
|
||||
// Voting.UIElementDataType.TEXT
|
||||
questions = command.getQuestions();
|
||||
answerGroup = new ToggleGroup();
|
||||
int choiceType = questions.get(index).getQuestion().getTypeValue();
|
||||
System.out.println(choiceType);
|
||||
switch (choiceType) {
|
||||
case 0: showQuestion(); //0==TEXT
|
||||
break;
|
||||
case 1: showCodeSelection();
|
||||
break;
|
||||
// : showError();
|
||||
}
|
||||
}
|
||||
|
||||
// @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() {
|
||||
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();
|
||||
VBox vbox = VistaNavigator.uiThread.showQuestionInFX(ballotQuestion, answerGroup);
|
||||
questionPane.getChildren().clear();
|
||||
questionPane.getChildren().addAll(vbox);
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void goBack() throws VoterCancelThrowable{
|
||||
if (index == 0) {
|
||||
doCancel();
|
||||
} else {
|
||||
--index;
|
||||
answers.remove(index);
|
||||
nextQuestion();
|
||||
}
|
||||
private void showError() {
|
||||
questionText = "There was an error reading the channel, please go back to polling station.";
|
||||
question.setText(questionText);
|
||||
|
||||
}
|
||||
|
||||
@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() {
|
||||
VistaNavigator.loadVista(VistaNavigator.LOADING);
|
||||
VistaNavigator.uiThread.answerChannelChoiceScreen(command, answers);
|
||||
if (answerGroup.getSelectedToggle()!=null) {
|
||||
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.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>
|
||||
<Button layoutX="469.0" layoutY="343.0" mnemonicParsing="false" onMousePressed="#nextQuestion" 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" />
|
||||
<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="Channel selection:" wrappingWidth="431.3046875" />
|
||||
<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" />
|
||||
<Button layoutX="84.0" layoutY="343.0" mnemonicParsing="false" onMousePressed="#goBack" text="Back" />
|
||||
<Text fx:id="warningMsg" fill="#ee0909" layoutX="82.0" layoutY="64.0" strokeType="OUTSIDE" strokeWidth="0.0" wrappingWidth="431.3046875" />
|
||||
</children>
|
||||
</Pane>
|
||||
|
|
Loading…
Reference in New Issue