From f39ab43fc0120b7fa97028d40acd7851de8d4a99 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Thu, 24 Nov 2022 14:14:37 +0100 Subject: Repository moved to GitHub: https://github.com/a-sit/pdf-over --- .../composites/configuration/AboutComposite.java | 132 ---- .../AdvancedConfigurationComposite.java | 709 -------------------- .../configuration/ConfigurationCompositeBase.java | 77 --- .../configuration/Fido2ConfigurationComposite.java | 95 --- .../KeystoreConfigurationComposite.java | 592 ----------------- .../SimpleConfigurationComposite.java | 717 --------------------- 6 files changed, 2322 deletions(-) delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/ConfigurationCompositeBase.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/Fido2ConfigurationComposite.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java deleted file mode 100644 index 14f7a015..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java +++ /dev/null @@ -1,132 +0,0 @@ -package at.asit.pdfover.gui.composites.configuration; - -import java.awt.Desktop; -import java.io.File; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.program.Program; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Link; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.utils.SWTUtils; -import at.asit.pdfover.gui.utils.UpdateCheckManager; -import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; -import at.asit.pdfover.gui.workflow.config.ConfigurationManager; -import at.asit.pdfover.gui.workflow.states.State; - -public class AboutComposite extends ConfigurationCompositeBase { - static final Logger log = LoggerFactory.getLogger(AboutComposite.class); - private Link lnkAbout; - private Link lnkDataProtection; - private Label lblDataProtection; - private Link lnkUpdateCheckStatus; - private Button btnUpdateCheck; - private Button btnOpenLogDirectory; - private UpdateCheckManager.Status latestUpdateStatus; - /** - * @param parent - * @param style - */ - public AboutComposite(Composite parent, int style, State state, ConfigurationDataInMemory container) { - super(parent, style, state, container); - - setLayout(new FormLayout()); - - this.lnkAbout = new Link(this, SWT.WRAP); - SWTUtils.anchor(lnkAbout).top(0,5).right(100,-5).left(0,5); - SWTUtils.setFontHeight(lnkAbout, Constants.TEXT_SIZE_NORMAL); - SWTUtils.addSelectionListener(lnkAbout, (e) -> { SWTUtils.openURL(Messages.getString("config.LicenseURL")); }); - - this.lblDataProtection = new Label(this, SWT.WRAP); - SWTUtils.anchor(lblDataProtection).top(lnkAbout, 15).left(0,5).right(100,-5); - SWTUtils.setFontHeight(lblDataProtection, Constants.TEXT_SIZE_BIG); - SWTUtils.setFontStyle(lblDataProtection, SWT.BOLD); - - this.lnkDataProtection = new Link(this, SWT.WRAP); - SWTUtils.anchor(lnkDataProtection).top(lblDataProtection,10).left(0,5).right(100,-5); - SWTUtils.setFontHeight(lnkDataProtection, Constants.TEXT_SIZE_NORMAL); - SWTUtils.addSelectionListener(lnkDataProtection, (e) -> { SWTUtils.openURL(Messages.getString("config.DataProtectionURL")); }); - - this.lnkUpdateCheckStatus = new Link(this, SWT.NONE); - SWTUtils.anchor(lnkUpdateCheckStatus).bottom(100, -5).left(0,5); - SWTUtils.setFontHeight(lnkUpdateCheckStatus, Constants.TEXT_SIZE_BUTTON); - UpdateCheckManager.registerStatusCallback((s) -> { if (isDisposed()) return; latestUpdateStatus = s; getDisplay().asyncExec(() -> { RefreshUpdateStatusText(); }); }); - SWTUtils.addSelectionListener(lnkUpdateCheckStatus, (e) -> { - if (latestUpdateStatus == UpdateCheckManager.Status.OUTDATED) - Program.launch(Constants.UPDATE_URL); - else - UpdateCheckManager.checkNow(getShell()); - }); - - this.btnUpdateCheck = new Button(this, SWT.CHECK); - SWTUtils.anchor(btnUpdateCheck).bottom(lnkUpdateCheckStatus,-5).left(0,5); - SWTUtils.setFontHeight(btnUpdateCheck, Constants.TEXT_SIZE_BUTTON); - SWTUtils.addSelectionListener(btnUpdateCheck, (e) -> { - boolean enabled = btnUpdateCheck.getSelection(); - this.configurationContainer.updateCheck = enabled; - if (enabled) - UpdateCheckManager.checkNow(getShell()); - }); - - this.btnOpenLogDirectory = new Button(this, SWT.NONE); - SWTUtils.anchor(btnOpenLogDirectory).bottom(100, -5).right(100, -5); - SWTUtils.setFontHeight(btnOpenLogDirectory, Constants.TEXT_SIZE_BUTTON); - - SWTUtils.reanchor(lnkDataProtection).bottom(btnUpdateCheck,-5); - - SWTUtils.addSelectionListener(btnOpenLogDirectory, (e) -> { - try { - if (Desktop.isDesktopSupported()) - Desktop.getDesktop().open(new File(Constants.CONFIG_DIRECTORY + File.separator + "logs")); - } catch (Exception ex) { - log.warn("Failed to open log directory: ", ex); - } - }); - - // Load localized strings - reloadResources(); - } - - private void RefreshUpdateStatusText() { - SWTUtils.setLocalizedText(lnkUpdateCheckStatus, "config.UpdateStatus." + latestUpdateStatus.name()); - } - - /* (non-Javadoc) - * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() - */ - @Override - public void reloadResources() { - SWTUtils.setLocalizedText(lnkAbout, "config.AboutText"); - SWTUtils.setLocalizedText(lblDataProtection, "config.DataProtection"); - SWTUtils.setLocalizedText(lnkDataProtection, "config.DataProtectionStatement"); - SWTUtils.setLocalizedText(btnUpdateCheck, "advanced_config.UpdateCheck"); - SWTUtils.setLocalizedToolTipText(btnUpdateCheck, "advanced_config.UpdateCheck_ToolTip"); - SWTUtils.setLocalizedText(btnOpenLogDirectory, "config.ShowLogDirectory"); - RefreshUpdateStatusText(); - } - - @Override - public void initConfiguration(ConfigurationManager provider) { - this.configurationContainer.updateCheck = provider.getUpdateCheck(); - } - - @Override - public void loadConfiguration() { - btnUpdateCheck.setSelection(this.configurationContainer.updateCheck); - } - - @Override - public void storeConfiguration(ConfigurationManager store) { - store.setUpdateCheckPersistent(this.configurationContainer.updateCheck); - } - - @Override - public void validateSettings(int resumeFrom) throws Exception {} -} \ No newline at end of file diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java deleted file mode 100644 index df1a809b..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java +++ /dev/null @@ -1,709 +0,0 @@ -/* - * 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.composites.configuration; - -// Imports -import java.io.File; -import java.util.Arrays; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - -import javax.annotation.Nonnull; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.layout.FormData; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Combo; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.DirectoryDialog; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.commons.BKUs; -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.commons.Profile; -import at.asit.pdfover.gui.composites.ConfigurationComposite; -import at.asit.pdfover.gui.controls.Dialog.BUTTONS; -import at.asit.pdfover.gui.controls.ErrorDialog; -import at.asit.pdfover.gui.controls.ErrorMarker; -import at.asit.pdfover.gui.exceptions.InvalidPortException; -import at.asit.pdfover.gui.exceptions.OutputfolderDoesntExistException; -import at.asit.pdfover.gui.exceptions.OutputfolderNotADirectoryException; -import at.asit.pdfover.gui.utils.SWTUtils; -import at.asit.pdfover.gui.workflow.config.ConfigurationManager; -import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; -import at.asit.pdfover.gui.workflow.states.State; - -/** - * Composite for advanced configuration - * - * Contains the simple configuration composite - */ -public class AdvancedConfigurationComposite extends ConfigurationCompositeBase { - - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory.getLogger(AdvancedConfigurationComposite.class); - - private ConfigurationComposite configurationComposite; - - private Group grpSignatur; - private Group grpPlaceholder; - Button btnAutomatischePositionierung; - Button btnPdfACompat; - Button btnPlatzhalterVerwenden; - Button btnSignatureFieldsUsage; - Button btnEnablePlaceholderUsage; - - private Group grpBkuAuswahl; - Combo cmbBKUAuswahl; - List bkuStrings; - Button btnKeystoreEnabled; - - private final Group grpSpeicherort; - private final Label lblDefaultOutputFolder; - Text txtOutputFolder; - private final Button btnBrowse; - private final Label lblSaveFilePostFix; - private final Text txtSaveFilePostFix; - - private final Group grpLocaleAuswahl; - Combo cmbLocaleAuswahl; - - private Group grpProxy; - private Label lblProxyHost; - private Text txtProxyHost; - private ErrorMarker proxyHostErrorMarker; - private Label lblProxyPort; - private Text txtProxyPort; - private ErrorMarker txtProxyPortErrorMarker; - FormData fd_txtProxyPort; - FormData fd_txtProxyPortErrorMarker; - - /** - * @param parent - * @param style - * @param state - * @param container - * @param config - */ - public AdvancedConfigurationComposite(Composite parent, int style, State state, ConfigurationDataInMemory container, - ConfigurationComposite config) { - super(parent, style, state, container); - this.configurationComposite = config; - setLayout(new FormLayout()); - - FormLayout STANDARD_LAYOUT = new FormLayout(); - STANDARD_LAYOUT.marginHeight = 10; - STANDARD_LAYOUT.marginWidth = 5; - - this.grpLocaleAuswahl = new Group(this, SWT.NONE); - this.grpLocaleAuswahl.setLayout(STANDARD_LAYOUT); - SWTUtils.anchor(grpLocaleAuswahl).top(0, 5).left(0,5).right(100,-5); - SWTUtils.setFontHeight(grpLocaleAuswahl, Constants.TEXT_SIZE_NORMAL); - - this.grpSignatur = new Group(this, SWT.NONE); - this.grpSignatur.setLayout(STANDARD_LAYOUT); - SWTUtils.anchor(grpSignatur).top(grpLocaleAuswahl,5).right(100,-5).left(0,5); - SWTUtils.setFontHeight(grpSignatur, Constants.TEXT_SIZE_NORMAL); - - this.grpPlaceholder = new Group(this, SWT.NONE); - this.grpPlaceholder.setLayout(STANDARD_LAYOUT); - SWTUtils.anchor(grpPlaceholder).top(grpSignatur, 5).left(0,5).right(100,-5); - SWTUtils.setFontHeight(grpPlaceholder, Constants.TEXT_SIZE_NORMAL); - - this.grpBkuAuswahl = new Group(this, SWT.NONE); - this.grpBkuAuswahl.setLayout(STANDARD_LAYOUT); - SWTUtils.anchor(grpBkuAuswahl).top(grpPlaceholder, 5).left(0,5).right(100,-5); - SWTUtils.setFontHeight(grpBkuAuswahl, Constants.TEXT_SIZE_NORMAL); - - this.grpSpeicherort = new Group(this, SWT.NONE); - grpSpeicherort.setLayout(new GridLayout(3, false)); - SWTUtils.anchor(grpSpeicherort).left(0,5).top(grpBkuAuswahl, 5).right(100,-5); - SWTUtils.setFontHeight(grpSpeicherort, Constants.TEXT_SIZE_NORMAL); - - this.grpProxy = new Group(this, SWT.NONE); - SWTUtils.anchor(grpProxy).right(100,-5).top(grpSpeicherort, 5).left(0,5); - this.grpProxy.setLayout(new GridLayout(2, false)); - SWTUtils.setFontHeight(grpProxy, Constants.TEXT_SIZE_NORMAL); - - this.btnAutomatischePositionierung = new Button(this.grpSignatur, SWT.CHECK); - SWTUtils.anchor(btnAutomatischePositionierung).right(100,-5).top(0).left(0,5); - SWTUtils.setFontHeight(btnAutomatischePositionierung, Constants.TEXT_SIZE_BUTTON); - SWTUtils.addSelectionListener(btnAutomatischePositionierung, e -> { performPositionSelection(btnAutomatischePositionierung.getSelection()); }); - - this.btnPdfACompat = new Button(this.grpSignatur, SWT.CHECK); - SWTUtils.anchor(btnPdfACompat).right(100,-5).top(btnAutomatischePositionierung, 5).left(0,5); - SWTUtils.setFontHeight(btnPdfACompat, Constants.TEXT_SIZE_BUTTON); - SWTUtils.addSelectionListener(btnPdfACompat, e -> { performPdfACompatSelection(btnPdfACompat.getSelection()); }); - - this.btnEnablePlaceholderUsage = new Button(this.grpPlaceholder, SWT.CHECK); - SWTUtils.anchor(btnEnablePlaceholderUsage).top(0,5).left(0,5).right(100,-5); - SWTUtils.setFontHeight(btnEnablePlaceholderUsage, Constants.TEXT_SIZE_BUTTON); - SWTUtils.addSelectionListener(btnEnablePlaceholderUsage, e -> { performEnableUsePlaceholder(btnEnablePlaceholderUsage.getSelection()); }); - - this.btnPlatzhalterVerwenden = new Button(this.grpPlaceholder, SWT.RADIO); - SWTUtils.anchor(btnPlatzhalterVerwenden).right(100,-5).top(btnEnablePlaceholderUsage,5).left(0,5); - SWTUtils.setFontHeight(btnPlatzhalterVerwenden, Constants.TEXT_SIZE_BUTTON); - SWTUtils.addSelectionListener(btnPlatzhalterVerwenden, e -> { performUseMarkerSelection(btnPlatzhalterVerwenden.getSelection()); }); - - this.btnSignatureFieldsUsage = new Button(this.grpPlaceholder, SWT.RADIO); - SWTUtils.anchor(btnSignatureFieldsUsage).right(100,-5).top(btnPlatzhalterVerwenden, 5).left(0,5); - SWTUtils.setFontHeight(btnSignatureFieldsUsage, Constants.TEXT_SIZE_BUTTON); - SWTUtils.addSelectionListener(btnSignatureFieldsUsage, e -> { performUseSignatureFieldsSelection(btnSignatureFieldsUsage.getSelection()); }); - - this.cmbBKUAuswahl = new Combo(this.grpBkuAuswahl, SWT.READ_ONLY); - SWTUtils.anchor(cmbBKUAuswahl).right(100,-5).top(0).left(0,5); - SWTUtils.setFontHeight(cmbBKUAuswahl, Constants.TEXT_SIZE_NORMAL); - SWTUtils.scrollPassthrough(cmbBKUAuswahl); - - this.bkuStrings = Arrays.stream(BKUs.values()).map(s -> Messages.getString("BKU."+s)).collect(Collectors.toList()); - this.cmbBKUAuswahl.setItems(bkuStrings.toArray(new String[0])); - SWTUtils.addSelectionListener(cmbBKUAuswahl, e -> { - int selectionIndex = getBKUElementIndex(configurationContainer.defaultBKU); - if (cmbBKUAuswahl.getSelectionIndex() != selectionIndex) { - selectionIndex = cmbBKUAuswahl.getSelectionIndex(); - performBKUSelectionChanged(cmbBKUAuswahl.getItem(selectionIndex)); - } - }); - - this.btnKeystoreEnabled = new Button(this.grpBkuAuswahl, SWT.CHECK); - SWTUtils.anchor(btnKeystoreEnabled).right(100,-5).top(cmbBKUAuswahl,5).left(0,5); - SWTUtils.setFontHeight(btnKeystoreEnabled, Constants.TEXT_SIZE_BUTTON); - SWTUtils.addSelectionListener(btnKeystoreEnabled, e -> { performKeystoreEnabledSelection(btnKeystoreEnabled.getSelection()); }); - - this.lblDefaultOutputFolder = new Label(this.grpSpeicherort, SWT.NONE); - SWTUtils.setFontHeight(lblDefaultOutputFolder, Constants.TEXT_SIZE_NORMAL); - - this.txtOutputFolder = new Text(this.grpSpeicherort, SWT.BORDER); - txtOutputFolder.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - SWTUtils.setFontHeight(txtOutputFolder, Constants.TEXT_SIZE_NORMAL); - - this.txtOutputFolder.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - performOutputFolderChanged(txtOutputFolder.getText()); - } - }); - - this.btnBrowse = new Button(this.grpSpeicherort, SWT.NONE); - btnBrowse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1)); - SWTUtils.setFontHeight(btnBrowse, Constants.TEXT_SIZE_BUTTON); - - SWTUtils.addSelectionListener(btnBrowse, 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 - SWTUtils.setLocalizedText(dlg, "advanced_config.OutputFolder.Dialog_Title"); - - // Customizable message displayed in the dialog - dlg.setMessage(Messages.getString("advanced_config.OutputFolder.Dialog")); - - // 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); - } - }); - - this.lblSaveFilePostFix = new Label(this.grpSpeicherort, SWT.NONE); - SWTUtils.setLocalizedText(lblSaveFilePostFix, "AdvancedConfigurationComposite.lblSaveFilePostFix.text"); - SWTUtils.setFontHeight(lblSaveFilePostFix, Constants.TEXT_SIZE_NORMAL); - - this.txtSaveFilePostFix = new Text(this.grpSpeicherort, SWT.BORDER); - txtSaveFilePostFix.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); - SWTUtils.setFontHeight(txtSaveFilePostFix, Constants.TEXT_SIZE_NORMAL); - - this.txtSaveFilePostFix.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - if (txtSaveFilePostFix.getText().trim().isEmpty()) - txtSaveFilePostFix.setText(Constants.DEFAULT_POSTFIX); - performPostFixChanged(Constants.ISNOTNULL(txtSaveFilePostFix.getText())); - } - }); - - this.cmbLocaleAuswahl = new Combo(this.grpLocaleAuswahl, SWT.READ_ONLY); - SWTUtils.anchor(cmbLocaleAuswahl).right(100,-5).top(0).left(0,5); - SWTUtils.setFontHeight(cmbLocaleAuswahl, Constants.TEXT_SIZE_NORMAL);; - this.cmbLocaleAuswahl.setItems(Arrays.stream(Constants.SUPPORTED_LOCALES).map(l -> l.getDisplayLanguage()).toArray(String[]::new)); - SWTUtils.scrollPassthrough(cmbLocaleAuswahl); - - SWTUtils.addSelectionListener(cmbLocaleAuswahl, e -> { - Locale currentLocale = configurationContainer.interfaceLocale; - Locale selectedLocale = Constants.SUPPORTED_LOCALES[cmbLocaleAuswahl.getSelectionIndex()]; - if (!currentLocale.equals(selectedLocale)) { - performLocaleSelectionChanged(selectedLocale); - } - }); - - this.lblProxyHost = new Label(this.grpProxy, SWT.NONE); - do { /* grid positioning */ - GridData gd_lblProxyHost = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1); - gd_lblProxyHost.widthHint = 66; - this.lblProxyHost.setLayoutData(gd_lblProxyHost); - this.lblProxyHost.setBounds(0, 0, 57, 15); - } while (false); - SWTUtils.setFontHeight(lblProxyHost, Constants.TEXT_SIZE_NORMAL); - - Composite compProxyHostContainer = new Composite(this.grpProxy, SWT.NONE); - compProxyHostContainer.setLayout(new FormLayout()); - compProxyHostContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); - - this.txtProxyHost = new Text(compProxyHostContainer, SWT.BORDER); - SWTUtils.anchor(txtProxyHost).right(100,-42).top(0).left(0,5); - SWTUtils.setFontHeight(txtProxyHost, Constants.TEXT_SIZE_NORMAL); - - this.proxyHostErrorMarker = new ErrorMarker(compProxyHostContainer, SWT.NONE, ""); - SWTUtils.anchor(proxyHostErrorMarker).left(100,-32).right(100).top(0).bottom(0,32); - this.proxyHostErrorMarker.setVisible(false); - - this.txtProxyHost.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - processProxyHostChanged(); - } - }); - - this.txtProxyHost.addTraverseListener(e -> { - if (e.detail == SWT.TRAVERSE_RETURN) { - processProxyHostChanged(); - } - }); - - this.lblProxyPort = new Label(this.grpProxy, SWT.NONE); - this.lblProxyPort.setBounds(0, 0, 57, 15); - SWTUtils.setFontHeight(lblProxyPort, Constants.TEXT_SIZE_NORMAL); - - Composite compProxyPortContainer = new Composite(this.grpProxy, SWT.NONE); - compProxyPortContainer.setLayout(new FormLayout()); - compProxyPortContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); - - this.txtProxyPort = new Text(compProxyPortContainer, SWT.BORDER); - SWTUtils.anchor(txtProxyPort).top(0,0).left(0,5).right(100,-42); - SWTUtils.setFontHeight(txtProxyPort, Constants.TEXT_SIZE_NORMAL); - - this.txtProxyPort.addTraverseListener(e -> { - if (e.detail == SWT.TRAVERSE_RETURN) { - processProxyPortChanged(); - } - }); - - this.txtProxyPortErrorMarker = new ErrorMarker(compProxyPortContainer, SWT.NONE, ""); - SWTUtils.anchor(txtProxyPortErrorMarker).left(100,-32).right(100).top(0).bottom(0,32); - this.txtProxyPortErrorMarker.setVisible(false); - - this.txtProxyPort.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - processProxyPortChanged(); - } - }); - - reloadResources(); - } - - private void performPostFixChanged(@Nonnull String postfix) { - - log.debug("Save file postfix changed to : {}", postfix); - this.configurationContainer.saveFilePostFix = postfix; - AdvancedConfigurationComposite.this.txtSaveFilePostFix.setText(postfix); - } - - void performOutputFolderChanged(String foldername) { - log.debug("Selected Output folder: {}", foldername); - this.configurationContainer.outputFolder = foldername; - AdvancedConfigurationComposite.this.txtOutputFolder.setText(foldername); - } - - int getBKUElementIndex(BKUs bku) { - String lookup = "BKU." + bku.toString(); - String bkuName = Messages.getString(lookup); - - int i = this.bkuStrings.indexOf(bkuName); - if (i == -1) { - log.warn("NO BKU match for {}", bkuName); - return 0; - } - return i; - } - - void performBKUSelectionChanged(@Nonnull BKUs selected) { - log.debug("Selected BKU: {}", selected); - this.configurationContainer.defaultBKU = selected; - this.cmbBKUAuswahl.select(this.getBKUElementIndex(selected)); - } - - void performBKUSelectionChanged(String selected) { - try { - BKUs bkuvalue = resolveBKU(selected); - this.performBKUSelectionChanged(bkuvalue); - } catch (Exception ex) { - log.error("Failed to parse BKU value: {} {}", selected, ex); - ErrorDialog dialog = new ErrorDialog(getShell(), Messages.getString("error.InvalidBKU"), BUTTONS.OK); - dialog.open(); - } - } - - @Nonnull BKUs resolveBKU(String localizedBKU) { - int blen = BKUs.values().length; - - for (int i = 0; i < blen; i++) { - String lookup = "BKU." + BKUs.values()[i].toString(); - if (Messages.getString(lookup).equals(localizedBKU)) { - return Constants.ISNOTNULL(BKUs.values()[i]); - } - } - - return BKUs.NONE; - } - - int getLocaleElementIndex(Locale locale) { - for (int i = 0; i < Constants.SUPPORTED_LOCALES.length; i++) { - if (Constants.SUPPORTED_LOCALES[i].equals(locale)) { - log.debug("Locale: {} IDX: {}", locale, i); - return i; - } - } - - log.warn("NO Locale match for {}", locale); - return 0; - } - - void performLocaleSelectionChanged(Locale selected) { - log.debug("Selected Locale: {}", selected); - this.configurationContainer.interfaceLocale = selected; - this.cmbLocaleAuswahl.select(this.getLocaleElementIndex(selected)); - } - - void performPositionSelection(boolean automatic) { - log.debug("Selected Position: {}", automatic); - this.configurationContainer.autoPositionSignature = automatic; - this.btnAutomatischePositionierung.setSelection(automatic); - } - - void performUseMarkerSelection(boolean useMarker) { - this.configurationContainer.setUseMarker(useMarker); - this.btnPlatzhalterVerwenden.setSelection(useMarker); - } - - void performUseSignatureFieldsSelection(boolean useFields) { - this.configurationContainer.setUseSignatureFields(useFields); - this.btnSignatureFieldsUsage.setSelection(useFields); - } - - void performEnableUsePlaceholder(boolean enable) { - this.btnPlatzhalterVerwenden.setEnabled(enable); - this.btnSignatureFieldsUsage.setEnabled(enable); - this.configurationContainer.enabledPlaceholderUsage = enable; - this.btnEnablePlaceholderUsage.setSelection(enable); - } - - void performPdfACompatSelection(boolean compat) { - this.configurationContainer.signaturePDFACompat = compat; - this.btnPdfACompat.setSelection(compat); - } - - void performKeystoreEnabledSelection(boolean enabled) { - this.configurationContainer.keystoreEnabled = enabled; - this.btnKeystoreEnabled.setSelection(enabled); - this.configurationComposite.keystoreEnabled(enabled); - - int ksIndex = getBKUElementIndex(BKUs.KS); - String ksText = this.bkuStrings.get(ksIndex); - if (enabled) { - if (!this.cmbBKUAuswahl.getItem(ksIndex).equals(ksText)) - this.cmbBKUAuswahl.add(ksText, ksIndex); - } else { - int i = this.cmbBKUAuswahl.indexOf(ksText); - if (i != -1) { - if (this.cmbBKUAuswahl.getSelectionIndex() == i) - performBKUSelectionChanged(BKUs.NONE); - this.cmbBKUAuswahl.remove(i); - } - } - } - - void processProxyHostChanged() { - try { - this.proxyHostErrorMarker.setVisible(false); - plainProxyHostSetter(); - } catch (Exception ex) { - this.proxyHostErrorMarker.setVisible(true); - this.proxyHostErrorMarker.setToolTipText(ex.getMessage()); - log.error("processProxyHost: ", ex); - } - } - - /** - * - */ - private void plainProxyHostSetter() { - String host = this.txtProxyHost.getText(); - this.configurationContainer.proxyHost = host; - } - - void processProxyPortChanged() { - try { - this.txtProxyPortErrorMarker.setVisible(false); - plainProxyPortSetter(); - } catch (Exception ex) { - this.txtProxyPortErrorMarker.setVisible(true); - this.txtProxyPortErrorMarker.setToolTipText(ex.getMessage()); - log.error("processProxyPort: ", ex); - } - } - - /** - * @throws InvalidPortException - */ - private void plainProxyPortSetter() throws InvalidPortException { - String portString = this.txtProxyPort.getText(); - int port = -1; - if (portString == null || portString.trim().isEmpty()) { - port = -1; - } else { - try { - port = Integer.parseInt(portString); - } catch (NumberFormatException e) { - throw new InvalidPortException(portString, e); - } - } - this.configurationContainer.setProxyPort(port); - } - - @Override - public void initConfiguration(ConfigurationManager provider) { - this.configurationContainer.autoPositionSignature = provider.getAutoPositionSignaturePersistent(); - this.configurationContainer.setUseMarker(provider.getUseMarker()); - this.configurationContainer.setUseSignatureFields(provider.getUseSignatureFields()); - this.configurationContainer.enabledPlaceholderUsage = provider.getEnablePlaceholderUsage(); - this.configurationContainer.signaturePDFACompat = provider.getSignaturePdfACompat(); - - this.configurationContainer.defaultBKU = provider.getDefaultBKUPersistent(); - this.configurationContainer.keystoreEnabled = provider.getKeyStoreEnabledPersistent(); - - this.configurationContainer.outputFolder = provider.getDefaultOutputFolderPersistent(); - this.configurationContainer.saveFilePostFix = provider.getSaveFilePostFix(); - - this.configurationContainer.interfaceLocale = provider.getInterfaceLocale(); - - this.configurationContainer.proxyHost = provider.getProxyHostPersistent(); - try { - this.configurationContainer.setProxyPort(provider.getProxyPortPersistent()); - } catch (InvalidPortException e) { - log.error("Failed to set proxy port!", e); - } - this.configurationContainer.proxyUser = provider.getProxyUserPersistent(); - this.configurationContainer.proxyPass = provider.getProxyPassPersistent(); - } - - /* - * (non-Javadoc) - * - * @see - * at.asit.pdfover.gui.composites.BaseConfigurationComposite#loadConfiguration() - */ - @Override - public void loadConfiguration() { - // load advanced settings - performBKUSelectionChanged(this.configurationContainer.defaultBKU); - String outputFolder = this.configurationContainer.outputFolder; - if (outputFolder != null) { - performOutputFolderChanged(outputFolder); - } - performPostFixChanged(this.configurationContainer.saveFilePostFix); - performPositionSelection(this.configurationContainer.autoPositionSignature); - performUseMarkerSelection(this.configurationContainer.getUseMarker()); - performUseSignatureFieldsSelection(this.configurationContainer.getUseSignatureFields()); - performEnableUsePlaceholder(this.configurationContainer.enabledPlaceholderUsage); - performLocaleSelectionChanged(this.configurationContainer.interfaceLocale); - performPdfACompatSelection(this.configurationContainer.signaturePDFACompat); - performKeystoreEnabledSelection(this.configurationContainer.keystoreEnabled); - - int port = this.configurationContainer.getProxyPort(); - if (port > 0) { - this.txtProxyPort.setText(Integer.toString(port)); - } - - String host = this.configurationContainer.proxyHost; - if (host != null) { - this.txtProxyHost.setText(host); - } - - } - - @Override - public void storeConfiguration(ConfigurationManager store) { - store.setAutoPositionSignaturePersistent(this.configurationContainer.autoPositionSignature); - store.setUseMarkerPersistent(this.configurationContainer.getUseMarker()); - store.setUseSignatureFieldsPersistent(this.configurationContainer.getUseSignatureFields()); - store.setEnablePlaceholderUsagePersistent(this.configurationContainer.enabledPlaceholderUsage); - store.setSignaturePdfACompatPersistent(this.configurationContainer.signaturePDFACompat); - - store.setDefaultBKUPersistent(this.configurationContainer.defaultBKU); - store.setKeyStoreEnabledPersistent(this.configurationContainer.keystoreEnabled); - - store.setDefaultOutputFolderPersistent(this.configurationContainer.outputFolder); - store.setSaveFilePostFixPersistent(this.configurationContainer.saveFilePostFix); - store.setInterfaceLocalePersistent(this.configurationContainer.interfaceLocale); - - String hostOld = store.getProxyHostPersistent(); - String hostNew = this.configurationContainer.proxyHost; - if (hostOld != null && !hostOld.isEmpty() && (hostNew == null || hostNew.isEmpty())) { - // Proxy has been removed, let's clear the system properties - // Otherwise, the proxy settings wouldn't get removed - System.clearProperty("http.proxyHost"); - System.clearProperty("https.proxyHost"); - } - store.setProxyHostPersistent(hostNew); - - int portOld = store.getProxyPortPersistent(); - int portNew = this.configurationContainer.getProxyPort(); - if (portOld != -1 && portNew == -1) { - // cf. above - System.clearProperty("http.proxyPort"); - System.clearProperty("https.proxyPort"); - } - store.setProxyPortPersistent(portNew); - - String userOld = store.getProxyUserPersistent(); - String userNew = this.configurationContainer.proxyUser; - if (userOld != null && !userOld.isEmpty() && (userNew == null || userNew.isEmpty())) { - // cf. above - System.clearProperty("http.proxyUser"); - System.clearProperty("https.proxyUser"); - } - store.setProxyUserPersistent(userNew); - - String passOld = store.getProxyPassPersistent(); - String passNew = this.configurationContainer.proxyPass; - if (passOld != null && passNew == null) { - // cf. above - System.clearProperty("http.proxyPassword"); - System.clearProperty("https.proxyPassword"); - } - store.setProxyPassPersistent(passNew); - } - - /* - * (non-Javadoc) - * - * @see - * at.asit.pdfover.gui.composites.BaseConfigurationComposite#validateSettings() - */ - @Override - public void validateSettings(int resumeIndex) throws Exception { - - String foldername = this.configurationContainer.outputFolder; - - switch (resumeIndex) { - case 0: - if (foldername != null && !foldername.isEmpty()) { - File outputFolder = new File(foldername); - if (!outputFolder.exists()) { - throw new OutputfolderDoesntExistException(outputFolder, 1); - } - if (!outputFolder.isDirectory()) { - throw new OutputfolderNotADirectoryException(outputFolder); - } - } - // Fall through - case 1: - this.plainProxyHostSetter(); - // Fall through - case 2: - this.plainProxyPortSetter(); - // Fall through - // case 3: - // this.plainProxyUserSetter(); - // // Fall through - // case 4: - // this.plainProxyPassSetter(); - } - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() - */ - @Override - public void reloadResources() { - SWTUtils.setLocalizedText(grpSignatur, "advanced_config.Signature_Title"); - SWTUtils.setLocalizedText(btnAutomatischePositionierung, "advanced_config.AutoPosition"); - SWTUtils.setLocalizedToolTipText(btnAutomatischePositionierung, "advanced_config.AutoPosition_ToolTip"); - SWTUtils.setLocalizedText(grpPlaceholder, "advanced_config.Placeholder_Title"); - SWTUtils.setLocalizedText(btnPlatzhalterVerwenden, "advanced_config.UseMarker"); - SWTUtils.setLocalizedToolTipText(btnPlatzhalterVerwenden, "advanced_config.UseMarker_ToolTip"); - SWTUtils.setLocalizedText(btnSignatureFieldsUsage, "advanced_config.UseSignatureFields"); - SWTUtils.setLocalizedToolTipText(btnSignatureFieldsUsage, "advanced_config.UseSignatureFields_ToolTip"); - SWTUtils.setLocalizedText(btnEnablePlaceholderUsage, "advanced_config.Placeholder_Enabled"); - SWTUtils.setLocalizedText(btnPdfACompat, "advanced_config.PdfACompat"); - SWTUtils.setLocalizedToolTipText(btnPdfACompat, "advanced_config.PdfACompat_ToolTip"); - - SWTUtils.setLocalizedText(grpBkuAuswahl, "advanced_config.BKUSelection_Title"); - SWTUtils.setLocalizedToolTipText(cmbBKUAuswahl, "advanced_config.BKUSelection_ToolTip"); - SWTUtils.setLocalizedText(btnKeystoreEnabled, "advanced_config.KeystoreEnabled"); - SWTUtils.setLocalizedToolTipText(btnKeystoreEnabled, "advanced_config.KeystoreEnabled_ToolTip"); - - SWTUtils.setLocalizedText(grpSpeicherort, "advanced_config.OutputFolder_Title"); - SWTUtils.setLocalizedText(lblDefaultOutputFolder, "advanced_config.OutputFolder"); - SWTUtils.setLocalizedToolTipText(txtOutputFolder, "advanced_config.OutputFolder_ToolTip"); - SWTUtils.setLocalizedText(btnBrowse, "common.browse"); - - SWTUtils.setLocalizedText(grpLocaleAuswahl, "advanced_config.LocaleSelection_Title"); - SWTUtils.setLocalizedToolTipText(cmbLocaleAuswahl, "advanced_config.LocaleSelection_ToolTip"); - - SWTUtils.setLocalizedText(grpProxy, "advanced_config.Proxy_Title"); - SWTUtils.setLocalizedText(lblProxyHost, "advanced_config.ProxyHost"); - SWTUtils.setLocalizedToolTipText(txtProxyHost, "advanced_config.ProxyHost_ToolTip"); - this.txtProxyHost.setMessage(Messages.getString("advanced_config.ProxyHost_Template")); - SWTUtils.setLocalizedText(lblProxyPort, "advanced_config.ProxyPort"); - SWTUtils.setLocalizedToolTipText(txtProxyPort, "advanced_config.ProxyPort_ToolTip"); - this.txtProxyPort.setMessage(Messages.getString("advanced_config.ProxyPort_Template")); - // StateComposite.setLocalizedText(lblProxyUser, "advanced_config.ProxyUser"); - - // this.txtProxyUser.setToolTipText(Messages - // .getString("advanced_config.ProxyUser_ToolTip")); - // this.txtProxyUser.setMessage(Messages - // .getString("advanced_config.ProxyUser_Template")); - // StateComposite.setLocalizedText(lblProxyPass, "advanced_config.ProxyPass"); - - // this.txtProxyPass.setToolTipText(Messages - // .getString("advanced_config.ProxyPass_ToolTip")); - // this.txtProxyPass.setMessage(Messages - // .getString("advanced_config.ProxyPass_Template")); - } -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/ConfigurationCompositeBase.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/ConfigurationCompositeBase.java deleted file mode 100644 index 54207292..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/ConfigurationCompositeBase.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.composites.configuration; - - -import org.eclipse.swt.widgets.Composite; - -import at.asit.pdfover.gui.composites.StateComposite; -import at.asit.pdfover.gui.workflow.config.ConfigurationManager; -import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; -import at.asit.pdfover.gui.workflow.states.State; - -/** - * Base class for configuration composites - */ -public abstract class ConfigurationCompositeBase extends StateComposite { - - /** - * the configuration container - */ - protected ConfigurationDataInMemory configurationContainer; - - /** - * @param parent - * @param style - * @param state - * @param configuration - */ - public ConfigurationCompositeBase(Composite parent, int style, State state, ConfigurationDataInMemory configuration) { - super(parent, style, state); - this.configurationContainer = configuration; - } - - /** - * Initialize ConfigurationContainer from ConfigProviderImpl - * @param provider the ConfigProviderImpl to load config from - */ - public abstract void initConfiguration(ConfigurationManager provider); - - /** - * Load configuration from ConfigurationContainer - */ - public abstract void loadConfiguration(); - - /** - * Store configuration from ConfigurationContainer to ConfigProvider - * @param store the ConfigProviderImpl to store config to - */ - public abstract void storeConfiguration(ConfigurationManager store); - - /** - * Called before exit. - * The method validates every setting in the configuration before exit - * - * There might be settings when the user can decide to ignore a validation exception - * (for example the Outputfolder validation) - * In this case, the validator throws a ResumableException, which includes the - * validator index to resume from (should the user choose to ignore the error) - * - * @param resumeFrom Resume from this validator index (initially 0) - * @throws Exception - */ - public abstract void validateSettings(int resumeFrom) throws Exception; -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/Fido2ConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/Fido2ConfigurationComposite.java deleted file mode 100644 index 9b2d3ef1..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/Fido2ConfigurationComposite.java +++ /dev/null @@ -1,95 +0,0 @@ -package at.asit.pdfover.gui.composites.configuration; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.layout.FormLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Link; - -import com.sun.jna.Platform; - -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.utils.SWTUtils; -import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; -import at.asit.pdfover.gui.workflow.config.ConfigurationManager; -import at.asit.pdfover.gui.workflow.states.State; -import at.asit.webauthn.WebAuthN; - -public class Fido2ConfigurationComposite extends ConfigurationCompositeBase { - - private Link lnkInfoText; - private Link unsupportedText; - - private Group grpFidoSettings; - private Button btnFido2ByDefault; - - public Fido2ConfigurationComposite(Composite parent, int style, State state, ConfigurationDataInMemory container) { - super(parent, style, state, container); - setLayout(new FormLayout()); - - this.lnkInfoText = new Link(this, SWT.WRAP); - SWTUtils.anchor(lnkInfoText).top(0,5).left(0,5).right(100,-5); - SWTUtils.setFontHeight(lnkInfoText, Constants.TEXT_SIZE_NORMAL); - SWTUtils.addSelectionListener(lnkInfoText, () -> { SWTUtils.openURL(Messages.getString("config.fido2.InfoURL")); }); - - this.unsupportedText = new Link(this, SWT.WRAP); - SWTUtils.anchor(unsupportedText).top(lnkInfoText,5).left(0,5).right(100,-5); - SWTUtils.setFontHeight(unsupportedText, Constants.TEXT_SIZE_NORMAL); - SWTUtils.addSelectionListener(unsupportedText, () -> { SWTUtils.openURL("https://developers.yubico.com/libfido2/#_installation"); }); - - FormLayout STANDARD_LAYOUT = new FormLayout(); - STANDARD_LAYOUT.marginHeight = 10; - STANDARD_LAYOUT.marginWidth = 5; - - this.grpFidoSettings = new Group(this, SWT.NONE); - this.grpFidoSettings.setLayout(STANDARD_LAYOUT); - SWTUtils.anchor(grpFidoSettings).top(lnkInfoText,10).left(0,5).right(100,-5); - SWTUtils.setFontHeight(grpFidoSettings, Constants.TEXT_SIZE_NORMAL); - - this.btnFido2ByDefault = new Button(this.grpFidoSettings, SWT.CHECK); - SWTUtils.anchor(btnFido2ByDefault).top(0).left(0,5).right(100,-5); - SWTUtils.setFontHeight(btnFido2ByDefault, Constants.TEXT_SIZE_BUTTON); - SWTUtils.addSelectionListener(btnFido2ByDefault, () -> { this.configurationContainer.fido2ByDefault = btnFido2ByDefault.getSelection(); }); - - if (WebAuthN.isAvailable()) - this.unsupportedText.setVisible(false); - else - this.grpFidoSettings.setVisible(false); - - reloadResources(); - } - - @Override - public void reloadResources() { - SWTUtils.setLocalizedText(lnkInfoText, "config.fido2.AboutFIDO"); - SWTUtils.setLocalizedText(grpFidoSettings, "config.fido2.Group"); - SWTUtils.setLocalizedText(btnFido2ByDefault, "config.fido2.ByDefault"); - - if (Platform.isLinux() || Platform.isMac()) - SWTUtils.setLocalizedText(unsupportedText, "config.fido2.UnsupportedTryLibFido2"); - else { - SWTUtils.setFontStyle(unsupportedText, SWT.BOLD); - SWTUtils.setLocalizedText(unsupportedText, "config.fido2.UnsupportedPlatform"); - } - } - - @Override - public void initConfiguration(ConfigurationManager provider) { - this.configurationContainer.fido2ByDefault = provider.getFido2ByDefault(); - } - - @Override - public void loadConfiguration() { - btnFido2ByDefault.setSelection(this.configurationContainer.fido2ByDefault); - } - - @Override - public void storeConfiguration(ConfigurationManager store) { - store.setFido2ByDefaultPersistent(this.configurationContainer.fido2ByDefault); - } - - @Override - public void validateSettings(int resumeIndex) throws Exception {} -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java deleted file mode 100644 index a477422e..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java +++ /dev/null @@ -1,592 +0,0 @@ -/* - * 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.composites.configuration; - -// Imports -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; -import java.security.cert.CertificateException; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; -import java.util.Vector; - -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -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.Combo; -import org.eclipse.swt.widgets.FileDialog; -import org.eclipse.swt.widgets.Group; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Text; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.gui.controls.Dialog.BUTTONS; -import at.asit.pdfover.gui.controls.ErrorDialog; -import at.asit.pdfover.gui.controls.PasswordInputDialog; -import at.asit.pdfover.gui.exceptions.CantLoadKeystoreException; -import at.asit.pdfover.gui.exceptions.KeystoreAliasDoesntExistException; -import at.asit.pdfover.gui.exceptions.KeystoreAliasNoKeyException; -import at.asit.pdfover.gui.exceptions.KeystoreDoesntExistException; -import at.asit.pdfover.gui.exceptions.KeystoreKeyPasswordException; -import at.asit.pdfover.gui.keystore.KeystoreUtils; -import at.asit.pdfover.gui.utils.SWTUtils; -import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.workflow.config.ConfigurationManager; -import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory.KeyStorePassStorageType; -import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; -import at.asit.pdfover.gui.workflow.states.State; - -/** - * - */ -public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { - - /** - * SLF4J Logger instance - **/ - static final Logger log = LoggerFactory.getLogger(KeystoreConfigurationComposite.class); - - private Group grpKeystore; - private Label lblKeystoreFile; - Text txtKeystoreFile; - private Button btnBrowse; - private Label lblKeystoreType; - Combo cmbKeystoreType; - private Button btnLoad; - private Label lblKeystoreAlias; - Combo cmbKeystoreAlias; - private Label lblKeystorePassStoreType; - Combo cmbKeystorePassStoreType; - private Label lblKeystoreStorePass; - Text txtKeystoreStorePass; - private Label lblKeystoreKeyPass; - Text txtKeystoreKeyPass; - - private KeyStore ks; - - /** - * @param parent - * @param style - * @param state - * @param container - */ - public KeystoreConfigurationComposite( - org.eclipse.swt.widgets.Composite parent, int style, State state, - ConfigurationDataInMemory container) { - super(parent, style, state, container); - setLayout(new FormLayout()); - - this.grpKeystore = new Group(this, SWT.NONE | SWT.RESIZE); - FormLayout layout = new FormLayout(); - layout.marginHeight = 10; - layout.marginWidth = 5; - this.grpKeystore.setLayout(layout); - - SWTUtils.anchor(grpKeystore).top(0,5).left(0,5).right(100,-5); - SWTUtils.setFontHeight(this.grpKeystore, Constants.TEXT_SIZE_NORMAL); - - this.lblKeystoreFile = new Label(this.grpKeystore, SWT.NONE); - SWTUtils.anchor(lblKeystoreFile).top(0).left(0,5); - FormData fd_lblKeystoreFile = new FormData(); - fd_lblKeystoreFile.top = new FormAttachment(0); - fd_lblKeystoreFile.left = new FormAttachment(0, 5); - this.lblKeystoreFile.setLayoutData(fd_lblKeystoreFile); - SWTUtils.setFontHeight(lblKeystoreFile, Constants.TEXT_SIZE_NORMAL); - - this.txtKeystoreFile = new Text(grpKeystore, SWT.BORDER); - this.btnBrowse = new Button(grpKeystore, SWT.NONE); - SWTUtils.setFontHeight(txtKeystoreFile, Constants.TEXT_SIZE_NORMAL); - SWTUtils.setFontHeight(btnBrowse, Constants.TEXT_SIZE_BUTTON); - SWTUtils.anchor(txtKeystoreFile).top(lblKeystoreFile, 5).left(0,15).right(btnBrowse,-5); - SWTUtils.anchor(btnBrowse).top(lblKeystoreFile, 5).right(100,-5); - - this.lblKeystoreType = new Label(grpKeystore, SWT.NONE); - SWTUtils.anchor(lblKeystoreType).top(txtKeystoreFile, 5).left(0,5); - SWTUtils.setFontHeight(lblKeystoreType, Constants.TEXT_SIZE_NORMAL); - - this.btnLoad = new Button(this.grpKeystore, SWT.NONE); - SWTUtils.anchor(btnLoad).top(lblKeystoreType, 5).right(100,-5); - SWTUtils.setFontHeight(btnLoad, Constants.TEXT_SIZE_BUTTON); - - this.cmbKeystoreType = new Combo(grpKeystore, SWT.READ_ONLY); - SWTUtils.anchor(cmbKeystoreType).top(lblKeystoreType, 5).left(0,15).right(btnLoad, -5); - SWTUtils.setFontHeight(cmbKeystoreType, Constants.TEXT_SIZE_NORMAL); - SWTUtils.scrollPassthrough(cmbKeystoreType); - - this.lblKeystoreAlias = new Label(grpKeystore, SWT.NONE); - SWTUtils.anchor(lblKeystoreAlias).top(cmbKeystoreType, 5).left(0, 5); - SWTUtils.setFontHeight(lblKeystoreAlias, Constants.TEXT_SIZE_NORMAL); - - this.cmbKeystoreAlias = new Combo(grpKeystore, SWT.NONE); - SWTUtils.anchor(cmbKeystoreAlias).top(lblKeystoreAlias, 5).left(0,15).right(100,-5); - SWTUtils.setFontHeight(cmbKeystoreAlias, Constants.TEXT_SIZE_NORMAL); - SWTUtils.scrollPassthrough(cmbKeystoreAlias); - - this.lblKeystorePassStoreType = new Label(this.grpKeystore, SWT.NONE); - SWTUtils.anchor(lblKeystorePassStoreType).top(cmbKeystoreAlias, 5).left(0,5); - SWTUtils.setFontHeight(lblKeystorePassStoreType, Constants.TEXT_SIZE_NORMAL); - - this.cmbKeystorePassStoreType = new Combo(grpKeystore, SWT.READ_ONLY); - SWTUtils.anchor(cmbKeystorePassStoreType).top(lblKeystorePassStoreType, 5).left(0,15).right(100,-5); - SWTUtils.setFontHeight(cmbKeystorePassStoreType, Constants.TEXT_SIZE_NORMAL); - SWTUtils.scrollPassthrough(cmbKeystorePassStoreType); - - this.lblKeystoreStorePass = new Label(grpKeystore, SWT.NONE); - SWTUtils.anchor(lblKeystoreStorePass).top(cmbKeystorePassStoreType, 5).left(0,5); - SWTUtils.setFontHeight(lblKeystoreStorePass, Constants.TEXT_SIZE_NORMAL); - - this.txtKeystoreStorePass = new Text(grpKeystore, SWT.BORDER | SWT.PASSWORD); - SWTUtils.anchor(txtKeystoreStorePass).right(100, -5).top(lblKeystoreStorePass, 5).left(0,15); - SWTUtils.setFontHeight(txtKeystoreStorePass, Constants.TEXT_SIZE_NORMAL); - - this.lblKeystoreKeyPass = new Label(grpKeystore, SWT.NONE); - SWTUtils.anchor(lblKeystoreKeyPass).top(txtKeystoreStorePass, 5).left(0,5); - SWTUtils.setFontHeight(lblKeystoreKeyPass, Constants.TEXT_SIZE_NORMAL); - - this.txtKeystoreKeyPass = new Text(grpKeystore, SWT.BORDER | SWT.PASSWORD); - SWTUtils.anchor(txtKeystoreKeyPass).top(lblKeystoreKeyPass, 5).left(0,15).right(100,-5); - SWTUtils.setFontHeight(txtKeystoreKeyPass, Constants.TEXT_SIZE_NORMAL); - - this.txtKeystoreFile.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - performKeystoreFileChanged(KeystoreConfigurationComposite.this.txtKeystoreFile.getText()); - } - }); - - this.btnBrowse.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog( - KeystoreConfigurationComposite.this.getShell(), SWT.OPEN); - dialog.setFilterExtensions(new String[] { - "*.p12;*.pkcs12;*.pfx;*.ks;*.jks", "*.p12;*.pkcs12;*.pfx;", "*.ks;*.jks*.", "*" }); - dialog.setFilterNames(new String[] { - Messages.getString("common.KeystoreExtension_Description"), - Messages.getString("common.PKCS12Extension_Description"), - Messages.getString("common.KSExtension_Description"), - Messages.getString("common.AllExtension_Description") }); - String fileName = dialog.open(); - File file = null; - if (fileName != null) { - file = new File(fileName); - if (file.exists()) { - performKeystoreFileChanged(fileName); - } - } - } - }); - - this.cmbKeystoreType.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - performKeystoreTypeChanged( - KeystoreConfigurationComposite.this.keystoreTypes.get( - KeystoreConfigurationComposite.this.cmbKeystoreType.getItem( - KeystoreConfigurationComposite.this.cmbKeystoreType.getSelectionIndex()))); - } - }); - - this.txtKeystoreStorePass.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - performKeystoreStorePassChanged(KeystoreConfigurationComposite. - this.txtKeystoreStorePass.getText()); - } - - }); - - this.btnLoad.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - File f = new File(KeystoreConfigurationComposite.this - .configurationContainer.keystoreFile); - try { - loadKeystore(); - } catch (KeyStoreException ex) { - log.error("Error loading keystore", ex); - showErrorDialog(Messages.getString("error.KeyStore")); - } catch (FileNotFoundException ex) { - log.error("Error loading keystore", ex); - showErrorDialog(Messages.formatString( - "error.KeyStoreFileNotExist", f.getName())); - } catch (NoSuchAlgorithmException ex) { - log.error("Error loading keystore", ex); - showErrorDialog(Messages.getString("error.KeyStore")); - } catch (CertificateException ex) { - log.error("Error loading keystore", ex); - showErrorDialog(Messages.getString("error.KeyStore")); - } catch (IOException ex) { - log.error("Error loading keystore", ex); - showErrorDialog(Messages.getString("error.KeyStore")); - } catch (NullPointerException ex) { - log.error("Error loading keystore - NPE?", ex); - showErrorDialog(Messages.getString("error.KeyStore")); - } catch (UnrecoverableKeyException ex) { - log.warn("Error loading keystore, invalid password", ex); - showErrorDialog(Messages.getString("error.KeyStoreStorePass")); - } - } - }); - - this.cmbKeystoreAlias.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - performKeystoreAliasChanged( - KeystoreConfigurationComposite.this.cmbKeystoreAlias.getItem( - KeystoreConfigurationComposite.this.cmbKeystoreAlias.getSelectionIndex())); - } - }); - this.cmbKeystoreAlias.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - performKeystoreAliasChanged(KeystoreConfigurationComposite.this.cmbKeystoreAlias.getText()); - } - }); - - this.cmbKeystorePassStoreType.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - performKeystorePassStorageTypeChanged( - keystorePassStorageTypeOptions.get( - KeystoreConfigurationComposite.this.cmbKeystorePassStoreType.getSelectionIndex() - ).getLeft() - ); - } - }); - - this.txtKeystoreKeyPass.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - performKeystoreKeyPassChanged(KeystoreConfigurationComposite.this.txtKeystoreKeyPass.getText()); - } - }); - - // Load localized strings - - reloadResources(); - } - - void showErrorDialog(String error) { - ErrorDialog e = new ErrorDialog(getShell(), error, BUTTONS.OK); - e.open(); - } - - void loadKeystore() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, UnrecoverableKeyException { - this.cmbKeystoreAlias.remove(0, this.cmbKeystoreAlias.getItemCount()-1); - - ConfigurationDataInMemory config = this.configurationContainer; - this.ks = null; - String pass = config.keystoreStorePass; - - while (this.ks == null) - { - if (pass == null) - { - pass = new PasswordInputDialog( - getShell(), - Messages.getString("keystore_config.KeystoreStorePass"), - Messages.getString("keystore.KeystoreStorePassEntry")).open(); - if (pass == null) - throw new UnrecoverableKeyException("User cancelled password input"); - } - - try { - this.ks = KeystoreUtils.tryLoadKeystore(new File(config.keystoreFile), config.keystoreType, pass); - } catch (UnrecoverableKeyException ex) { - new ErrorDialog(getShell(), Messages.getString("error.KeyStoreStorePass"), BUTTONS.OK).open(); - pass = null; - } - } - config.keystoreStorePass = pass; - - Enumeration aliases = this.ks.aliases(); - while (aliases.hasMoreElements()) - this.cmbKeystoreAlias.add(aliases.nextElement()); - } - - /** - * @param fileName - */ - protected void performKeystoreFileChanged(String fileName) { - log.debug("Selected keystore file: " + fileName); - this.configurationContainer.keystoreFile = fileName; - KeystoreConfigurationComposite.this.txtKeystoreFile.setText(fileName); - int i = fileName.lastIndexOf('.'); - if (i > 0) { - String ext = fileName.substring(i+1); - if ( - ext.equalsIgnoreCase("p12") || - ext.equalsIgnoreCase("pkcs12") || - ext.equalsIgnoreCase("pfx")) - performKeystoreTypeChanged("PKCS12"); - else if ( - ext.equalsIgnoreCase("ks") || - ext.equalsIgnoreCase("jks")) - performKeystoreTypeChanged("JCEKS"); - } - } - - /** - * @param type - */ - protected void performKeystoreTypeChanged(String type) { - log.debug("Selected keystore type: " + type); - this.configurationContainer.keystoreType = type; - for (int i = 0; i < this.cmbKeystoreType.getItemCount(); ++i) { - if (this.keystoreTypes.get(this.cmbKeystoreType.getItem(i)).equals(type)) { - this.cmbKeystoreType.select(i); - break; - } - } - } - - protected void performKeystorePassStorageTypeChanged(KeyStorePassStorageType p) { - this.configurationContainer.keystorePassStorageType = p; - for (int i=0; i keystoreTypes; - private void reloadKeystoreTypeStrings() { - this.keystoreTypes = new HashMap(); - this.keystoreTypes.put(Messages.getString("keystore_config.KeystoreType_PKCS12"), "PKCS12"); - this.keystoreTypes.put(Messages.getString("keystore_config.KeystoreType_JKS"), "JCEKS"); - } - - Vector> keystorePassStorageTypeOptions; - private void reloadKeystorePassStorageTypeStrings() { - keystorePassStorageTypeOptions = new Vector>(); - java.util.function.BiConsumer add = (k,v) -> { - keystorePassStorageTypeOptions.add(new ImmutablePair(k,Messages.getString(v))); - }; - add.accept(null, "keystore_config.SaveToWhere.None"); - add.accept(KeyStorePassStorageType.MEMORY, "keystore_config.SaveToWhere.Memory"); - add.accept(KeyStorePassStorageType.DISK, "keystore_config.SaveToWhere.Disk"); - - int n = keystorePassStorageTypeOptions.size(); - cmbKeystorePassStoreType.setVisibleItemCount(n); - cmbKeystorePassStoreType.setItems(); - for (int i=0; i { - if (e.detail == SWT.TRAVERSE_RETURN) { - processNumberChanged(); - } - }); - - this.txtMobileNumber.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - processNumberChanged(); - } - }); - - this.grpSignatureProfile = new Group(this, SWT.NONE); - SWTUtils.anchor(grpSignatureProfile).right(100,-5).left(0,5).top(grpHandySignatur, 5); - this.grpSignatureProfile.setLayout(new FormLayout()); - SWTUtils.setFontHeight(grpSignatureProfile, Constants.TEXT_SIZE_NORMAL); - - this.cmbSignatureProfiles = new Combo(this.grpSignatureProfile, SWT.READ_ONLY); - SWTUtils.anchor(cmbSignatureProfiles).left(0,10).right(100,-10).top(0,10).bottom(100,-10); - SWTUtils.setFontHeight(cmbSignatureProfiles, Constants.TEXT_SIZE_NORMAL); - SWTUtils.scrollPassthrough(cmbSignatureProfiles); - this.cmbSignatureProfiles.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - Profile current = SimpleConfigurationComposite.this.configurationContainer.getSignatureProfile(); - int index = SimpleConfigurationComposite.this.cmbSignatureProfiles.getSelectionIndex(); - Profile selected = Profile.values()[index]; - if (!current.equals(selected)) { - performProfileSelectionChanged(selected); - } - } - }); - - this.grpSignatureLang = new Group(this, SWT.NONE); - SWTUtils.anchor(grpSignatureLang).right(100,-5).top(grpSignatureProfile, 5).left(0,5); - this.grpSignatureLang.setLayout(new FormLayout()); - SWTUtils.setFontHeight(grpSignatureLang, Constants.TEXT_SIZE_NORMAL); - - this.cmbSignatureLang = new Combo(this.grpSignatureLang, SWT.READ_ONLY); - SWTUtils.anchor(cmbSignatureLang).left(0,10).right(100,-10).top(0,10).bottom(100,-10); - SWTUtils.setFontHeight(cmbSignatureLang, Constants.TEXT_SIZE_NORMAL); - SWTUtils.scrollPassthrough(cmbSignatureLang); - this.cmbSignatureLang.setItems(Arrays.stream(Constants.SUPPORTED_LOCALES).map(l -> l.getDisplayLanguage()).toArray(String[]::new)); - - this.cmbSignatureLang.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - Locale currentLocale = SimpleConfigurationComposite.this.configurationContainer.signatureLocale; - Locale selectedLocale = Constants.SUPPORTED_LOCALES[SimpleConfigurationComposite.this.cmbSignatureLang.getSelectionIndex()]; - if (!currentLocale.equals(selectedLocale)) { - performSignatureLangSelectionChanged(selectedLocale, currentLocale); - } - } - }); - - this.grpSignatureNote = new Group(this, SWT.NONE); - SWTUtils.anchor(grpSignatureNote).right(100,-5).top(grpSignatureLang,5).left(0,5); - this.grpSignatureNote.setLayout(new GridLayout(2, false)); - SWTUtils.setFontHeight(grpSignatureNote, Constants.TEXT_SIZE_NORMAL); - - this.lblSignatureNote = new Label(this.grpSignatureNote, SWT.NONE); - do { /* grid positioning */ - GridData gd_lblSignatureNote = new GridData(SWT.LEFT, SWT.CENTER, - false, false, 1, 1); - gd_lblSignatureNote.widthHint = 66; - this.lblSignatureNote.setLayoutData(gd_lblSignatureNote); - this.lblSignatureNote.setBounds(0, 0, 57, 15); - } while (false); - SWTUtils.setFontHeight(lblSignatureNote, Constants.TEXT_SIZE_NORMAL); - - Composite compSignatureNoteContainer = new Composite(this.grpSignatureNote, SWT.NONE); - compSignatureNoteContainer.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1)); - compSignatureNoteContainer.setLayout(new FormLayout()); - - this.txtSignatureNote = new Text(compSignatureNoteContainer, SWT.BORDER); - SWTUtils.anchor(txtSignatureNote).top(0,0).left(0,5).right(100,-42); - SWTUtils.setFontHeight(txtSignatureNote, Constants.TEXT_SIZE_NORMAL); - - this.txtSignatureNote.addFocusListener(new FocusAdapter() { - @Override - public void focusLost(FocusEvent e) { - processSignatureNoteChanged(); - } - }); - - this.txtSignatureNote.addTraverseListener(e -> { - if (e.detail == SWT.TRAVERSE_RETURN) { - processSignatureNoteChanged(); - } - }); - - Composite compSignatureNoteButtonContainer = new Composite(this.grpSignatureNote, SWT.NONE); - compSignatureNoteButtonContainer.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 2, 1)); - compSignatureNoteButtonContainer.setLayout(new FormLayout()); - - this.btnSignatureNoteDefault = new Button(compSignatureNoteButtonContainer, SWT.NONE); - SWTUtils.anchor(btnSignatureNoteDefault).top(0,0).right(100,-42); - SWTUtils.setFontHeight(btnSignatureNoteDefault, Constants.TEXT_SIZE_BUTTON); - this.btnSignatureNoteDefault.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - SimpleConfigurationComposite.this.txtSignatureNote.setText(getDefaultSignatureBlockNoteTextFor(null, null)); - } - }); - - this.grpLogoOnlyTargetSize = new Group(this, SWT.NONE); - SWTUtils.anchor(grpLogoOnlyTargetSize).left(0,5).right(100,-5).top(grpSignatureProfile,5); - this.grpLogoOnlyTargetSize.setLayout(new FormLayout()); - SWTUtils.setFontHeight(grpLogoOnlyTargetSize, Constants.TEXT_SIZE_NORMAL); - - Label lblLOTSLeft = new Label(this.grpLogoOnlyTargetSize, SWT.HORIZONTAL); - SWTUtils.anchor(lblLOTSLeft).top(0, 5).left(0, 15); - lblLOTSLeft.setText("1cm"); - SWTUtils.setFontHeight(lblLOTSLeft, Constants.TEXT_SIZE_NORMAL); - - Label lblLOTSRight = new Label(this.grpLogoOnlyTargetSize, SWT.HORIZONTAL); - SWTUtils.anchor(lblLOTSRight).top(0,5).right(100, -5); - lblLOTSRight.setText("20cm"); - SWTUtils.setFontHeight(lblLOTSRight, Constants.TEXT_SIZE_NORMAL); - - this.sclLogoOnlyTargetSize = new Scale(this.grpLogoOnlyTargetSize, SWT.HORIZONTAL); - SWTUtils.anchor(sclLogoOnlyTargetSize).top(0,5).left(lblLOTSLeft,5).right(lblLOTSRight,-5); - sclLogoOnlyTargetSize.setMinimum(10); - sclLogoOnlyTargetSize.setMaximum(200); - sclLogoOnlyTargetSize.setIncrement(1); - sclLogoOnlyTargetSize.setPageIncrement(1); - SWTUtils.scrollPassthrough(sclLogoOnlyTargetSize); - SWTUtils.addSelectionListener(sclLogoOnlyTargetSize, e -> - { - configurationContainer.logoOnlyTargetSize = sclLogoOnlyTargetSize.getSelection(); - this.updateLogoOnlyTargetSizeCurrentValueLabel(); - }); - sclLogoOnlyTargetSize.addFocusListener(new FocusAdapter() { - public void focusLost(FocusEvent e) { signatureBlockPreviewChanged(); }; - }); - - this.lblLogoOnlyTargetSizeCurrentValue = new Label(this.grpLogoOnlyTargetSize, SWT.HORIZONTAL); - SWTUtils.anchor(lblLogoOnlyTargetSizeCurrentValue).top(sclLogoOnlyTargetSize, 5).left(0,5).right(100,-5); - lblLogoOnlyTargetSizeCurrentValue.setAlignment(SWT.CENTER); - SWTUtils.setFontHeight(lblLogoOnlyTargetSizeCurrentValue, Constants.TEXT_SIZE_NORMAL); - - this.grpPreview = new Group(this, SWT.NONE); - SWTUtils.anchor(grpPreview).left(0,5).right(100,-5).top(grpSignatureNote, 5).height(250); - this.grpPreview.setLayout(new FormLayout()); - SWTUtils.setFontHeight(grpPreview, Constants.TEXT_SIZE_NORMAL); - - Composite containerComposite = new Composite(this.grpPreview, SWT.NONE); - SWTUtils.anchor(containerComposite).left(0).right(100).top(0).bottom(100); - containerComposite.setLayout(new FormLayout()); - - this.btnBrowseLogo = new Button(containerComposite, SWT.NONE); - SWTUtils.anchor(btnBrowseLogo).top(0,5).right(50,-5); - SWTUtils.setFontHeight(btnBrowseLogo, Constants.TEXT_SIZE_BUTTON); - - this.btnClearImage = new Button(containerComposite, SWT.NATIVE); - SWTUtils.anchor(btnClearImage).top(0,5).left(50, 5); - SWTUtils.setFontHeight(btnClearImage, Constants.TEXT_SIZE_BUTTON); - this.btnClearImage.setEnabled(false); - - this.cSigPreview = new Canvas(containerComposite, SWT.RESIZE); - SWTUtils.anchor(cSigPreview).left(0, 5).right(100,-5).top(btnBrowseLogo,5).bottom(100,-5); - SWTUtils.setFontHeight(cSigPreview, Constants.TEXT_SIZE_NORMAL); - this.cSigPreview.addPaintListener(e -> SimpleConfigurationComposite.this.paintSignaturePreview(e)); - - DropTarget dnd_target = new DropTarget(containerComposite, 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: {} does not exist!", files[0]); //// - return; - } - performProfileSelectionChanged(Profile.BASE_LOGO); - 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.btnClearImage.addSelectionListener(new SelectionAdapter() { - @Override - public void widgetSelected(SelectionEvent e) { - SimpleConfigurationComposite.this.processEmblemChanged(null); - } - }); - this.btnBrowseLogo.addSelectionListener(new ImageFileBrowser()); - - this.cSigPreview.addMouseListener(new MouseAdapter() { - @Override - public void mouseUp(MouseEvent e) { - SimpleConfigurationComposite.this.forceFocus(); - } - }); - - // Load localized strings - reloadResources(); - } - - private PdfAs4SignatureParameter sigPreviewParam = null; - private Image sigPreview = null; - void paintSignaturePreview(PaintEvent evt) { - if (this.sigPreview == null) - return; - Rectangle r = this.sigPreview.getBounds(); - int srcW = r.width; - int srcH = r.height; - Point p = ((Canvas)evt.widget).getSize(); - float dstW = p.x; - float dstH = p.y; - - float scale = dstW / srcW; - if (srcH * scale > dstH) - scale = dstH / srcH; - - float w = srcW * scale; - float h = srcH * scale; - - int x = (int) ((dstW / 2) - (w / 2)); - int y = (int) ((dstH / 2) - (h / 2)); - evt.gc.drawImage(this.sigPreview, 0, 0, srcW, srcH, x, y, (int) w, (int) h); - } - - /** - * - */ - private final class ImageFileBrowser extends SelectionAdapter { - /** - * - */ - public ImageFileBrowser() { - // Nothing to do - } - - @Override - public void widgetSelected(SelectionEvent e) { - FileDialog dialog = new FileDialog( - SimpleConfigurationComposite.this.getShell(), SWT.OPEN); - dialog.setFilterExtensions(new String[] { - "*.jpg;*.png;*.gif", "*.jpg", "*.png", "*.gif", "*" }); - dialog.setFilterNames(new String[] { - Messages.getString("common.ImageExtension_Description"), - Messages.getString("common.JPGExtension_Description"), - Messages.getString("common.PNGExtension_Description"), - Messages.getString("common.GIFExtension_Description"), - Messages.getString("common.AllExtension_Description") }); - String fileName = dialog.open(); - File file = null; - if (fileName != null) { - file = new File(fileName); - if (file.exists()) { - processEmblemChanged(fileName); - } - } - } - } - - private void setEmblemFileInternal(final String filename, boolean force) - throws Exception { - if (!force && this.configurationContainer.getEmblemPath() != null) { - if (this.configurationContainer.getEmblemPath().equals(filename)) { - return; // Ignore ... - } - } - - this.configurationContainer.setEmblem(filename); - this.btnClearImage.setEnabled(filename != null); - this.signatureBlockPreviewChanged(); - this.doLayout(); - } - - void signatureBlockPreviewChanged() { - try { - PdfAs4SignatureParameter param = new PdfAs4SignatureParameter(); - param.signatureProfile = this.configurationContainer.getSignatureProfile(); - if(this.configurationContainer.signatureNote != null && !this.configurationContainer.signatureNote.isEmpty()) { - param.signatureNote = this.configurationContainer.signatureNote; - } - - param.signatureLanguage = this.configurationContainer.signatureLocale.getLanguage(); - param.enablePDFACompat = this.configurationContainer.signaturePDFACompat; - param.targetLogoSize = Math.min(120.0, this.configurationContainer.logoOnlyTargetSize); // TODO WORKAROUND FOR #117 - String image = this.configurationContainer.getEmblemPath(); - if (image != null && !image.trim().isEmpty()) { - param.emblem = new Emblem(image); - } - - this.sigPreviewParam = param; - PdfAs4SignaturePlaceholder.For(param, (p) -> { - if (this.isDisposed()) - return; - - this.getDisplay().syncExec(() -> { - if (this.isDisposed()) - return; - if (this.sigPreviewParam != param) - return; - if (this.sigPreview != null) - this.sigPreview.dispose(); - if (p.hasImage()) - this.sigPreview = new Image(this.getDisplay(), p.getSWTImage()); - this.cSigPreview.redraw(); - }); - }); - } catch (Exception e) { - log.error("Failed to load image for display...", e); - } - } - - void processEmblemChanged(String filename) { - try { - setEmblemFileInternal(filename, false); - } catch (Exception ex) { - log.error("processEmblemChanged: ", ex); - ErrorDialog dialog = new ErrorDialog( - getShell(), - Messages.getString("error.FailedToLoadEmblem"), BUTTONS.OK); - dialog.open(); - } - } - - void processNumberChanged() { - try { - this.txtMobileNumberErrorMarker.setVisible(false); - plainMobileNumberSetter(); - } catch (Exception ex) { - this.txtMobileNumberErrorMarker.setVisible(true); - this.txtMobileNumberErrorMarker.setToolTipText(Messages - .getString("error.InvalidPhoneNumber")); - log.error("processNumberChanged: ", ex); - this.redraw(); - this.doLayout(); - } - } - - int getLocaleElementIndex(Locale locale) { - for (int i = 0; i < Constants.SUPPORTED_LOCALES.length; i++) { - if (Constants.SUPPORTED_LOCALES[i].equals(locale)) { - log.debug("Locale: {} IDX: {}",locale, i); - return i; - } - } - - log.warn("NO Locale match for {}", locale); - return 0; - } - - void performSignatureLangSelectionChanged(Locale selected, Locale previous) { - log.debug("Selected Sign Locale: {}", selected); - this.configurationContainer.signatureLocale = selected; - this.cmbSignatureLang.select(this.getLocaleElementIndex(selected)); - - if ((previous != null) && (txtSignatureNote.getText().equals(getDefaultSignatureBlockNoteTextFor(null, previous)))) - txtSignatureNote.setText(getDefaultSignatureBlockNoteTextFor(null, selected)); - - signatureBlockPreviewChanged(); - } - - - - void performProfileSelectionChanged(Profile newProfile) { - log.debug("Signature Profile {} was selected", newProfile.name()); - Profile oldProfile = this.configurationContainer.getSignatureProfile(); - this.configurationContainer.setSignatureProfile(newProfile); - this.cmbSignatureProfiles.select(newProfile.ordinal()); - - if (txtSignatureNote.getText().equals(getDefaultSignatureBlockNoteTextFor(oldProfile, null))) - txtSignatureNote.setText(getDefaultSignatureBlockNoteTextFor(newProfile, null)); - - this.grpSignatureLang.setVisible(newProfile.hasText()); - this.grpSignatureNote.setVisible(newProfile.hasText()); - this.grpLogoOnlyTargetSize.setVisible(newProfile.equals(Profile.BASE_LOGO)); - - SWTUtils.reanchor(grpPreview).top(newProfile.hasText() ? grpSignatureNote : grpLogoOnlyTargetSize, 5); - this.grpPreview.setVisible(newProfile.isVisibleSignature()); - this.grpPreview.requestLayout(); - signatureBlockPreviewChanged(); - } - - String getDefaultSignatureBlockNoteTextFor(Profile profile, Locale locale){ - if (profile == null) - profile = configurationContainer.getSignatureProfile(); - if (locale == null) - locale = configurationContainer.signatureLocale; - return profile.getDefaultSignatureBlockNote(locale); - } - - private void plainMobileNumberSetter() { - String number = this.txtMobileNumber.getText(); - this.configurationContainer.setMobileNumber(number); - number = this.configurationContainer.getMobileNumber(); - if (number == null) { - this.txtMobileNumber.setText(""); - return; - } - this.txtMobileNumber.setText(number); - } - - void processSignatureNoteChanged() { - String note = this.txtSignatureNote.getText(); - this.configurationContainer.signatureNote = note; - signatureBlockPreviewChanged(); - } - - @Override - public void initConfiguration(ConfigurationManager provider) { - this.configurationContainer.setMobileNumber(provider.getDefaultMobileNumberPersistent()); - - try { - this.configurationContainer.setEmblem(provider.getDefaultEmblemPersistent()); - } catch (InvalidEmblemFile e) { - log.error("Failed to set emblem!", e); - } - - this.configurationContainer.signatureLocale = provider.getSignatureLocale(); - this.configurationContainer.signatureNote = provider.getSignatureNote(); - this.configurationContainer.logoOnlyTargetSize = provider.getLogoOnlyTargetSize(); - } - - /* - * (non-Javadoc) - * @see at.asit.pdfover.gui.composites.BaseConfigurationComposite#loadConfiguration - * () - */ - @Override - public void loadConfiguration() { - // Initialize form fields from configuration Container - String number = this.configurationContainer.getMobileNumber(); - if (number != null) { - this.txtMobileNumber.setText(number); - } - - String emblemFile = this.configurationContainer.getEmblemPath(); - if (emblemFile != null && !emblemFile.trim().isEmpty()) { - this.logoFile = emblemFile; - try { - setEmblemFileInternal(emblemFile, true); - this.btnClearImage.setSelection(true); - } catch (Exception e1) { - log.error("Failed to load emblem: ", e1); - ErrorDialog dialog = new ErrorDialog( - getShell(), - Messages.getString("error.FailedToLoadEmblem"), BUTTONS.OK); - dialog.open(); - } - } - - String note = this.configurationContainer.signatureNote; - - if (note != null) { - this.txtSignatureNote.setText(note); - } - - this.sclLogoOnlyTargetSize.setSelection((int)this.configurationContainer.logoOnlyTargetSize); - this.updateLogoOnlyTargetSizeCurrentValueLabel(); - - this.signatureBlockPreviewChanged(); - - this.performSignatureLangSelectionChanged(this.configurationContainer.signatureLocale, null); - - this.performProfileSelectionChanged(this.configurationContainer.getSignatureProfile()); - - } - - @Override - public void storeConfiguration(ConfigurationManager store) { - store.setDefaultMobileNumberPersistent(this.configurationContainer.getMobileNumber()); - store.setDefaultEmblemPersistent(this.configurationContainer.getEmblemPath()); - store.setSignatureLocalePersistent(this.configurationContainer.signatureLocale); - store.setSignatureNotePersistent(this.configurationContainer.signatureNote); - store.setSignatureProfilePersistent(this.configurationContainer.getSignatureProfile()); - store.setLogoOnlyTargetSizePersistent(this.configurationContainer.logoOnlyTargetSize); - } - - /* - * (non-Javadoc) - * - * @see - * at.asit.pdfover.gui.composites.BaseConfigurationComposite#validateSettings - * () - */ - @Override - public void validateSettings(int resumeFrom) throws Exception { - switch (resumeFrom) { - case 0: - this.plainMobileNumberSetter(); - // Fall through - case 1: - this.processSignatureNoteChanged(); - break; - default: - break; - } - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.composites.StateComposite#reloadResources() - */ - @Override - public void reloadResources() { - SWTUtils.setLocalizedText(grpHandySignatur, "simple_config.MobileBKU_Title"); - SWTUtils.setLocalizedText(lblMobileNumber, "simple_config.PhoneNumber"); - SWTUtils.setLocalizedToolTipText(txtMobileNumber, "simple_config.ExampleNumber_ToolTip"); - this.txtMobileNumber.setMessage(Messages.getString("simple_config.ExampleNumber")); - - SWTUtils.setLocalizedText(grpPreview, "simple_config.Preview_Title"); - SWTUtils.setLocalizedText(btnClearImage, "simple_config.ClearEmblem"); - SWTUtils.setLocalizedText(btnBrowseLogo, "simple_config.ReplaceEmblem"); - SWTUtils.setLocalizedText(grpSignatureNote, "simple_config.Note_Title"); - SWTUtils.setLocalizedText(lblSignatureNote, "simple_config.Note"); - SWTUtils.setLocalizedToolTipText(txtSignatureNote, "simple_config.Note_Tooltip"); - SWTUtils.setLocalizedText(btnSignatureNoteDefault, "simple_config.Note_SetDefault"); - - SWTUtils.setLocalizedText(grpSignatureLang, "simple_config.SigBlockLang_Title"); - SWTUtils.setLocalizedToolTipText(cmbSignatureLang, "simple_config.SigBlockLang_ToolTip"); - - SWTUtils.setLocalizedText(grpSignatureProfile, "simple_config.SigProfile_Title"); - this.cmbSignatureProfiles.setItems(Arrays.stream(Profile.values()).map(v -> Messages.getString("simple_config."+v.name())).toArray(String[]::new)); - - SWTUtils.setLocalizedText(grpLogoOnlyTargetSize, "simple_config.LogoOnlyTargetSize_Title"); - } -} -- cgit v1.2.3