diff --git a/classes/production/voting-booth-gui/main/VotingBoothGUIManager.class b/classes/production/voting-booth-gui/main/VotingBoothGUIManager.class
deleted file mode 100644
index edf8cb2..0000000
Binary files a/classes/production/voting-booth-gui/main/VotingBoothGUIManager.class and /dev/null differ
diff --git a/classes/production/voting-booth-gui/main/select_candidate_by_picture/SelectCandidateByPictureController.class b/classes/production/voting-booth-gui/main/select_candidate_by_picture/SelectCandidateByPictureController.class
deleted file mode 100644
index 6a409a6..0000000
Binary files a/classes/production/voting-booth-gui/main/select_candidate_by_picture/SelectCandidateByPictureController.class and /dev/null differ
diff --git a/classes/production/voting-booth-gui/main/select_candidate_by_picture/select_candidate_by_picture.fxml b/classes/production/voting-booth-gui/main/select_candidate_by_picture/select_candidate_by_picture.fxml
deleted file mode 100644
index 6095f9b..0000000
--- a/classes/production/voting-booth-gui/main/select_candidate_by_picture/select_candidate_by_picture.fxml
+++ /dev/null
@@ -1,220 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/voting-booth/build.gradle b/voting-booth/build.gradle
index 23f2dec..2a2bcc2 100644
--- a/voting-booth/build.gradle
+++ b/voting-booth/build.gradle
@@ -56,6 +56,7 @@ dependencies {
// Jar that creates barcodes
compile group: 'net.sourceforge.barbecue', name: 'barbecue', version: '1.5-beta1'
+ compile 'com.google.zxing:core:3.3.0'
// Google protobufs
compile 'com.google.protobuf:protobuf-java:3.+'
diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/PrinterController.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/PrinterController.java
index 61bb7de..99f3682 100644
--- a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/PrinterController.java
+++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/PrinterController.java
@@ -3,40 +3,65 @@ package meerkat.voting.gui.ui.controllersFX;
/**
* Created by Laura on 01/12/2017.
*/
+import javafx.embed.swing.SwingFXUtils;
import javafx.fxml.FXML;
import javafx.scene.Node;
+import javafx.scene.control.Label;
+import javafx.scene.image.Image;
+import javafx.scene.image.ImageView;
import javafx.scene.layout.StackPane;
+import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import meerkat.voting.gui.ui.CommandPend;
import meerkat.voting.gui.ui.uicommands.UICommand;
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.io.InputStream;
+
/**
* Main controller class for the entire layout.
*/
public class PrinterController {
- /** Holder of a switchable vista. */
+ /** Holder of vista. */
@FXML
- private StackPane printerHolder;
+ private VBox vBox;
@FXML
private Text content;
- /**
- * Replaces the vista displayed in the vista holder with a new vista.
- *
- * @param node the vista node to be swapped in.
- */
- public void setVista(Node node) {
- printerHolder.getChildren().setAll(node);
- }
public void setContent(String s) {
- content.setText(s);
+ Text txt = new Text(s);
+ vBox.getChildren().clear();
+ vBox.getChildren().add(txt);
+ vBox.getScene().getWindow().sizeToScene();
}
public void addContent(String s) {
- String old_content = content.getText();
- content.setText(old_content+"\n"+s);
+ Text txt = new Text(s);
+ vBox.getChildren().add(txt);
+ vBox.getScene().getWindow().sizeToScene();
+ }
+
+ public void setContent(BufferedImage i) {
+ ImageView imageView = new ImageView();
+ Image image = SwingFXUtils.toFXImage(i, null);
+ imageView.setImage(image);
+ vBox.getChildren().clear();
+ vBox.getChildren().add(imageView);
+ vBox.getScene().getWindow().sizeToScene();
+ }
+
+ public void addContent(BufferedImage i) {
+ ImageView imageView = new ImageView();
+ Image image = SwingFXUtils.toFXImage(i, null);
+ imageView.setImage(image);
+ vBox.getChildren().add(imageView);
+// String old_content = content.getText();
+// content.setText(old_content+"\n"+s);
+ vBox.getScene().getWindow().sizeToScene();
}
}
\ No newline at end of file
diff --git a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VistaNavigator.java b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VistaNavigator.java
index d2568dd..ef75eb1 100644
--- a/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VistaNavigator.java
+++ b/voting-booth/src/main/java/meerkat/voting/gui/ui/controllersFX/VistaNavigator.java
@@ -9,6 +9,7 @@ import javafx.scene.Node;
import meerkat.voting.gui.ui.GraphicalUI;
import meerkat.voting.gui.ui.uicommands.UICommand;
+import java.awt.image.BufferedImage;
import java.io.IOException;
/**
@@ -145,6 +146,26 @@ public class VistaNavigator {
);
}
+ /**
+ * Prints the content into the printer application layout.
+ *
+ * @param content a String with the content that should be printed.
+ * @param mode if value 'a' means append, any other character will erase current content of printer
+ */
+ public static void printFX(BufferedImage content, char mode) {
+ Platform.runLater(new Runnable() {
+ @Override
+ public void run() {
+ if (mode=='a') {
+ printerController.addContent(content);
+ } else {
+ printerController.setContent(content);
+ }
+ }
+ }
+ );
+ }
+
/**
* Loads the 'LOADING' vista
* vistaHolder pane of the main application layout.
diff --git a/voting-booth/src/main/java/meerkat/voting/output/AsyncRunnableOutputDevice.java b/voting-booth/src/main/java/meerkat/voting/output/AsyncRunnableOutputDevice.java
index 0052a2c..e8acad6 100644
--- a/voting-booth/src/main/java/meerkat/voting/output/AsyncRunnableOutputDevice.java
+++ b/voting-booth/src/main/java/meerkat/voting/output/AsyncRunnableOutputDevice.java
@@ -1,6 +1,7 @@
package meerkat.voting.output;
import com.google.common.util.concurrent.FutureCallback;
+import com.google.zxing.WriterException;
import meerkat.protobuf.Voting.BallotSecrets;
import meerkat.protobuf.Voting.PlaintextBallot;
import meerkat.protobuf.Voting.SignedEncryptedBallot;
@@ -11,6 +12,7 @@ import meerkat.voting.output.outputcommands.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
import java.util.concurrent.ArrayBlockingQueue;
/**
diff --git a/voting-booth/src/main/java/meerkat/voting/output/FXWindowOutputDevice.java b/voting-booth/src/main/java/meerkat/voting/output/FXWindowOutputDevice.java
index 64ba1c5..6becf44 100644
--- a/voting-booth/src/main/java/meerkat/voting/output/FXWindowOutputDevice.java
+++ b/voting-booth/src/main/java/meerkat/voting/output/FXWindowOutputDevice.java
@@ -1,6 +1,7 @@
package meerkat.voting.output;
import com.google.protobuf.ByteString;
+import com.google.zxing.WriterException;
import meerkat.protobuf.Crypto.EncryptionRandomness;
import meerkat.protobuf.Crypto.RandomnessGenerationProof;
import meerkat.protobuf.Voting.BallotSecrets;
@@ -14,6 +15,9 @@ import meerkat.voting.output.outputcommands.CommitOutputCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
/**
* A toy OutputDevice class
* outputs everything simply to the System console
@@ -35,31 +39,32 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice {
public void doCommitToBallot(CommitOutputCommand command) {
logger.debug("entered method doCommitToBallot");
PlaintextBallot plaintextBallot = command.getPlaintext();
- long plaintextSerialNumber = plaintextBallot.getSerialNumber();
- String toPrint = "";
+ ByteString channel = command.getChannelIdentifierByteString();
+ printPlainText(plaintextBallot, channel);
- toPrint+="Commitment of Ballot #" + plaintextSerialNumber;
- toPrint+="\n";
- toPrint+="(channel): ";
- toPrint+="\n";
- toPrint+=bytesToString(command.getChannelIdentifierByteString());
- toPrint+="\n";
- toPrint+="(plaintext): ";
- toPrint+="\n";
- toPrint+=plaintextBallot;
- SignedEncryptedBallot signedEncryptedBallot = command.getSignedEncryptedBallot();
- long encryptedSerialNumber = signedEncryptedBallot.getEncryptedBallot().getSerialNumber();
- toPrint+="Commitment of Ballot #" + encryptedSerialNumber + " (ciphertext):";
- toPrint+="\n";
- if (plaintextSerialNumber != encryptedSerialNumber) {
- logger.error("plaintext and encryption serial numbers do not match!! plaintext# = " +
- plaintextSerialNumber + ", ciphertext# = " + encryptedSerialNumber);
+ String toQRCode;
+// SignedEncryptedBallot signedEncryptedBallot = command.getSignedEncryptedBallot();
+// long encryptedSerialNumber = signedEncryptedBallot.getEncryptedBallot().getSerialNumber();
+// toPrint+="Commitment of Ballot #" + encryptedSerialNumber + " (ciphertext):";
+// toPrint+="\n";
+// if (plaintextSerialNumber != encryptedSerialNumber) {
+// logger.error("plaintext and encryption serial numbers do not match!! plaintext# = " +
+// plaintextSerialNumber + ", ciphertext# = " + encryptedSerialNumber);
+// }
+// ByteString encryptedData = signedEncryptedBallot.getEncryptedBallot().getData().getData();
+// toPrint+=bytesToString(encryptedData);
+// toPrint+="\n";
+// VistaNavigator.printFX(toPrint, 'w');
+ toQRCode = "test";
+ try {
+ printQRCode(toQRCode, 250);
+ command.getCallback().onSuccess(null);
+ } catch (IOException e) {
+ command.getCallback().onFailure(e);
+ } catch (WriterException e) {
+ command.getCallback().onFailure(e);
}
- ByteString encryptedData = signedEncryptedBallot.getEncryptedBallot().getData().getData();
- toPrint+=bytesToString(encryptedData);
- toPrint+="\n";
- VistaNavigator.printFX(toPrint, 'w');
- command.getCallback().onSuccess(null);
+
}
@@ -105,6 +110,26 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice {
command.getCallback().onSuccess(null);
}
+ private void printPlainText(PlaintextBallot plaintextBallot, ByteString channel) {
+ long plaintextSerialNumber = plaintextBallot.getSerialNumber();
+ String toPrint = "";
+ toPrint+="Commitment of Ballot #" + plaintextSerialNumber;
+ toPrint+="\n";
+ toPrint+="(channel): ";
+ toPrint+="\n";
+ toPrint+=bytesToString(channel);
+ toPrint+="\n";
+ toPrint+="(plaintext): ";
+ toPrint+="\n";
+ toPrint+=plaintextBallot;
+ VistaNavigator.printFX(toPrint, 'w');
+ }
+
+ private void printQRCode(String toQRCode, int size) throws IOException, WriterException {
+ BufferedImage image = null;
+ image = GenerateQRCode.createQRImage(toQRCode, size);
+ VistaNavigator.printFX(image, 'a');
+ }
private void printEncryptionRandomness (EncryptionRandomness encryptionRandomness) {
String msg = "Encryption Randomness = ";
diff --git a/voting-booth/src/main/java/meerkat/voting/output/GenerateQRCode.java b/voting-booth/src/main/java/meerkat/voting/output/GenerateQRCode.java
new file mode 100644
index 0000000..bc46815
--- /dev/null
+++ b/voting-booth/src/main/java/meerkat/voting/output/GenerateQRCode.java
@@ -0,0 +1,64 @@
+package meerkat.voting.output;
+
+/**
+ * Created by Laura on 1/25/2017.
+ */
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+import java.util.Hashtable;
+
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.WriterException;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.qrcode.QRCodeWriter;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+
+public class GenerateQRCode {
+
+ /**
+ * @param args
+ * @throws WriterException
+ * @throws IOException
+ */
+ public static void main(String[] args) throws WriterException, IOException {
+ String qrCodeText = "http://www.journaldev.com";
+ int size = 125;
+ createQRImage(qrCodeText, size);
+ System.out.println("DONE");
+ }
+
+ public static BufferedImage createQRImage(String qrCodeText, int size) throws WriterException, IOException {
+ // Create the ByteMatrix for the QR-Code that encodes the given String
+ Hashtable hintMap = new Hashtable();
+ hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
+ QRCodeWriter qrCodeWriter = new QRCodeWriter();
+ BitMatrix byteMatrix = qrCodeWriter.encode(qrCodeText,
+ BarcodeFormat.QR_CODE, size, size, hintMap);
+ // Make the BufferedImage that are to hold the QRCode
+ int matrixWidth = byteMatrix.getWidth();
+ BufferedImage image = new BufferedImage(matrixWidth, matrixWidth,
+ BufferedImage.TYPE_INT_RGB);
+ image.createGraphics();
+
+ Graphics2D graphics = (Graphics2D) image.getGraphics();
+ graphics.setColor(Color.WHITE);
+ graphics.fillRect(0, 0, matrixWidth, matrixWidth);
+ // Paint and save the image using the ByteMatrix
+ graphics.setColor(Color.BLACK);
+
+ for (int i = 0; i < matrixWidth; i++) {
+ for (int j = 0; j < matrixWidth; j++) {
+ if (byteMatrix.get(i, j)) {
+ graphics.fillRect(i, j, 1, 1);
+ }
+ }
+ }
+ return image;
+// ImageIO.write(image, fileType, qrFile);
+ }
+
+}
\ No newline at end of file
diff --git a/voting-booth/src/main/resources/views/printer.fxml b/voting-booth/src/main/resources/views/printer.fxml
index db1d265..e79205e 100644
--- a/voting-booth/src/main/resources/views/printer.fxml
+++ b/voting-booth/src/main/resources/views/printer.fxml
@@ -1,21 +1,10 @@
-
-
-
-
+
-
-
-
-
-
-
-
-
-
+