Created the VotingBoothGUIManager

This object creates a map of visual panels and can convert the
VotingBoothUI methods into actions (can execute them on wanted panels)
android-scanner
Vladimir Eliezer Tokarev 2016-09-17 13:29:21 +03:00
parent 9444072f40
commit d8adf7b49e
6 changed files with 131 additions and 83 deletions

View File

@ -1,24 +1,24 @@
package main;
import javafx.scene.Scene;
import javafx.stage.Stage;
import main.ballot_summary.BallotSummaryLoader;
import main.cast_or_audit.CastOrAuditLoader;
import main.select_candidate_by_picture.SelectCandidateByPictureLoader;
import main.select_candidate_name.SelectCandidateNameLoader;
import main.straight_channel_section.StraightChannelSectionLoader;
import main.vote_have_been_cast.VoteHaveBeenCastController;
import main.vote_have_been_cast.VoteHaveBeenCastLoader;
import main.welcome_splash.WelcomeSplashLoader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
* ChainBuilder builds all the two way nodes that are in current project (voting-booth-gui)
* and connects between all of them so they can keep their flow
*/
public class ChainBuilder {
class ChainBuilder {
/**
* Creates all the twoWayNodes and connects between them
@ -41,7 +41,7 @@ public class ChainBuilder {
* and the previous this way the flow between will be easy .
* The Build method creates all the screens and connect between them
*/
public static void Build(Stage primaryStage) throws IOException {
static Map<String, TwoWayNode> Build(Stage primaryStage) throws IOException {
WelcomeSplashLoader welcomeSplashLoader = new WelcomeSplashLoader(primaryStage);
TwoWayNode welcomeSplashController = welcomeSplashLoader.GetWelcomeSplash();
@ -79,5 +79,15 @@ public class ChainBuilder {
*/
primaryStage.setScene(welcomeSplashController.GetNode());
Map<String, TwoWayNode> nameToTwoWayNodeMap = new HashMap<>();
nameToTwoWayNodeMap.put("welcomeSplashController", welcomeSplashController);
nameToTwoWayNodeMap.put("straightChannelSectionController", straightChannelSectionController);
nameToTwoWayNodeMap.put("selectCandidateNameController", selectCandidateNameController);
nameToTwoWayNodeMap.put("selectCandidateByPictureController", selectCandidateByPictureController);
nameToTwoWayNodeMap.put("ballotSummaryController", ballotSummaryController);
nameToTwoWayNodeMap.put("voteHaveBeenCastController", voteHaveBeenCastController);
return nameToTwoWayNodeMap;
}
}

View File

@ -3,6 +3,7 @@ package main;
import javafx.application.Application;
import javafx.stage.Stage;
/**
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
* Main calls to ChainBuilder which initilizes all the TwoWayNode's

View File

@ -0,0 +1,110 @@
package main;
import com.google.common.util.concurrent.FutureCallback;
import javafx.application.Application;
import javafx.stage.Stage;
import meerkat.protobuf.Voting;
import meerkat.voting.ui.VotingBoothUI;
import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
/**
* Created by Vladimir Eliezer Tokarev on 9/17/2016.
* This class managers the gui of the voting booth thruogth external commands
*/
public class VotingBoothGUIManager extends Application implements VotingBoothUI {
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(VotingBoothGUIManager.class);
private Map<String, TwoWayNode> visualPanelsMap;
/**
* Creates new instance of VotingBoothGUIManager
*/
public VotingBoothGUIManager() {
}
@Override
public void start(Stage primaryStage) throws Exception {
visualPanelsMap = ChainBuilder.Build(primaryStage);
}
@Override
public void callShutDown() {
}
/**
* show an error to the voter. let him press a (chosen) button for handling the error.
* @param errorMessage message to show in UI device
* @param buttonLabels labels for buttons to present to voter
* @param callback the number of the selected button
*/
@Override
public void showErrorMessageWithButtons(Voting.UIElement errorMessage, Voting.UIElement[] buttonLabels, FutureCallback<Integer> callback) {
logger.debug("Graphical user interface call to showErrorMessageWithButtons");
}
/**
* show an error to the voter. Halts the system until a technician handles it
* @param errorMessage message to show in UI device
* @param callback returns interrupt
*/
@Override
public void showErrorMessageAndHalt(Voting.UIElement errorMessage, FutureCallback<Boolean> callback) {
logger.debug("Graphical user interface call to showErrorMessageAndHalt");
}
/**
* makes the UI (and voter) wait for something else to happen, by registering a WaitForFinishUICommand in the queue
* @param message a message to show the user on the UI device while waiting
* @param callback a success return value of the wait (cancelling returns false)
*/
@Override
public void notifyVoterToWaitForFinish(Voting.UIElement message, FutureCallback<Void> callback) {
logger.debug("Graphical user interface call to notifyVoterToWaitForFinish");
}
/**
* call for the cast-or-audit phase by registering a CastOrAuditUICommand in the queue
* @param callback the returned choice of how to finalize the ballot
*/
@Override
public void castOrAudit(FutureCallback<VotingBoothUI.FinalizeBallotChoice> callback) {
logger.debug("Graphical user interface call to castOrAudit");
}
/**
* call for the race voting question phase by registering a RaceVotingUICommand in the queue
* @param questions all ballot questions to present to the voter
* @param callback the responses to the questions collected by the UI, to send back to the controller. Responses are null if voter chose to cancel session
*/
@Override
public void askVoterQuestions(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) {
logger.debug("Graphical user interface call to chooseChannel");
}
/**
* call for the channel choice phase by registering a ChannelChoiceUICommand in the queue
* @param questions questions to determine the right voting channel for this voter
* @param callback that's where we store the answers to decide channel upon for the current voter
*/
@Override
public void chooseChannel(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) {
logger.debug("Graphical user interface call to chooseChannel");
}
/**
* start a new session by registering a StartSessionUICommand
* @param callback - a boolean future callback to return when done
*/
@Override
public void startNewVoterSession(FutureCallback<Void> callback) {
logger.debug("Graphical user interface call to startNewVoterSession");
}
}

View File

@ -1,39 +1,38 @@
package meerkat.voting.ui;
import com.google.common.util.concurrent.FutureCallback;
import main.VotingBoothGUIManager;
import meerkat.protobuf.Voting;
import meerkat.voting.controller.callbacks.*;
import meerkat.voting.ui.uicommands.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import static java.lang.System.in;
/**
* Created by Vladimir Eliezer Tokarev on 9/17/2016.
* This class forwards and receives different information for voter voting process
* and displays it in to voting booth gui
*/
public class GraphicalUserInterface implements VotingBoothUI, Runnable {
private static final Logger logger = LoggerFactory.getLogger(SystemConsoleUI.class);
public class GraphicalUserInterface implements Runnable {
private static final Logger logger = LoggerFactory.getLogger(GraphicalUserInterface.class);
private CommandPend<UICommand> cmdPend;
private Date startWaitingTime;
private VotingBoothGUIManager votingGUIManager;
private volatile boolean shutDownHasBeenCalled;
public GraphicalUserInterface() {
final int tickDurationInMilliSeconds = 10; // period between view update calls
logger.info("A Voting Booth graphical user interface is constructed");
cmdPend = new CommandPend<>();
votingGUIManager = new VotingBoothGUIManager();
startWaitingTime = null;
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TickerTimerTask(cmdPend), new Date(), tickDurationInMilliSeconds);
@ -107,21 +106,6 @@ public class GraphicalUserInterface implements VotingBoothUI, Runnable {
private void doTick() {
}
@Override
public void callShutDown() {
}
/**
* start a new session by registering a StartSessionUICommand
* @param callback - a boolean future callback to return when done
*/
@Override
public void startNewVoterSession(FutureCallback<Void> callback) {
logger.debug("Graphical user interface call to startNewVoterSession");
}
/**
* welcomes the new voter at the beginning of the session
* @param command a StartSessionUICommand with a acallback
@ -136,16 +120,6 @@ public class GraphicalUserInterface implements VotingBoothUI, Runnable {
private void stopWaiting () {
}
/**
* call for the channel choice phase by registering a ChannelChoiceUICommand in the queue
* @param questions questions to determine the right voting channel for this voter
* @param callback that's where we store the answers to decide channel upon for the current voter
*/
@Override
public void chooseChannel(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) {
logger.debug("Graphical user interface call to chooseChannel");
}
/**
* lists the channel choice questions to the voter and gathers the voter's answers
* @param command a ChannelChoiceUICommand with the data and a callback
@ -154,15 +128,6 @@ public class GraphicalUserInterface implements VotingBoothUI, Runnable {
logger.debug("Graphical user interface doAskChannelChoiceQuestions");
}
/**
* call for the race voting question phase by registering a RaceVotingUICommand in the queue
* @param questions all ballot questions to present to the voter
* @param callback the responses to the questions collected by the UI, to send back to the controller. Responses are null if voter chose to cancel session
*/
@Override
public void askVoterQuestions(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) {
logger.debug("Graphical user interface call to chooseChannel");
}
/**
* lists the race voting questions to the voter and gathers the voter's answers
@ -172,15 +137,6 @@ public class GraphicalUserInterface implements VotingBoothUI, Runnable {
logger.debug("Graphical user interface doAskVotingQuestions");
}
/**
* call for the cast-or-audit phase by registering a CastOrAuditUICommand in the queue
* @param callback the returned choice of how to finalize the ballot
*/
@Override
public void castOrAudit(FutureCallback<FinalizeBallotChoice> callback) {
logger.debug("Graphical user interface call to castOrAudit");
}
/**
* asks the voter whether to cast or audit the ballot
* @param command a simple CastOrAuditUICommand with the callback
@ -189,15 +145,6 @@ public class GraphicalUserInterface implements VotingBoothUI, Runnable {
logger.debug("Graphical user interface entered doCastOrAudit");
}
/**
* makes the UI (and voter) wait for something else to happen, by registering a WaitForFinishUICommand in the queue
* @param message a message to show the user on the UI device while waiting
* @param callback a success return value of the wait (cancelling returns false)
*/
@Override
public void notifyVoterToWaitForFinish(Voting.UIElement message, FutureCallback<Void> callback) {
logger.debug("Graphical user interface call to notifyVoterToWaitForFinish");
}
/**
* Tells the voter (in the console) to wait until some other process is finished
@ -207,26 +154,6 @@ public class GraphicalUserInterface implements VotingBoothUI, Runnable {
logger.debug("Graphical user interface entered doWaitForFinish");
}
/**
* show an error to the voter. Halts the system until a technician handles it
* @param errorMessage message to show in UI device
* @param callback returns interrupt
*/
@Override
public void showErrorMessageAndHalt(Voting.UIElement errorMessage, FutureCallback<Boolean> callback) {
logger.debug("Graphical user interface call to showErrorMessageAndHalt");
}
/**
* show an error to the voter. let him press a (chosen) button for handling the error.
* @param errorMessage message to show in UI device
* @param buttonLabels labels for buttons to present to voter
* @param callback the number of the selected button
*/
@Override
public void showErrorMessageWithButtons(Voting.UIElement errorMessage, Voting.UIElement[] buttonLabels, FutureCallback<Integer> callback) {
logger.debug("Graphical user interface call to showErrorMessageWithButtons");
}
/**
* show an error to the voter. let him press a (chosen) button for handling the error.