Created Succesefully whole config object

android-scanner
VladimirEliTokarev 2016-10-02 22:26:38 +03:00
parent ef1ff8dea1
commit fe5a4d7be1
2 changed files with 48 additions and 21 deletions

View File

@ -23,7 +23,7 @@ message Question {
// Message object which contains the question and its type // Message object which contains the question and its type
message UIQuestion{ message UIQuestion{
int32 Type = 1; int32 QuestionType = 1;
Question question = 2; Question question = 2;
} }

View File

@ -1,7 +1,16 @@
package meerkat.voting.gui; package meerkat.voting.gui;
import com.google.protobuf.ByteString;
import javafx.application.Application; import javafx.application.Application;
import javafx.stage.Stage; import javafx.stage.Stage;
import meerkat.protobuf.BallotQuestionUIElementOuterClass;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import java.awt.image.WritableRaster;
import java.io.File;
import java.io.IOException;
/** /**
@ -10,46 +19,64 @@ import javafx.stage.Stage;
* Main calls to ChainBuilder which initilizes all the TwoWayNode's * Main calls to ChainBuilder which initilizes all the TwoWayNode's
*/ */
public class Main extends Application { public class Main extends Application {
public VotingBoothConfiguration GetConfig(){
/** VotingBoothConfiguration config = new VotingBoothConfiguration(); /**
* Converts the image from given path to bytes array
* @param filepath the path to the wanted picture
* @return byte array of the image
* @throws IOException
*/
private byte[] GetData(String filepath) throws IOException {
File imgPath = new File(filepath);
BufferedImage bufferedImage = ImageIO.read(imgPath);
WritableRaster raster = bufferedImage .getRaster();
DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
return ( data.getData() );
}
/**
* Creates configuration for example
* @return VotingBoothConfiguration object
* @throws IOException
*/
private VotingBoothConfiguration GetConfig() throws IOException {
VotingBoothConfiguration config = new VotingBoothConfiguration();
config.NameSelectionQuestion = BallotQuestionUIElementOuterClass.BallotQuestionUIElement.newBuilder() config.NameSelectionQuestion = BallotQuestionUIElementOuterClass.BallotQuestionUIElement.newBuilder()
.setQuestion(BallotQuestionUIElementOuterClass.UIQuestion.newBuilder() .setQuestion(BallotQuestionUIElementOuterClass.UIQuestion.newBuilder()
.setType(0) .setQuestionType(0)
.setQuestion(BallotQuestionUIElementOuterClass.Question.newBuilder() .setQuestion(BallotQuestionUIElementOuterClass.Question.newBuilder()
.setQuestion(ByteString.copyFromUtf8("Who you vote for?")) .setQuestion(ByteString.copyFromUtf8("Who you vote for?"))))
.setType(0))
.setAnswers(BallotQuestionUIElementOuterClass.UIAnswers.newBuilder() .setAnswers(BallotQuestionUIElementOuterClass.UIAnswers.newBuilder()
.setAnswersType(0) .setAnswersType(0)
.setAnswers(BallotQuestionUIElementOuterClass.ListOfAnswers.newBuilder() .setAnswers(BallotQuestionUIElementOuterClass.ListOfAnswers.newBuilder()
.setAnswers(0, ByteString.copyFromUtf8("George Boosh")) .addAnswers(ByteString.copyFromUtf8("George Boosh"))
.setAnswers(1, ByteString.copyFromUtf8("Antonio Banderas")) .addAnswers(ByteString.copyFromUtf8("Antonio Banderas"))
.setAnswers(2, ByteString.copyFromUtf8("Michal Jakson")))) .addAnswers(ByteString.copyFromUtf8("Michal Jakson"))))
.setRandomizeListOrder(true).build(); .setRandomizeListOrder(true).build();
config.NameSelectionByPictureQuestion = BallotQuestionUIElementOuterClass.BallotQuestionUIElement.newBuilder() config.NameSelectionByPictureQuestion = BallotQuestionUIElementOuterClass.BallotQuestionUIElement.newBuilder()
.setQuestion(BallotQuestionUIElementOuterClass.UIQuestion.newBuilder() .setQuestion(BallotQuestionUIElementOuterClass.UIQuestion.newBuilder()
.setType(2) .setQuestionType(0)
.setQuestion(BallotQuestionUIElementOuterClass.Question.newBuilder() .setQuestion(BallotQuestionUIElementOuterClass.Question.newBuilder()
.mergeFrom() .setQuestion(ByteString.copyFromUtf8("Who you vote for?"))))
.setAnswers(BallotQuestionUIElementOuterClass.UIAnswers.newBuilder() .setAnswers(BallotQuestionUIElementOuterClass.UIAnswers.newBuilder()
.setAnswersType(0) .setAnswersType(2)
.setAnswers(BallotQuestionUIElementOuterClass.ListOfAnswers.newBuilder() .setAnswers(BallotQuestionUIElementOuterClass.ListOfAnswers.newBuilder()
.setAnswers(0, ByteString.copyFromUtf8("George Boosh")) .addAnswers(ByteString.copyFrom(GetData("F:\\vova\\meerkat\\meerkat-java\\voting-booth-gui\\src\\main\\resources\\images\\GeorgeBush.png")))
.setAnswers(1, ByteString.copyFromUtf8("Antonio Banderas")) .addAnswers(ByteString.copyFrom(GetData("F:\\vova\\meerkat\\meerkat-java\\voting-booth-gui\\src\\main\\resources\\images\\MichaelJackson.png")))
.setAnswers(2, ByteString.copyFromUtf8("Michal Jakson")))) .addAnswers(ByteString.copyFrom(GetData("F:\\vova\\meerkat\\meerkat-java\\voting-booth-gui\\src\\main\\resources\\images\\AntonioBanderass.jpg")))))
.setRandomizeListOrder(true).build(); .setRandomizeListOrder(true).build();
.
**/ return config;
return null;
} }
@Override @Override
public void start(Stage primaryStage) throws Exception public void start(Stage primaryStage) throws Exception
{ {
VotingBoothConfiguration config = GetConfig(); ChainBuilder.Build(primaryStage, GetConfig());
ChainBuilder.Build(primaryStage, config);
primaryStage.setTitle("Meerkat Polling Station"); primaryStage.setTitle("Meerkat Polling Station");
primaryStage.show(); primaryStage.show();
} }