Commit caf9bede by Facundo Javier Gelatti

Push syncExecs into embeddingComplete and extractingComplete methods

1 parent 605aca9a
......@@ -244,7 +244,7 @@ public class EmbedUi {
private void extract(EmbeddingProgress progress) {
try {
embedding.extract(payload, progress, (embeddingMethod) ->
Display.getDefault().asyncExec(() -> extractingComplete(embeddingMethod))
extractingComplete(embeddingMethod)
);
} catch (SteganoExtractException e) {
......@@ -260,24 +260,51 @@ public class EmbedUi {
}
}
private void displayError(String statusBarMessage, Button actionButton, String message) {
Display.getDefault().syncExec(() -> {
MessageBox dialog = new MessageBox(composite.getShell(), SWT.ICON_ERROR | SWT.OK);
dialog.setText("Error");
dialog.setMessage(message);
dialog.open();
actionButton.setEnabled(true);
cursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
compositeImage.getShell().setCursor(cursor);
progressBar.dispose();
Gui.setStatusBarMsg(statusBarMessage);
});
private void extractingComplete(EmbeddingMethod<? extends ImageFormat> embeddingMethod) {
Display.getDefault().asyncExec(() -> {
String outPath = null;
ListIterator<Block> iterator = payload.getBlocks().listIterator();
while (iterator.hasNext()) {
Block block = iterator.next();
if (block.hasIdentifier(FileBlock.IDENTIFIER)) {
outPath = FileUtils.changeFileName(image.getFile().getAbsolutePath(),
((FileBlock) block).getFileName());
try {
Files.write(Paths.get(outPath), ((FileBlock) block).getFileContent(), StandardOpenOption.CREATE);
} catch (IOException e) {
e.printStackTrace();
}
iterator.remove();
iterator.add(new FileBlock(outPath));
addPayloadFile(outPath);
} else if (block.hasIdentifier(MessageBlock.IDENTIFIER)) {
String message = ((MessageBlock) block).getMessage();
messageField.setText(message);
}
}
String statusMessage = "Extracting completed.";
if (outPath != null) {
statusMessage += " Extracted file saved to " + outPath;
}
Gui.setStatusBarMsg(statusMessage);
imageContainer.setImageData(ImageState.STEG, image.getImageData());
if (embeddingMethod.getVisualizer() != null) {
imageContainer.setImageData(ImageState.STEG_VISUALIZED, embeddingMethod.getVisualizer().getImageData());
}
extractButton.setEnabled(true);
visualizationCheckbox();
// payload = new Payload();
cursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
compositeImage.getShell().setCursor(cursor);
progressBar.dispose();
});
}
private void embed(EmbeddingProgress progress) {
try {
embedding.embed(payload, progress, (embeddingMethod, embeddedImage) ->
Display.getDefault().asyncExec(() -> embeddingComplete(embeddingMethod, embeddedImage))
embeddingComplete(embeddingMethod, embeddedImage)
);
} catch (SteganoEmbedException e) {
......@@ -293,83 +320,47 @@ public class EmbedUi {
}
}
/**
* Gets called after the embedding-process is finished. Displays the image, disposes the
* progress bar etc.
*
* @param embeddingMethod
* @param embeddedImage
*/
public void embeddingComplete(EmbeddingMethod<?> embeddingMethod, ImageFormat embeddedImage) {
String outputPath = FileUtils.addFileNameSuffix(embeddedImage.getFile().getAbsolutePath(), "_embed");
try {
embeddedImage.save(new File(outputPath));
} catch (SteganoImageException e) {
e.printStackTrace();
}
imageContainer.setImageData(ImageState.STEG, embeddedImage.getImageData());
if (embeddingMethod.getVisualizer() != null) {
imageContainer.setImageData(ImageState.STEG_VISUALIZED, embeddingMethod.getVisualizer().getImageData());
}
Gui.setStatusBarMsg("Embedding completed. File saved to " + outputPath);
embedButton.setEnabled(true);
imageLabel.setImage(imageContainer.scaleImage(ImageState.STEG));
visualizationCheckbox();
compositeImage.layout(true, true);
payload = new Payload();
fileTable.clearAll();
fileTable.setItemCount(0);
fileSizeSum = 0;
payloadFileSize.setText("");
updateFilesCount();
cursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
compositeImage.getShell().setCursor(cursor);
progressBar.dispose();
}
/**
* Gets called after the extracting-process is finished. Displays the message, saves the
* extracted files, disposes the progress bar etc.
*
* @param embeddingMethod
*/
public void extractingComplete(EmbeddingMethod<?> embeddingMethod) {
String outPath = null;
ListIterator<Block> iterator = payload.getBlocks().listIterator();
while (iterator.hasNext()) {
Block block = iterator.next();
if (block.hasIdentifier(FileBlock.IDENTIFIER)) {
outPath = FileUtils.changeFileName(image.getFile().getAbsolutePath(),
((FileBlock) block).getFileName());
try {
Files.write(Paths.get(outPath), ((FileBlock) block).getFileContent(), StandardOpenOption.CREATE);
} catch (IOException e) {
e.printStackTrace();
}
iterator.remove();
iterator.add(new FileBlock(outPath));
addPayloadFile(outPath);
} else if (block.hasIdentifier(MessageBlock.IDENTIFIER)) {
String message = ((MessageBlock) block).getMessage();
messageField.setText(message);
private void embeddingComplete(EmbeddingMethod<? extends ImageFormat> embeddingMethod, ImageFormat embeddedImage) {
Display.getDefault().asyncExec(() -> {
String outputPath = FileUtils.addFileNameSuffix(embeddedImage.getFile().getAbsolutePath(), "_embed");
try {
embeddedImage.save(new File(outputPath));
} catch (SteganoImageException e) {
e.printStackTrace();
}
}
imageContainer.setImageData(ImageState.STEG, embeddedImage.getImageData());
if (embeddingMethod.getVisualizer() != null) {
imageContainer.setImageData(ImageState.STEG_VISUALIZED, embeddingMethod.getVisualizer().getImageData());
}
Gui.setStatusBarMsg("Embedding completed. File saved to " + outputPath);
embedButton.setEnabled(true);
imageLabel.setImage(imageContainer.scaleImage(ImageState.STEG));
visualizationCheckbox();
compositeImage.layout(true, true);
payload = new Payload();
fileTable.clearAll();
fileTable.setItemCount(0);
fileSizeSum = 0;
payloadFileSize.setText("");
updateFilesCount();
cursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
compositeImage.getShell().setCursor(cursor);
progressBar.dispose();
});
}
String statusMessage = "Extracting completed.";
if (outPath != null) {
statusMessage += " Extracted file saved to " + outPath;
}
Gui.setStatusBarMsg(statusMessage);
imageContainer.setImageData(ImageState.STEG, image.getImageData());
if (embeddingMethod.getVisualizer() != null) {
imageContainer.setImageData(ImageState.STEG_VISUALIZED, embeddingMethod.getVisualizer().getImageData());
}
extractButton.setEnabled(true);
visualizationCheckbox();
// payload = new Payload();
cursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
compositeImage.getShell().setCursor(cursor);
progressBar.dispose();
private void displayError(String statusBarMessage, Button actionButton, String message) {
Display.getDefault().syncExec(() -> {
MessageBox dialog = new MessageBox(composite.getShell(), SWT.ICON_ERROR | SWT.OK);
dialog.setText("Error");
dialog.setMessage(message);
dialog.open();
actionButton.setEnabled(true);
cursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
compositeImage.getShell().setCursor(cursor);
progressBar.dispose();
Gui.setStatusBarMsg(statusBarMessage);
});
}
/**
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!