diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalFX.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalFX.java index 06a2dec..36fb88b 100644 --- a/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalFX.java +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalFX.java @@ -5,12 +5,11 @@ package meerkat.voting.gui.ui; */ import javafx.application.Application; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; import javafx.scene.Scene; -import javafx.scene.control.Button; 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; @@ -23,6 +22,8 @@ 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) { @@ -39,42 +40,75 @@ public class GraphicalFX extends Application { // 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() { +// +// @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) { - primaryStage.setTitle("Hello World!"); - Button btn = new Button(); - btn.setText("Say 'Hello World'"); - btn.setOnAction(new EventHandler() { + this.activeStage=primaryStage; - @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); - -// System.out.println("Working Directory = " + -// System.getProperty("user.dir")); -// Parent root = null; -// try { -// File dir1 = new File ("."); -// System.out.println ("Current dir : " + dir1.getCanonicalPath()); -// root = FXMLLoader.load(getClass().getClassLoader().getResource("/graphical_fxml/welcome_splash_screen.fxml")); -// } catch (IOException e) { -// e.printStackTrace(); -// System.out.println("Working Directory = " + -// System.getProperty("user.dir")); -// } -// +// Parent root = new StackPane(); // Scene scene = new Scene(root, 300, 275); +// primaryStage.setScene(scene); +// primaryStage.show(); - 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(); + } + } diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalUI.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalUI.java index 36ff127..8350c24 100644 --- a/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalUI.java +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/GraphicalUI.java @@ -60,15 +60,26 @@ public class GraphicalUI implements VotingBoothUI, Runnable { @Override public void run () { logger.info("UI starts running"); + // Application.launch(GraphicalFX.class); + new Thread() { + @Override + public void run() { + Application.launch(GraphicalFX.class); + } + }.start(); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } while (! wasShutDownCalled()) { - Application.launch(GraphicalFX.class); -// try { -// UICommand command = cmdPend.take(); -// handleSingleCommand(command); -// } -// catch (InterruptedException e) { -// logger.warn ("Interrupted while reading the pending command " + e); -// } + try { + UICommand command = cmdPend.take(); + handleSingleCommand(command); + } + catch (InterruptedException e) { + logger.warn ("Interrupted while reading the pending command " + e); + } } } @@ -146,8 +157,13 @@ public class GraphicalUI implements VotingBoothUI, Runnable { */ private void doShowWelcomeScreen(StartSessionUICommand command) { logger.debug("UI entered doShowWelcomeScreen"); - System.out.println("Welcome, new voter!"); - waitForEnter(null); + this.ui.showWelcomeScreen(command); +// waitForEnter(null); +// ControllerCallback callback = command.getCallback(); +// callback.onSuccess(null); + } + + protected void answerWelcomeScreen(StartSessionUICommand command) { ControllerCallback callback = command.getCallback(); callback.onSuccess(null); } diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/StraightChannelSectionController.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/StraightChannelSectionController.java new file mode 100644 index 0000000..425be45 --- /dev/null +++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllerFX/StraightChannelSectionController.java @@ -0,0 +1,109 @@ +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 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 + " )."); + } + } + + +} diff --git a/voting-booth/src/main/resources/graphical_fxml/straight_channel_section.fxml b/voting-booth/src/main/resources/graphical_fxml/straight_channel_section.fxml new file mode 100644 index 0000000..01f0781 --- /dev/null +++ b/voting-booth/src/main/resources/graphical_fxml/straight_channel_section.fxml @@ -0,0 +1,322 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + +
+
+ + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +
+
+ +
+ + + + + +
+
+ +
+ + + + + +
+
+ +
+ + + + + +
+
+
+
+ + + + + + + + + + + + +
+ +
+
+ + +
+ +
+
+ +
+ +
+
+ +
+
+ + + + + + + + + + + + +
+ +
+
+ +
+ +
+
+ +
+ +
+
+ +
+ +
+
+
+
+ + + + + + + + + + + + +
+ +
+
+ + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + + + + + + + + + + +
+ +
+
+
+
+
+
diff --git a/voting-booth/src/main/resources/graphical_fxml/welcome_splash_screen.fxml b/voting-booth/src/main/resources/graphical_fxml/welcome_splash_screen.fxml index aa9140e..67dbad7 100644 --- a/voting-booth/src/main/resources/graphical_fxml/welcome_splash_screen.fxml +++ b/voting-booth/src/main/resources/graphical_fxml/welcome_splash_screen.fxml @@ -5,7 +5,7 @@ - + @@ -61,7 +61,7 @@
-