summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java
diff options
context:
space:
mode:
authortkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:59:29 +0000
committertkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7>2013-04-10 18:59:29 +0000
commite60e1df5284c93b25cf6f6a477b924850dffb9d5 (patch)
tree86a8bec1e0bcac482b742174a87d1a1190a405f8 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java
parentac47a525b1338100c7489ec60fed24ce10f57394 (diff)
downloadpdf-over-e60e1df5284c93b25cf6f6a477b924850dffb9d5.tar.gz
pdf-over-e60e1df5284c93b25cf6f6a477b924850dffb9d5.tar.bz2
pdf-over-e60e1df5284c93b25cf6f6a477b924850dffb9d5.zip
UI Improvements
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@69 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java131
1 files changed, 97 insertions, 34 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java
index 1b24b678..cf579b7b 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java
@@ -18,8 +18,11 @@ package at.asit.pdfover.gui.composites;
// Imports
import java.awt.Desktop;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
+import java.io.IOException;
+import org.apache.commons.io.FilenameUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -28,7 +31,9 @@ import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Listener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -45,8 +50,66 @@ public class OutputComposite extends StateComposite {
/**
* SLF4J Logger instance
**/
- static final Logger log = LoggerFactory
- .getLogger(OutputComposite.class);
+ static final Logger log = LoggerFactory.getLogger(OutputComposite.class);
+
+ private File inputFile;
+
+ /**
+ * Sets the input file
+ *
+ * @param inputFile
+ * the input file
+ */
+ public void setInputFile(File inputFile) {
+ this.inputFile = inputFile;
+ }
+
+ /**
+ * Gets the input file
+ *
+ * @return the input file
+ */
+ public File getInputFile() {
+ return this.inputFile;
+ }
+
+ /**
+ * Saves the file
+ *
+ * @throws IOException
+ */
+ void saveFile() throws IOException {
+ FileDialog save = new FileDialog(OutputComposite.this.getShell(),
+ SWT.SAVE | SWT.NATIVE);
+ save.setFilterExtensions(new String[] { "*.pdf" }); //$NON-NLS-1$
+ save.setFilterNames(new String[] { Messages
+ .getString("common.PDFExtension_Description") }); //$NON-NLS-1$
+
+ String proposed = OutputComposite.this.getInputFile().getAbsolutePath();
+
+ String extension = FilenameUtils.getExtension(proposed);
+
+ proposed = FilenameUtils.removeExtension(proposed);
+
+ proposed = proposed + "_signed." + extension; //$NON-NLS-1$
+
+ save.setFileName(proposed);
+
+ String target = save.open();
+
+ if (target != null) {
+ File targetFile = new File(target);
+
+ DocumentSource source = OutputComposite.this.getSignedDocument();
+
+ FileOutputStream outstream = new FileOutputStream(targetFile);
+ outstream.write(source.getByteArray(), 0,
+ source.getByteArray().length);
+ outstream.close();
+
+ OutputComposite.this.savedFile = targetFile;
+ }
+ }
/**
* SelectionListener for save button
@@ -61,24 +124,7 @@ public class OutputComposite extends StateComposite {
@Override
public void widgetSelected(SelectionEvent e) {
try {
- FileDialog save = new FileDialog(OutputComposite.this.getShell(), SWT.SAVE | SWT.NATIVE);
- save.setFilterExtensions(new String[] {"*.pdf"}); //$NON-NLS-1$
- save.setFilterNames(new String[] {Messages.getString("common.PDFExtension_Description")}); //$NON-NLS-1$
-
- String target = save.open();
-
- File targetFile = new File(target);
-
- DocumentSource source = OutputComposite.this
- .getSignedDocument();
-
- FileOutputStream outstream = new FileOutputStream(targetFile);
- outstream.write(source.getByteArray(), 0,
- source.getByteArray().length);
- outstream.close();
-
- OutputComposite.this.savedFile = targetFile;
-
+ OutputComposite.this.saveFile();
} catch (Exception ex) {
log.error("SaveSelectionListener: ", ex); //$NON-NLS-1$
}
@@ -105,9 +151,11 @@ public class OutputComposite extends StateComposite {
File open = OutputComposite.this.savedFile;
if (open == null) {
// Save as temp file ...
- java.util.Date date= new java.util.Date();
- String fileName = String.format("%d_tmp_signed.pdf", date.getTime()); //$NON-NLS-1$
- open = new File(OutputComposite.this.tempDirectory + "/" + fileName); //$NON-NLS-1$
+ java.util.Date date = new java.util.Date();
+ String fileName = String.format(
+ "%d_tmp_signed.pdf", date.getTime()); //$NON-NLS-1$
+ open = new File(OutputComposite.this.tempDirectory
+ + "/" + fileName); //$NON-NLS-1$
FileOutputStream outstream = new FileOutputStream(open);
outstream.write(source.getByteArray(), 0,
source.getByteArray().length);
@@ -121,9 +169,11 @@ public class OutputComposite extends StateComposite {
}
} else {
log.error("OutputComposite:OpenSelectionListener:widgetSelected -> source is null!!"); //$NON-NLS-1$
- ErrorDialog dialog = new ErrorDialog(getShell(),
- SWT.NONE, Messages.getString("error.FailedToGetSignedDocument"),//$NON-NLS-1$
- "", false); //$NON-NLS-1$
+ ErrorDialog dialog = new ErrorDialog(
+ getShell(),
+ SWT.NONE,
+ Messages.getString("error.FailedToGetSignedDocument"),//$NON-NLS-1$
+ "", false); //$NON-NLS-1$
dialog.open();
}
} catch (Exception ex) {
@@ -155,10 +205,10 @@ public class OutputComposite extends StateComposite {
btn_open.setText(Messages.getString("common.open")); //$NON-NLS-1$
// Point mobile_size = btn_mobile.computeSize(SWT.DEFAULT, SWT.DEFAULT);
FormData fd_btn_open = new FormData();
- //fd_btn_open.left = new FormAttachment(40, 0);
+ // fd_btn_open.left = new FormAttachment(40, 0);
fd_btn_open.right = new FormAttachment(50, -5);
fd_btn_open.top = new FormAttachment(40, 0);
- //fd_btn_open.bottom = new FormAttachment(55, 0);
+ // fd_btn_open.bottom = new FormAttachment(55, 0);
btn_open.setLayoutData(fd_btn_open);
btn_open.addSelectionListener(new OpenSelectionListener());
@@ -171,26 +221,27 @@ public class OutputComposite extends StateComposite {
// Point card_size = btn_card.computeSize(SWT.DEFAULT, SWT.DEFAULT);
FormData fd_btn_save = new FormData();
fd_btn_save.left = new FormAttachment(50, 5);
- //fd_btn_save.right = new FormAttachment(60, 0);
+ // fd_btn_save.right = new FormAttachment(60, 0);
fd_btn_save.top = new FormAttachment(40, 0);
- //fd_btn_save.bottom = new FormAttachment(55, 0);
+ // fd_btn_save.bottom = new FormAttachment(55, 0);
btn_save.setLayoutData(fd_btn_save);
btn_save.addSelectionListener(new SaveSelectionListener());
- this.pack();
+ //this.pack();
}
String tempDirectory;
-
+
/**
* @param tempDirectory
*/
public void setTempDirectory(String tempDirectory) {
this.tempDirectory = tempDirectory;
}
-
+
/**
* Gets the signed document
+ *
* @return the signed document
*/
public DocumentSource getSignedDocument() {
@@ -199,7 +250,9 @@ public class OutputComposite extends StateComposite {
/**
* Sets the signed document
- * @param signedDocument the signed document
+ *
+ * @param signedDocument
+ * the signed document
*/
public void setSignedDocument(final DocumentSource signedDocument) {
this.signedDocument = signedDocument;
@@ -210,6 +263,8 @@ public class OutputComposite extends StateComposite {
// Disable the check that prevents subclassing of SWT components
}
+ private boolean save_showed = false;
+
/*
* (non-Javadoc)
*
@@ -218,6 +273,14 @@ public class OutputComposite extends StateComposite {
@Override
public void doLayout() {
// Nothing to do
+ try {
+ if (!this.save_showed) {
+ OutputComposite.this.saveFile();
+ this.save_showed = true;
+ }
+ } catch (Exception ex) {
+ log.error("SaveSelectionListener: ", ex); //$NON-NLS-1$
+ }
}
}