From 1dafb1445de6728a339c9265c678fd2484bd7dc4 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:27:20 +0000 Subject: Make main window size configurable git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@331 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../pdfover/gui/workflow/ConfigProviderImpl.java | 539 +++++++++++---------- 1 file changed, 291 insertions(+), 248 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java') 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 83dea41f..daa04261 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 @@ -25,6 +25,7 @@ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.eclipse.swt.graphics.Point; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,7 +69,7 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { private int proxyPort = -1; - private String mobileBKU = Constants.DEFAULT_MOBILE_BKU_URL; + private String mobileBKUURL = Constants.DEFAULT_MOBILE_BKU_URL; private String outputFolder = STRING_EMPTY; @@ -76,6 +77,278 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { private int placeholderTransparency = 170; + private Point mainWindowSize; + + /* + * (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(Constants.CFG_EMBLEM)); + + // Set Mobile Phone Number + this.setDefaultMobileNumber(config + .getProperty(Constants.CFG_MOBILE_NUMBER)); + + // Set signature note + this.setSignatureNote(config + .getProperty(Constants.CFG_SIGNATURE_NOTE)); + + // Set Proxy Host + this.setProxyHost(config + .getProperty(Constants.CFG_PROXY_HOST)); + + // Set Output Folder + this.setDefaultOutputFolder(config + .getProperty(Constants.CFG_OUTPUT_FOLDER)); + + String localString = config.getProperty(Constants.CFG_LOCALE); + + Locale targetLocale = LocaleSerializer.parseFromString(localString); + if(targetLocale != null) { + this.setLocale(targetLocale); + } + + String signlocalString = config.getProperty(Constants.CFG_SIGN_LOCALE); + + Locale signtargetLocale = LocaleSerializer.parseFromString(signlocalString); + if(signtargetLocale != null) { + this.setSignLocale(signtargetLocale); + } + + String bku = config + .getProperty(Constants.CFG_MOBILE_BKU_URL); + + if (bku != null && !bku.isEmpty()) { + this.mobileBKUURL = bku; + } + + // Set Proxy Port + String proxyPortString = config + .getProperty(Constants.CFG_PROXY_PORT); + + if (proxyPortString != null && !proxyPortString.trim().isEmpty()) { + 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(Constants.CFG_BKU); + + 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 placeholder transparency + int transparency = 170; + try { + transparency = Integer + .parseInt(config + .getProperty(Constants.CFG_SIGNATURE_PLACEHOLDER_TRANSPARENCY)); + } catch (NumberFormatException e) { + log.debug("Couldn't parse placeholder transparency", e); //$NON-NLS-1$ + // ignore parsing exception + } + this.setPlaceholderTransparency(transparency); + + // Set MainWindow size + int width = Constants.DEFAULT_MAINWINDOW_WIDTH; + int height = Constants.DEFAULT_MAINWINDOW_HEIGHT; + String size = config.getProperty(Constants.CFG_MAINWINDOW_SIZE); + parse: { + if (size == null) + break parse; + int pos = size.indexOf(','); + if (pos <= 0) + break parse; + + try { + width = Integer.parseInt(size.substring(0, pos).trim()); + height = Integer.parseInt(size.substring(pos + 1).trim()); + } catch (NumberFormatException e) { + log.debug("Couldn't parse main window size", e); //$NON-NLS-1$ + // ignore parsing exception + } + } + this.mainWindowSize = new Point(width, height); + + // Set Signature Position + String signaturePosition = config + .getProperty(Constants.CFG_SIGNATURE_POSITION); + + SignaturePosition position = null; + + if (signaturePosition != null && !signaturePosition.trim().isEmpty()) { + + 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); + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.workflow.ConfigManipulator#saveCurrentConfiguration() + */ + @Override + public void saveCurrentConfiguration() throws IOException { + String filename = this.getConfigurationFile(); + + File configFile = new File(this.getConfigurationDirectory() + + File.separator + filename); + + Properties props = new Properties(); + props.clear(); + + props.setProperty(Constants.CFG_BKU, this.getDefaultBKU().toString()); + props.setProperty(Constants.CFG_PROXY_HOST, this.getProxyHost()); + props.setProperty(Constants.CFG_PROXY_PORT, + Integer.toString(this.getProxyPort())); + props.setProperty(Constants.CFG_EMBLEM, this.getDefaultEmblem()); + props.setProperty(Constants.CFG_SIGNATURE_NOTE, this.getSignatureNote()); + props.setProperty(Constants.CFG_MOBILE_NUMBER, this.getDefaultMobileNumber()); + props.setProperty(Constants.CFG_OUTPUT_FOLDER, this.getDefaultOutputFolder()); + props.setProperty(Constants.CFG_SIGNATURE_PLACEHOLDER_TRANSPARENCY, + Integer.toString(this.getPlaceholderTransparency())); + + props.setProperty(Constants.CFG_MAINWINDOW_SIZE, + this.mainWindowSize.x + "," + this.mainWindowSize.y); //$NON-NLS-1$ + + Locale configLocale = this.getConfigLocale(); + if(configLocale != null) { + props.setProperty(Constants.CFG_LOCALE, LocaleSerializer.getParsableString(configLocale)); + } + + Locale signLocale = this.getSignLocale(); + if(signLocale != null) { + props.setProperty(Constants.CFG_SIGN_LOCALE, LocaleSerializer.getParsableString(signLocale)); + } + + SignaturePosition pos = this.getDefaultSignaturePosition(); + + if (pos == null) { + props.setProperty(Constants.CFG_SIGNATURE_POSITION, ""); //$NON-NLS-1$ + } else if (pos.useAutoPositioning()) { + props.setProperty(Constants.CFG_SIGNATURE_POSITION, "auto"); //$NON-NLS-1$ + } else { + props.setProperty(Constants.CFG_SIGNATURE_POSITION, + String.format((Locale) null, "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.ConfigProvider#getConfigurationDirectory() + */ + @Override + public String getConfigurationDirectory() { + return Constants.CONFIG_DIRECTORY; + } + + /* + * (non-Javadoc) + * + * @see + * at.asit.pdfover.gui.workflow.ConfigManipulator#setConfigurationFile(java + * .lang.String) + */ + @Override + public void setConfigurationFile(String configurationFile) { + this.configurationFile = configurationFile; + } + + /* + * (non-Javadoc) + * + * @see at.asit.pdfover.gui.workflow.ConfigProvider#getConfigurationFile() + */ + @Override + public String getConfigurationFile() { + return this.configurationFile; + } + /** * Sets the default bku type * @@ -295,253 +568,7 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { */ @Override public String getMobileBKUURL() { - return this.mobileBKU; - } - - /* - * (non-Javadoc) - * - * @see - * at.asit.pdfover.gui.workflow.ConfigProvider#getConfigurationDirectory() - */ - @Override - public String getConfigurationDirectory() { - return Constants.CONFIG_DIRECTORY; - } - - /* - * (non-Javadoc) - * - * @see - * at.asit.pdfover.gui.workflow.ConfigManipulator#setConfigurationFile(java - * .lang.String) - */ - @Override - public void setConfigurationFile(String configurationFile) { - this.configurationFile = configurationFile; - } - - /* - * (non-Javadoc) - * - * @see at.asit.pdfover.gui.workflow.ConfigProvider#getConfigurationFile() - */ - @Override - public String getConfigurationFile() { - return this.configurationFile; - } - - /* - * (non-Javadoc) - * - * @see - * at.asit.pdfover.gui.workflow.ConfigManipulator#saveCurrentConfiguration() - */ - @Override - public void saveCurrentConfiguration() throws IOException { - String filename = this.getConfigurationFile(); - - File configFile = new File(this.getConfigurationDirectory() - + File.separator + filename); - - Properties props = new Properties(); - props.clear(); - - props.setProperty(Constants.CFG_BKU, this.getDefaultBKU().toString()); - props.setProperty(Constants.CFG_PROXY_HOST, this.getProxyHost()); - props.setProperty(Constants.CFG_PROXY_PORT, - Integer.toString(this.getProxyPort())); - props.setProperty(Constants.CFG_EMBLEM, this.getDefaultEmblem()); - props.setProperty(Constants.CFG_SIGNATURE_NOTE, this.getSignatureNote()); - props.setProperty(Constants.CFG_MOBILE_NUMBER, this.getDefaultMobileNumber()); - props.setProperty(Constants.CFG_OUTPUT_FOLDER, this.getDefaultOutputFolder()); - props.setProperty(Constants.CFG_SIGNATURE_PLACEHOLDER_TRANSPARENCY, - Integer.toString(this.getPlaceholderTransparency())); - - Locale configLocale = this.getConfigLocale(); - if(configLocale != null) { - props.setProperty(Constants.CFG_LOCALE, LocaleSerializer.getParsableString(configLocale)); - } - - Locale signLocale = this.getSignLocale(); - if(signLocale != null) { - props.setProperty(Constants.CFG_SIGN_LOCALE, LocaleSerializer.getParsableString(signLocale)); - } - - SignaturePosition pos = this.getDefaultSignaturePosition(); - - if (pos == null) { - props.setProperty(Constants.CFG_SIGNATURE_POSITION, ""); //$NON-NLS-1$ - } else if (pos.useAutoPositioning()) { - props.setProperty(Constants.CFG_SIGNATURE_POSITION, "auto"); //$NON-NLS-1$ - } else { - props.setProperty(Constants.CFG_SIGNATURE_POSITION, - String.format((Locale) null, "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.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(Constants.CFG_EMBLEM)); - - // Set Mobile Phone Number - this.setDefaultMobileNumber(config - .getProperty(Constants.CFG_MOBILE_NUMBER)); - - // Set signature note - this.setSignatureNote(config - .getProperty(Constants.CFG_SIGNATURE_NOTE)); - - // Set Proxy Host - this.setProxyHost(config - .getProperty(Constants.CFG_PROXY_HOST)); - - // Set Output Folder - this.setDefaultOutputFolder(config - .getProperty(Constants.CFG_OUTPUT_FOLDER)); - - String localString = config.getProperty(Constants.CFG_LOCALE); - - Locale targetLocale = LocaleSerializer.parseFromString(localString); - if(targetLocale != null) { - this.setLocale(targetLocale); - } - - String signlocalString = config.getProperty(Constants.CFG_SIGN_LOCALE); - - Locale signtargetLocale = LocaleSerializer.parseFromString(signlocalString); - if(signtargetLocale != null) { - this.setSignLocale(signtargetLocale); - } - - String bku = config - .getProperty(Constants.CFG_MOBILE_BKU_URL); - - if (bku != null && !bku.isEmpty()) { - this.mobileBKU = bku; - } - - // Set Proxy Port - String proxyPortString = config - .getProperty(Constants.CFG_PROXY_PORT); - - if (proxyPortString != null && !proxyPortString.trim().isEmpty()) { - 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(Constants.CFG_BKU); - - 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 placeholder transparency - int transparency = 170; - try { - transparency = Integer - .parseInt(config - .getProperty(Constants.CFG_SIGNATURE_PLACEHOLDER_TRANSPARENCY)); - } catch (NumberFormatException e) { - log.debug("Couldn't parse placeholder transparency", e); //$NON-NLS-1$ - // ignore parsing exception - } - this.setPlaceholderTransparency(transparency); - - // Set Signature Position - String signaturePosition = config - .getProperty(Constants.CFG_SIGNATURE_POSITION); - - SignaturePosition position = null; - - if (signaturePosition != null && !signaturePosition.trim().isEmpty()) { - - 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); + return this.mobileBKUURL; } /* @@ -612,4 +639,20 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { return this.signLocale; } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigManipulator#setMainWindowSize(org.eclipse.swt.graphics.Point) + */ + @Override + public void setMainWindowSize(Point size) { + this.mainWindowSize = size; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigProvider#getMainWindowSize() + */ + @Override + public Point getMainWindowSize() { + return this.mainWindowSize; + } + } -- cgit v1.2.3