Commit 26ad0ece by Facundo Javier Gelatti

Reduce scope of asyncExec in embeddingComplete and extractingComplete methods

1 parent 396a851f
......@@ -23,6 +23,7 @@ import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
......@@ -249,40 +250,43 @@ public class EmbedUi {
}
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 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();
Display.getDefault().asyncExec(() -> {
messageField.setText(message);
});
}
}
String statusMessage = "Extracting completed.";
if (outPath != null) {
statusMessage += " Extracted file saved to " + outPath;
}
Gui.setStatusBarMsg(statusMessage);
String statusMessage = "Extracting completed.";
if (outPath != null) {
statusMessage += " Extracted file saved to " + outPath;
}
String finalStatusMessage = statusMessage;
ImageData imageData = embeddingMethod.getVisualizer().getImageData();
Display.getDefault().asyncExec(() -> {
Gui.setStatusBarMsg(finalStatusMessage);
imageContainer.setImageData(ImageState.STEG, image.getImageData());
if (embeddingMethod.getVisualizer() != null) {
imageContainer.setImageData(ImageState.STEG_VISUALIZED, embeddingMethod.getVisualizer().getImageData());
imageContainer.setImageData(ImageState.STEG_VISUALIZED, imageData);
}
extractButton.setEnabled(true);
visualizationCheckbox();
// payload = new Payload();
cursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
compositeImage.getShell().setCursor(cursor);
progressBar.dispose();
......@@ -290,17 +294,17 @@ public class EmbedUi {
}
private void embeddingComplete(EmbeddingMethod<? extends ImageFormat> 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());
}
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));
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!