Commit 7fe34a99 by Tobias

bug fix

1 parent 6cf9de2c
......@@ -6,6 +6,7 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Iterator;
import java.util.ListIterator;
import java.util.ResourceBundle;
import org.eclipse.swt.SWT;
......@@ -129,7 +130,10 @@ public class EmbedUi {
@Override
public void drop(final DropTargetEvent event) {
final String[] filenames = (String[]) event.data;
addPayloadFile(filenames[0]);
if (filenames[0] != null) {
payload.getBlocks().add(new FileBlock(filenames[0]));
addPayloadFile(filenames[0]);
}
}
});
......@@ -147,7 +151,10 @@ public class EmbedUi {
item2.addListener(SWT.Selection, event -> {
final FileDialog dlg = new FileDialog(c1.getShell(), SWT.OPEN);
final String filePath = dlg.open();
addPayloadFile(filePath);
if (filePath != null) {
payload.getBlocks().add(new FileBlock(filePath));
addPayloadFile(filePath);
}
});
fileTable.addKeyListener(new KeyAdapter() {
......@@ -318,6 +325,8 @@ public class EmbedUi {
payload = new Payload();
fileTable.clearAll();
fileTable.setItemCount(0);
payloadFileSize.setText("");
payloadFileCounter.setText(fileTable.getItemCount() + " embedded files");
cursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
compositeImage.getShell().setCursor(cursor);
progressBar.dispose();
......@@ -331,7 +340,9 @@ public class EmbedUi {
*/
public void extractingComplete(EmbeddingMethod<?> embeddingMethod) {
String outPath = null;
for (Block block : payload.getBlocks()) {
ListIterator<Block> iterator = payload.getBlocks().listIterator();
while (iterator.hasNext()) {
Block block = iterator.next();
if (block.getIdentifier() == FileBlock.IDENTIFIER) {
outPath = FileUtils.changeFileName(image.getFile().getAbsolutePath(),
((FileBlock) block).getFileName());
......@@ -340,12 +351,32 @@ public class EmbedUi {
} catch (IOException e) {
e.printStackTrace();
}
iterator.remove();
iterator.add(new FileBlock(outPath));
addPayloadFile(outPath);
} else if (block.getIdentifier() == MessageBlock.IDENTIFIER) {
String message = ((MessageBlock) block).getMessage();
messageField.setText(message);
}
}
// for (Block block : payload.getBlocks()) {
// if (block.getIdentifier() == 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();
// }
// } else if (block.getIdentifier() == MessageBlock.IDENTIFIER) {
// String message = ((MessageBlock) block).getMessage();
// messageField.setText(message);
// }
// }
String statusMessage = "Extracting completed.";
if (outPath != null) {
statusMessage += " Extracted file saved to " + outPath;
......@@ -357,7 +388,7 @@ public class EmbedUi {
}
extractButton.setEnabled(true);
visualizationCheckbox();
payload = new Payload();
// payload = new Payload();
cursor = new Cursor(Display.getDefault(), SWT.CURSOR_ARROW);
compositeImage.getShell().setCursor(cursor);
progressBar.dispose();
......@@ -395,6 +426,10 @@ public class EmbedUi {
messageField.setEnabled(false);
}
fileTable.clearAll();
fileTable.setItemCount(0);
payloadFileSize.setText("");
payloadFileCounter.setText(fileTable.getItemCount() + " embedded files");
payload = new Payload();
visualizationCheckbox();
compositeImage.layout(true, true);
......@@ -447,24 +482,21 @@ public class EmbedUi {
}
private void addPayloadFile(String filePath) {
if (filePath != null) {
String filename = Paths.get(filePath).getFileName().toString();
payload.getBlocks().add(new FileBlock(filePath));
TableItem item = new TableItem(fileTable, SWT.NONE);
item.setText(filename);
payloadFileCounter.setText(fileTable.getItemCount() + " embedded files");
File f = new File(filePath);
fileSizeSum += f.length();
payloadFileSize.setText(ImageUtils.formatSize(fileSizeSum));
item.setText(1, ImageUtils.formatSize(f.length()));
item.setForeground(1, Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
final TableColumn[] columns = fileTable.getColumns();
for (TableColumn column : columns) {
column.pack();
}
payloadFileSize.getParent().layout(true, true);
String filename = Paths.get(filePath).getFileName().toString();
TableItem item = new TableItem(fileTable, SWT.NONE);
item.setText(filename);
payloadFileCounter.setText(fileTable.getItemCount() + " embedded files");
File f = new File(filePath);
fileSizeSum += f.length();
payloadFileSize.setText(ImageUtils.formatSize(fileSizeSum));
item.setText(1, ImageUtils.formatSize(f.length()));
item.setForeground(1, Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
final TableColumn[] columns = fileTable.getColumns();
for (TableColumn column : columns) {
column.pack();
}
payloadFileSize.getParent().layout(true, true);
}
private void removeSelectedPayloadFile() {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!