got to Cast or Audit screen
parent
29b8ef9734
commit
b8418156b1
|
@ -10,6 +10,7 @@ import javafx.scene.layout.VBox;
|
|||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontPosture;
|
||||
import javafx.scene.text.Text;
|
||||
import meerkat.protobuf.Voting;
|
||||
import meerkat.protobuf.Voting.BallotAnswer;
|
||||
import meerkat.protobuf.Voting.BallotQuestion;
|
||||
import meerkat.protobuf.Voting.UIElement;
|
||||
|
@ -171,6 +172,21 @@ public class GraphicalUI implements VotingBoothUI, Runnable {
|
|||
callback.onSuccess(null);
|
||||
}
|
||||
|
||||
public void answerChannelChoiceScreen(ChannelChoiceUICommand command, List<Voting.BallotAnswer> answers) {
|
||||
command.getCallback().onSuccess(answers);
|
||||
}
|
||||
|
||||
|
||||
public void answerVotingScreen(RaceVotingUICommand command, List<Voting.BallotAnswer> answers) {
|
||||
command.getCallback().onSuccess(answers);
|
||||
}
|
||||
|
||||
public void answerCastOrAuditScreen(CastOrAuditUICommand command, VotingBoothUI.FinalizeBallotChoice fChoice) {
|
||||
ControllerCallback callback = command.getCallback();
|
||||
assert (callback instanceof CastOrAuditCallback);
|
||||
((CastOrAuditCallback)callback).onSuccess(fChoice);
|
||||
}
|
||||
|
||||
/**
|
||||
* marks that the waiting, for something else to have happened, is finished
|
||||
*/
|
||||
|
@ -241,20 +257,9 @@ public class GraphicalUI implements VotingBoothUI, Runnable {
|
|||
*/
|
||||
private void doAskVotingQuestions (RaceVotingUICommand command) {
|
||||
logger.debug("UI: doAskVotingQuestions");
|
||||
System.out.println("Showing questions for race voting:\n");
|
||||
try {
|
||||
List<BallotAnswer> answers = askVoterForAnswers(command.getQuestions());
|
||||
command.getCallback().onSuccess(answers);
|
||||
}
|
||||
catch (VoterCancelThrowable e) {
|
||||
command.getCallback().onFailure(e);
|
||||
}
|
||||
catch (IOException e) {
|
||||
String errorMessage = "Asking voting questions failed due to IOException: " + e;
|
||||
logger.error (errorMessage);
|
||||
System.err.println(errorMessage);
|
||||
command.getCallback().onFailure(e);
|
||||
}
|
||||
UIUtils.assertQuestionsAreValid(command.getQuestions(), logger);
|
||||
VistaNavigator.setCurrentCommand(command);
|
||||
VistaNavigator.loadVista(VistaNavigator.VOTING);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package meerkat.voting.gui.ui.controllersFX;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import meerkat.protobuf.Voting;
|
||||
import meerkat.voting.controller.callbacks.CastOrAuditCallback;
|
||||
import meerkat.voting.controller.callbacks.ControllerCallback;
|
||||
import meerkat.voting.controller.callbacks.VoterCancelThrowable;
|
||||
import meerkat.voting.gui.ui.UIUtils;
|
||||
import meerkat.voting.gui.ui.VotingBoothUI;
|
||||
import meerkat.voting.gui.ui.uicommands.CastOrAuditUICommand;
|
||||
import meerkat.voting.gui.ui.uicommands.RaceVotingUICommand;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//import meerkat.voting.gui.ui.UIUtils;
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
||||
* ChannelChoiceController handle the behavior of select channel section screen
|
||||
*/
|
||||
public class CastOrAuditController {
|
||||
|
||||
CastOrAuditUICommand command = (CastOrAuditUICommand) VistaNavigator.getCurrentCommand();
|
||||
VotingBoothUI.FinalizeBallotChoice fChoice;
|
||||
|
||||
|
||||
@FXML
|
||||
private void cast() {
|
||||
fChoice = VotingBoothUI.FinalizeBallotChoice.CAST;
|
||||
}
|
||||
|
||||
@FXML
|
||||
private void audit() {
|
||||
fChoice = VotingBoothUI.FinalizeBallotChoice.AUDIT;
|
||||
}
|
||||
|
||||
private void nextPane() {
|
||||
VistaNavigator.loadVista(VistaNavigator.LOADING);
|
||||
VistaNavigator.uiThread.answerCastOrAuditScreen(command, fChoice);
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// @FXML
|
||||
// private void doCancel() throws VoterCancelThrowable{
|
||||
// String errorMessage = "doCastOrAudit: some error with reading input from console. details: " + e;
|
||||
// logger.error(errorMessage);
|
||||
// command.getCallback().onFailure(e);
|
||||
// //see what is done in the original (basically need to call the callback of the command onFailure()
|
||||
// }
|
||||
|
||||
|
||||
}
|
|
@ -60,7 +60,7 @@ public class ChannelChoiceController {
|
|||
|
||||
private void showQuestion() {
|
||||
Voting.BallotQuestion ballotQuestion = questions.get(index);
|
||||
question.setText("This question n. "+index);
|
||||
question.setText("This is question n. "+index);
|
||||
answerGroup.getToggles().clear();
|
||||
VBox vbox = VistaNavigator.uiThread.showQuestionInFX(ballotQuestion, answerGroup);
|
||||
questionPane.getChildren().clear();
|
||||
|
@ -88,19 +88,8 @@ public class ChannelChoiceController {
|
|||
|
||||
private void nextPane() {
|
||||
VistaNavigator.loadVista(VistaNavigator.LOADING);
|
||||
command.getCallback().onSuccess(answers);
|
||||
VistaNavigator.uiThread.answerChannelChoiceScreen(command, answers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the visual channel value
|
||||
*/
|
||||
private void updateVisualChanel(){
|
||||
for (int i = 0 ; i < 4 ; i ++ ){
|
||||
String id = "#textarea_"+i;
|
||||
// TextField textField = ((TextField)this.currentStage.getScene().lookup(id));
|
||||
// textField.setText(String.valueOf(this.chanelValue.get(i)));
|
||||
}
|
||||
// this.logger.debug("Updated the visual representation of the channel (its visual value).");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ public class VistaNavigator {
|
|||
public static final String WELCOME_SCREEN = "/views/welcome_screen.fxml";
|
||||
public static final String VISTA_2 = "/views/vista2.fxml";
|
||||
public static final String CHANNEL_CHOICE = "/views/channel_choice.fxml";
|
||||
public static final String VOTING = "/views/voting.fxml";
|
||||
|
||||
/** The main application layout controller. */
|
||||
private static MainController mainController;
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
package meerkat.voting.gui.ui.controllersFX;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.scene.control.ToggleGroup;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.scene.layout.VBox;
|
||||
import javafx.scene.text.Text;
|
||||
import meerkat.protobuf.Voting;
|
||||
import meerkat.voting.controller.callbacks.VoterCancelThrowable;
|
||||
import meerkat.voting.gui.ui.UIUtils;
|
||||
import meerkat.voting.gui.ui.uicommands.ChannelChoiceUICommand;
|
||||
import meerkat.voting.gui.ui.uicommands.RaceVotingUICommand;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//import meerkat.voting.gui.ui.UIUtils;
|
||||
|
||||
/**
|
||||
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
||||
* ChannelChoiceController handle the behavior of select channel section screen
|
||||
*/
|
||||
public class VotingController {
|
||||
|
||||
// private List<Integer> chanelValue;
|
||||
// private int pointer;
|
||||
// private boolean lock;
|
||||
|
||||
List<Voting.BallotAnswer> answers = new ArrayList<>();
|
||||
List<Voting.BallotQuestion> questions = new ArrayList<>();
|
||||
int index = 0;
|
||||
RaceVotingUICommand command = (RaceVotingUICommand) VistaNavigator.getCurrentCommand();
|
||||
|
||||
@FXML ToggleGroup answerGroup;
|
||||
@FXML private Text question;
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
private void showQuestion() {
|
||||
Voting.BallotQuestion ballotQuestion = questions.get(index);
|
||||
question.setText("This is question n. "+index);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@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.answerVotingScreen(command, answers);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?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.ui.controllersFX.CastOrAuditController">
|
||||
<children>
|
||||
<Text fx:id="question" layoutX="84.0" layoutY="89.0" strokeType="OUTSIDE" strokeWidth="0.0" text="Cast or Audit?" textAlignment="CENTER" wrappingWidth="431.3046875" />
|
||||
<Pane fx:id="questionPane" layoutX="84.0" layoutY="97.0" prefHeight="234.0" prefWidth="422.0" />
|
||||
<Button layoutX="84.0" layoutY="343.0" mnemonicParsing="false" onMousePressed="#cast" text="Cast" />
|
||||
<Button layoutX="469.0" layoutY="343.0" mnemonicParsing="false" onMousePressed="#audit" text="Audit" />
|
||||
</children>
|
||||
</Pane>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<?import javafx.scene.control.Button?>
|
||||
<?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.ui.controllersFX.VotingController">
|
||||
<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" />
|
||||
<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" />
|
||||
</children>
|
||||
</Pane>
|
Loading…
Reference in New Issue