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

View File

@ -37,6 +37,19 @@ public class VotingBoothGUIManager extends Application implements VotingBoothUI
this.currentStage.show(); 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) * 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 * @param args array of strings to pass to the start method as argument
@ -99,7 +112,15 @@ public class VotingBoothGUIManager extends Application implements VotingBoothUI
@Override @Override
public void askVoterQuestions(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) { public void askVoterQuestions(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) {
logger.debug("Graphical user interface call to chooseChannel"); 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 * call for the channel choice phase by registering a ChannelChoiceUICommand in the queue
@ -109,6 +130,7 @@ public class VotingBoothGUIManager extends Application implements VotingBoothUI
@Override @Override
public void chooseChannel(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) { public void chooseChannel(List<Voting.BallotQuestion> questions, FutureCallback<List<Voting.BallotAnswer>> callback) {
logger.debug("Graphical user interface call to chooseChannel"); 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"); logger.debug("Graphical user interface call to startNewVoterSession");
try { try {
this.doStartNewSession(this.currentStage); this.doStartNewSession(this.currentStage);
callback.onSuccess(null);
} catch (IOException e) { } catch (IOException e) {
logger.error(String.format("Couldn't start new session of the voting process :", 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; package main.select_candidate_by_picture;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.input.MouseEvent; 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 main.TwoWayNode;
import meerkat.protobuf.Voting;
import java.awt.*;
import java.util.List;
/** /**
* Created by Vladimir Eliezer Tokarev on 8/27/2016. * Created by Vladimir Eliezer Tokarev on 8/27/2016.
* SelectCandidateNameController handle the behavior of select by picture screen * SelectCandidateNameController handle the behavior of select by picture screen
*/ */
public class SelectCandidateByPictureController extends TwoWayNode { 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 @FXML
private void GetToSelectByName(MouseEvent mousePressed){ private void GetToSelectByName(MouseEvent mousePressed){

View File

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