fx gui with MainController and Navigator (incomplete)
parent
c97519c28e
commit
5113c2235b
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
||||||
* StraightChannelSectionController handle the behavior of select channel section screen
|
* ChannelChoiceController handle the behavior of select channel section screen
|
||||||
*/
|
*/
|
||||||
public class StraightChannelSectionController extends TwoWayNode {
|
public class StraightChannelSectionController extends TwoWayNode {
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
||||||
* WelcomeSplashController handle the behavior of welcome splash class
|
* StartSessionController handle the behavior of welcome splash class
|
||||||
*/
|
*/
|
||||||
public class WelcomeSplashController extends TwoWayNode {
|
public class WelcomeSplashController extends TwoWayNode {
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
package meerkat.voting;
|
package meerkat.voting;
|
||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.sun.corba.se.impl.orbutil.graph.Graph;
|
|
||||||
import meerkat.crypto.DigitalSignature;
|
import meerkat.crypto.DigitalSignature;
|
||||||
import meerkat.crypto.Encryption;
|
import meerkat.crypto.Encryption;
|
||||||
import meerkat.protobuf.Voting;
|
import meerkat.protobuf.Voting;
|
||||||
import meerkat.voting.controller.VotingBoothImpl;
|
import meerkat.voting.controller.VotingBoothImpl;
|
||||||
import meerkat.voting.encryptor.VBCryptoManager;
|
import meerkat.voting.encryptor.VBCryptoManager;
|
||||||
import meerkat.voting.encryptor.VBCryptoManagerImpl;
|
import meerkat.voting.encryptor.VBCryptoManagerImpl;
|
||||||
import meerkat.voting.gui.ui.GraphicalFX;
|
|
||||||
import javafx.application.Application;
|
|
||||||
import meerkat.voting.gui.ui.GraphicalUI;
|
import meerkat.voting.gui.ui.GraphicalUI;
|
||||||
import meerkat.voting.gui.ui.SystemConsoleUI;
|
|
||||||
import meerkat.voting.output.SystemConsoleOutputDevice;
|
import meerkat.voting.output.SystemConsoleOutputDevice;
|
||||||
import meerkat.voting.storage.StorageManager;
|
import meerkat.voting.storage.StorageManager;
|
||||||
import meerkat.voting.storage.StorageManagerMockup;
|
import meerkat.voting.storage.StorageManagerMockup;
|
||||||
|
@ -26,7 +22,7 @@ import java.util.*;
|
||||||
public class VotingBoothToyGraphicalRun {
|
public class VotingBoothToyGraphicalRun {
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
// Application.launch(GraphicalFX.class, args);
|
// Application.launch(MainFX.class, args);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,114 +0,0 @@
|
||||||
package meerkat.voting.gui.ui;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Laura on 12/12/2016.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import javafx.application.Application;
|
|
||||||
import javafx.scene.Scene;
|
|
||||||
import javafx.scene.layout.StackPane;
|
|
||||||
import javafx.stage.Stage;
|
|
||||||
import meerkat.voting.gui.ui.uicommands.StartSessionUICommand;
|
|
||||||
import meerkat.voting.gui.ui.uicommands.UICommand;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import javafx.scene.Parent;
|
|
||||||
import javafx.fxml.FXMLLoader;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class GraphicalFX extends Application {
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(GraphicalUI.class);
|
|
||||||
private static GraphicalUI parent;
|
|
||||||
private Stage activeStage;
|
|
||||||
private static UICommand currentCommand;
|
|
||||||
|
|
||||||
public static void setParent(GraphicalUI ui) {
|
|
||||||
if (GraphicalFX.parent==null) {
|
|
||||||
GraphicalFX.parent = ui;
|
|
||||||
}
|
|
||||||
logger.warn("Trying to assign again the parent of GraphicalFX.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void init() throws Exception {
|
|
||||||
// System.out.println("init() of Hello World FX");
|
|
||||||
parent.setGraphicalFx(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
|
||||||
// launch(args);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public void start(Stage primaryStage) {
|
|
||||||
// primaryStage.setTitle("Hello World!");
|
|
||||||
// Button btn = new Button();
|
|
||||||
// btn.setText("Say 'Hello World'");
|
|
||||||
// btn.setOnAction(new EventHandler<ActionEvent>() {
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// public void handle(ActionEvent event) {
|
|
||||||
// System.out.println("Hello World!");
|
|
||||||
// System.out.println(parent.testPrint());
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// StackPane root = new StackPane();
|
|
||||||
// root.getChildren().add(btn);
|
|
||||||
// Scene scene = new Scene(root, 300, 250);
|
|
||||||
//
|
|
||||||
// primaryStage.setScene(scene);
|
|
||||||
// primaryStage.show();
|
|
||||||
// }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(Stage primaryStage) {
|
|
||||||
this.activeStage=primaryStage;
|
|
||||||
|
|
||||||
// Parent root = new StackPane();
|
|
||||||
// Scene scene = new Scene(root, 300, 275);
|
|
||||||
// primaryStage.setScene(scene);
|
|
||||||
// primaryStage.show();
|
|
||||||
|
|
||||||
Parent root = null;
|
|
||||||
try {
|
|
||||||
root = FXMLLoader.load(getClass().getResource("/graphical_fxml/welcome_splash_screen.fxml"));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene scene = new Scene(root, 300, 275);
|
|
||||||
|
|
||||||
this.activeStage.setScene(scene);
|
|
||||||
this.activeStage.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showWelcomeScreen(UICommand command) {
|
|
||||||
GraphicalFX.currentCommand = command;
|
|
||||||
System.out.println("in FX showWelcomeScreen");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void answerWelcomeScreen() {
|
|
||||||
GraphicalFX.parent.answerWelcomeScreen((StartSessionUICommand) GraphicalFX.currentCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showChannelChoiceScreen(UICommand command) {
|
|
||||||
GraphicalFX.currentCommand = command;
|
|
||||||
System.out.println("in FX showChannelChoiceScreen");
|
|
||||||
Parent root = null;
|
|
||||||
try {
|
|
||||||
root = FXMLLoader.load(getClass().getResource("/graphical_fxml/welcome_splash_screen.fxml"));
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
Scene scene = new Scene(root, 300, 275);
|
|
||||||
|
|
||||||
this.activeStage.setScene(scene);
|
|
||||||
this.activeStage.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -2,26 +2,23 @@ package meerkat.voting.gui.ui;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
import javafx.stage.Stage;
|
|
||||||
import meerkat.protobuf.Voting.BallotAnswer;
|
import meerkat.protobuf.Voting.BallotAnswer;
|
||||||
import meerkat.protobuf.Voting.BallotQuestion;
|
import meerkat.protobuf.Voting.BallotQuestion;
|
||||||
import meerkat.protobuf.Voting.UIElement;
|
import meerkat.protobuf.Voting.UIElement;
|
||||||
import meerkat.protobuf.Voting.UIElementDataType;
|
import meerkat.protobuf.Voting.UIElementDataType;
|
||||||
import meerkat.voting.controller.callbacks.*;
|
import meerkat.voting.controller.callbacks.*;
|
||||||
|
import meerkat.voting.gui.ui.controllersFX.VistaNavigator;
|
||||||
import meerkat.voting.gui.ui.uicommands.*;
|
import meerkat.voting.gui.ui.uicommands.*;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
import static java.lang.System.in;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* an asynchronous thread implementation of the VotingBoothUI interface
|
* an asynchronous thread implementation of the VotingBoothUI interface
|
||||||
|
@ -37,15 +34,14 @@ public class GraphicalUI implements VotingBoothUI, Runnable {
|
||||||
|
|
||||||
private volatile boolean shutDownHasBeenCalled;
|
private volatile boolean shutDownHasBeenCalled;
|
||||||
|
|
||||||
private GraphicalFX ui;
|
private MainFX ui;
|
||||||
|
|
||||||
public GraphicalUI() {
|
public GraphicalUI() {
|
||||||
final int tickDurationInMillisec = 10; // period between view update calls
|
final int tickDurationInMillisec = 10; // period between view update calls
|
||||||
|
|
||||||
logger.info("A graphical UI console is constructed");
|
logger.info("A graphical UI console is constructed");
|
||||||
cmdPend = new CommandPend<>();
|
cmdPend = new CommandPend<>();
|
||||||
// bufferedReader = new BufferedReader(new InputStreamReader(in));
|
VistaNavigator.setUIThread(this);
|
||||||
GraphicalFX.setParent(this);
|
|
||||||
|
|
||||||
startWaitingTime = null;
|
startWaitingTime = null;
|
||||||
Timer timer = new Timer();
|
Timer timer = new Timer();
|
||||||
|
@ -60,11 +56,11 @@ public class GraphicalUI implements VotingBoothUI, Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run () {
|
public void run () {
|
||||||
logger.info("UI starts running");
|
logger.info("UI starts running");
|
||||||
// Application.launch(GraphicalFX.class);
|
// Application.launch(MainFX.class);
|
||||||
new Thread() {
|
new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Application.launch(GraphicalFX.class);
|
Application.launch(MainFX.class);
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
try {
|
try {
|
||||||
|
@ -157,13 +153,13 @@ public class GraphicalUI implements VotingBoothUI, Runnable {
|
||||||
*/
|
*/
|
||||||
private void doShowWelcomeScreen(StartSessionUICommand command) {
|
private void doShowWelcomeScreen(StartSessionUICommand command) {
|
||||||
logger.debug("UI entered doShowWelcomeScreen");
|
logger.debug("UI entered doShowWelcomeScreen");
|
||||||
this.ui.showWelcomeScreen(command);
|
VistaNavigator.setCurrentCommand(command);
|
||||||
// waitForEnter(null);
|
// waitForEnter(null);
|
||||||
// ControllerCallback<Void> callback = command.getCallback();
|
// ControllerCallback<Void> callback = command.getCallback();
|
||||||
// callback.onSuccess(null);
|
// callback.onSuccess(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void answerWelcomeScreen(StartSessionUICommand command) {
|
public void answerWelcomeScreen(StartSessionUICommand command) {
|
||||||
ControllerCallback<Void> callback = command.getCallback();
|
ControllerCallback<Void> callback = command.getCallback();
|
||||||
callback.onSuccess(null);
|
callback.onSuccess(null);
|
||||||
}
|
}
|
||||||
|
@ -216,20 +212,7 @@ public class GraphicalUI implements VotingBoothUI, Runnable {
|
||||||
*/
|
*/
|
||||||
private void doAskChannelChoiceQuestions (ChannelChoiceUICommand command) {
|
private void doAskChannelChoiceQuestions (ChannelChoiceUICommand command) {
|
||||||
logger.debug("UI: doAskChannelChoiceQuestions");
|
logger.debug("UI: doAskChannelChoiceQuestions");
|
||||||
System.out.println("Showing questions for choosing channel:\n");
|
VistaNavigator.getMainController().showChannelChoiceScreen(command, logger);
|
||||||
try {
|
|
||||||
List<BallotAnswer> answers = askVoterForAnswers(command.getQuestions());
|
|
||||||
command.getCallback().onSuccess(answers);
|
|
||||||
}
|
|
||||||
catch (VoterCancelThrowable e) {
|
|
||||||
command.getCallback().onFailure(e);
|
|
||||||
}
|
|
||||||
catch (IOException e) {
|
|
||||||
String errorMessage = "Channel choice failed due to IOException: " + e;
|
|
||||||
logger.error (errorMessage);
|
|
||||||
System.err.println(errorMessage);
|
|
||||||
command.getCallback().onFailure(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -503,8 +486,8 @@ public class GraphicalUI implements VotingBoothUI, Runnable {
|
||||||
return "testPrint called";
|
return "testPrint called";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGraphicalFx(GraphicalFX graphicalFX) {
|
public void setGraphicalFx(MainFX mainFX) {
|
||||||
this.ui = graphicalFX;
|
this.ui = mainFX;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
package meerkat.voting.gui.ui;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Laura on 12/12/2016.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import javafx.application.Application;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.layout.Pane;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import meerkat.voting.gui.ui.controllersFX.MainController;
|
||||||
|
import meerkat.voting.gui.ui.controllersFX.VistaNavigator;
|
||||||
|
import meerkat.voting.gui.ui.uicommands.StartSessionUICommand;
|
||||||
|
import meerkat.voting.gui.ui.uicommands.UICommand;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import javafx.scene.Parent;
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class MainFX extends Application {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(GraphicalUI.class);
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// public void init() throws Exception {
|
||||||
|
// parent.setGraphicalFx(this);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
// launch(args);
|
||||||
|
// }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(Stage stage) throws Exception{
|
||||||
|
stage.setTitle("Vista Viewer");
|
||||||
|
stage.setScene(
|
||||||
|
createScene(
|
||||||
|
loadMainPane()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
stage.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the main fxml layout.
|
||||||
|
* Sets up the vista switching VistaNavigator.
|
||||||
|
* Loads the first vista into the fxml layout.
|
||||||
|
*
|
||||||
|
* @return the loaded pane.
|
||||||
|
* @throws IOException if the pane could not be loaded.
|
||||||
|
*/
|
||||||
|
private Pane loadMainPane() throws IOException {
|
||||||
|
FXMLLoader loader = new FXMLLoader(getClass().getResource(VistaNavigator.MAIN));
|
||||||
|
|
||||||
|
Pane mainPane = (Pane) loader.load();
|
||||||
|
|
||||||
|
MainController mainController = loader.getController();
|
||||||
|
mainController.setCurrentCommand(null);
|
||||||
|
|
||||||
|
VistaNavigator.setMainController(mainController);
|
||||||
|
VistaNavigator.loadVista(VistaNavigator.VISTA_1);
|
||||||
|
|
||||||
|
return mainPane;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the main application scene.
|
||||||
|
*
|
||||||
|
* @param mainPane the main application layout.
|
||||||
|
*
|
||||||
|
* @return the created scene.
|
||||||
|
*/
|
||||||
|
private Scene createScene(Pane mainPane) {
|
||||||
|
Scene scene = new Scene(mainPane);
|
||||||
|
// scene.getStylesheets().setAll(
|
||||||
|
// getClass().getResource("/views/vista.css").toExternalForm()
|
||||||
|
// );
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,109 +0,0 @@
|
||||||
package meerkat.voting.gui.ui.controllerFX;
|
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.scene.control.Button;
|
|
||||||
import javafx.scene.control.TextField;
|
|
||||||
import javafx.scene.input.MouseEvent;
|
|
||||||
import meerkat.voting.gui.managment.TwoWayNode;
|
|
||||||
import meerkat.voting.gui.ui.GraphicalFX;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
|
||||||
* StraightChannelSectionController handle the behavior of select channel section screen
|
|
||||||
*/
|
|
||||||
public class StraightChannelSectionController {
|
|
||||||
|
|
||||||
private List<Integer> chanelValue;
|
|
||||||
private int pointer;
|
|
||||||
private boolean lock;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
public void answerWelcomeScreen() {
|
|
||||||
GraphicalFX.parent.answerWelcomeScreen((StartSessionUICommand) GraphicalFX.currentCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ProceedToNameSelection(MouseEvent boutonPressed) {
|
|
||||||
this.currentStage.close();
|
|
||||||
this.currentStage.setScene(this.next.GetCurrentScene());
|
|
||||||
this.next.UpdateNode();
|
|
||||||
this.currentStage.show();
|
|
||||||
this.logger.debug("Created the proceess to name selection object loader.");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
/**
|
|
||||||
* Creates the array of the canel value
|
|
||||||
*/
|
|
||||||
public void UpdateNode() {
|
|
||||||
this.pointer = 0;
|
|
||||||
this.lock = false;
|
|
||||||
|
|
||||||
// created the channel value list
|
|
||||||
// every value in the list represents one of the cells values
|
|
||||||
this.chanelValue = new ArrayList<>();
|
|
||||||
this.chanelValue.add(0);
|
|
||||||
this.chanelValue.add(0);
|
|
||||||
this.chanelValue.add(0);
|
|
||||||
this.chanelValue.add(0);
|
|
||||||
this.logger.debug("Created and filled with zeros the channel value.");
|
|
||||||
|
|
||||||
this.updateVisualChanel();
|
|
||||||
this.UpdateVotersChoise();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the channel in the voters choise
|
|
||||||
*/
|
|
||||||
private void UpdateVotersChoise(){
|
|
||||||
this.votersBallot.VoterChannel = this.chanelValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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).");
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void numberPressed(MouseEvent mousePressed){
|
|
||||||
if (!this.lock) {
|
|
||||||
String value = ((Button) mousePressed.getSource()).getId().split("_")[1];
|
|
||||||
this.chanelValue.set(this.pointer, Integer.parseInt(value));
|
|
||||||
this.pointer++;
|
|
||||||
this.updateVisualChanel();
|
|
||||||
this.UpdateVotersChoise();
|
|
||||||
if (this.pointer == 4) {
|
|
||||||
this.lock = true;
|
|
||||||
}
|
|
||||||
// this.logger.debug("The " + value +" button have been pressed, then this value was pushed to channel value.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void clearLastNumber(MouseEvent mousePressed){
|
|
||||||
if (this.pointer >= 1) {
|
|
||||||
int lastValueLocation = this.pointer - 1;
|
|
||||||
int lastValue = this.chanelValue.get(lastValueLocation);
|
|
||||||
this.chanelValue.set(lastValueLocation, 0);
|
|
||||||
this.currentStage.show();
|
|
||||||
this.pointer--;
|
|
||||||
this.updateVisualChanel();
|
|
||||||
this.UpdateVotersChoise();
|
|
||||||
this.lock = false;
|
|
||||||
// this.logger.debug("The last value was removed from channel value (the value was " + lastValue + " ).");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,39 +0,0 @@
|
||||||
package meerkat.voting.gui.ui.controllerFX;
|
|
||||||
|
|
||||||
import javafx.fxml.FXML;
|
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.input.MouseEvent;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
|
||||||
* WelcomeSplashController handle the behavior of welcome splash class
|
|
||||||
*/
|
|
||||||
public class WelcomeSplashController {
|
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(WelcomeSplashController.class);
|
|
||||||
private final String INVALID_CONFIGURATION_ERROR_TEXT = "The given configuration is invalid please run this voting booth with different configuraiton.";
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private Label ErrorPanel;
|
|
||||||
|
|
||||||
@FXML
|
|
||||||
private void StartVotingProcess(MouseEvent mousePressed) {
|
|
||||||
// this.currentStage.close();
|
|
||||||
// this.currentStage.setScene(this.next.GetCurrentScene());
|
|
||||||
// this.next.UpdateNode();
|
|
||||||
// this.currentStage.show();
|
|
||||||
// this.logger.debug("Jumping to the select channel object.");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the given string to user in ErrorLabel
|
|
||||||
* @param message is the error string to represent to the user
|
|
||||||
*/
|
|
||||||
private void RepresentErrorToVoter(String message) {
|
|
||||||
// ErrorPanel.setText(message);
|
|
||||||
// this.currentStage.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -0,0 +1,157 @@
|
||||||
|
package meerkat.voting.gui.ui.controllersFX;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
|
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.UICommand;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
||||||
|
* ChannelChoiceController handle the behavior of select channel section screen
|
||||||
|
*/
|
||||||
|
public class ChannelChoiceController {
|
||||||
|
|
||||||
|
private List<Integer> chanelValue;
|
||||||
|
private int pointer;
|
||||||
|
private boolean lock;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void answerWelcomeScreen() {
|
||||||
|
// MainFX.parent.answerWelcomeScreen((StartSessionUICommand) MainFX.currentCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextPane() {
|
||||||
|
ChannelChoiceUICommand command = (ChannelChoiceUICommand) VistaNavigator.getCurrentCommand();
|
||||||
|
System.out.println("Showing questions for choosing channel:\n");
|
||||||
|
try {
|
||||||
|
List<Voting.BallotAnswer> answers = askVoterForAnswers(command.getQuestions());
|
||||||
|
VistaNavigator.getCurrentCommand().getCallback().onSuccess(answers);
|
||||||
|
}
|
||||||
|
catch (VoterCancelThrowable e) {
|
||||||
|
VistaNavigator.getCurrentCommand().getCallback().onFailure(e);
|
||||||
|
}
|
||||||
|
catch (IOException e) {
|
||||||
|
// String errorMessage = "Channel choice failed due to IOException: " + e;
|
||||||
|
// logger.error (errorMessage);
|
||||||
|
// System.err.println(errorMessage);
|
||||||
|
VistaNavigator.getCurrentCommand().getCallback().onFailure(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
//askVoterForAnswers:
|
||||||
|
List<Voting.BallotAnswer> answers = new ArrayList<>();
|
||||||
|
int index = 0;
|
||||||
|
while (index < questions.size()) {
|
||||||
|
Voting.BallotQuestion question = questions.get(index);
|
||||||
|
System.out.println("Question number " + index);
|
||||||
|
showQuestionInConsole(question);
|
||||||
|
|
||||||
|
System.out.println("UI screen: Enter your answer. You can also type '(b)ack' or '(c)ancel' or '(s)kip");
|
||||||
|
String s = readInputLine();
|
||||||
|
|
||||||
|
if ((s.equals("cancel") || s.equals("c")) || (index == 0 && (s.equals("back") || s.equals("b")))) {
|
||||||
|
throw new VoterCancelThrowable();
|
||||||
|
}
|
||||||
|
else if (s.equals("back") || s.equals("b")) {
|
||||||
|
--index;
|
||||||
|
answers.remove(index);
|
||||||
|
}
|
||||||
|
else if (s.equals("skip") || s.equals("s")) {
|
||||||
|
answers.add(UIUtils.translateStringAnswerToProtoBufMessageAnswer(""));
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
answers.add(UIUtils.translateStringAnswerToProtoBufMessageAnswer(s));
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return answers;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ProceedToNameSelection(MouseEvent boutonPressed) {
|
||||||
|
// this.currentStage.close();
|
||||||
|
// this.currentStage.setScene(this.next.GetCurrentScene());
|
||||||
|
// this.next.UpdateNode();
|
||||||
|
// this.currentStage.show();
|
||||||
|
// this.logger.debug("Created the proceess to name selection object loader.");
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
/**
|
||||||
|
* Creates the array of the canel value
|
||||||
|
*/
|
||||||
|
public void UpdateNode() {
|
||||||
|
this.pointer = 0;
|
||||||
|
this.lock = false;
|
||||||
|
|
||||||
|
// created the channel value list
|
||||||
|
// every value in the list represents one of the cells values
|
||||||
|
this.chanelValue = new ArrayList<>();
|
||||||
|
this.chanelValue.add(0);
|
||||||
|
this.chanelValue.add(0);
|
||||||
|
this.chanelValue.add(0);
|
||||||
|
this.chanelValue.add(0);
|
||||||
|
// this.logger.debug("Created and filled with zeros the channel value.");
|
||||||
|
|
||||||
|
this.updateVisualChanel();
|
||||||
|
// this.UpdateVotersChoise();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the channel in the voters choise
|
||||||
|
*/
|
||||||
|
// private void UpdateVotersChoise(){
|
||||||
|
// this.votersBallot.VoterChannel = this.chanelValue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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).");
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void numberPressed(MouseEvent mousePressed){
|
||||||
|
if (!this.lock) {
|
||||||
|
String value = ((Button) mousePressed.getSource()).getId().split("_")[1];
|
||||||
|
this.chanelValue.set(this.pointer, Integer.parseInt(value));
|
||||||
|
this.pointer++;
|
||||||
|
this.updateVisualChanel();
|
||||||
|
// this.UpdateVotersChoise();
|
||||||
|
if (this.pointer == 4) {
|
||||||
|
this.lock = true;
|
||||||
|
}
|
||||||
|
// this.logger.debug("The " + value +" button have been pressed, then this value was pushed to channel value.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void clearLastNumber(MouseEvent mousePressed){
|
||||||
|
if (this.pointer >= 1) {
|
||||||
|
int lastValueLocation = this.pointer - 1;
|
||||||
|
int lastValue = this.chanelValue.get(lastValueLocation);
|
||||||
|
this.chanelValue.set(lastValueLocation, 0);
|
||||||
|
// this.currentStage.show();
|
||||||
|
this.pointer--;
|
||||||
|
this.updateVisualChanel();
|
||||||
|
// this.UpdateVotersChoise();
|
||||||
|
this.lock = false;
|
||||||
|
// this.logger.debug("The last value was removed from channel value (the value was " + lastValue + " ).");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
package meerkat.voting.gui.ui.controllersFX;
|
||||||
|
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import meerkat.voting.gui.ui.uicommands.StartSessionUICommand;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
|
||||||
|
* StartSessionController handle the behavior of welcome splash class
|
||||||
|
*/
|
||||||
|
public class StartSessionController {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event handler fired when the user requests a new vista.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
|
// void nextPane() {
|
||||||
|
// VistaNavigator.loadVista(VistaNavigator.VISTA_2);
|
||||||
|
// }
|
||||||
|
|
||||||
|
void nextPane() {
|
||||||
|
VistaNavigator.loadVista(VistaNavigator.LOADING);
|
||||||
|
VistaNavigator.uiThread.answerWelcomeScreen((StartSessionUICommand) VistaNavigator.getCurrentCommand());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package meerkat.voting.gui.ui.controllersFX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Laura on 12/16/2016.
|
||||||
|
*/
|
||||||
|
import javafx.event.ActionEvent;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controller class for the second vista.
|
||||||
|
*/
|
||||||
|
public class Vista2Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event handler fired when the user requests a previous vista.
|
||||||
|
*
|
||||||
|
* @param event the event that triggered the handler.
|
||||||
|
*/
|
||||||
|
@FXML
|
||||||
|
void previousPane(ActionEvent event) {
|
||||||
|
VistaNavigator.loadVista(VistaNavigator.VISTA_1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,100 @@
|
||||||
|
package meerkat.voting.gui.ui.controllersFX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Laura on 12/16/2016.
|
||||||
|
*/
|
||||||
|
import javafx.fxml.FXMLLoader;
|
||||||
|
import meerkat.voting.gui.ui.GraphicalUI;
|
||||||
|
import meerkat.voting.gui.ui.uicommands.UICommand;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility class for controlling navigation between vistas.
|
||||||
|
*
|
||||||
|
* All methods on the navigator are static to facilitate
|
||||||
|
* simple access from anywhere in the application.
|
||||||
|
*/
|
||||||
|
public class VistaNavigator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience constants for fxml layouts managed by the navigator.
|
||||||
|
*/
|
||||||
|
public static final String MAIN = "/views/main.fxml";
|
||||||
|
public static final String LOADING = "/views/loading.fxml";
|
||||||
|
public static final String VISTA_1 = "/views/starting_session.fxml";
|
||||||
|
public static final String VISTA_2 = "/views/vista2.fxml";
|
||||||
|
public static final String CHANNEL_CHOICE = "/views/channel_choice.fxml";
|
||||||
|
|
||||||
|
/** The main application layout controller. */
|
||||||
|
private static MainController mainController;
|
||||||
|
public static GraphicalUI uiThread;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the main controller for later use in navigation tasks.
|
||||||
|
*
|
||||||
|
* @param mainController the main application layout controller.
|
||||||
|
*/
|
||||||
|
public static void setMainController(MainController mainController) {
|
||||||
|
VistaNavigator.mainController = mainController;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static MainController getMainController() {
|
||||||
|
return VistaNavigator.mainController;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the thread that controls the UI.
|
||||||
|
*
|
||||||
|
* @param ui the thread that launched the fx application.
|
||||||
|
*/
|
||||||
|
public static void setUIThread(GraphicalUI ui) {
|
||||||
|
VistaNavigator.uiThread = ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stores the command that is requested to be executed.
|
||||||
|
*
|
||||||
|
* @param command the command that needs to be executed.
|
||||||
|
*/
|
||||||
|
public static void setCurrentCommand(UICommand command) {
|
||||||
|
VistaNavigator.mainController.setCurrentCommand(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the command that is requested to be executed.
|
||||||
|
*/
|
||||||
|
public static UICommand getCurrentCommand() {
|
||||||
|
return VistaNavigator.mainController.getCurrentCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the vista specified by the fxml file into the
|
||||||
|
* vistaHolder pane of the main application layout.
|
||||||
|
*
|
||||||
|
* Previously loaded vista for the same fxml file are not cached.
|
||||||
|
* The fxml is loaded anew and a new vista node hierarchy generated
|
||||||
|
* every time this method is invoked.
|
||||||
|
*
|
||||||
|
* A more sophisticated load function could potentially add some
|
||||||
|
* enhancements or optimizations, for example:
|
||||||
|
* cache FXMLLoaders
|
||||||
|
* cache loaded vista nodes, so they can be recalled or reused
|
||||||
|
* allow a user to specify vista node reuse or new creation
|
||||||
|
* allow back and forward history like a browser
|
||||||
|
*
|
||||||
|
* @param fxml the fxml file to be loaded.
|
||||||
|
*/
|
||||||
|
public static void loadVista(String fxml) {
|
||||||
|
try {
|
||||||
|
mainController.setVista(
|
||||||
|
FXMLLoader.load(VistaNavigator.class.getResource(fxml)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<GridPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="meerkat.voting.gui.ui.GraphicalFX">
|
<GridPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="meerkat.voting.gui.ui.MainFX">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
</columnConstraints>
|
</columnConstraints>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.layout.StackPane?>
|
||||||
|
<?import javafx.scene.text.Text?>
|
||||||
|
|
||||||
|
|
||||||
|
<StackPane 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">
|
||||||
|
<children>
|
||||||
|
<Text strokeType="OUTSIDE" strokeWidth="0.0" text="Loading..." />
|
||||||
|
</children>
|
||||||
|
</StackPane>
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?scenebuilder-stylesheet vista.css?>
|
||||||
|
|
||||||
|
<VBox prefHeight="200.0" prefWidth="300.0" xmlns:fx="http://javafx.com/fxml" fx:controller="meerkat.voting.gui.ui.controllersFX.MainController">
|
||||||
|
<children>
|
||||||
|
<Label fx:id="headerLabel" maxWidth="1.7976931348623157E308" text="Header" VBox.vgrow="NEVER" />
|
||||||
|
<StackPane fx:id="vistaHolder" VBox.vgrow="ALWAYS" />
|
||||||
|
</children>
|
||||||
|
</VBox>
|
|
@ -5,7 +5,7 @@
|
||||||
<?import java.lang.*?>
|
<?import java.lang.*?>
|
||||||
<?import javafx.scene.layout.*?>
|
<?import javafx.scene.layout.*?>
|
||||||
|
|
||||||
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="meerkat.voting.gui.ui.GraphicalFX">
|
<GridPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="meerkat.voting.gui.ui.controllersFX.StartSessionController">
|
||||||
<columnConstraints>
|
<columnConstraints>
|
||||||
<ColumnConstraints />
|
<ColumnConstraints />
|
||||||
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
|
||||||
|
@ -61,7 +61,7 @@
|
||||||
<children>
|
<children>
|
||||||
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
|
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
|
||||||
<center>
|
<center>
|
||||||
<Button mnemonicParsing="false" onMousePressed="#answerWelcomeScreen" prefHeight="50.0" prefWidth="170.0" text="Start Here" BorderPane.alignment="CENTER">
|
<Button mnemonicParsing="false" onMousePressed="#nextPane" prefHeight="50.0" prefWidth="170.0" text="Start Here" BorderPane.alignment="CENTER">
|
||||||
<font>
|
<font>
|
||||||
<Font size="24.0" />
|
<Font size="24.0" />
|
||||||
</font>
|
</font>
|
|
@ -0,0 +1,28 @@
|
||||||
|
/**
|
||||||
|
* vista.css
|
||||||
|
* Place in the same source directory as Main.java
|
||||||
|
* Ensure that your build system copies this file to your build output directory.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#headerLabel {
|
||||||
|
-fx-background-color: steelblue;
|
||||||
|
-fx-text-fill: white;
|
||||||
|
-fx-padding: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#vistaHolder {
|
||||||
|
-fx-background-color: lightgrey;
|
||||||
|
}
|
||||||
|
|
||||||
|
#vista1 {
|
||||||
|
-fx-background-color: aliceblue;
|
||||||
|
}
|
||||||
|
|
||||||
|
#vista2 {
|
||||||
|
-fx-background-color: coral;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button {
|
||||||
|
-fx-base: lightblue;
|
||||||
|
-fx-font-size: 20px;
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.*?>
|
||||||
|
<?import javafx.scene.layout.*?>
|
||||||
|
<?scenebuilder-stylesheet vista.css?>
|
||||||
|
|
||||||
|
<StackPane fx:id="vista1" xmlns:fx="http://javafx.com/fxml" fx:controller="meerkat.voting.gui.ui.controllersFX.Vista1Controller">
|
||||||
|
<children>
|
||||||
|
<Button mnemonicParsing="false" onAction="#nextPane" text="Next Pane" />
|
||||||
|
</children>
|
||||||
|
</StackPane>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?scenebuilder-stylesheet vista.css?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.layout.StackPane?>
|
||||||
|
<StackPane fx:id="vista2" xmlns:fx="http://javafx.com/fxml" fx:controller="meerkat.voting.gui.ui.controllersFX.Vista2Controller">
|
||||||
|
<children>
|
||||||
|
<Button mnemonicParsing="false" onAction="#previousPane" text="Previous Pane" />
|
||||||
|
</children>
|
||||||
|
</StackPane>
|
Loading…
Reference in New Issue