From 0cf9390fa5a1ab8e6cec0bd8d00789b5081b324b Mon Sep 17 00:00:00 2001 From: Laura Radaelli Date: Wed, 25 Jan 2017 12:50:01 +0200 Subject: [PATCH] prints test qr-code to virtual printer --- .../main/VotingBoothGUIManager.class | Bin 5864 -> 0 bytes .../SelectCandidateByPictureController.class | Bin 3685 -> 0 bytes .../select_candidate_by_picture.fxml | 220 ------------------ voting-booth/build.gradle | 1 + .../ui/controllersFX/PrinterController.java | 51 ++-- .../gui/ui/controllersFX/VistaNavigator.java | 21 ++ .../output/AsyncRunnableOutputDevice.java | 2 + .../voting/output/FXWindowOutputDevice.java | 71 ++++-- .../meerkat/voting/output/GenerateQRCode.java | 64 +++++ .../src/main/resources/views/printer.fxml | 15 +- 10 files changed, 176 insertions(+), 269 deletions(-) delete mode 100644 classes/production/voting-booth-gui/main/VotingBoothGUIManager.class delete mode 100644 classes/production/voting-booth-gui/main/select_candidate_by_picture/SelectCandidateByPictureController.class delete mode 100644 classes/production/voting-booth-gui/main/select_candidate_by_picture/select_candidate_by_picture.fxml create mode 100644 voting-booth/src/main/java/meerkat/voting/output/GenerateQRCode.java 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 edf8cb253344dfd421c365f91fdd8a8fca779885..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 5864 zcmc&&`F9i775<(VMwSHu115IB6%8cDHV8MQO)ZzkHa2l$o1|VyLRvDG$I{rN8D|!Z zX}YKBmZl+F_cmSAbWhp@Xixh?f9xOC)9<|}jbtHX)Sk4Q!_4R{_q+GI_uYG+|M{=K z{2jn4ypu!^yd(}{Es1B~xA7~Gk1&BKiAz|QkIQnwh8(_`P52gN{wX&?zm(Jk?A~Yx|S16n`<1IS}`w~nJBcK3=l z`I|fW{=LQB| z71*=namEj4to2zd2sloC%wUy(mOtV7BW|#6`BY?FBWNP0>>$ie<-B4h?|FI0%J8%3 zxq33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DEtz!=JI=+MNYWSXx@8bsoL&2o747;4pdM*dbly6$h0w>mys9lzIyoMjD=RJhJL z#DeZ4%PjNRc^!hz>)qXnphT@|nI5Y%njLLf8bAJAI04#e0(&-;s5r_hkMXME)+CPt zd$&@=7TebmU6te0O9ws2LA*Hgq`*jLzqWDE^8+2yQSDDVF5k07qhzv4`)1}Aa!Ue- zI@N4urMAIHTUk04>ACgvtX-2Hn|@zYxa)>8`L00~`nRCs7;j32^Joi`O@?l@YQm&a zAvEKGij_Hs!k1N9Q)hN0SH_oYBD_Im zURBAdxlGKWifg$U&?(q&RI5@AkyBe`K8QT5`i|bG;3y~T+g!&zCzNROEqEd#hx#qY zx#3s0DcvUGVM$7aJ4<>JIWvO3fS zd5D6_V{dK6S>X^#LC(;OqKwhVc~W}0 zKM`Rt$!|V+k>Qg(DFB3^v#`Y zpg*ZK5br(nM+{7yyp6~3Js*#31SH?SLI$Y8?a zI7tLg(V^3rAkYfSvCvctfb+PBrx;3{uFT?Tx-^6o-ir(aZBK4Yy`AJ!4*xB3INx(_ zwEuNn9{WA+ZQ#D!*t@ij!Q@Z_`$iiWZeXN=`x(&u=>4zZ!BgE~jCP0dQcS$@pSLy= zIKnCb3q_;V6d_iTT;ll(E1(%m3daJ!d+2$Vw;Aq0z7=0Sh(%z5R2@D4V#fZ7%s+w> zzuZc}vy@VDBVj1})yCfg4IBt52RG171_(YuuO^XXNer_nls92%jkGL}M96lcxOgX< phqkwQkv5;A%~{%f`Yvo{>0Jyt9Os_o*D<_6Jcn5wFA&q={{n4tvD*Lu 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 @@ - - - - + - - - - - - - - - +