Added the ability to submit questions and answers

android-scanner
Vladimir Eliezer Tokarev 2016-09-24 19:08:24 +03:00
parent f1704ce16e
commit 37be8f3a52
7 changed files with 113 additions and 29 deletions

View File

@ -146,7 +146,16 @@
<RowConstraints maxHeight="76.0" minHeight="10.0" prefHeight="32.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<BorderPane fx:id="picture_0" prefHeight="200.0" prefWidth="200.0" onMousePressed="#submitTheSelection">
<center>
<ImageView BorderPane.alignment="CENTER">
<image>
<Image url="@../pics/profile.png" />
</image>
</ImageView>
</center>
</BorderPane>
<BorderPane fx:id="picture_1" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" onMousePressed="#submitTheSelection">
<center>
<ImageView BorderPane.alignment="CENTER">
<image>
@ -155,16 +164,7 @@
</ImageView>
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
<center>
<ImageView BorderPane.alignment="CENTER">
<image>
<Image url="@../pics/profile.png" />
</image>
</ImageView>
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2">
<BorderPane fx:id="picture_2" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" onMousePressed="#submitTheSelection">
<center>
<ImageView BorderPane.alignment="CENTER">
<image>
@ -175,7 +175,7 @@
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
<top>
<Label text="Name" BorderPane.alignment="CENTER">
<Label fx:id="name0" text="Name" BorderPane.alignment="CENTER" >
<font>
<Font size="15.0" />
</font>
@ -184,7 +184,7 @@
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
<top>
<Label text="Name" BorderPane.alignment="CENTER">
<Label fx:id="name1" text="Name" BorderPane.alignment="CENTER">
<font>
<Font size="15.0" />
</font>
@ -193,7 +193,7 @@
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="1">
<top>
<Label text="Name" BorderPane.alignment="CENTER">
<Label fx:id="name2" text="Name" BorderPane.alignment="CENTER">
<font>
<Font size="15.0" />
</font>

View File

@ -16,7 +16,7 @@ public class Main extends Application {
ChainBuilder.Build(primaryStage);
primaryStage.setTitle("Meerkat Polling Station");
primaryStage.show();
}
}
public static void main(String[] args) throws InterruptedException {
launch(args);

View File

@ -37,6 +37,19 @@ public class VotingBoothGUIManager extends Application implements VotingBoothUI
this.currentStage.show();
}
/**
* Communicates with the select * panels and passes to them the questions to ask the voter
* @param questions list of voting ballot questions (such as choose the racing candidate picture)
* @param callback is a call back to method that handles users answers
* @return List of voting ballot answers
*/
private void askVoterForAnswers(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback)
{
}
/**
* Method that activates the application and passes to start the primary stage (can be called outside this class)
* @param args array of strings to pass to the start method as argument
@ -99,8 +112,16 @@ public class VotingBoothGUIManager extends Application implements VotingBoothUI
@Override
public void askVoterQuestions(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) {
logger.debug("Graphical user interface call to chooseChannel");
try {
askVoterForAnswers(questions, callback);
}
catch (Error e) {
logger.debug(String.format("Couldn't ask voter questions: ", e));
callback.onFailure(e);
}
}
/**
* 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
@ -109,6 +130,7 @@ public class VotingBoothGUIManager extends Application implements VotingBoothUI
@Override
public void chooseChannel(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) {
logger.debug("Graphical user interface call to chooseChannel");
}
/**
@ -120,8 +142,10 @@ public class VotingBoothGUIManager extends Application implements VotingBoothUI
logger.debug("Graphical user interface call to startNewVoterSession");
try {
this.doStartNewSession(this.currentStage);
callback.onSuccess(null);
} catch (IOException e) {
logger.error(String.format("Couldn't start new session of the voting process :", e));
callback.onFailure(e);
}
}

View File

@ -1,14 +1,74 @@
package main.select_candidate_by_picture;
import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.CornerRadii;
import javafx.scene.paint.Color;
import main.TwoWayNode;
import meerkat.protobuf.Voting;
import java.awt.*;
import java.util.List;
/**
* Created by Vladimir Eliezer Tokarev on 8/27/2016.
* SelectCandidateNameController handle the behavior of select by picture screen
*/
public class SelectCandidateByPictureController extends TwoWayNode {
private List<Voting.BallotQuestion> questions;
private List<Voting.BallotAnswer> answers;
private int QuestionId:
public void SetQuestions(List<Voting.BallotQuestion> questions) throws InterruptedException {
this.questions = questions;
this.GetAnswers();
}
public List<Voting.BallotAnswer> GetAnswers() throws InterruptedException {
return null;
}
@FXML
private void submitTheSelection(MouseEvent mousePressed){
BorderPane b = (BorderPane) mousePressed.getSource();
int id = Integer.parseInt(b.getId().split("_")[1]);
unColorAllOthers(id);
b.setBackground(new Background(new BackgroundFill(Color.RED, CornerRadii.EMPTY, Insets.EMPTY)));
}
private List<Voting.BallotAnswer> getAnswers(String id){
String name = getCandidateName(id);
}
/**
* Gets the name of the candidate
* @param id
* @return
*/
private String getCandidateName(String id){
return ((Label)this.currentStage.getScene().lookup("#name"+id)).getText();
}
/**
* Uncolors all the not selected picttures of candidates
* @param id the id of the selected candidate
*/
private void unColorAllOthers(int id){
for (int i = 0 ; i < 3 ; i++ ){
BorderPane b = (BorderPane)currentStage.getScene().lookup("#picture_"+i);
if (i != id) {
b.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
}
}
}
@FXML
private void GetToSelectByName(MouseEvent mousePressed){

View File

@ -146,7 +146,16 @@
<RowConstraints maxHeight="76.0" minHeight="10.0" prefHeight="32.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<BorderPane prefHeight="200.0" prefWidth="200.0">
<BorderPane fx:id="picture_0" prefHeight="200.0" prefWidth="200.0" onMousePressed="#submitTheSelection">
<center>
<ImageView BorderPane.alignment="CENTER">
<image>
<Image url="@../pics/profile.png" />
</image>
</ImageView>
</center>
</BorderPane>
<BorderPane fx:id="picture_1" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" onMousePressed="#submitTheSelection">
<center>
<ImageView BorderPane.alignment="CENTER">
<image>
@ -155,16 +164,7 @@
</ImageView>
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1">
<center>
<ImageView BorderPane.alignment="CENTER">
<image>
<Image url="@../pics/profile.png" />
</image>
</ImageView>
</center>
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2">
<BorderPane fx:id="picture_2" prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" onMousePressed="#submitTheSelection">
<center>
<ImageView BorderPane.alignment="CENTER">
<image>
@ -175,7 +175,7 @@
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1">
<top>
<Label text="Name" BorderPane.alignment="CENTER">
<Label fx:id="name0" text="Name" BorderPane.alignment="CENTER" >
<font>
<Font size="15.0" />
</font>
@ -184,7 +184,7 @@
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="1">
<top>
<Label text="Name" BorderPane.alignment="CENTER">
<Label fx:id="name1" text="Name" BorderPane.alignment="CENTER">
<font>
<Font size="15.0" />
</font>
@ -193,7 +193,7 @@
</BorderPane>
<BorderPane prefHeight="200.0" prefWidth="200.0" GridPane.columnIndex="2" GridPane.rowIndex="1">
<top>
<Label text="Name" BorderPane.alignment="CENTER">
<Label fx:id="name2" text="Name" BorderPane.alignment="CENTER">
<font>
<Font size="15.0" />
</font>