The summiting of the voters selections working

android-scanner
VladimirEliTokarev 2016-10-05 15:37:53 +03:00
parent 8e2fdb7828
commit ef5cd70cc9
3 changed files with 169 additions and 127 deletions

View File

@ -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
}
}
}

View File

@ -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<Integer> 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;
}
}

View File

@ -81,8 +81,8 @@
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="156.0" minHeight="10.0" prefHeight="109.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="225.0" minHeight="10.0" prefHeight="212.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="156.0" minHeight="10.0" prefHeight="51.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="285.0" minHeight="10.0" prefHeight="270.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<GridPane>
@ -114,15 +114,15 @@
</BorderPane>
</children>
</GridPane>
<GridPane GridPane.rowIndex="1">
<GridPane prefHeight="241.0" prefWidth="600.0" GridPane.rowIndex="1">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="144.0" minWidth="10.0" prefWidth="37.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="529.0" minWidth="10.0" prefWidth="519.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="195.0" minWidth="0.0" prefWidth="37.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="66.0" minHeight="0.0" prefHeight="15.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="184.0" minHeight="10.0" prefHeight="176.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="66.0" minHeight="0.0" prefHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="227.0" minHeight="10.0" prefHeight="227.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="43.0" minHeight="8.0" prefHeight="15.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
@ -133,140 +133,34 @@
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints maxHeight="53.0" minHeight="10.0" prefHeight="33.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="145.0" minHeight="10.0" prefHeight="145.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="53.0" minHeight="0.0" prefHeight="0.0" vgrow="SOMETIMES" />
<RowConstraints maxHeight="198.0" minHeight="10.0" prefHeight="198.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<GridPane>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<center>
<Label text="Name of contest" BorderPane.alignment="CENTER">
<font>
<Font size="16.0" />
</font>
</Label>
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
<center>
<Label text="Your selection" BorderPane.alignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
</center>
</BorderPane>
</children>
</GridPane>
<ScrollPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
<ScrollPane prefHeight="300.0" prefWidth="507.0" GridPane.rowIndex="1">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="299.0" prefWidth="507.0">
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="200.0" prefWidth="500.0">
<children>
<GridPane prefHeight="300.0" prefWidth="510.0">
<GridPane fx:id="VotersChoices" prefHeight="200.0" prefWidth="500.0">
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<center>
<Label text="Name of contest" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
<center>
<Label text="Name of contest" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2">
<center>
<Label text="Name of contest" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<right>
<BorderPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
</right>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="3">
<center>
<Label text="Name of contest" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="4">
<center>
<Label text="Name of contest" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="5">
<center>
<Label text="Name of contest" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="6">
<center>
<Label text="Name of contest" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" />
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
<center>
<Label text="Candidate Name" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
<center>
<Label text="Candidate Name" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="2">
<center>
<Label text="Candidate Name" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="3">
<center>
<Label text="Candidate Name" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="4">
<center>
<Label text="Candidate Name" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="5">
<center>
<Label text="Candidate Name" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="6">
<center>
<Label text="Candidate Name" BorderPane.alignment="CENTER" />
</center>
</BorderPane>
</children>
</GridPane>
</children>
</AnchorPane>
</children></AnchorPane>
</content>
</ScrollPane>
<BorderPane prefHeight="75.0" prefWidth="521.0">
<center>
<Label text="Your selection" BorderPane.alignment="CENTER">
<font>
<Font size="18.0" />
</font>
</Label>
</center>
</BorderPane>
</children>
</GridPane>
</center>