diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:57:07 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:57:07 +0000 |
commit | a8222b9d16145d8b2f8803d13e5afe2b99d47fc0 (patch) | |
tree | 36637499e140a59d6e43f74eaceb3e23ec3e1f07 /pdf-over-gui/src | |
parent | 9f07d0ac1f3d53d03a4f105b1b99dccd4ac2d473 (diff) | |
download | pdf-over-a8222b9d16145d8b2f8803d13e5afe2b99d47fc0.tar.gz pdf-over-a8222b9d16145d8b2f8803d13e5afe2b99d47fc0.tar.bz2 pdf-over-a8222b9d16145d8b2f8803d13e5afe2b99d47fc0.zip |
Configuration and Main Bar Buttons
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@53 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src')
35 files changed, 1975 insertions, 504 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java index b8cd9ea7..6b5914e0 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindow.java @@ -16,19 +16,23 @@ package at.asit.pdfover.gui; // Imports +import java.io.InputStream; import java.util.EnumMap; import java.util.Map; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CLabel; import org.eclipse.swt.custom.StackLayout; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.layout.FormAttachment; 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.Control; import org.eclipse.swt.widgets.Display; @@ -37,6 +41,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.composites.StateComposite; +import at.asit.pdfover.gui.controls.MainBarButton; +import at.asit.pdfover.gui.controls.MainBarEndButton; +import at.asit.pdfover.gui.controls.MainBarMiddleButton; +import at.asit.pdfover.gui.controls.MainBarRectangleButton; +import at.asit.pdfover.gui.controls.MainBarStartButton; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.states.ConfigurationUIState; import at.asit.pdfover.gui.workflow.states.OpenState; @@ -48,64 +57,6 @@ import at.asit.pdfover.gui.workflow.states.PositioningState; public class MainWindow { /** - * - */ - private final class ConfigSelectionListener implements SelectionListener { - /** - * - */ - public ConfigSelectionListener() { - // Nothing to do here - } - - @Override - public void widgetSelected(SelectionEvent e) { - MainWindow.this.stateMachine.jumpToState(new ConfigurationUIState( - MainWindow.this.stateMachine)); - } - - @Override - public void widgetDefaultSelected(SelectionEvent e) { - // Nothing to do here - } - } - - /** - * Selection Listener for Position Button - */ - private final class PositionSelectionListener extends SelectionAdapter { - /** - * Empty constructor - */ - public PositionSelectionListener() { - } - - @Override - public void widgetSelected(SelectionEvent e) { - MainWindow.this.stateMachine.jumpToState(new PositioningState( - MainWindow.this.stateMachine)); - } - } - - /** - * Selection Listener for Open Button - */ - private final class DataSourceSelectionListener extends SelectionAdapter { - /** - * Empty constructor - */ - public DataSourceSelectionListener() { - } - - @Override - public void widgetSelected(SelectionEvent e) { - MainWindow.this.stateMachine - .jumpToState(new OpenState( - MainWindow.this.stateMachine)); - } - } - - /** * SFL4J Logger instance **/ static final Logger log = LoggerFactory.getLogger(MainWindow.class); @@ -115,10 +66,10 @@ public class MainWindow { private Composite container; private StackLayout stack; StateMachine stateMachine; - private Button btn_sign; - private Button btn_position; - private Button btn_open; - private Button btn_config; + private MainBarButton btn_sign; + private MainBarButton btn_position; + private MainBarButton btn_open; + private MainBarButton btn_config; /** * Main bar Buttons @@ -127,7 +78,9 @@ public class MainWindow { CONFIG, OPEN, POSITION, SIGN, FINAL } - private Map<Buttons, Button> buttonMap; + private Map<Buttons, MainBarButton> buttonMap; + + private FormData mainBarFormData; /** * Default constructor @@ -140,7 +93,7 @@ public class MainWindow { this.stateMachine = stateMachine; - this.buttonMap = new EnumMap<MainWindow.Buttons, Button>(Buttons.class); + this.buttonMap = new EnumMap<MainWindow.Buttons, MainBarButton>(Buttons.class); } /** @@ -152,7 +105,7 @@ public class MainWindow { if (this.getShell().isDisposed()) { return; } - this.lbl_status.setText("[DEBUG]: Current workflow state: " + value); + this.lbl_status.setText("[DEBUG]: Current workflow state: " + value); //$NON-NLS-1$ } /** @@ -161,7 +114,7 @@ public class MainWindow { * @param ctrl */ public void setTopControl(Control ctrl) { - log.debug("Top control: " + ctrl.toString()); + log.debug("Top control: " + ctrl.toString()); //$NON-NLS-1$ this.stack.topControl = ctrl; this.doLayout(); } @@ -175,7 +128,9 @@ public class MainWindow { this.shell.layout(true, true); // Note: SWT only layouts children! No grandchildren! if (ctrl instanceof StateComposite) { - ((StateComposite) ctrl).doLayout(); + if (!ctrl.isDisposed()) { + ((StateComposite) ctrl).doLayout(); + } } } @@ -229,62 +184,127 @@ public class MainWindow { getShell().setLayout(new FormLayout()); Composite composite = new Composite(getShell(), SWT.NONE); - FormData fd_composite = new FormData(); - fd_composite.left = new FormAttachment(0, 5); - fd_composite.right = new FormAttachment(100, -5); - fd_composite.top = new FormAttachment(0, 5); - fd_composite.bottom = new FormAttachment(0, 40); - composite.setLayoutData(fd_composite); composite.setLayout(new FormLayout()); - - this.btn_config = new Button(composite, SWT.NONE); - FormData fd_config = new FormData(); - fd_config.left = new FormAttachment(0, 0); - fd_config.right = new FormAttachment(25, 0); - fd_config.top = new FormAttachment(0, 0); - fd_config.bottom = new FormAttachment(100, 0); - this.btn_config.setLayoutData(fd_config); - this.btn_config.setText("Config ..."); - this.btn_config.addSelectionListener(new ConfigSelectionListener()); + this.mainBarFormData = new FormData(); + this.mainBarFormData.left = new FormAttachment(0, 5); + this.mainBarFormData.right = new FormAttachment(100, -5); + this.mainBarFormData.top = new FormAttachment(0, 5); + this.mainBarFormData.bottom = new FormAttachment(0, 60); + composite.setLayoutData(this.mainBarFormData); + + this.btn_config = new MainBarRectangleButton(composite, SWT.NONE); + FormData fd_btn_config = new FormData(); + fd_btn_config.bottom = new FormAttachment(0, 45); + fd_btn_config.right = new FormAttachment(10,0); + fd_btn_config.top = new FormAttachment(0); + fd_btn_config.left = new FormAttachment(0, 2); + this.btn_config.setLayoutData(fd_btn_config); + this.btn_config.setText("Config"); + this.btn_config.addMouseListener(new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + MainWindow.this.stateMachine.jumpToState(new ConfigurationUIState( + MainWindow.this.stateMachine)); + } + + @Override + public void mouseDown(MouseEvent e) { + // NOTHING TO DO HERE + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + // NOTHING TO DO HERE + } + }); this.buttonMap.put(Buttons.CONFIG, this.btn_config); - - this.btn_open = new Button(composite, SWT.NONE); - FormData fd_open = new FormData(); - fd_open.left = new FormAttachment(25, 0); - fd_open.right = new FormAttachment(50, 0); - fd_open.top = new FormAttachment(0, 0); - fd_open.bottom = new FormAttachment(100, 0); - this.btn_open.setLayoutData(fd_open); - this.btn_open.setText("Open ..."); - this.btn_open.addSelectionListener(new DataSourceSelectionListener()); + + InputStream is = this.getClass().getResourceAsStream("/img/config.png"); + + this.btn_config.setImage(new Image(Display.getDefault(), new ImageData(is))); + + this.btn_open = new MainBarStartButton(composite, SWT.NONE); + FormData fd_btn_open = new FormData(); + fd_btn_open.bottom = new FormAttachment(0, 45); + fd_btn_open.right = new FormAttachment(35, 5); + fd_btn_open.top = new FormAttachment(0); + fd_btn_open.left = new FormAttachment(10, 0); + this.btn_open.setLayoutData(fd_btn_open); + this.btn_open.setText("Open"); + this.btn_open.addMouseListener(new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + MainWindow.this.stateMachine.jumpToState(new OpenState( + MainWindow.this.stateMachine)); + } + + @Override + public void mouseDown(MouseEvent e) { + // NOTHING TO DO HERE + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + // NOTHING TO DO HERE + } + }); this.buttonMap.put(Buttons.OPEN, this.btn_open); - this.btn_position = new Button(composite, SWT.NONE); - FormData fd_position = new FormData(); - fd_position.left = new FormAttachment(50, 0); - fd_position.right = new FormAttachment(75, 0); - fd_position.top = new FormAttachment(0, 0); - fd_position.bottom = new FormAttachment(100, 0); - this.btn_position.setLayoutData(fd_position); + this.btn_position = new MainBarMiddleButton(composite, SWT.NONE); + FormData fd_btn_position = new FormData(); + fd_btn_position.bottom = new FormAttachment(0, 45); + fd_btn_position.right = new FormAttachment(60, 5); + fd_btn_position.top = new FormAttachment(0); + fd_btn_position.left = new FormAttachment(35, -5); + this.btn_position.setLayoutData(fd_btn_position); this.btn_position.setText("Positon ..."); - this.btn_position.addSelectionListener(new PositionSelectionListener()); + this.btn_position.addMouseListener(new MouseListener() { + + @Override + public void mouseUp(MouseEvent e) { + MainWindow.this.stateMachine.jumpToState(new PositioningState( + MainWindow.this.stateMachine)); + } + + @Override + public void mouseDown(MouseEvent e) { + // NOTHING TO DO HERE + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + // NOTHING TO DO HERE + } + }); this.buttonMap.put(Buttons.POSITION, this.btn_position); - this.btn_sign = new Button(composite, SWT.NONE); - FormData fd_sign = new FormData(); - fd_sign.left = new FormAttachment(75, 0); - fd_sign.right = new FormAttachment(100, 0); - fd_sign.top = new FormAttachment(0, 0); - fd_sign.bottom = new FormAttachment(100, 0); - this.btn_sign.setLayoutData(fd_sign); + this.btn_sign = new MainBarMiddleButton(composite, SWT.NONE); + FormData fd_btn_sign = new FormData(); + fd_btn_sign.bottom = new FormAttachment(0, 45); + fd_btn_sign.right = new FormAttachment(85, 5); + fd_btn_sign.top = new FormAttachment(0); + fd_btn_sign.left = new FormAttachment(60, -5); + this.btn_sign.setLayoutData(fd_btn_sign); this.btn_sign.setText("Sign ..."); this.buttonMap.put(Buttons.SIGN, this.btn_sign); + MainBarEndButton end = new MainBarEndButton(composite, SWT.NONE); + FormData fd_btn_end = new FormData(); + fd_btn_end.bottom = new FormAttachment(0, 45); + fd_btn_end.right = new FormAttachment(100, -2); + fd_btn_end.top = new FormAttachment(0); + fd_btn_end.left = new FormAttachment(85, -5); + end.setLayoutData(fd_btn_end); + end.setText("Done"); + this.buttonMap.put(Buttons.FINAL, end); + this.container = new Composite(getShell(), SWT.BORDER | SWT.RESIZE); FormData fd_composite_1 = new FormData(); fd_composite_1.bottom = new FormAttachment(100, -25); fd_composite_1.right = new FormAttachment(100, -5); - fd_composite_1.top = new FormAttachment(0, 45); + fd_composite_1.top = new FormAttachment(0, 60); fd_composite_1.left = new FormAttachment(0, 5); this.container.setLayoutData(fd_composite_1); this.stack = new StackLayout(); @@ -298,7 +318,6 @@ public class MainWindow { fd_lblNewLabel.left = new FormAttachment(0, 5); this.lbl_status.setLayoutData(fd_lblNewLabel); this.lbl_status.setText("New Label"); - } /** @@ -308,21 +327,25 @@ public class MainWindow { MainWindowBehavior behavior = this.stateMachine.getStatus() .getBehavior(); - log.debug("Updating MainWindow state for : " + log.debug("Updating MainWindow state for : " //$NON-NLS-1$ + this.stateMachine.getStatus().getCurrentState().toString()); for (Buttons button : Buttons.values()) { boolean active = behavior.getActive(button); boolean enabled = behavior.getEnabled(button); - Button theButton = this.buttonMap.get(button); - if (theButton != null) - { + MainBarButton theButton = this.buttonMap.get(button); + if (theButton != null) { theButton.setEnabled(enabled); + theButton.setActive(active); } } - //TODO: Display/Hide main bar + if(behavior.getMainBarVisible()) { + this.mainBarFormData.bottom = new FormAttachment(0, 60); + } else { + this.mainBarFormData.bottom = new FormAttachment(0, 0); + } } /** diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindowBehavior.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindowBehavior.java index 1d0094c9..a2f53e63 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindowBehavior.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/MainWindowBehavior.java @@ -24,8 +24,19 @@ import at.asit.pdfover.gui.MainWindow.Buttons; * Behavior manipulation for Main Window */ public class MainWindowBehavior { + /** + * Enabled buttons map + */ protected Map<Buttons, Boolean> buttonsEnabled; + + /** + * active buttons map + */ protected Map<Buttons, Boolean> buttonsActive; + + /** + * Main bar visible + */ protected boolean mainBarVisible; /** @@ -37,18 +48,38 @@ public class MainWindowBehavior { reset(); } + /** + * set active buttons + * @param button + * @param active + */ public void setActive(Buttons button, boolean active) { this.buttonsActive.put(button, active); } + /** + * Gets the active state of a button from main bar + * @param button the button + * @return the active state + */ public boolean getActive(Buttons button) { return this.buttonsActive.get(button); } + /** + * Sets the enabled buttons in the main bar + * @param button + * @param enabled + */ public void setEnabled(Buttons button, boolean enabled) { this.buttonsEnabled.put(button, enabled); } + /** + * Get the enabled state of a button in main bar + * @param button the button + * @return the enabled state + */ public boolean getEnabled(Buttons button) { return this.buttonsEnabled.get(button); } @@ -67,10 +98,18 @@ public class MainWindowBehavior { setMainBarVisible(true); } + /** + * Sets the main bar visible + * @param visible + */ public void setMainBarVisible(boolean visible) { this.mainBarVisible = visible; } + /** + * Gets wether the main bar is visible + * @return the visibility of the main bar + */ public boolean getMainBarVisible() { return this.mainBarVisible; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java index 5b826097..e3869105 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/AdvancedConfigurationComposite.java @@ -17,12 +17,30 @@ package at.asit.pdfover.gui.composites; // Imports import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TabItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.workflow.ConfigurationContainer; import at.asit.pdfover.gui.workflow.states.State; +import at.asit.pdfover.signator.BKUs; + import org.eclipse.swt.widgets.Label; import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.widgets.DirectoryDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Text; /** * @@ -36,11 +54,234 @@ public class AdvancedConfigurationComposite extends BaseConfigurationComposite { public AdvancedConfigurationComposite(Composite parent, int style, State state, ConfigurationContainer container) { super(parent, style, state, container); + setLayout(new FormLayout()); + + TabFolder tabFolder = new TabFolder(this, SWT.NONE); + FormData fd_tabFolder = new FormData(); + fd_tabFolder.bottom = new FormAttachment(100, -5); + fd_tabFolder.right = new FormAttachment(100, -5); + fd_tabFolder.top = new FormAttachment(0, 5); + fd_tabFolder.left = new FormAttachment(0, 5); + tabFolder.setLayoutData(fd_tabFolder); + + TabItem simpleTabItem = new TabItem(tabFolder, SWT.NULL); + simpleTabItem.setText("Simple"); + + this.simpleComposite = new SimpleConfigurationComposite(tabFolder, + SWT.NONE, state, container); + + simpleTabItem.setControl(this.simpleComposite); + + TabItem advancedTabItem = new TabItem(tabFolder, SWT.NULL); + advancedTabItem.setText("Advanced"); + + Composite advancedComposite = new Composite(tabFolder, SWT.NONE); + + advancedTabItem.setControl(advancedComposite); + advancedComposite.setLayout(new FormLayout()); + + Group grpSignaturPosition = new Group(advancedComposite, SWT.NONE); + grpSignaturPosition.setText("Signatur Position"); + grpSignaturPosition.setLayout(new FormLayout()); + FormData fd_grpSignaturPosition = new FormData(); + fd_grpSignaturPosition.top = new FormAttachment(0, 5); + fd_grpSignaturPosition.bottom = new FormAttachment(33, -5); + fd_grpSignaturPosition.right = new FormAttachment(100, -5); + fd_grpSignaturPosition.left = new FormAttachment(0, 5); + grpSignaturPosition.setLayoutData(fd_grpSignaturPosition); + + this.btnAutomatischePositionierung = new Button(grpSignaturPosition, + SWT.CHECK); + FormData fd_btnAutomatischePositionierung = new FormData(); + fd_btnAutomatischePositionierung.right = new FormAttachment(100, -5); + fd_btnAutomatischePositionierung.top = new FormAttachment(0, 5); + fd_btnAutomatischePositionierung.left = new FormAttachment(0, 5); + this.btnAutomatischePositionierung + .setLayoutData(fd_btnAutomatischePositionierung); + this.btnAutomatischePositionierung.setText("Automatische Positionierung"); - Label lblAdvancedConfigLayout = new Label(this, SWT.NONE); - lblAdvancedConfigLayout.setBounds(113, 126, 243, 15); - lblAdvancedConfigLayout.setText("Advanced Config Layout!"); - // TODO Auto-generated constructor stub + this.btnAutomatischePositionierung.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + AdvancedConfigurationComposite.this.performPositionSelection( + AdvancedConfigurationComposite.this.btnAutomatischePositionierung.getSelection()); + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing to do + } + }); + + Group grpBkuAuswahl = new Group(advancedComposite, SWT.NONE); + grpBkuAuswahl.setText("BKU Selection"); + grpBkuAuswahl.setLayout(new FormLayout()); + FormData fd_grpBkuAuswahl = new FormData(); + fd_grpBkuAuswahl.top = new FormAttachment(33, 5); + fd_grpBkuAuswahl.left = new FormAttachment(0, 5); + fd_grpBkuAuswahl.right = new FormAttachment(100, -5); + fd_grpBkuAuswahl.bottom = new FormAttachment(66, -5); + grpBkuAuswahl.setLayoutData(fd_grpBkuAuswahl); + + this.cmbBKUAuswahl = new Combo(grpBkuAuswahl, SWT.NONE); + FormData fd_cmbBKUAuswahl = new FormData(); + fd_cmbBKUAuswahl.right = new FormAttachment(100, -5); + fd_cmbBKUAuswahl.top = new FormAttachment(0, 5); + fd_cmbBKUAuswahl.left = new FormAttachment(0, 5); + + int blen = BKUs.values().length; + + this.bkuStrings = new String[blen]; + + // TODO: Implement translation into user language for ENUM Values!! + for (int i = 0; i < blen; i++) { + this.bkuStrings[i] = BKUs.values()[i].toString(); + } + + this.cmbBKUAuswahl.setItems(this.bkuStrings); + + this.cmbBKUAuswahl.setLayoutData(fd_cmbBKUAuswahl); + + this.cmbBKUAuswahl.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + int selectionIndex = getBKUElementIndex(AdvancedConfigurationComposite.this.configurationContainer.getBKUSelection()); + if(AdvancedConfigurationComposite.this.cmbBKUAuswahl.getSelectionIndex() != selectionIndex) { + selectionIndex = AdvancedConfigurationComposite.this.cmbBKUAuswahl.getSelectionIndex(); + performBKUSelectionChanged(AdvancedConfigurationComposite.this.cmbBKUAuswahl.getItem(selectionIndex)); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing to do here + } + }); + + Group grpSpeicherort = new Group(advancedComposite, SWT.NONE); + grpSpeicherort.setText("Outputfolder"); + grpSpeicherort.setLayout(new FormLayout()); + FormData fd_grpSpeicherort = new FormData(); + fd_grpSpeicherort.top = new FormAttachment(66, 5); + fd_grpSpeicherort.left = new FormAttachment(0, 5); + fd_grpSpeicherort.right = new FormAttachment(100, -5); + fd_grpSpeicherort.bottom = new FormAttachment(100, -5); + grpSpeicherort.setLayoutData(fd_grpSpeicherort); + + Label lblDefaultOutputFolder = new Label(grpSpeicherort, SWT.NONE); + FormData fd_lblDefaultOutputFolder = new FormData(); + fd_lblDefaultOutputFolder.top = new FormAttachment(0, 5); + fd_lblDefaultOutputFolder.left = new FormAttachment(0, 5); + lblDefaultOutputFolder.setLayoutData(fd_lblDefaultOutputFolder); + lblDefaultOutputFolder.setText("Default output folder:"); + + this.txtOutputFolder = new Text(grpSpeicherort, SWT.BORDER); + FormData fd_text = new FormData(); + fd_text.top = new FormAttachment(lblDefaultOutputFolder, 5); + fd_text.left = new FormAttachment(0, 5); + this.txtOutputFolder.setLayoutData(fd_text); + + this.txtOutputFolder.addFocusListener(new FocusListener() { + + @Override + public void focusLost(FocusEvent e) { + performOutputFolderChanged(AdvancedConfigurationComposite.this.txtOutputFolder.getText()); + } + + @Override + public void focusGained(FocusEvent e) { + // Nothing to do here! + } + }); + + Button btnBrowse = new Button(grpSpeicherort, SWT.NONE); + fd_text.right = new FormAttachment(btnBrowse, -5); + + FormData fd_btnBrowse = new FormData(); + fd_btnBrowse.top = new FormAttachment(lblDefaultOutputFolder, 5); + fd_btnBrowse.right = new FormAttachment(100, -5); + btnBrowse.setLayoutData(fd_btnBrowse); + btnBrowse.setText("browse"); + + btnBrowse.addSelectionListener(new SelectionListener() { + + @Override + public void widgetSelected(SelectionEvent e) { + DirectoryDialog dlg = new DirectoryDialog( + AdvancedConfigurationComposite.this.getShell()); + + // Set the initial filter path according + // to anything they've selected or typed in + dlg.setFilterPath(AdvancedConfigurationComposite.this.txtOutputFolder + .getText()); + + // Change the title bar text + dlg.setText("Select Output folder"); + + // Customizable message displayed in the dialog + dlg.setMessage("Select a directory"); + + // Calling open() will open and run the dialog. + // It will return the selected directory, or + // null if user cancels + String dir = dlg.open(); + if (dir != null) { + // Set the text box to the new selection + performOutputFolderChanged(dir); + } + } + + @Override + public void widgetDefaultSelected(SelectionEvent e) { + // Nothing to do + } + }); + } + + void performOutputFolderChanged(String foldername) { + log.debug("Selected Output folder: " + foldername); //$NON-NLS-1$ + this.configurationContainer.setOutputFolder(foldername); + AdvancedConfigurationComposite.this.txtOutputFolder.setText(foldername); + } + + int getBKUElementIndex(BKUs bku) { + // TODO: Translate to user language! + String bkuName = bku.toString(); + + for(int i = 0; i < this.bkuStrings.length; i++) { + if(this.bkuStrings[i].equals(bkuName)) { + log.debug("BKU: " + bkuName + " IDX: " + i); //$NON-NLS-1$ //$NON-NLS-2$ + return i; + } + } + + log.warn("NO BKU match for " + bkuName); //$NON-NLS-1$ + return 0; + } + + void performBKUSelectionChanged(BKUs selected) { + log.debug("Selected BKU: " + selected.toString()); //$NON-NLS-1$ + this.configurationContainer.setBKUSelection(selected); + this.cmbBKUAuswahl.select(this.getBKUElementIndex(selected)); + } + + void performBKUSelectionChanged(String selected) { + try { + BKUs bkuvalue = BKUs.valueOf(selected); + this.performBKUSelectionChanged(bkuvalue); + } catch (Exception ex) { + log.error("Failed to parse BKU value: " + selected, ex); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, "Invalid BKU selection. Please check.", ex); + dialog.open(); + } + } + + void performPositionSelection(boolean automatic) { + log.debug("Selected Position: " + automatic); //$NON-NLS-1$ + this.configurationContainer.setAutomaticPosition(automatic); + this.btnAutomatischePositionierung.setSelection(automatic); } /** @@ -48,13 +289,44 @@ public class AdvancedConfigurationComposite extends BaseConfigurationComposite { **/ private static final Logger log = LoggerFactory .getLogger(AdvancedConfigurationComposite.class); + SimpleConfigurationComposite simpleComposite; + Text txtOutputFolder; + Combo cmbBKUAuswahl; + String[] bkuStrings; + Button btnAutomatischePositionierung; - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.composites.StateComposite#doLayout() */ @Override public void doLayout() { - // TODO Auto-generated method stub - + // Nothing to do here + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#loadConfiguration + * () + */ + @Override + public void loadConfiguration() { + this.simpleComposite.loadConfiguration(); + + // load advanced settings + this.performBKUSelectionChanged(this.configurationContainer.getBKUSelection()); + this.performOutputFolderChanged(this.configurationContainer.getOutputFolder()); + this.performPositionSelection(this.configurationContainer.getAutomaticPosition()); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.composites.BaseConfigurationComposite#validateSettings() + */ + @Override + public void validateSettings() throws Exception { + this.simpleComposite.validateSettings(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java index 88156343..19b3f46c 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BKUSelectionComposite.java @@ -19,6 +19,8 @@ package at.asit.pdfover.gui.composites; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; @@ -111,24 +113,32 @@ public class BKUSelectionComposite extends StateComposite { btn_mobile.setText("MOBILE"); //Point mobile_size = btn_mobile.computeSize(SWT.DEFAULT, SWT.DEFAULT); FormData fd_btn_mobile = new FormData(); - fd_btn_mobile.left = new FormAttachment(40, 0); - fd_btn_mobile.right = new FormAttachment(50, 0); - fd_btn_mobile.top = new FormAttachment(45, 0); - fd_btn_mobile.bottom = new FormAttachment(55, 0); + //fd_btn_mobile.left = new FormAttachment(40, 0); + fd_btn_mobile.right = new FormAttachment(50, -5); + fd_btn_mobile.top = new FormAttachment(40, 0); + //fd_btn_mobile.bottom = new FormAttachment(55, 0); btn_mobile.setLayoutData(fd_btn_mobile); btn_mobile.addSelectionListener(new MobileSelectionListener()); + Image mobile = new Image(getDisplay(), new ImageData(this.getClass().getResourceAsStream("/img/handy.gif"))); + + btn_mobile.setImage(mobile); + Button btn_card = new Button(this, SWT.NATIVE | SWT.RESIZE); btn_card.setText("CARD"); //Point card_size = btn_card.computeSize(SWT.DEFAULT, SWT.DEFAULT); FormData fd_btn_card = new FormData(); - fd_btn_card.left = new FormAttachment(50, 0); - fd_btn_card.right = new FormAttachment(60, 0); - fd_btn_card.top = new FormAttachment(45, 0); - fd_btn_card.bottom = new FormAttachment(55, 0); + fd_btn_card.left = new FormAttachment(50, 5); + //fd_btn_card.right = new FormAttachment(60, 0); + fd_btn_card.top = new FormAttachment(40, 0); + //fd_btn_card.bottom = new FormAttachment(55, 0); btn_card.setLayoutData(fd_btn_card); btn_card.addSelectionListener(new LocalSelectionListener()); + Image karte = new Image(getDisplay(), new ImageData(this.getClass().getResourceAsStream("/img/karte.gif"))); + + btn_card.setImage(karte); + this.pack(); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java index 831a4aa6..3c79e124 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/BaseConfigurationComposite.java @@ -17,6 +17,8 @@ package at.asit.pdfover.gui.composites; import org.eclipse.swt.widgets.Composite; + +import at.asit.pdfover.gui.workflow.ConfigurationContainer; import at.asit.pdfover.gui.workflow.states.State; /** @@ -39,4 +41,16 @@ public abstract class BaseConfigurationComposite extends StateComposite { super(parent, style, state); this.configurationContainer = configuration; } + + /** + * Load configuration from ConfigurationContainer + */ + public abstract void loadConfiguration(); + + /** + * Called before exit. + * The method validates every setting in the configuration before exit + * @throws Exception + */ + public abstract void validateSettings() throws Exception; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java index db58ae4a..0e78e507 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java @@ -16,13 +16,23 @@ package at.asit.pdfover.gui.composites; // Imports +import java.io.IOException; + import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.controls.ErrorDialog; +import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; +import at.asit.pdfover.gui.exceptions.InvalidNumberException; +import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.workflow.ConfigManipulator; +import at.asit.pdfover.gui.workflow.ConfigProvider; +import at.asit.pdfover.gui.workflow.ConfigurationContainer; +import at.asit.pdfover.gui.workflow.ConfigurationContainerImpl; import at.asit.pdfover.gui.workflow.states.State; +import at.asit.pdfover.signator.SignaturePosition; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Button; @@ -38,7 +48,7 @@ import org.eclipse.swt.layout.FormAttachment; * */ public class ConfigurationComposite extends StateComposite { - + /** * */ @@ -57,7 +67,7 @@ public class ConfigurationComposite extends StateComposite { // switch to advanced ConfigurationComposite.this.configComposite.dispose(); ConfigurationComposite.this.configComposite = new AdvancedConfigurationComposite( - ConfigurationComposite.this.containerComposite, + ConfigurationComposite.this.containerComposite, ConfigurationComposite.this.style, ConfigurationComposite.this.state, ConfigurationComposite.this.configurationContainer); @@ -66,13 +76,14 @@ public class ConfigurationComposite extends StateComposite { // switch to simple ConfigurationComposite.this.configComposite.dispose(); ConfigurationComposite.this.configComposite = new SimpleConfigurationComposite( - ConfigurationComposite.this.containerComposite, + ConfigurationComposite.this.containerComposite, ConfigurationComposite.this.style, ConfigurationComposite.this.state, ConfigurationComposite.this.configurationContainer); ConfigurationComposite.this.btnAdvanced.setText("Advanced"); } - + + ConfigurationComposite.this.configComposite.loadConfiguration(); ConfigurationComposite.this.compositeStack.topControl = ConfigurationComposite.this.configComposite; ConfigurationComposite.this.doLayout(); } @@ -91,10 +102,12 @@ public class ConfigurationComposite extends StateComposite { ConfigManipulator configManipulator = null; + ConfigProvider configProvider = null; + BaseConfigurationComposite configComposite; ConfigurationContainer configurationContainer = new ConfigurationContainerImpl(); - + StackLayout compositeStack = new StackLayout(); int style; @@ -115,6 +128,54 @@ public class ConfigurationComposite extends StateComposite { } /** + * Sets the configuration provider + * + * @param provider + */ + public void setConfigProvider(ConfigProvider provider) { + this.configProvider = provider; + if (this.configProvider != null) { + + // Initialize Configuration Container + if (this.configProvider.getDefaultSignaturePosition() != null) { + this.configurationContainer + .setAutomaticPosition(this.configProvider + .getDefaultSignaturePosition() + .useAutoPositioning()); + } + + this.configurationContainer.setBKUSelection(this.configProvider + .getDefaultBKU()); + try { + this.configurationContainer.setEmblem(this.configProvider + .getDefaultEmblem()); + } catch (InvalidEmblemFile e) { + log.error("Failed to set emblem!", e); //$NON-NLS-1$ + } + try { + this.configurationContainer.setNumber(this.configProvider + .getDefaultMobileNumber()); + } catch (InvalidNumberException e) { + log.error("Failed to set mobile phone number!", e); //$NON-NLS-1$ + } + + this.configurationContainer.setOutputFolder(this.configProvider + .getDefaultOutputFolder()); + + this.configurationContainer.setProxyHost(this.configProvider + .getProxyHost()); + try { + this.configurationContainer.setProxyPort(this.configProvider + .getProxyPort()); + } catch (InvalidPortException e) { + log.error("Failed to set proxy port!", e); //$NON-NLS-1$ + } + + this.configComposite.loadConfiguration(); + } + } + + /** * Create the composite. * * @param parent @@ -130,7 +191,8 @@ public class ConfigurationComposite extends StateComposite { this.containerComposite = new Composite(this, SWT.FILL | SWT.RESIZE); this.configComposite = new SimpleConfigurationComposite( - this.containerComposite, SWT.FILL | style, state, this.configurationContainer); + this.containerComposite, SWT.FILL | style, state, + this.configurationContainer); FormData fd_composite = new FormData(); fd_composite.top = new FormAttachment(0, 5); @@ -151,6 +213,10 @@ public class ConfigurationComposite extends StateComposite { btnSpeichern.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { + if (ConfigurationComposite.this.storeConfiguration()) { + ConfigurationComposite.this.userDone = true; + ConfigurationComposite.this.state.updateStateMachine(); + } } }); btnSpeichern.setText("Speichern"); @@ -180,16 +246,63 @@ public class ConfigurationComposite extends StateComposite { } - private void storeConfiguration() { - // TODO: Collect info from UI and set in ConfigManipulator + boolean storeConfiguration() { + + try { + this.configComposite.validateSettings(); - // TODO: call save configuration in ConfigManipulator + // Write current Configuration + this.configManipulator.setDefaultBKU(this.configurationContainer + .getBKUSelection()); + this.configManipulator + .setDefaultMobileNumber(this.configurationContainer + .getNumber()); + if (this.configurationContainer.getAutomaticPosition()) { + this.configManipulator + .setDefaultSignaturePosition(new SignaturePosition()); + } else { + this.configManipulator + .setDefaultSignaturePosition(null); + } + + this.configManipulator + .setDefaultOutputFolder(this.configurationContainer + .getOutputFolder()); + + this.configManipulator.setProxyHost(this.configurationContainer + .getProxyHost()); + this.configManipulator.setProxyPort(this.configurationContainer + .getProxyPort()); + this.configManipulator.setDefaultEmblem(this.configurationContainer + .getEmblem()); + + } catch (Exception e) { + log.error("Settings validation failed!", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog( + getShell(), + SWT.NONE, + "Invalid settings are still present. Please check your input.", + e); + dialog.open(); + return false; + } + // Save current config to file + try { + this.configManipulator.saveCurrentConfiguration(); + } catch (IOException e) { + log.error("Failed to save configuration to file!", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(getShell(), SWT.NONE, + "Failed to save configuration file!", e); + dialog.open(); + return false; + } + return true; } /** * Checks if the user has finished working with the configuration composite * - * @return + * @return if the user is done */ public boolean isUserDone() { return this.userDone; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java index 91ac7d6d..ac7494e8 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/DataSourceSelectComposite.java @@ -118,9 +118,9 @@ public class DataSourceSelectComposite extends StateComposite { this.setLayout(new FormLayout()); - Color back = new Color(Display.getCurrent(), 77, 190, 250); + //Color back = new Color(Display.getCurrent(), 77, 190, 250); - this.drop_area = new Composite(this, SWT.RESIZE | SWT.BORDER_DASH); + this.drop_area = new Composite(this, SWT.RESIZE | SWT.BORDER); FormData fd_drop_area = new FormData(); fd_drop_area.left = new FormAttachment(0, 0); fd_drop_area.right = new FormAttachment(100, 0); @@ -128,7 +128,7 @@ public class DataSourceSelectComposite extends StateComposite { fd_drop_area.bottom = new FormAttachment(100, 0); this.drop_area.setLayoutData(fd_drop_area); this.drop_area.setLayout(new FormLayout()); - this.drop_area.setBackground(back); + //this.drop_area.setBackground(back); DropTarget dnd_target = new DropTarget(this.drop_area, DND.DROP_DEFAULT | DND.DROP_COPY); @@ -195,17 +195,17 @@ public class DataSourceSelectComposite extends StateComposite { final Label lbl_drag = new Label(this.drop_area, SWT.NONE | SWT.RESIZE); FormData fd_lbl_drag = new FormData(); - fd_lbl_drag.left = new FormAttachment(5, 5); - fd_lbl_drag.right = new FormAttachment(100, -5); - fd_lbl_drag.top = new FormAttachment(5, 5); - fd_lbl_drag.bottom = new FormAttachment(55, -5); + fd_lbl_drag.left = new FormAttachment(0, 10); + fd_lbl_drag.right = new FormAttachment(100, -10); + fd_lbl_drag.top = new FormAttachment(0, 10); + //fd_lbl_drag.bottom = new FormAttachment(100, -10); lbl_drag.setLayoutData(fd_lbl_drag); FontData[] fD = lbl_drag.getFont().getFontData(); fD[0].setHeight(18); lbl_drag.setFont(new Font(Display.getCurrent(), fD[0])); - lbl_drag.setText("Drag and Drop"); + lbl_drag.setText("To sign a document\ndrag and drop it here\nor use the button below"); lbl_drag.setAlignment(SWT.CENTER); - lbl_drag.setBackground(back); + //lbl_drag.setBackground(back); Button btn_open = new Button(this.drop_area, SWT.NATIVE | SWT.RESIZE); btn_open.setText("Choose file ..."); @@ -216,24 +216,9 @@ public class DataSourceSelectComposite extends StateComposite { fd_btn_open.top = new FormAttachment(100, size.y * -1 - 10); fd_btn_open.bottom = new FormAttachment(100, -5); btn_open.setLayoutData(fd_btn_open); - btn_open.setBackground(back); + //btn_open.setBackground(back); btn_open.addSelectionListener(new FileBrowseDialogListener()); this.drop_area.pack(); - - /* - * Button btn = new Button(this, SWT.NATIVE); btn.setBounds(50, 20, 100, - * 50); btn.setText("Click Me"); btn.addSelectionListener(new - * SelectionListener() { - * - * @Override public void widgetSelected(SelectionEvent arg0) { - * DataSourceSelectComposite.this.setPress(true); - * DataSourceSelectComposite.this.workflow.update(); } - * - * @Override public void widgetDefaultSelected(SelectionEvent arg0) { // - * TODO Auto-generated method stub - * - * } }); - */ } private boolean press = false; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java index bd630f8e..595ca1bd 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/MobileBKUEnterNumberComposite.java @@ -16,12 +16,9 @@ package at.asit.pdfover.gui.composites; // Imports -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import org.eclipse.swt.SWT; -import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.FormAttachment; import org.eclipse.swt.layout.FormData; import org.eclipse.swt.layout.FormLayout; @@ -37,13 +34,6 @@ import at.asit.pdfover.gui.exceptions.InvalidPasswordException; import at.asit.pdfover.gui.workflow.states.State; import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.events.SelectionListener; -import org.eclipse.swt.layout.FormAttachment; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; - /** * */ 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 f6653da8..26e5480c 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 @@ -147,10 +147,10 @@ public class OutputComposite extends StateComposite { btn_open.setText("OPEN"); // 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.right = new FormAttachment(50, 0); - fd_btn_open.top = new FormAttachment(45, 0); - fd_btn_open.bottom = new FormAttachment(55, 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); btn_open.setLayoutData(fd_btn_open); btn_open.addSelectionListener(new OpenSelectionListener()); @@ -162,10 +162,10 @@ public class OutputComposite extends StateComposite { btn_save.setText("SAVE"); // Point card_size = btn_card.computeSize(SWT.DEFAULT, SWT.DEFAULT); FormData fd_btn_save = new FormData(); - fd_btn_save.left = new FormAttachment(50, 0); - fd_btn_save.right = new FormAttachment(60, 0); - fd_btn_save.top = new FormAttachment(45, 0); - fd_btn_save.bottom = new FormAttachment(55, 0); + fd_btn_save.left = new FormAttachment(50, 5); + //fd_btn_save.right = new FormAttachment(60, 0); + fd_btn_save.top = new FormAttachment(40, 0); + //fd_btn_save.bottom = new FormAttachment(55, 0); btn_save.setLayoutData(fd_btn_save); btn_save.addSelectionListener(new SaveSelectionListener()); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java index 0e8bea04..3830d6cf 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/SimpleConfigurationComposite.java @@ -19,6 +19,12 @@ package at.asit.pdfover.gui.composites; import java.io.File; import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.DropTarget; +import org.eclipse.swt.dnd.DropTargetAdapter; +import org.eclipse.swt.dnd.DropTargetEvent; +import org.eclipse.swt.dnd.FileTransfer; +import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; import org.eclipse.swt.events.MouseEvent; @@ -50,6 +56,9 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.controls.ErrorMarker; import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; +import at.asit.pdfover.gui.exceptions.InvalidNumberException; +import at.asit.pdfover.gui.exceptions.InvalidPortException; +import at.asit.pdfover.gui.workflow.ConfigurationContainer; import at.asit.pdfover.gui.workflow.states.State; import org.eclipse.swt.layout.FillLayout; @@ -195,7 +204,8 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { this.recalculateEmblemSize(); } catch (Exception e) { - this.lblEmblem.setText("No Image"); + this.lblEmblem + .setText("No Image. Drag and Drop a Image. Or use the browse button to select an emblem."); this.lblEmblem.setImage(null); if (this.origEmblem != null) { this.origEmblem.dispose(); @@ -212,27 +222,27 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { void processEmblemChanged(String filename) { try { // String filename = this.txtEmblemFile.getText(); - this.emblemFile = filename; - this.setEmblemFileInternal(filename); - this.btnUseImage.setSelection(true); + plainEmblemSetter(filename); } catch (Exception ex) { // TODO: Show error message! log.error("processEmblemChanged: ", ex); //$NON-NLS-1$ } } + /** + * @param filename + * @throws Exception + */ + private void plainEmblemSetter(String filename) throws Exception { + this.emblemFile = filename; + this.setEmblemFileInternal(filename); + this.btnUseImage.setSelection(true); + } + void processNumberChanged() { try { - this.txtMobileNumberErrorMarker.setVisible(false); - String number = this.txtMobileNumber.getText(); - this.configurationContainer.setNumber(number); - number = this.configurationContainer.getNumber(); - if (number == null) { - this.txtMobileNumber.setText(""); //$NON-NLS-1$ - return; - } - this.txtMobileNumber.setText(number); + plainMobileNumberSetter(); } catch (Exception ex) { // TODO: Show error message! this.txtMobileNumberErrorMarker.setVisible(true); @@ -242,11 +252,24 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } } + /** + * @throws InvalidNumberException + */ + private void plainMobileNumberSetter() throws InvalidNumberException { + String number = this.txtMobileNumber.getText(); + this.configurationContainer.setNumber(number); + number = this.configurationContainer.getNumber(); + if (number == null) { + this.txtMobileNumber.setText(""); //$NON-NLS-1$ + return; + } + this.txtMobileNumber.setText(number); + } + void processProxyHostChanged() { try { this.proxyHostErrorMarker.setVisible(false); - String host = this.txtProxyHost.getText(); - this.configurationContainer.setProxyHost(host); + plainProxyHostSetter(); } catch (Exception ex) { // TODO: Show error message! this.proxyHostErrorMarker.setVisible(true); @@ -255,17 +278,18 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } } + /** + * + */ + private void plainProxyHostSetter() { + String host = this.txtProxyHost.getText(); + this.configurationContainer.setProxyHost(host); + } + void processProxyPortChanged() { try { this.txtProxyPortErrorMarker.setVisible(false); - String portString = this.txtProxyPort.getText(); - int port = -1; - if (portString == null || portString.trim().equals("")) { - port = -1; - } else { - port = Integer.parseInt(portString); - } - this.configurationContainer.setProxyPort(port); + plainProxyPortSetter(); } catch (Exception ex) { // TODO: Show error message! this.txtProxyPortErrorMarker.setVisible(true); @@ -274,6 +298,20 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } } + /** + * @throws InvalidPortException + */ + private void plainProxyPortSetter() throws InvalidPortException { + String portString = this.txtProxyPort.getText(); + int port = -1; + if (portString == null || portString.trim().equals("")) { //$NON-NLS-1$ + port = -1; + } else { + port = Integer.parseInt(portString); + } + this.configurationContainer.setProxyPort(port); + } + ConfigurationComposite configurationComposite; FormData fd_txtProxyPortErrorMarker; @@ -396,45 +434,84 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } }); - /* - * Label lblDateiname = new Label(grpBildmarke, SWT.NONE); - * lblDateiname.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, - * false, false, 1, 1)); lblDateiname.setText("Dateiname:"); new - * Label(grpBildmarke, SWT.NONE); - */ + DropTarget dnd_target = new DropTarget(this.lblEmblem, DND.DROP_DEFAULT + | DND.DROP_COPY); + final FileTransfer fileTransfer = FileTransfer.getInstance(); + Transfer[] types = new Transfer[] { fileTransfer }; + dnd_target.setTransfer(types); + + dnd_target.addDropListener(new DropTargetAdapter() { + @Override + public void drop(DropTargetEvent event) { + if (fileTransfer.isSupportedType(event.currentDataType)) { + String[] files = (String[]) event.data; + if (files.length > 0) { + // Only taking first file ... + File file = new File(files[0]); + if (!file.exists()) { + log.error("File: " + files[0] + " does not exist!"); //$NON-NLS-1$//$NON-NLS-2$ + return; + } + processEmblemChanged(file.getAbsolutePath()); + } + } + } + + @Override + public void dragOperationChanged(DropTargetEvent event) { + if (event.detail == DND.DROP_DEFAULT) { + if ((event.operations & DND.DROP_COPY) != 0) { + event.detail = DND.DROP_COPY; + } else { + event.detail = DND.DROP_NONE; + } + } + } + + @Override + public void dragEnter(DropTargetEvent event) { + if (event.detail == DND.DROP_DEFAULT) { + if ((event.operations & DND.DROP_COPY) != 0) { + event.detail = DND.DROP_COPY; + } else { + event.detail = DND.DROP_NONE; + } + } + // Only drop one item! + if (event.dataTypes.length > 1) { + event.detail = DND.DROP_NONE; + return; + } + // will accept text but prefer to have files dropped + for (int i = 0; i < event.dataTypes.length; i++) { + if (fileTransfer.isSupportedType(event.dataTypes[i])) { + event.currentDataType = event.dataTypes[i]; + // files should only be copied + if (event.detail != DND.DROP_COPY) { + event.detail = DND.DROP_NONE; + } + break; + } + } + } + }); - /* - * this.txtEmblemFile = new Text(grpBildmarke, SWT.BORDER); GridData - * gd_txtEmblemFile = new GridData(SWT.FILL, SWT.FILL, false, false, 2, - * 1); gd_txtEmblemFile.widthHint = 123; - * this.txtEmblemFile.setLayoutData(gd_txtEmblemFile); - * this.txtEmblemFile.addFocusListener(new FocusListener() { - * - * @Override public void focusLost(FocusEvent e) { - * processEmblemChanged(); } - * - * @Override public void focusGained(FocusEvent e) { // Nothing to do - * here! } }); this.txtEmblemFile.addTraverseListener(new - * TraverseListener() { - * - * @Override public void keyTraversed(TraverseEvent e) { if (e.detail == - * SWT.TRAVERSE_RETURN) { processEmblemChanged(); } } }); new - * Label(grpBildmarke, SWT.NONE); - */ new Label(grpBildmarke, SWT.NONE); new Label(grpBildmarke, SWT.NONE); this.btnUseImage = new Button(grpBildmarke, SWT.CHECK); this.btnUseImage.setText("Use Image"); this.btnUseImage.addSelectionListener(new SelectionListener() { - + @Override public void widgetSelected(SelectionEvent e) { - if(SimpleConfigurationComposite.this.btnUseImage.getSelection()) { + if (SimpleConfigurationComposite.this.btnUseImage + .getSelection()) { processEmblemChanged(SimpleConfigurationComposite.this.emblemFile); } else { try { - SimpleConfigurationComposite.this.configurationContainer.setEmblem(null); + SimpleConfigurationComposite.this.configurationContainer + .setEmblem(null); } catch (InvalidEmblemFile e1) { // TODO Auto-generated catch block e1.printStackTrace(); @@ -572,35 +649,6 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { } }); - // Initialize form fields from configuration Container - String number = this.configurationContainer.getNumber(); - if (number != null) { - this.txtMobileNumber.setText(number); - } - - String emblemFile = this.configurationContainer.getEmblem(); - if (emblemFile != null && !emblemFile.trim().equals("")) { //$NON-NLS-1$ - // this.txtEmblemFile.setText(emblemFile); - this.emblemFile = emblemFile; - try { - this.setEmblemFileInternal(emblemFile, true); - } catch (Exception e1) { - // TODO Auto-generated catch block - log.error("initialize emblem: ", e1); //$NON-NLS-1$ - } - } - - int port = this.configurationContainer.getProxyPort(); - if (port > 0) { - this.txtProxyPort.setText(Integer.toString(port)); - } - - String host = this.configurationContainer.getProxyHost(); - - if (host != null) { - this.txtProxyHost.setText(host); - } - this.addListener(SWT.Resize, new Listener() { @Override @@ -638,7 +686,7 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { /** * SLF4J Logger instance **/ - private static final Logger log = LoggerFactory + static final Logger log = LoggerFactory .getLogger(SimpleConfigurationComposite.class); private ErrorMarker proxyHostErrorMarker; ErrorMarker txtMobileNumberErrorMarker; @@ -655,7 +703,61 @@ public class SimpleConfigurationComposite extends BaseConfigurationComposite { */ @Override public void doLayout() { - // TODO Auto-generated method stub + // Nothing to do here + } + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#loadConfiguration + * () + */ + @Override + public void loadConfiguration() { + // Initialize form fields from configuration Container + String number = this.configurationContainer.getNumber(); + if (number != null) { + this.txtMobileNumber.setText(number); + } + + String emblemFile = this.configurationContainer.getEmblem(); + if (emblemFile != null && !emblemFile.trim().equals("")) { //$NON-NLS-1$ + // this.txtEmblemFile.setText(emblemFile); + this.emblemFile = emblemFile; + try { + this.setEmblemFileInternal(emblemFile, true); + this.btnUseImage.setSelection(true); + } catch (Exception e1) { + // TODO Auto-generated catch block + log.error("Failed to load emblem: ", e1); //$NON-NLS-1$ + } + } + + int port = this.configurationContainer.getProxyPort(); + if (port > 0) { + this.txtProxyPort.setText(Integer.toString(port)); + } + + String host = this.configurationContainer.getProxyHost(); + + if (host != null) { + this.txtProxyHost.setText(host); + } + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.composites.BaseConfigurationComposite#validateSettings + * () + */ + @Override + public void validateSettings() throws Exception { + this.plainMobileNumberSetter(); + this.plainEmblemSetter(this.emblemFile); + this.plainProxyHostSetter(); + this.plainProxyPortSetter(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ErrorDialog.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ErrorDialog.java new file mode 100644 index 00000000..1025c1fe --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ErrorDialog.java @@ -0,0 +1,176 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.controls; + +// Imports +import java.io.InputStream; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class ErrorDialog extends Dialog { + /** + * @param parent + * @param style + * @param message + * @param exception + */ + public ErrorDialog(Shell parent, int style, String message, + Throwable exception) { + super(parent, style); + this.message = message; + + final StringBuilder result = new StringBuilder(); + result.append(exception.getLocalizedMessage()); + final String NEW_LINE = System.getProperty("line.separator"); //$NON-NLS-1$ + result.append(NEW_LINE); + result.append(NEW_LINE); + result.append(NEW_LINE); + + // add each element of the stack trace + for (StackTraceElement element : exception.getStackTrace()) { + result.append(element); + result.append(NEW_LINE); + } + this.details = result.toString(); + } + + /** + * @param parent + * @param style + * @param message + * @param details + */ + public ErrorDialog(Shell parent, int style, String message, String details) { + super(parent, style); + this.message = message; + this.details = details; + } + + private String message = null; + + private String details = null; + + /** + * SLF4J Logger instance + **/ + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory + .getLogger(ErrorDialog.class); + + /** + * Open error dialog + */ + public void open() { + Shell parent = getParent(); + final Shell shell = new Shell(parent, SWT.DIALOG_TRIM + | SWT.APPLICATION_MODAL); + shell.setText(getText()); + shell.setLayout(new FormLayout()); + + Label lblErrorImage = new Label(shell, SWT.NONE); + FormData fd_lblErrorImage = new FormData(); + fd_lblErrorImage.top = new FormAttachment(50, -16); + fd_lblErrorImage.left = new FormAttachment(0, 5); + lblErrorImage.setLayoutData(fd_lblErrorImage); + lblErrorImage.setText(""); //$NON-NLS-1$ + + String imgPath = "/img/error.png"; //$NON-NLS-1$ + + InputStream stream = this.getClass().getResourceAsStream(imgPath); + + Image orig = new Image(Display.getCurrent(), + new ImageData(stream).scaledTo(32, 32)); + + lblErrorImage.setImage(orig); + + Label lblerrorMessage = new Label(shell, SWT.NONE); + FormData fd_lblerrorMessage = new FormData(); + fd_lblerrorMessage.top = new FormAttachment(0, 5); + fd_lblerrorMessage.left = new FormAttachment(0, 42); + lblerrorMessage.setLayoutData(fd_lblerrorMessage); + lblerrorMessage.setText(this.message); + + Group group = new Group(shell, SWT.NONE); + group.setLayout(new FormLayout()); + FormData fd_group = new FormData(); + + fd_group.right = new FormAttachment(100, -5); + fd_group.top = new FormAttachment(lblerrorMessage, 5); + fd_group.left = new FormAttachment(lblErrorImage, 5); + group.setLayoutData(fd_group); + group.setText("Details"); + Button btnOk = new Button(shell, SWT.NONE); + btnOk.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + shell.dispose(); + } + }); + fd_group.bottom = new FormAttachment(btnOk, -5); + + ScrolledComposite scrolledComposite = new ScrolledComposite(group, + SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + FormData fd_scrolledComposite = new FormData(); + fd_scrolledComposite.top = new FormAttachment(0, 5); + fd_scrolledComposite.left = new FormAttachment(0, 5); + fd_scrolledComposite.bottom = new FormAttachment(100, -5); + fd_scrolledComposite.right = new FormAttachment(100, -5); + scrolledComposite.setLayoutData(fd_scrolledComposite); + scrolledComposite.setExpandHorizontal(true); + scrolledComposite.setExpandVertical(true); + + Label lblDetails = new Label(scrolledComposite, SWT.NONE); + + lblDetails.setText(this.details); + + scrolledComposite.setContent(lblDetails); + scrolledComposite.setMinSize(lblDetails.computeSize(SWT.DEFAULT, + SWT.DEFAULT)); + FormData fd_btnOk = new FormData(); + fd_btnOk.bottom = new FormAttachment(100, -5); + fd_btnOk.right = new FormAttachment(100, -5); + btnOk.setLayoutData(fd_btnOk); + btnOk.setText("Ok"); + + shell.pack(); + shell.open(); + shell.pack(); + Display display = parent.getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) + display.sleep(); + } + } +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ErrorMarker.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ErrorMarker.java index 11cefa13..01505895 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ErrorMarker.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/ErrorMarker.java @@ -18,13 +18,9 @@ package at.asit.pdfover.gui.controls; // Imports import java.io.InputStream; -import org.eclipse.swt.events.PaintEvent; -import org.eclipse.swt.events.PaintListener; -import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.graphics.ImageData; import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; @@ -39,6 +35,7 @@ public class ErrorMarker { /** * SLF4J Logger instance **/ + @SuppressWarnings("unused") private static final Logger log = LoggerFactory .getLogger(ErrorMarker.class); @@ -49,6 +46,7 @@ public class ErrorMarker { * @param style * @param exception * @param message + * @param control */ public ErrorMarker(Composite parent, int style, Throwable exception, String message, Control control) { @@ -74,19 +72,35 @@ public class ErrorMarker { this.lbl.setImage(this.orig); } + /** + * Sets the layout data + * @param object the layout data + */ public void setLayoutData(Object object) { this.lbl.setLayoutData(object); } + /** + * Sets the visibilty + * @param visible the visibilty + */ public void setVisible(boolean visible) { this.lbl.setVisible(visible); } + /** + * Sets the tooltip text + * @param msg the tooltip text + */ public void setToolTipText(String msg) { this.lbl.setToolTipText(msg); } + /** + * Scales the image to the new size + * @param size + */ public void resize(Point size) { String imgPath = "/img/error.png"; //$NON-NLS-1$ @@ -101,6 +115,10 @@ public class ErrorMarker { this.lbl.setImage(this.orig); } + /** + * Gets the size of the underlying label + * @return the size + */ public Point getSize() { return this.lbl.getSize(); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarButton.java new file mode 100644 index 00000000..631ee3e8 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarButton.java @@ -0,0 +1,183 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.controls; + +// Imports +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Region; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public abstract class MainBarButton extends Canvas { + /** + * @param parent + * @param style + */ + public MainBarButton(Composite parent, int style) { + super(parent, style); + this.addPaintListener(new PaintListener() { + + @Override + public void paintControl(PaintEvent e) { + MainBarButton.this.paintButton(e); + } + }); + + this.addListener(SWT.Resize, new Listener() { + + @Override + public void handleEvent(Event event) { + MainBarButton.this.setRegion(MainBarButton.this + .getCustomRegion()); + MainBarButton.this.redraw(); + } + }); + + this.inactiveBackground = new Color(getDisplay(), 0x4B, 0x95, 0x00); + this.activeBackground = new Color(getDisplay(), 0x98, 0xF2, 0x3D); + + } + + private Color inactiveBackground = null; + + /** + * @param inactiveBackground + * the inactiveBackground to set + */ + public void setInactiveBackground(Color inactiveBackground) { + this.inactiveBackground = inactiveBackground; + } + + /** + * @param activeBackground + * the activeBackground to set + */ + public void setActiveBackground(Color activeBackground) { + this.activeBackground = activeBackground; + } + + private Color activeBackground = null; + + private String text = ""; //$NON-NLS-1$ + + private boolean active = true; + + private Image image = null; + + /** + * @return the imgage + */ + public Image getImage() { + return this.image; + } + + /** + * @param imgage + * the imgage to set + */ + public void setImage(Image image) { + this.image = image; + } + + /** + * Sets if this button is active + * + * @param active + * the active state + */ + public void setActive(boolean active) { + this.active = active; + if (this.active) { + this.setBackground(this.activeBackground); + } else { + this.setBackground(this.inactiveBackground); + } + } + + /** + * Gets if this button is active + * + * @return the active state + */ + public boolean getActive() { + return this.active; + } + + /** + * @return the text + */ + public String getText() { + return this.text; + } + + /** + * @param text + * the text to set + */ + public void setText(String text) { + this.text = text; + } + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(MainBarButton.class); + + /** + * @param e + */ + protected void paintButton(PaintEvent e) { + Point size = this.getSize(); + int height = size.y - 2; + + int width = size.x; + + if (this.image == null) { + int textlen = 0; + + if (this.getText() != null) { + textlen = this.getText().length(); + } + + int texty = (height - e.gc.getFontMetrics().getHeight()) / 2; + int textx = (width - e.gc.getFontMetrics().getAverageCharWidth() + * textlen) / 2; + e.gc.drawText(this.getText(), textx, texty); + } else { + int imgx = (width - height) / 2; + Image tmp = new Image(getDisplay(), this.image.getImageData().scaledTo(height, height)); + e.gc.drawImage(tmp, imgx, 0); + } + } + + /** + * @return + */ + protected abstract Region getCustomRegion(); +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarEndButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarEndButton.java new file mode 100644 index 00000000..b80b9645 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarEndButton.java @@ -0,0 +1,97 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.controls; + +// Imports +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Region; +import org.eclipse.swt.widgets.Composite; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class MainBarEndButton extends MainBarButton { + /** + * @param parent + * @param style + */ + public MainBarEndButton(Composite parent, int style) { + super(parent, style); + } + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(MainBarEndButton.class); + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.controls.MainBarButton#paintButton(org.eclipse.swt + * .events.PaintEvent) + */ + /*@Override + protected void paintButton(PaintEvent e) { + Point size = this.getSize(); + int height = size.y - 2; + + int split = 10; + int width = size.x; + + int textlen = 0; + + if(this.getText() != null) { + textlen = this.getText().length(); + } + + e.gc.drawLine(0, 0, width, 0); + e.gc.drawLine(width, 0, width+split, (height) / 2); + e.gc.drawLine(width, height, 0, height); + e.gc.drawLine(0, height, 0+split, (height) / 2); + e.gc.drawLine(0+split, (height) / 2, 0, 0); + + int texty = (height - e.gc.getFontMetrics().getHeight()) / 2; + int textx = (width - e.gc.getFontMetrics().getAverageCharWidth() * textlen) / 2; + e.gc.drawText(this.getText(), textx, texty); + }*/ + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.controls.MainBarButton#getCustomRegion() + */ + @Override + protected Region getCustomRegion() { + Point size = this.getSize(); + + int height = size.y - 2; + + int split = 10; + + int width = size.x; + + Region reg = new Region(); + reg.add(new int[] { 0, 0, width, 0, width, height, 0, height, + 0 + split, (height) / 2, 0, 0 }); + return reg; + } + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarMiddleButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarMiddleButton.java new file mode 100644 index 00000000..5b9b580f --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarMiddleButton.java @@ -0,0 +1,100 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.controls; + +// Imports +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Region; +import org.eclipse.swt.widgets.Composite; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class MainBarMiddleButton extends MainBarButton { + /** + * @param parent + * @param style + */ + public MainBarMiddleButton(Composite parent, int style) { + super(parent, style); + } + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(MainBarMiddleButton.class); + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.controls.MainBarButton#paintButton(org.eclipse.swt.events.PaintEvent) + */ + /*@Override + protected void paintButton(PaintEvent e) { + Point size = this.getSize(); + + int height = size.y - 2; + + int split = 10; + int width = size.x - split; + + e.gc.drawLine(0, 0, width, 0); + e.gc.drawLine(width, 0, width+split, (height) / 2); + e.gc.drawLine(width+split, (height) / 2, width, height); + e.gc.drawLine(width, height, 0, height); + e.gc.drawLine(0, height, 0+split, (height) / 2); + e.gc.drawLine(0+split, (height) / 2, 0, 0); + + int textlen = 0; + + if(getText() != null) { + textlen = this.getText().length(); + } + + int texty = (height - e.gc.getFontMetrics().getHeight()) / 2; + int textx = (width - e.gc.getFontMetrics().getAverageCharWidth() * textlen) / 2; + e.gc.drawText(this.getText(), textx, texty); + }*/ + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.controls.MainBarButton#getCustomRegion() + */ + @Override + protected Region getCustomRegion() { + Point size = this.getSize(); + + int height = size.y - 2; + + int split = 10; + + int width = size.x - split; + + Region reg = new Region(); + reg.add(new int[] { + 0, 0, + width, 0, + width + split, (height) / 2, + width, height, + 0, height, + 0+split, (height) / 2, + 0, 0 }); + + return reg; + } + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarRectangleButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarRectangleButton.java new file mode 100644 index 00000000..edac29e5 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarRectangleButton.java @@ -0,0 +1,87 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.controls; + +// Imports +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Region; +import org.eclipse.swt.widgets.Composite; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class MainBarRectangleButton extends MainBarButton { + /** + * @param parent + * @param style + */ + public MainBarRectangleButton(Composite parent, int style) { + super(parent, style); + this.setActiveBackground(null); + this.setInactiveBackground(null); + } + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(MainBarRectangleButton.class); + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.controls.MainBarButton#paintButton(org.eclipse.swt.events.PaintEvent) + */ + /*@Override + protected void paintButton(PaintEvent e) { + Point size = this.getSize(); + + int height = size.y - 2; + + int width = size.x; + + int textlen = 0; + if(getText() != null) { + textlen = getText().length(); + } + + e.gc.drawLine(0, 0, width, 0); + e.gc.drawLine(width, 0, width, height); + e.gc.drawLine(width, height, 0, height); + e.gc.drawLine(0, height, 0, 0); + int texty = (height - e.gc.getFontMetrics().getHeight()) / 2; + int textx = (width - e.gc.getFontMetrics().getAverageCharWidth() * textlen) / 2; + e.gc.drawText(getText(), textx, texty); + }*/ + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.controls.MainBarButton#getCustomRegion() + */ + @Override + protected Region getCustomRegion() { + Point size = this.getSize(); + + int height = size.y - 2; + + int width = size.x; + + Region reg = new Region(); + reg.add(new int[] { 0, 0, width, 0, width, height, 0, height, 0, 0 }); + return reg; + } + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarStartButton.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarStartButton.java new file mode 100644 index 00000000..2577ce40 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/controls/MainBarStartButton.java @@ -0,0 +1,91 @@ +/* + * Copyright 2012 by A-SIT, Secure Information Technology Center Austria + * + * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by + * the European Commission - subsequent versions of the EUPL (the "Licence"); + * You may not use this work except in compliance with the Licence. + * You may obtain a copy of the Licence at: + * http://joinup.ec.europa.eu/software/page/eupl + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the Licence is distributed on an "AS IS" basis, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the Licence for the specific language governing permissions and + * limitations under the Licence. + */ +package at.asit.pdfover.gui.controls; + +// Imports +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Region; +import org.eclipse.swt.widgets.Composite; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + */ +public class MainBarStartButton extends MainBarButton { + /** + * @param parent + * @param style + */ + public MainBarStartButton(Composite parent, int style) { + super(parent, style); + } + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(MainBarStartButton.class); + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.controls.MainBarButton#paintButton(org.eclipse.swt.events.PaintEvent) + */ + /* + @Override + protected void paintButton(PaintEvent e) { + Point size = this.getSize(); + + int height = size.y - 2; + + int split = 10; + int width = size.x - split; + + int textlen = 0; + if(getText() != null) { + textlen = getText().length(); + } + + e.gc.drawLine(0, 0, width, 0); + e.gc.drawLine(width, 0, width + split, (height) / 2); + e.gc.drawLine(width + split, (height) / 2, width, height); + e.gc.drawLine(width, height, 0, height); + e.gc.drawLine(0, height, 0, 0); + int texty = (height - e.gc.getFontMetrics().getHeight()) / 2; + int textx = (width - e.gc.getFontMetrics().getAverageCharWidth() * textlen) / 2; + e.gc.drawText(getText(), textx, texty); + }*/ + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.controls.MainBarButton#getRegion() + */ + @Override + protected Region getCustomRegion() { + Point size = this.getSize(); + + int height = size.y - 2; + + int split = 10; + + int width = size.x - split; + + Region reg = new Region(); + reg.add(new int[] { 0, 0, width, 0, width + split, + (height) / 2, width, height, 0, height, 0, 0 }); + return reg; + } + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java index 702fa6bb..a669803b 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java @@ -68,6 +68,12 @@ public interface ConfigManipulator { public static final String PROXY_PORT_CONFIG = "PROXY_PORT"; //$NON-NLS-1$ /** + * The output folder config parameter + */ + public static final String OUTPUT_FOLDER_CONFIG = "OUTPUT_FOLDER"; //$NON-NLS-1$ + + + /** * Sets the default bku type * @param bku the bku type */ @@ -119,6 +125,12 @@ public interface ConfigManipulator { public void setConfigurationFile(String configurationFile); /** + * Sets the default output folder + * @param outputFolder the default output folder + */ + public void setDefaultOutputFolder(String outputFolder); + + /** * Saves the current configuration to the current configuration file * @throws IOException */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java index 8ada4d2d..1adc45a4 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProvider.java @@ -15,6 +15,9 @@ */ package at.asit.pdfover.gui.workflow; +import java.io.IOException; +import java.io.InputStream; + import at.asit.pdfover.signator.BKUs; import at.asit.pdfover.signator.SignaturePosition; @@ -25,6 +28,12 @@ public interface ConfigProvider { //TODO: define interface for config provider .... /** + * Regex for parsing signature position + */ + public static final String SIGN_POS_REGEX = "(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?);p=(\\d))|(auto)|(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?))"; //$NON-NLS-1$ + + + /** * Gets the configuration file * @return the configuration file */ @@ -71,4 +80,17 @@ public interface ConfigProvider { * @return the default configured SignaturePosition or null if not configured */ public SignaturePosition getDefaultSignaturePosition(); + + /** + * Gets the default output folder for signed documents + * @return the default output folder + */ + public String getDefaultOutputFolder(); + + /** + * Loads the current configuration to the current configuration file + * @param configSource + * @throws IOException + */ + public void loadConfiguration(InputStream configSource) throws IOException; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java index 6a128e73..529f9d5c 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java @@ -19,7 +19,10 @@ package at.asit.pdfover.gui.workflow; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,36 +37,46 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { /** * SLF4J Logger instance **/ - @SuppressWarnings("unused") private static final Logger log = LoggerFactory .getLogger(ConfigProviderImpl.class); - + private BKUs defaultBKU = BKUs.NONE; - + private SignaturePosition defaultSignaturePosition = null; - - private String defaultMobileNumber = null; - - private String defaultPassword = null; - - private String emblem = null; - - private String proxyHost = null; - + + /** + * An Emtpy property entry + */ + public static final String STRING_EMPTY = ""; //$NON-NLS-1$ + + private String defaultMobileNumber = STRING_EMPTY; + + private String defaultPassword = STRING_EMPTY; + + private String emblem = STRING_EMPTY; + + private String proxyHost = STRING_EMPTY; + private String configurationFile = ConfigManipulator.DEFAULT_CONFIG_FILE; - + private int proxyPort = -1; - + + private String outputFolder = STRING_EMPTY; + /** * Sets the default bku type - * @param bku the bku type + * + * @param bku + * the bku type */ @Override public void setDefaultBKU(BKUs bku) { this.defaultBKU = bku; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultBKU() */ @Override @@ -74,15 +87,19 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { /** * Sets the default signature position * - * @param signaturePosition the default signature position + * @param signaturePosition + * the default signature position */ @Override public void setDefaultSignaturePosition(SignaturePosition signaturePosition) { this.defaultSignaturePosition = signaturePosition; } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultSignaturePosition() + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultSignaturePosition() */ @Override public SignaturePosition getDefaultSignaturePosition() { @@ -91,39 +108,47 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { /** * Sets the default mobile number - * @param number the default mobile number + * + * @param number + * the default mobile number */ @Override public void setDefaultMobileNumber(String number) { - if(number == null || number.trim().equals("")) { //$NON-NLS-1$ - this.defaultMobileNumber = null; + if (number == null || number.trim().equals("")) { //$NON-NLS-1$ + this.defaultMobileNumber = STRING_EMPTY; } else { this.defaultMobileNumber = number; } } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultMobileNumber() */ @Override public String getDefaultMobileNumber() { return this.defaultMobileNumber; } - + /** * Sets the default password - * @param password the default password + * + * @param password + * the default password */ @Override public void setDefaultPassword(String password) { - if(password == null || password.trim().equals("")) { //$NON-NLS-1$ - this.defaultPassword = null; + if (password == null || password.trim().equals("")) { //$NON-NLS-1$ + this.defaultPassword = STRING_EMPTY; } else { this.defaultPassword = password; } } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultPassword() */ @Override @@ -134,18 +159,21 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { /** * Sets the default emblem * - * @param emblem the default emblem + * @param emblem + * the default emblem */ @Override public void setDefaultEmblem(String emblem) { - if(emblem == null || emblem.trim().equals("")) { //$NON-NLS-1$ - this.emblem = null; + if (emblem == null || emblem.trim().equals("")) { //$NON-NLS-1$ + this.emblem = STRING_EMPTY; } else { this.emblem = emblem; } } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultEmblem() */ @Override @@ -155,18 +183,22 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { /** * Sets the proxy host - * @param host the proxy host + * + * @param host + * the proxy host */ @Override public void setProxyHost(String host) { - if(host == null || host.trim().equals("")) { //$NON-NLS-1$ - this.emblem = null; + if (host == null || host.trim().equals("")) { //$NON-NLS-1$ + this.proxyHost = STRING_EMPTY; } else { - this.emblem = host; + this.proxyHost = host; } } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.ConfigProvider#getProxyHost() */ @Override @@ -177,14 +209,17 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { /** * Sets the proxy port * - * @param port the proxy port + * @param port + * the proxy port */ @Override public void setProxyPort(int port) { this.proxyPort = port; } - - /* (non-Javadoc) + + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.ConfigProvider#getProxyPort() */ @Override @@ -192,15 +227,21 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { return this.proxyPort; } - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.ConfigManipulator#setConfigurationFile(java.lang.String) + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.workflow.ConfigManipulator#setConfigurationFile(java + * .lang.String) */ @Override public void setConfigurationFile(String configurationFile) { this.configurationFile = configurationFile; } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.ConfigProvider#getConfigurationFile() */ @Override @@ -208,41 +249,188 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { return this.configurationFile; } - /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.ConfigManipulator#saveCurrentConfiguration() + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.workflow.ConfigManipulator#saveCurrentConfiguration() */ @Override - public void saveCurrentConfiguration() throws IOException{ + public void saveCurrentConfiguration() throws IOException { String filename = this.getConfigurationFile(); - + File configFile = new File(filename); - + Properties props = new Properties(); - + props.clear(); + props.setProperty(BKU_CONFIG, this.getDefaultBKU().toString()); props.setProperty(PROXY_HOST_CONFIG, this.getProxyHost()); - props.setProperty(PROXY_PORT_CONFIG, Integer.toString(this.getProxyPort())); + props.setProperty(PROXY_PORT_CONFIG, + Integer.toString(this.getProxyPort())); props.setProperty(EMBLEM_CONFIG, this.getDefaultEmblem()); props.setProperty(MOBILE_NUMBER_CONFIG, this.getDefaultMobileNumber()); - + props.setProperty(OUTPUT_FOLDER_CONFIG, this.getDefaultOutputFolder()); + SignaturePosition pos = this.getDefaultSignaturePosition(); - - if(pos == null) { + + if (pos == null) { props.setProperty(SIGNATURE_POSITION_CONFIG, ""); //$NON-NLS-1$ - } else if(pos.useAutoPositioning()) { + } else if (pos.useAutoPositioning()) { props.setProperty(SIGNATURE_POSITION_CONFIG, "auto"); //$NON-NLS-1$ } else { - props.setProperty(SIGNATURE_POSITION_CONFIG, - String.format("x=%f;y=%f;p=%d", //$NON-NLS-1$ - pos.getX(), - pos.getY(), - pos.getPage())); + props.setProperty(SIGNATURE_POSITION_CONFIG, + String.format("x=%f;y=%f;p=%d", //$NON-NLS-1$ + pos.getX(), pos.getY(), pos.getPage())); } - + FileOutputStream outputstream = new FileOutputStream(configFile, false); - + props.store(outputstream, "Configuration file was generated!"); //$NON-NLS-1$ + + log.info("Configuration file saved to " + configFile.getAbsolutePath()); //$NON-NLS-1$ + + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.workflow.ConfigManipulator#setDefaultOutputFolder + * (java.lang.String) + */ + @Override + public void setDefaultOutputFolder(String outputFolder) { + this.outputFolder = outputFolder; + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.workflow.ConfigProvider#getDefaultOutputFolder() + */ + @Override + public String getDefaultOutputFolder() { + return this.outputFolder; + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.workflow.ConfigProvider#loadConfiguration(java.io + * .InputStream) + */ + @Override + public void loadConfiguration(InputStream configSource) throws IOException { + + Properties config = new Properties(); + config.load(configSource); + + // Set Emblem + this.setDefaultEmblem(config + .getProperty(ConfigManipulator.EMBLEM_CONFIG)); + + // Set Mobile Phone Number + this.setDefaultMobileNumber(config + .getProperty(ConfigManipulator.MOBILE_NUMBER_CONFIG)); + + // Set Proxy Host + this.setProxyHost(config + .getProperty(ConfigManipulator.PROXY_HOST_CONFIG)); + + // Set Output Folder + this.setDefaultOutputFolder(config + .getProperty(ConfigManipulator.OUTPUT_FOLDER_CONFIG)); + + // Set Proxy Port + String proxyPortString = config + .getProperty(ConfigManipulator.PROXY_PORT_CONFIG); + + if (proxyPortString != null && !proxyPortString.trim().equals("")) { //$NON-NLS-1$ + int port = Integer.parseInt(proxyPortString); + + if (port > 0 && port <= 0xFFFF) { + this.setProxyPort(port); + } else { + log.warn("Proxy port is out of range!: " + port); //$NON-NLS-1$ + } + } + + // Set Default BKU + String bkuString = config.getProperty(ConfigManipulator.BKU_CONFIG); + + BKUs defaultBKU = BKUs.NONE; + + try { + defaultBKU = BKUs.valueOf(bkuString); + } catch (IllegalArgumentException ex) { + log.error("Invalid BKU config value " + bkuString + " using none!"); //$NON-NLS-1$ //$NON-NLS-2$ + defaultBKU = BKUs.NONE; + } catch (NullPointerException ex) { + log.error("Invalid BKU config value " + bkuString + " using none!"); //$NON-NLS-1$ //$NON-NLS-2$ + defaultBKU = BKUs.NONE; + } + + this.setDefaultBKU(defaultBKU); + + // Set Signature Position + String signaturePosition = config + .getProperty(ConfigManipulator.SIGNATURE_POSITION_CONFIG); + + SignaturePosition position = null; + + if (signaturePosition != null && !signaturePosition.trim().equals("")) { //$NON-NLS-1$ + + signaturePosition = signaturePosition.trim().toLowerCase(); + + Pattern pattern = Pattern.compile(SIGN_POS_REGEX); + + Matcher matcher = pattern.matcher(signaturePosition); + + if (matcher.matches()) { + if (matcher.groupCount() == 8) { + if (matcher.group(1) != null) { + // we have format: x=..;y=..;p=... + try { + // group 2 = x value + float x = Float.parseFloat(matcher.group(2)); + + // group 3 = y value + float y = Float.parseFloat(matcher.group(3)); + + // group 4 = p value + int p = Integer.parseInt(matcher.group(3)); + + position = new SignaturePosition(x, y, p); + } catch (NumberFormatException ex) { + log.error( + "Signature Position read from config failed: Not a valid number", ex); //$NON-NLS-1$ + } + } else if (matcher.group(5) != null) { + // we have format auto + position = new SignaturePosition(); + } else if (matcher.group(6) != null) { + // we have format x=...;y=...; + // group 7 = x value + float x = Float.parseFloat(matcher.group(7)); + + // group 8 = y value + float y = Float.parseFloat(matcher.group(8)); + + position = new SignaturePosition(x, y); + } + } else { + log.error("Signature Position read from config failed: wrong group Count!"); //$NON-NLS-1$ + } + } else { + log.error("Signature Position read from config failed: not matching string"); //$NON-NLS-1$ + } + + } + + this.setDefaultSignaturePosition(position); } - + } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainer.java index 66245123..796a4cec 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainer.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainer.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.composites; +package at.asit.pdfover.gui.workflow; import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; import at.asit.pdfover.gui.exceptions.InvalidNumberException; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainerImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainerImpl.java index dd305201..081f4072 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationContainerImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigurationContainerImpl.java @@ -13,7 +13,7 @@ * See the Licence for the specific language governing permissions and * limitations under the Licence. */ -package at.asit.pdfover.gui.composites; +package at.asit.pdfover.gui.workflow; // Imports import java.io.File; @@ -38,6 +38,7 @@ public class ConfigurationContainerImpl implements ConfigurationContainer { /** * SLF4J Logger instance **/ + @SuppressWarnings("unused") private static final Logger log = LoggerFactory .getLogger(ConfigurationContainerImpl.class); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java index 4b468ad8..52dfb5c9 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java @@ -19,6 +19,9 @@ package at.asit.pdfover.gui.workflow.states; import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.composites.ConfigurationComposite; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; @@ -30,6 +33,7 @@ public class ConfigurationUIState extends State { /** * SLF4J Logger instance **/ + @SuppressWarnings("unused") private static final Logger log = LoggerFactory .getLogger(ConfigurationUIState.class); @@ -41,6 +45,7 @@ public class ConfigurationUIState extends State { this.configurationComposite = this.stateMachine.getGUIProvider().createComposite(ConfigurationComposite.class, SWT.RESIZE, this); this.configurationComposite.setConfigManipulator(this.stateMachine.getConfigManipulator()); + this.configurationComposite.setConfigProvider(this.stateMachine.getConfigProvider()); } return this.configurationComposite; @@ -88,6 +93,8 @@ public class ConfigurationUIState extends State { @Override public void updateMainWindowBehavior() { // Leave the state as it is + MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + behavior.setMainBarVisible(false); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 234cd215..f39deada 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -41,7 +41,7 @@ public class MobileBKUState extends State { */ public MobileBKUState(StateMachine stateMachine) { super(stateMachine); - this.status = new MobileBKUStatus(); + this.status = new MobileBKUStatus(this.stateMachine.getConfigProvider()); } /** diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java index 50aee387..2ebc3f39 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java @@ -16,6 +16,10 @@ package at.asit.pdfover.gui.workflow.states; //Imports +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -23,8 +27,10 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.MainWindowBehavior; import at.asit.pdfover.gui.composites.OutputComposite; +import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; +import at.asit.pdfover.signator.DocumentSource; /** * Procduces the output of the signature process. (save file, open file) @@ -42,48 +48,74 @@ public class OutputState extends State { * SFL4J Logger instance **/ @SuppressWarnings("unused") - private static final Logger log = LoggerFactory.getLogger(OutputState.class); - + private static final Logger log = LoggerFactory + .getLogger(OutputState.class); + private OutputComposite outputComposite = null; private OutputComposite getSelectionComposite() { if (this.outputComposite == null) { - this.outputComposite = - this.stateMachine.getGUIProvider().createComposite(OutputComposite.class, SWT.RESIZE, this); + this.outputComposite = this.stateMachine.getGUIProvider() + .createComposite(OutputComposite.class, SWT.RESIZE, this); } return this.outputComposite; } - + + private boolean saved = false; + @Override public void run() { // TODO Preform output operations ... end workflow - + Status status = this.stateMachine.getStatus(); - - if(status.getSignResult() != null) - { + + if (status.getSignResult() != null) { OutputComposite outputComposite = this.getSelectionComposite(); - outputComposite.setSignedDocument(status.getSignResult().getSignedDocument()); + outputComposite.setSignedDocument(status.getSignResult() + .getSignedDocument()); this.stateMachine.getGUIProvider().display(outputComposite); - - /*DocumentSource signedDocument = status.getSignResult().getSignedDocument(); - - FileOutputStream output; - try { - output = new FileOutputStream(new File("/tmp/test.pdf")); - output.write(signedDocument.getByteArray(), 0, signedDocument.getByteArray().length); - output.close(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - }*/ + + if (!this.saved) { + this.saved = true; + String outputFolder = this.stateMachine.getConfigProvider() + .getDefaultOutputFolder(); + String fileName = status.getDocument().getName(); + if (outputFolder != null && !outputFolder.trim().equals("")) { //$NON-NLS-1$ + DocumentSource signedDocument = status.getSignResult().getSignedDocument(); + FileOutputStream output; + try { + output = new FileOutputStream(new File(outputFolder + "/" + fileName + "_signed.pdf")); //$NON-NLS-1$ //$NON-NLS-2$ + output.write(signedDocument.getByteArray(), 0, + signedDocument.getByteArray().length); + output.close(); + } catch (IOException e) { + log.error("Failed to save signed document to configured output folder.", e); //$NON-NLS-1$ + ErrorDialog dialog = new ErrorDialog(outputComposite.getShell(), SWT.NONE, "Failed to save signed document to configured output folder.", e); + dialog.open(); + } + } + } + + /* + * DocumentSource signedDocument = + * status.getSignResult().getSignedDocument(); + * + * FileOutputStream output; try { output = new FileOutputStream(new + * File("/tmp/test.pdf")); + * output.write(signedDocument.getByteArray(), 0, + * signedDocument.getByteArray().length); output.close(); } catch + * (IOException e) { // TODO Auto-generated catch block + * e.printStackTrace(); } + */ } - - //this.stateMachine.exit(); + + // this.stateMachine.exit(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.states.State#cleanUp() */ @Override @@ -92,12 +124,15 @@ public class OutputState extends State { this.outputComposite.dispose(); } - /* (non-Javadoc) + /* + * (non-Javadoc) + * * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + MainWindowBehavior behavior = this.stateMachine.getStatus() + .getBehavior(); behavior.reset(); behavior.setEnabled(Buttons.CONFIG, true); behavior.setEnabled(Buttons.OPEN, true); @@ -110,7 +145,7 @@ public class OutputState extends State { } @Override - public String toString() { + public String toString() { return this.getClass().getName(); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java index b4b05318..a1de09d0 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java @@ -20,9 +20,6 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,9 +32,7 @@ import at.asit.pdfover.gui.cliarguments.PhoneNumberArgument; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.signator.BKUs; import at.asit.pdfover.signator.Signator; -import at.asit.pdfover.signator.SignaturePosition; /** * Starting state of workflow proccess @@ -46,11 +41,7 @@ import at.asit.pdfover.signator.SignaturePosition; */ public class PrepareConfigurationState extends State { - /** - * Regex for parsing signature position - */ - public static final String SIGN_POS_REGEX = "(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?);p=(\\d))|(auto)|(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?))"; //$NON-NLS-1$ - + /** * @param stateMachine */ @@ -81,10 +72,12 @@ public class PrepareConfigurationState extends State { private void initializeFromConfigurationFile(String filename) throws InitializationException { try { - Properties config = new Properties(); try { - config.load(new FileInputStream(filename)); + this.stateMachine.getConfigProvider().loadConfiguration(new FileInputStream(filename)); + + log.info("Loaded config from file : " + filename); //$NON-NLS-1$ + } catch (FileNotFoundException ex) { if (filename.equals(ConfigManipulator.DEFAULT_CONFIG_FILE)) { // we only check for resource config file if it is the @@ -92,7 +85,9 @@ public class PrepareConfigurationState extends State { try { InputStream is = this.getClass().getResourceAsStream( "/" + filename); //$NON-NLS-1$ - config.load(is); + this.stateMachine.getConfigProvider().loadConfiguration(is); + + log.info("Loaded config from resource : " + filename); //$NON-NLS-1$ } catch (Exception eex) { throw ex; } @@ -100,112 +95,7 @@ public class PrepareConfigurationState extends State { throw ex; } } - - // Load ok ... - ConfigManipulator configManipulator = this.stateMachine - .getConfigManipulator(); - - // Set Emblem - configManipulator.setDefaultEmblem(config - .getProperty(ConfigManipulator.EMBLEM_CONFIG)); - - // Set Mobile Phone Number - configManipulator.setDefaultMobileNumber(config - .getProperty(ConfigManipulator.MOBILE_NUMBER_CONFIG)); - - // Set Proxy Host - configManipulator.setProxyHost(config - .getProperty(ConfigManipulator.PROXY_HOST_CONFIG)); - - // Set Proxy Port - String proxyPortString = config - .getProperty(ConfigManipulator.PROXY_PORT_CONFIG); - - if (proxyPortString != null && !proxyPortString.trim().equals("")) { //$NON-NLS-1$ - int port = Integer.parseInt(proxyPortString); - - if (port > 0 && port <= 0xFFFF) { - configManipulator.setProxyPort(port); - } else { - log.warn("Proxy port is out of range!: " + port); //$NON-NLS-1$ - } - } - - // Set Default BKU - String bkuString = config.getProperty(ConfigManipulator.BKU_CONFIG); - - BKUs defaultBKU = BKUs.NONE; - - try { - defaultBKU = BKUs.valueOf(bkuString); - } catch (IllegalArgumentException ex) { - log.error("Invalid BKU config value " + bkuString + " using none!"); //$NON-NLS-1$ //$NON-NLS-2$ - defaultBKU = BKUs.NONE; - } catch (NullPointerException ex) { - log.error("Invalid BKU config value " + bkuString + " using none!"); //$NON-NLS-1$ //$NON-NLS-2$ - defaultBKU = BKUs.NONE; - } - - configManipulator.setDefaultBKU(defaultBKU); - - // Set Signature Position - String signaturePosition = config - .getProperty(ConfigManipulator.SIGNATURE_POSITION_CONFIG); - - SignaturePosition position = null; - - if (signaturePosition != null - && !signaturePosition.trim().equals("")) { //$NON-NLS-1$ - - signaturePosition = signaturePosition.trim().toLowerCase(); - - Pattern pattern = Pattern.compile(SIGN_POS_REGEX); - - Matcher matcher = pattern.matcher(signaturePosition); - - if (matcher.matches()) { - if (matcher.groupCount() == 8) { - if (matcher.group(1) != null) { - // we have format: x=..;y=..;p=... - try { - // group 2 = x value - float x = Float.parseFloat(matcher.group(2)); - - // group 3 = y value - float y = Float.parseFloat(matcher.group(3)); - - // group 4 = p value - int p = Integer.parseInt(matcher.group(3)); - - position = new SignaturePosition(x, y, p); - } catch (NumberFormatException ex) { - log.error( - "Signature Position read from config failed: Not a valid number", ex); //$NON-NLS-1$ - } - } else if (matcher.group(5) != null) { - // we have format auto - position = new SignaturePosition(); - } else if (matcher.group(6) != null) { - // we have format x=...;y=...; - // group 7 = x value - float x = Float.parseFloat(matcher.group(7)); - - // group 8 = y value - float y = Float.parseFloat(matcher.group(8)); - - position = new SignaturePosition(x, y); - } - } else { - log.error("Signature Position read from config failed: wrong group Count!"); //$NON-NLS-1$ - } - } else { - log.error("Signature Position read from config failed: not matching string"); //$NON-NLS-1$ - } - - } - - configManipulator.setDefaultSignaturePosition(position); - + } catch (IOException ex) { throw new InitializationException( "Failed to read configuration from config file", ex); //$NON-NLS-1$ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java index 1b7ed600..88acc84b 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java @@ -23,9 +23,11 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.MainWindowBehavior; import at.asit.pdfover.gui.composites.WaitingComposite; +import at.asit.pdfover.gui.workflow.ConfigProvider; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; import at.asit.pdfover.signator.BKUs; +import at.asit.pdfover.signator.FileNameEmlbem; import at.asit.pdfover.signator.PDFFileDocumentSource; import at.asit.pdfover.signator.SignatureParameter; import at.asit.pdfover.signator.Signer; @@ -57,6 +59,11 @@ public class PrepareSigningState extends State { @Override public void run() { try { + + Status status = this.state.stateMachine.getStatus(); + + ConfigProvider configuration = this.state.stateMachine.getConfigProvider(); + if(this.state.signer == null) { this.state.signer = this.state.stateMachine.getPDFSigner().getPDFSigner(); } @@ -65,12 +72,15 @@ public class PrepareSigningState extends State { this.state.signatureParameter = this.state.signer.newParameter(); } - this.state.signatureParameter.setInputDocument(new PDFFileDocumentSource(this.state.stateMachine.getStatus().getDocument())); - this.state.signatureParameter.setSignatureDevice(this.state.stateMachine.getStatus().getBKU()); - this.state.signatureParameter.setSignaturePosition(this.state.stateMachine.getStatus().getSignaturePosition()); + this.state.signatureParameter.setInputDocument(new PDFFileDocumentSource(status.getDocument())); + this.state.signatureParameter.setSignatureDevice(status.getBKU()); + this.state.signatureParameter.setSignaturePosition(status.getSignaturePosition()); // TODO: Fill library specific signature Parameters ... - // TODO: setEmblem etc. + + if(configuration.getDefaultEmblem() != null && !configuration.getDefaultEmblem().equals("")) { //$NON-NLS-1$ + this.state.signatureParameter.setEmblem(new FileNameEmlbem(configuration.getDefaultEmblem())); + } this.state.signingState = this.state.signer.prepare(this.state.signatureParameter); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java index 1ea265ad..a1868462 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/ATrustHelper.java @@ -22,7 +22,6 @@ import java.util.regex.Pattern; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.composites.MobileBKUEnterNumberComposite; import at.asit.pdfover.gui.exceptions.InvalidNumberException; import at.asit.pdfover.gui.exceptions.InvalidPasswordException; import at.asit.pdfover.gui.exceptions.PasswordTooLongException; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java index 344eaf58..fe85d492 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/MobileBKUStatus.java @@ -19,6 +19,8 @@ package at.asit.pdfover.gui.workflow.states.mobilebku; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.workflow.ConfigProvider; + /** * */ @@ -26,16 +28,22 @@ public class MobileBKUStatus { /** * SLF4J Logger instance **/ + @SuppressWarnings("unused") private static final Logger log = LoggerFactory .getLogger(MobileBKUStatus.class); + /** + * Maximum number of TAN tries! + */ public static final int MOBILE_MAX_TAN_TRIES = 3; /** * Constructor + * @param provider */ - public MobileBKUStatus() { - // TODO: Fill number and password with possible config values! + public MobileBKUStatus(ConfigProvider provider) { + this.setPhoneNumber(provider.getDefaultMobileNumber()); + this.setMobilePassword(provider.getDefaultPassword()); } String viewstate; @@ -122,7 +130,7 @@ public class MobileBKUStatus { } /** - * @param credentialsFormAction the credentialsFormAction to set + * @param baseURL */ public void setBaseURL(String baseURL) { this.baseURL = baseURL; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java index df18c231..bfb6f66a 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostCredentialsThread.java @@ -68,7 +68,7 @@ public class PostCredentialsThread implements Runnable { client.getParams().setParameter("http.useragent", //$NON-NLS-1$ LocalBKUState.PDF_OVER_USER_AGENT_STRING); - PostMethod method = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); + PostMethod method = new PostMethod(status.getBaseURL() + "/identification.aspx?sid=" + status.getSessionID()); //$NON-NLS-1$ method.addParameter("__VIEWSTATE", status.getViewstate()); //$NON-NLS-1$ method.addParameter("__EVENTVALIDATION", status.getEventvalidation()); //$NON-NLS-1$ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java index f8f7eac2..bd2f5b53 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/PostSLRequestThread.java @@ -70,10 +70,9 @@ public class PostSLRequestThread implements Runnable { client.getParams().setParameter("http.useragent", //$NON-NLS-1$ LocalBKUState.PDF_OVER_USER_AGENT_STRING); - // TODO: move URL to config!! - - //String url = "https://www.a-trust.at/mobile/https-security-layer-request/default.aspx"; - String url = "https://test1.a-trust.at/https-security-layer-request/default.aspx"; + // TODO: move URL to config? + String url = "https://www.a-trust.at/mobile/https-security-layer-request/default.aspx"; //$NON-NLS-1$ + //String url = "https://test1.a-trust.at/https-security-layer-request/default.aspx"; PostMethod method = new PostMethod(url); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java index 5e9d8159..91aa6caa 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/mobilebku/TrustedSocketFactory.java @@ -46,7 +46,7 @@ public class TrustedSocketFactory implements ProtocolSocketFactory { private static final Logger log = LoggerFactory .getLogger(TrustedSocketFactory.class); - private SSLSocketFactory getFactory() throws NoSuchAlgorithmException, + private static SSLSocketFactory getFactory() throws NoSuchAlgorithmException, KeyManagementException, Exception { SSLContext sslContext = SSLContext.getInstance("TLS"); //$NON-NLS-1$ sslContext.init(null, new TrustManager[] { new ASITTrustManager() }, @@ -71,7 +71,7 @@ public class TrustedSocketFactory implements ProtocolSocketFactory { return sslSocket; } catch (Exception ex) { - log.error("TrustedSocketFactory: ", ex); + log.error("TrustedSocketFactory: ", ex); //$NON-NLS-1$ if (ex instanceof IOException) { throw (IOException) ex; } else if (ex instanceof UnknownHostException) { @@ -99,7 +99,7 @@ public class TrustedSocketFactory implements ProtocolSocketFactory { return sslSocket; } catch (Exception ex) { - log.error("TrustedSocketFactory: ", ex); + log.error("TrustedSocketFactory: ", ex); //$NON-NLS-1$ if (ex instanceof IOException) { throw (IOException) ex; } else if (ex instanceof UnknownHostException) { @@ -144,7 +144,7 @@ public class TrustedSocketFactory implements ProtocolSocketFactory { } return socket; } catch (Exception ex) { - log.error("TrustedSocketFactory: ", ex); + log.error("TrustedSocketFactory: ", ex); //$NON-NLS-1$ if (ex instanceof IOException) { throw (IOException) ex; } else if (ex instanceof UnknownHostException) { diff --git a/pdf-over-gui/src/main/resources/img/config.png b/pdf-over-gui/src/main/resources/img/config.png Binary files differnew file mode 100644 index 00000000..6e52db7c --- /dev/null +++ b/pdf-over-gui/src/main/resources/img/config.png diff --git a/pdf-over-gui/src/main/resources/img/handy.gif b/pdf-over-gui/src/main/resources/img/handy.gif Binary files differnew file mode 100644 index 00000000..5aeb542d --- /dev/null +++ b/pdf-over-gui/src/main/resources/img/handy.gif diff --git a/pdf-over-gui/src/main/resources/img/karte.gif b/pdf-over-gui/src/main/resources/img/karte.gif Binary files differnew file mode 100644 index 00000000..ee9ab7ca --- /dev/null +++ b/pdf-over-gui/src/main/resources/img/karte.gif |