diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/PrinterController.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/PrinterController.java index 3916f22..b23dcc9 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/PrinterController.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/PrinterController.java @@ -32,11 +32,8 @@ public class PrinterController { private Text content; - public void setContent(String s) { - Text txt = new Text(s); + public void clean() { vBox.getChildren().clear(); - vBox.getChildren().add(txt); - vBox.getScene().getWindow().sizeToScene(); } public void addContent(String s) { @@ -45,15 +42,6 @@ public class PrinterController { 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); diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/VistaNavigator.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/VistaNavigator.java index e94efa6..76cf9da 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/VistaNavigator.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/controllersFX/VistaNavigator.java @@ -125,22 +125,16 @@ 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(String content, char mode) { + public static void cleanPrinterFX() { Platform.runLater(new Runnable() { @Override public void run() { - if (mode=='a') { - printerController.addContent(content); - } else { - printerController.setContent(content); - } + printerController.clean(); } } ); @@ -150,17 +144,27 @@ 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) { + public static void printFX(String content) { Platform.runLater(new Runnable() { @Override public void run() { - if (mode=='a') { - printerController.addContent(content); - } else { - printerController.setContent(content); - } + printerController.addContent(content); + } + } + ); + } + + /** + * Prints the content into the printer application layout. + * + * @param content a String with the content that should be printed. + */ + public static void printFX(BufferedImage content) { + Platform.runLater(new Runnable() { + @Override + public void run() { + printerController.addContent(content); } } ); diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/output/FXWindowOutputDevice.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/output/FXWindowOutputDevice.java index 765fce5..77ae2eb 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/output/FXWindowOutputDevice.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/output/FXWindowOutputDevice.java @@ -6,6 +6,7 @@ import meerkat.protobuf.Crypto.EncryptionRandomness; import meerkat.protobuf.Crypto.RandomnessGenerationProof; import meerkat.protobuf.Voting.BallotSecrets; import meerkat.protobuf.Voting.PlaintextBallot; +import meerkat.protobuf.Voting.SignedEncryptedBallot; import meerkat.voting.gui.controllersFX.VistaNavigator; import meerkat.voting.output.AsyncRunnableOutputDevice; import meerkat.voting.output.outputcommands.AuditOutputCommand; @@ -42,29 +43,7 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice { ByteString channel = command.getChannelIdentifierByteString(); printPlainText(plaintextBallot, channel); - 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); - } - + printEncryptedText(plaintextBallot, command); } @@ -75,13 +54,8 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice { */ public void doAudit(AuditOutputCommand command) { logger.debug("entered method doAudit"); - try { - Thread.sleep(500); - } catch (InterruptedException e) { - e.printStackTrace(); - } String msg = "Auditing"; - VistaNavigator.printFX(msg, 'a'); + VistaNavigator.printFX(msg); BallotSecrets ballotSecrets = command.getBallotSecrets(); printEncryptionRandomness(ballotSecrets.getEncryptionRandomness()); printRandomnessGenerationProof (ballotSecrets.getProof()); @@ -95,7 +69,7 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice { public void doCastBallot(CastOutputCommand command) { logger.debug("entered method doCastBallot"); String msg = "Ballot finalized for casting!"; - VistaNavigator.printFX(msg, 'a'); + VistaNavigator.printFX(msg); command.getCallback().onSuccess(null); } @@ -122,27 +96,55 @@ public class FXWindowOutputDevice extends AsyncRunnableOutputDevice { toPrint+="(plaintext): "; toPrint+="\n"; toPrint+=plaintextBallot; - VistaNavigator.printFX(toPrint, 'w'); + VistaNavigator.printFX(toPrint); + } + + private void printEncryptedText(PlaintextBallot plaintextBallot, CommitOutputCommand command) { + String encryptedText; + SignedEncryptedBallot signedEncryptedBallot = command.getSignedEncryptedBallot(); + long encryptedSerialNumber = signedEncryptedBallot.getEncryptedBallot().getSerialNumber(); + long plaintextSerialNumber = plaintextBallot.getSerialNumber(); + + String toPrint = ""; + toPrint+="Commitment of Ballot #" + encryptedSerialNumber + " (ciphertext):"; + toPrint+="\n"; + VistaNavigator.printFX(toPrint); + if (plaintextSerialNumber != encryptedSerialNumber) { + logger.error("plaintext and encryption serial numbers do not match!! plaintext# = " + + plaintextSerialNumber + ", ciphertext# = " + encryptedSerialNumber); + } + ByteString encryptedData = signedEncryptedBallot.getEncryptedBallot().getData().getData(); + encryptedText = encryptedSerialNumber+"|"+bytesToString(encryptedData); + + try { + printQRCode(encryptedText, 250); + command.getCallback().onSuccess(null); + } catch (IOException e) { + command.getCallback().onFailure(e); + } catch (WriterException e) { + command.getCallback().onFailure(e); + } + } private void printQRCode(String toQRCode, int size) throws IOException, WriterException { BufferedImage image = null; image = GenerateQRCode.createQRImage(toQRCode, size); - VistaNavigator.printFX(image, 'a'); + VistaNavigator.printFX(image); } private void printEncryptionRandomness (EncryptionRandomness encryptionRandomness) { String msg = "Encryption Randomness = "; ByteString data = encryptionRandomness.getData(); msg+=bytesToString(data); - VistaNavigator.printFX(msg, 'a'); + VistaNavigator.printFX(msg); } private void printRandomnessGenerationProof (RandomnessGenerationProof proof) { String msg = "Proof of randomness generation:"; ByteString data = proof.getData(); msg+=bytesToString(data); - VistaNavigator.printFX(msg, 'a'); + VistaNavigator.printFX(msg); } diff --git a/voting-booth-gui/src/main/java/meerkat/voting/gui/uiFX/MainFX.java b/voting-booth-gui/src/main/java/meerkat/voting/gui/uiFX/MainFX.java index 2585812..b0f68af 100644 --- a/voting-booth-gui/src/main/java/meerkat/voting/gui/uiFX/MainFX.java +++ b/voting-booth-gui/src/main/java/meerkat/voting/gui/uiFX/MainFX.java @@ -65,6 +65,11 @@ public class MainFX extends Application { notifyLaunched(); } + @Override + public void stop(){ + System.out.println("MainFX: Stage is closing ---- need to callShutDown() on VotingBoothImpl"); + } + /** * Loads the main fxml layout. * Sets up the vista switching VistaNavigator.