diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/ballot_summary/BallotSummaryController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/ballot_summary/BallotSummaryController.java index ebe0034..675be3d 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/ballot_summary/BallotSummaryController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/ballot_summary/BallotSummaryController.java @@ -4,6 +4,8 @@ import javafx.fxml.FXML; import javafx.scene.input.MouseEvent; import meerkat.voting.gui.managment.TwoWayNode; +import java.io.IOException; + /** * Created by Vladimir Eliezer Tokarev on 8/27/2016. * BallotSummaryController handle the behavior of ballot summary screen @@ -25,8 +27,21 @@ public class BallotSummaryController extends TwoWayNode { this.currentStage.show(); } + /** + * This method activates the representor of all the voters choises + */ + private void ShowAllVotersChoices() throws IOException { + VotersChoicesAdder votersChoicesAdder = new VotersChoicesAdder(this.currentStage, this.votersBallot); + votersChoicesAdder.ShowVotersChoices(); + } + @Override public void UpdateNode() { - // Nothing relevant to do + try { + this.ShowAllVotersChoices(); + } catch (IOException e) { + e.printStackTrace(); + // TODO: log about it + } } } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/ballot_summary/VotersChoicesAdder.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/ballot_summary/VotersChoicesAdder.java new file mode 100644 index 0000000..5916f00 --- /dev/null +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/panels/ballot_summary/VotersChoicesAdder.java @@ -0,0 +1,133 @@ +package meerkat.voting.gui.panels.ballot_summary; + +import com.google.protobuf.ByteString; +import javafx.embed.swing.SwingFXUtils; +import javafx.scene.Node; +import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.BorderPane; +import javafx.scene.layout.GridPane; +import javafx.stage.Stage; +import meerkat.voting.gui.managment.VotersBallot; + +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.List; + +/** + * Created by Vladimir Eliezer Tokarev on 10/5/2016. + * This object add all the information inputed by the voter and displays it in the right section + */ +public class VotersChoicesAdder { + private Stage currentStage; + private int rowIndex; + private VotersBallot votersBallot; + + VotersChoicesAdder(Stage primaryStage, VotersBallot votersBallot) { + this.currentStage = primaryStage; + this.rowIndex = 0; + this.votersBallot = votersBallot; + + // The lookup works only after the css have been randered + this.currentStage.getScene().getRoot().applyCss(); + } + + /** + * Adds all of the voters choises to the right panel + */ + public void ShowVotersChoices() throws IOException { + this.RemoveAllAnswers(); + this.addAnswer(this.getChannelChoice(this.votersBallot.Votershannel)); + this.addAnswer(this.getNameChoice(this.votersBallot.VotersNameSelection)); + this.addAnswer(this.getImageChoice(this.votersBallot.VotersImageSelection)); + Label error = new Label(); + error.setPrefSize(250,30); + this.addAnswer(error); + } + + /** + * Remove all previous binaryDatas from the container + */ + private void RemoveAllAnswers() { + this.GetAnswersContainer().getChildren().removeAll(); + } + + /** + * Gets the container of all the answers + * + * @return GridPane object + */ + private GridPane GetAnswersContainer() { + return (GridPane) this.currentStage.getScene().lookup("#VotersChoices"); + } + + /** + * Adds the GridPane binaryData to the panel + * + */ + private void addAnswer(Node node) throws IOException { + GridPane container = this.GetAnswersContainer(); + //container.addRow(this.rowIndex); + this.rowIndex++; + BorderPane borderPane = new BorderPane(); + borderPane.setCenter(node); + + container.add(borderPane, 0, this.rowIndex); + this.currentStage.show(); + } + + /** + * Creates binaryData element which is grid pane with the binaryData and check box + * + * @param binaryData string binaryData to show to the voter + * @return ImageView which contains the answer image + */ + private ImageView getImageChoice(ByteString binaryData) throws IOException { + ImageView imageView = new ImageView(); + if (binaryData != null) { + BufferedImage bufferedImage = ImageIO.read(binaryData.newInput()); + Image image = SwingFXUtils.toFXImage(bufferedImage, null); + + imageView = new ImageView(); + imageView.setImage(image); + + } + return imageView; + } + + /** + * Create label with the chanel inside + * @param chanel the chanel the coter selected + * @return BorderPane + */ + private BorderPane getChannelChoice(List chanel){ + BorderPane borderPane = new BorderPane(); + if (chanel != null) { + Label label = new Label(); + label.setText("Your chanel: " + chanel.get(0) + "" + chanel.get(1) + "" + chanel.get(2) + "" + chanel.get(3)); + label.setPrefSize(250, 30); + borderPane.setCenter(label); + borderPane.setPrefSize(250, 30); + } + return borderPane; + } + + /** + * Create grid pane element that contains the name of the answer + * @param name the name of the candidate the voter selected + * @return GridPane object + */ + private BorderPane getNameChoice(String name){ + BorderPane borderPane = new BorderPane(); + if (name != null ) { + Label label = new Label(); + label.setText("Your candidate name: " + name); + label.setPrefSize(250, 30); + borderPane.setCenter(label); + borderPane.setPrefSize(250,30); + } + return borderPane; + } +} diff --git a/voting-booth-gui/src/main/resources/view/ballot_summary.fxml b/voting-booth-gui/src/main/resources/view/ballot_summary.fxml index 82d804e..9963a7e 100644 --- a/voting-booth-gui/src/main/resources/view/ballot_summary.fxml +++ b/voting-booth-gui/src/main/resources/view/ballot_summary.fxml @@ -81,8 +81,8 @@ - - + + @@ -114,15 +114,15 @@ - + - - + + @@ -133,140 +133,34 @@ - - + + - - - - - - - - - - -
- -
-
- -
- -
-
-
-
- + - + - + - - - - - - - - - -
-
-
- -
-
-
- -
-
-
- - - - - - -
-
-
- -
-
-
- -
-
-
- -
-
-
- - -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
- -
-
-
-
-
-
+
+ +
+ +
+