[Schmitzm-commits] r2003 - in trunk/schmitzm-core/src/main: java/de/schmitzm/io java/de/schmitzm/swing java/de/schmitzm/swing/input resources/de/schmitzm/swing/resource/locales

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Thu May 24 15:25:49 CEST 2012


Author: mojays
Date: 2012-05-24 15:25:49 +0200 (Thu, 24 May 2012)
New Revision: 2003

Added:
   trunk/schmitzm-core/src/main/java/de/schmitzm/io/ConnectionSettings.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ConnectionSettingsDialog.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ConnectionSettingsPanel.java
Removed:
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsDialog.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsPanel.java
Modified:
   trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/ManualInputOption.java
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
   trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
Log:
ProxySettingsPanel/Dialog renamed to ConnectionSettingsPanel/Dialog
ConnectionSettingsPanel extended with timeout settings
new ConnectionSettings to hold all information

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/io/ConnectionSettings.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/ConnectionSettings.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/ConnectionSettings.java	2012-05-24 13:25:49 UTC (rev 2003)
@@ -0,0 +1,166 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.io;
+
+import java.io.IOException;
+import java.net.Proxy;
+import java.net.URL;
+import java.net.URLConnection;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Holds several intenet connection settings.
+ * <ul>
+ *   <li>proxy setting</li>
+ *   <li>connection timeout</li>
+ *   <li>read timeout</li>
+ *   <li>number of download retries</li>
+ * </ul>
+ * @author Martin O.J. Schmitz
+ */
+public class ConnectionSettings {
+  private static Logger LOGGER = Logger.getLogger(ConnectionSettings.class.getName());
+
+  /** Holds whether proxy should be used. */
+  protected boolean proxyUsed = false;
+  /** Holds the proxy settings. */
+  protected Proxy proxy = null;
+  /** Holds the connection timeout in ms */
+  protected int connTimeout = 0;
+  /** Holds the connection read timeout in ms */
+  protected int connReadTimeout = 0;
+  /** Holds the number of connection/download retries */
+  protected int connRetries = 0;
+  
+  
+  /**
+   * Returns whether proxy server should be used.
+   */
+  public boolean isProxyUsed() {
+    return proxyUsed;
+  }
+
+  /**
+   * Sets whether proxy server should be used.
+   */
+  public void setProxyUsed(boolean proxyUsed) {
+    this.proxyUsed = proxyUsed;
+  }
+
+  /**
+   * Returns the proxy settings.
+   */
+  public Proxy getProxy() {
+    return proxy;
+  }
+
+  /**
+   * Returns the proxy to be used for connection and is never {@code null}.
+   * Returns {@link Proxy#NO_PROXY} if "proxy used" flag is set to {@code false} or
+   * no proxy is specified in settings.
+   */
+  public Proxy getProxyForConnection() {
+    if ( !isProxyUsed() )
+      return Proxy.NO_PROXY;
+    if ( proxy == null )
+      return Proxy.NO_PROXY;
+    return proxy;
+  }
+
+  /**
+   * Sets the proxy settings.
+   */
+  public void setProxy(Proxy proxy) {
+    this.proxy = proxy;
+  }
+  
+  /**
+   * Returns the connection timeout in ms.
+   */
+  public int getConnTimeout() {
+    return connTimeout;
+  }
+  
+  /**
+   * Sets the connection timeout in ms.
+   */
+  public void setConnTimeout(int connTimeout) {
+    this.connTimeout = connTimeout;
+  }
+  
+  /**
+   * Returns the connection read timeout in ms.
+   */
+  public int getConnReadTimeout() {
+    return connReadTimeout;
+  }
+  
+  /**
+   * Sets the connection read timeout in ms.
+   */
+  public void setConnReadTimeout(int connReadTimeout) {
+    this.connReadTimeout = connReadTimeout;
+  }
+  
+  /**
+   * Returns the number of connection/download retries.
+   */
+  public int getConnRetries() {
+    return connRetries;
+  }
+
+  /**
+   * Sets the number of connection/download retries.
+   */
+  public void setConnRetries(int connRetries) {
+    this.connRetries = connRetries;
+  }
+  
+  /**
+   * Opens an {@link URLConnection} with the current settings.
+   * Note: This method only sets the timeout propertiesm, but does not
+   * handle the retries! This must be done by the calling application!
+   * @param url URL to open the connection for
+   */
+  public URLConnection openConnection(URL url) throws IOException {
+    LOGGER.debug("Open connection to: "+url);
+    URLConnection connection = url.openConnection( getProxyForConnection() );
+    if ( getConnTimeout() > 0 ) {
+      connection.setConnectTimeout(getConnTimeout());
+      LOGGER.debug("Connection timeout set: "+connTimeout+"ms");
+    }
+    if ( getConnReadTimeout() > 0 ) {
+      connection.setReadTimeout(getConnTimeout());
+      LOGGER.debug("Read timeout set: "+getConnReadTimeout()+"ms");
+    }
+    return connection;
+  }
+}

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2012-05-17 14:37:55 UTC (rev 2002)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2012-05-24 13:25:49 UTC (rev 2003)
@@ -573,11 +573,11 @@
      * @param url   remote URL
      * @param file  local file (if {@code null} a temporary file is created, which will be
      *              deleted after JVM exit!)
-     * @param timeout connection timeout in ms
+     * @param timeout timeout in ms used for connection timeout and read timeout
      * @param maxRetries number of download retries in case of any error 
      */
     public static File downloadUrlToFile(URL url, File file, int timeout, int maxRetries) throws IOException {
-      return downloadUrlToFile(url, null, file, timeout, maxRetries);
+      return downloadUrlToFile(url, null, file, timeout, timeout, maxRetries);
     }
 
     /**
@@ -586,10 +586,10 @@
      * @param proxy proxy server used for url connection (can be {@code null})
      * @param file  local file (if {@code null} a temporary file is created, which will be
      *              deleted after JVM exit!)
-     * @param timeout connection timeout in ms
+     * @param timeout timeout in ms used for connection timeout and read timeout
      */
     public static File downloadUrlToFile(URL url, Proxy proxy, File file, int timeout) throws IOException {
-     return downloadUrlToFile(url, proxy, file, timeout, 0);
+     return downloadUrlToFile(url, proxy, file, timeout, timeout, 0);
     }
     
     /**
@@ -598,10 +598,41 @@
      * @param proxy proxy server used for url connection (can be {@code null})
      * @param file  local file (if {@code null} a temporary file is created, which will be
      *              deleted after JVM exit!)
-     * @param timeout connection timeout in ms
+     * @param timeout timeout in ms used for connection timeout and read timeout
      * @param maxRetries number of download retries in case of any error 
      */
     public static File downloadUrlToFile(URL url, Proxy proxy, File file, int timeout, int maxRetries) throws IOException {
+      return downloadUrlToFile(url, proxy, file, timeout, timeout, maxRetries);
+    }
+    
+    /**
+     * Downloads an {@link URL} to local file.
+     * @param url   remote URL
+     * @param connSettings connection settings (proxy, timeouts, retries)
+     * @param file  local file (if {@code null} a temporary file is created, which will be
+     *              deleted after JVM exit!)
+     */
+    public static File downloadUrlToFile(URL url, ConnectionSettings connSettings, File file) throws IOException {
+      return downloadUrlToFile(url,
+                               connSettings.getProxyForConnection(),
+                               file,
+                               connSettings.getConnTimeout(),
+                               connSettings.getConnReadTimeout(),
+                               connSettings.getConnRetries()
+      );
+    }
+
+    /**
+     * Downloads an {@link URL} to local file.
+     * @param url   remote URL
+     * @param proxy proxy server used for url connection (can be {@code null})
+     * @param file  local file (if {@code null} a temporary file is created, which will be
+     *              deleted after JVM exit!)
+     * @param connTimeout connection timeout in ms
+     * @param readTimeout read timeout in ms
+     * @param maxRetries number of download retries in case of any error 
+     */
+    public static File downloadUrlToFile(URL url, Proxy proxy, File file, int connTimeout, int readTimeout, int maxRetries) throws IOException {
       if ( file == null )
         file = createTemporaryFile("java-schmitzm-",null,true);
       if ( proxy == null )
@@ -616,10 +647,14 @@
           // JUST HANDLE USING PROXY!!
           // Note: Problem with read timeout exception remains! :-(
           URLConnection connection = url.openConnection(proxy);
-          connection.setConnectTimeout(timeout);
-          LOGGER.debug("Connection timeout set: "+timeout+"ms");
-          connection.setReadTimeout(timeout);
-          LOGGER.debug("Read timeout set: "+timeout+"ms");
+          if ( connTimeout > 0 ) {
+            connection.setConnectTimeout(connTimeout);
+            LOGGER.debug("Connection timeout set: "+connTimeout+"ms");
+          }
+          if ( readTimeout > 0 ) {
+            connection.setReadTimeout(readTimeout);
+            LOGGER.debug("Read timeout set: "+readTimeout+"ms");
+          }
           LOGGER.debug("Download: "+url+" to "+file);
           InputStream input = connection.getInputStream();
           copyInputStreamToFile(input, file);
@@ -679,7 +714,7 @@
 
       return file;
     }
-
+    
     /**
      * Copies the content of an {@link InputStream} to local {@link File}.<br>
      * Copied 1:1 from FileUtils (Apache Commons IO 2.0).
@@ -1423,8 +1458,35 @@
 	  return new Proxy(proxyType, proxySocket);
 	}
 	
-	
     /**
+     * Returns the host name of a proxy.
+     */
+    public static String getProxyHost(Proxy proxy) {
+      if ( proxy == null )
+        return null;
+      InetSocketAddress socketAddr = (InetSocketAddress)proxy.address();
+      if ( socketAddr == null )
+        return null;
+      try {
+        return socketAddr.getHostString();
+      } catch (Throwable err) {
+        return socketAddr.getHostName();
+      } 
+    }
+
+    /**
+     * Returns the port of a proxy.
+     */
+    public static int getProxyPort(Proxy proxy) {
+      if ( proxy == null )
+        return 0;
+      InetSocketAddress socketAddr = (InetSocketAddress)proxy.address();
+      if ( socketAddr == null )
+        return 0;
+      return socketAddr.getPort();
+    }
+
+    /**
      * Extracts all links (href tags) from website document.
      * @param url URL of a website
      * @return an empty list, if {@code null} URL is given

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ConnectionSettingsDialog.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ConnectionSettingsDialog.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ConnectionSettingsDialog.java	2012-05-24 13:25:49 UTC (rev 2003)
@@ -0,0 +1,103 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.swing;
+
+import java.awt.BorderLayout;
+import java.awt.Dialog;
+import java.awt.Frame;
+import java.net.Proxy;
+
+import de.schmitzm.io.ConnectionSettings;
+
+/**
+ * Dialog to specify internet connection settings.
+ * @see ConnectionSettingsPanel
+ * @author Martin O.J. Schmitz
+ *
+ */
+public class ConnectionSettingsDialog extends OkCancelDialog {
+  /** Holds the component to specify settings. */
+  protected ConnectionSettingsPanel connPanel;
+  
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   */
+  public ConnectionSettingsDialog(Frame owner, String title) {
+    super(owner, title, true);
+  }
+  
+  /**
+   * Creates a new dialog 
+   * @param owner parent component
+   * @param title dialog title
+   */
+  public ConnectionSettingsDialog(Dialog owner, String title) {
+    super(owner, title, true);
+  }
+
+  /**
+   * Called immediately by the constructor to initialize the
+   * dialog.
+   */
+  @Override
+  protected void init() {
+    super.init();
+    setPreferredSize( null );
+    this.connPanel = new ConnectionSettingsPanel();
+    getContentPane().add(connPanel, BorderLayout.CENTER);
+    pack();
+    SwingUtil.setRelativeFramePosition(this, getOwner(), 0.5, 0.5);
+  }
+
+  /**
+   * Returns the {@link Proxy} specified by the settings.
+   */
+  public Proxy getProxy() {
+    return connPanel.getProxy();
+  }
+  
+  /**
+   * Returns the complete specified settings.
+   * @return
+   */
+  public ConnectionSettings getConnectionSettings() {
+    return connPanel.getConnectionSettings();
+  }
+
+  /**
+   * Returns the panel holding the proxy settings.
+   */
+  public ConnectionSettingsPanel getConnectionSettingsPanel() {
+    return connPanel;
+  }
+
+}

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ConnectionSettingsPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ConnectionSettingsPanel.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ConnectionSettingsPanel.java	2012-05-24 13:25:49 UTC (rev 2003)
@@ -0,0 +1,203 @@
+/**
+ * Copyright (c) 2009 Martin O. J. Schmitz.
+ * 
+ * This file is part of the SCHMITZM library - a collection of utility 
+ * classes based on Java 1.6, focusing (not only) on Java Swing 
+ * and the Geotools library.
+ * 
+ * The SCHMITZM project is hosted at:
+ * http://wald.intevation.org/projects/schmitzm/
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 3
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public License (license.txt)
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ * or try this link: http://www.gnu.org/licenses/lgpl.html
+ * 
+ * Contributors:
+ *     Martin O. J. Schmitz - initial API and implementation
+ *     Stefan A. Tzeggai - additional utility classes
+ */
+package de.schmitzm.swing;
+
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.Proxy.Type;
+
+import javax.swing.JLabel;
+
+import net.miginfocom.swing.MigLayout;
+
+import org.apache.log4j.Logger;
+
+import de.schmitzm.io.ConnectionSettings;
+import de.schmitzm.io.IOUtil;
+import de.schmitzm.lang.LangUtil;
+import de.schmitzm.swing.input.InputOption;
+import de.schmitzm.swing.input.InputOptionAdapter;
+import de.schmitzm.swing.input.ManualInputOption;
+import de.schmitzm.swing.input.SelectionInputOption;
+
+/**
+ * Panel to specify internet connection settings:
+ * <ul>
+ *   <li>proxy setting</li>
+ *   <li>connection timeout</li>
+ *   <li>read timeout</li>
+ *   <li>number of download retries</li>
+ * </ul>
+ * @author Martin O.J. Schmitz
+ */
+public class ConnectionSettingsPanel extends JPanel {
+  private Logger LOGGER = LangUtil.createLogger(this);  
+  
+  protected JLabel proxyUsedCaption;
+  protected SelectionInputOption.Radio<Boolean> proxyUsed;
+  protected JLabel proxyTypeCaption;
+  protected SelectionInputOption.Combo<Proxy.Type> proxyType;
+  protected JLabel proxyHostCaption;
+  protected ManualInputOption.Text proxyHost;
+  protected JLabel proxyPortCaption;
+  protected ManualInputOption.Integer proxyPort;
+  protected JLabel connTimeoutCaption;
+  protected ManualInputOption.Integer connTimeout;
+  protected JLabel readTimeoutCaption;
+  protected ManualInputOption.Integer readTimeout;
+  protected JLabel connRetriesCaption;
+  protected ManualInputOption.Integer connRetries;
+  
+  public ConnectionSettingsPanel()  {
+    super( new MigLayout("wrap 3","[]20[grow]","[top]") );
+    
+    proxyUsed = new SelectionInputOption.Radio<Boolean>(null, false, new Boolean[] {false,true}, false, new String[] {SwingUtil.R("ConnectionSettingsPanel.proxy.disabled"),SwingUtil.R("ConnectionSettingsPanel.proxy.enabled")} );
+    proxyUsed.addInputOptionListener( new InputOptionAdapter() {
+      @Override
+      public <E> void optionChanged(InputOption<E> inputOption, E oldValue, E newValue) {
+        updateComponentsEnabled();
+      }
+    });
+    proxyTypeCaption = new JLabel(SwingUtil.R("ConnectionSettingsPanel.proxy.type")+":");
+    proxyType = new SelectionInputOption.Combo<Proxy.Type>(null, true, new Proxy.Type[] {Proxy.Type.HTTP, Proxy.Type.SOCKS}, Proxy.Type.HTTP, new String[] {"HTTP","SOCKS"} );
+    proxyHostCaption = new JLabel(SwingUtil.R("ConnectionSettingsPanel.proxy.host")+":");
+    proxyHost = new ManualInputOption.Text(null,false);
+    proxyPortCaption = new JLabel(SwingUtil.R("ConnectionSettingsPanel.proxy.port")+":");
+    proxyPort = new ManualInputOption.Integer(null,false,0);
+    connTimeoutCaption = new JLabel(SwingUtil.R("ConnectionSettingsPanel.conn.timeout")+":");
+    connTimeout = new ManualInputOption.Integer(null,false,0);
+    readTimeoutCaption = new JLabel(SwingUtil.R("ConnectionSettingsPanel.conn.readtimeout")+":");
+    readTimeout = new ManualInputOption.Integer(null,false,0);
+    connRetriesCaption = new JLabel(SwingUtil.R("ConnectionSettingsPanel.conn.retries")+":");
+    connRetries = new ManualInputOption.Integer(null,false,0);
+    
+    add(proxyUsed,"span 3");
+    add(proxyTypeCaption,"gapleft 30");
+    add(proxyType,"span 2");
+    add(proxyHostCaption,"gapleft 30");
+    add(proxyHost,"span 2, w 150, growx");
+    add(proxyPortCaption,"gapleft 30");
+    add(proxyPort,"span 2, w 50");
+    add(new JLabel(" "),"wrap");
+    add(connTimeoutCaption,"span 2");
+    add(connTimeout,"w 50");
+    add(readTimeoutCaption,"span 2");
+    add(readTimeout,"w 50");
+    add(connRetriesCaption,"span 2");
+    add(connRetries,"w 50");
+    
+    updateComponentsEnabled();
+  }
+  
+  /**
+   * Updated the enabled state of the input components according to the
+   * "Use proxy" radio buttons.
+   */
+  protected void updateComponentsEnabled() {
+    boolean useProxy = (Boolean)proxyUsed.getValue();
+    proxyType.setEnabled(useProxy);
+    proxyHost.setEnabled(useProxy);
+    proxyPort.setEnabled(useProxy);
+  }
+  
+  /**
+   * Returns the {@link Proxy} specified by the panel components.
+   */
+  public Proxy getProxy() {
+    LOGGER.debug("getProxy():  ProxyUsed = "+proxyUsed.getValue()+"\tProxyType = "+proxyType.getValue()+"\tHost = '"+proxyHost.getValue()+"'\tPort = "+proxyPort.getValue());
+    if ( !((Boolean)proxyUsed.getValue()) )
+      return Proxy.NO_PROXY;
+    Proxy.Type type = (Proxy.Type)proxyType.getValue();
+    String     host = (String)proxyHost.getValue();
+    Integer    port = (Integer)proxyPort.getValue();
+    if ( port == null )
+      port = 0;
+    
+    return IOUtil.createProxy(type, host, port);
+  }
+  
+  /**
+   * Sets the {@link Proxy} settings for the panel components.
+   */
+  public void setProxy(boolean used, Proxy.Type type, String host, int port) {
+//    LOGGER.debug("setProxy(.) method parameter:  ProxyUsed = "+used+"\tProxyType = "+type+"\tHost = '"+host+"'\tPort = "+port);
+    proxyUsed.setValue(used);
+    proxyType.setSelectedItem(type);
+    proxyHost.setValue(host);
+    proxyPort.setValue(String.valueOf(port));
+    updateComponentsEnabled();
+//    LOGGER.debug("setProxy(.) components after set:  ProxyUsed = "+proxyUsed.getValue()+"\tProxyType = "+proxyType.getValue()+"\tHost = '"+proxyHost.getValue()+"'\tPort = "+proxyPort.getValue());
+  }
+  
+  /**
+   * Returns a {@link ConnectionSettings} object which holds all of the 
+   * current GUI settings.
+   * @return always a new {@link ConnectionSettings} instance, so changes
+   *         on this object does not effect GUI unless {@link #setConnectionSettings(ConnectionSettings)}
+   *         is called!
+   */
+  public ConnectionSettings getConnectionSettings() {
+    ConnectionSettings settings = new ConnectionSettings();
+    settings.setProxy( IOUtil.createProxy((Proxy.Type)proxyType.getValue(), (String)proxyHost.getValue(), (Integer)proxyPort.getValue()) );
+    settings.setProxyUsed( (Boolean)proxyUsed.getValue() );
+    settings.setConnTimeout( connTimeout.getValue() );
+    settings.setConnReadTimeout( readTimeout.getValue() );
+    settings.setConnRetries( connRetries.getValue() );
+    return settings;
+  }
+
+  /**
+   * Sets the GUI settings by a {@link ConnectionSettings} object.
+   */
+  public void setConnectionSettings(ConnectionSettings settings) {
+    if ( settings == null ){
+      setProxy(false, null, "", 0);
+      connTimeout.setValue(0);
+      readTimeout.setValue(0);
+      connRetries.setValue(0);
+      return;
+    }
+    Proxy             proxy      = settings.getProxy();
+    InetSocketAddress socketAddr = proxy != null ? (InetSocketAddress)proxy.address() : null;
+    String host = "";
+    try {
+      host = socketAddr != null ? socketAddr.getHostString() : null;
+    } catch (Throwable err) {
+      host = socketAddr != null ? socketAddr.getHostName() : null;
+    }    
+    setProxy(settings.isProxyUsed(),
+             proxy != null ? proxy.type() : Type.HTTP,
+             IOUtil.getProxyHost(proxy),
+             IOUtil.getProxyPort(proxy));
+    connTimeout.setValue(settings.getConnTimeout());
+    readTimeout.setValue(settings.getConnReadTimeout());
+    connRetries.setValue(settings.getConnRetries());
+  }
+}

Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsDialog.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsDialog.java	2012-05-17 14:37:55 UTC (rev 2002)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsDialog.java	2012-05-24 13:25:49 UTC (rev 2003)
@@ -1,92 +0,0 @@
-/**
- * Copyright (c) 2009 Martin O. J. Schmitz.
- * 
- * This file is part of the SCHMITZM library - a collection of utility 
- * classes based on Java 1.6, focusing (not only) on Java Swing 
- * and the Geotools library.
- * 
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- * 
- * Contributors:
- *     Martin O. J. Schmitz - initial API and implementation
- *     Stefan A. Tzeggai - additional utility classes
- */
-package de.schmitzm.swing;
-
-import java.awt.BorderLayout;
-import java.awt.Dialog;
-import java.awt.Frame;
-import java.net.Proxy;
-
-/**
- * Dialog to specify proxy settings.
- * @author Martin O.J. Schmitz
- *
- */
-public class ProxySettingsDialog extends OkCancelDialog {
-  /** Holds the component to specify settings. */
-  protected ProxySettingsPanel proxyPanel;
-  
-  /**
-   * Creates a new dialog 
-   * @param owner parent component
-   * @param title dialog title
-   */
-  public ProxySettingsDialog(Frame owner, String title) {
-    super(owner, title, true);
-  }
-  
-  /**
-   * Creates a new dialog 
-   * @param owner parent component
-   * @param title dialog title
-   */
-  public ProxySettingsDialog(Dialog owner, String title) {
-    super(owner, title, true);
-  }
-
-  /**
-   * Called immediately by the constructor to initialize the
-   * dialog.
-   */
-  @Override
-  protected void init() {
-    super.init();
-    setPreferredSize( null );
-    this.proxyPanel = new ProxySettingsPanel();
-    getContentPane().add(proxyPanel, BorderLayout.CENTER);
-    pack();
-    SwingUtil.setRelativeFramePosition(this, getOwner(), 0.5, 0.5);
-  }
-
-  /**
-   * Returns the {@link Proxy} specified by the settings.
-   */
-  public Proxy getProxy() {
-    return proxyPanel.getProxy();
-  }
-
-  /**
-   * Returns the panel holding the proxy settings.
-   */
-  public ProxySettingsPanel getProxySettingsPanel() {
-    return proxyPanel;
-  }
-
-}

Deleted: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsPanel.java	2012-05-17 14:37:55 UTC (rev 2002)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsPanel.java	2012-05-24 13:25:49 UTC (rev 2003)
@@ -1,130 +0,0 @@
-/**
- * Copyright (c) 2009 Martin O. J. Schmitz.
- * 
- * This file is part of the SCHMITZM library - a collection of utility 
- * classes based on Java 1.6, focusing (not only) on Java Swing 
- * and the Geotools library.
- * 
- * The SCHMITZM project is hosted at:
- * http://wald.intevation.org/projects/schmitzm/
- * 
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 3
- * of the License, or (at your option) any later version.
- * 
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- * 
- * You should have received a copy of the GNU Lesser General Public License (license.txt)
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
- * or try this link: http://www.gnu.org/licenses/lgpl.html
- * 
- * Contributors:
- *     Martin O. J. Schmitz - initial API and implementation
- *     Stefan A. Tzeggai - additional utility classes
- */
-package de.schmitzm.swing;
-
-import java.net.Proxy;
-
-import javax.swing.JLabel;
-
-import net.miginfocom.swing.MigLayout;
-
-import org.apache.log4j.Logger;
-
-import de.schmitzm.io.IOUtil;
-import de.schmitzm.lang.LangUtil;
-import de.schmitzm.swing.input.InputOption;
-import de.schmitzm.swing.input.InputOptionAdapter;
-import de.schmitzm.swing.input.ManualInputOption;
-import de.schmitzm.swing.input.SelectionInputOption;
-
-/**
- * Panel to specify proxy server settings.
- * @author Martin O.J. Schmitz
- */
-public class ProxySettingsPanel extends JPanel {
-  private Logger LOGGER = LangUtil.createLogger(this);  
-  
-  protected JLabel oroxyUsedCaption;
-  protected SelectionInputOption.Radio<Boolean> proxyUsed;
-  protected JLabel proxyTypeCaption;
-  protected SelectionInputOption.Combo<Proxy.Type> proxyType;
-  protected JLabel proxyHostCaption;
-  protected ManualInputOption.Text proxyHost;
-  protected JLabel proxyPortCaption;
-  protected ManualInputOption.Integer proxyPort;
-  
-  public ProxySettingsPanel()  {
-    super( new MigLayout("wrap 2","[]20[grow]","[top]") );
-    
-    proxyUsed = new SelectionInputOption.Radio<Boolean>(null, false, new Boolean[] {false,true}, false, new String[] {SwingUtil.R("ProxySettingsPanel.proxy.disabled"),SwingUtil.R("ProxySettingsPanel.proxy.enabled")} );
-    proxyUsed.addInputOptionListener( new InputOptionAdapter() {
-      @Override
-      public <E> void optionChanged(InputOption<E> inputOption, E oldValue, E newValue) {
-        updateComponentsEnabled();
-      }
-    });
-    proxyTypeCaption = new JLabel(SwingUtil.R("ProxySettingsPanel.proxy.type")+":");
-    proxyType = new SelectionInputOption.Combo<Proxy.Type>(null, true, new Proxy.Type[] {Proxy.Type.HTTP, Proxy.Type.SOCKS}, Proxy.Type.HTTP, new String[] {"HTTP","SOCKS"} );
-    proxyHostCaption = new JLabel(SwingUtil.R("ProxySettingsPanel.proxy.host")+":");
-    proxyHost = new ManualInputOption.Text(null,false);
-    proxyPortCaption = new JLabel(SwingUtil.R("ProxySettingsPanel.proxy.port")+":");
-    proxyPort = new ManualInputOption.Integer(null,false,0);
-    
-    add(proxyUsed,"span 2");
-    add(proxyTypeCaption,"gapleft 30");
-    add(proxyType,"");
-    add(proxyHostCaption,"gapleft 30");
-    add(proxyHost,"w 150, growx");
-    add(proxyPortCaption,"gapleft 30");
-    add(proxyPort,"w 50");
-    
-    updateComponentsEnabled();
-  }
-  
-  /**
-   * Updated the enabled state of the input components according to the
-   * "Use proxy" radio buttons.
-   */
-  protected void updateComponentsEnabled() {
-    boolean useProxy = (Boolean)proxyUsed.getValue();
-    proxyType.setEnabled(useProxy);
-    proxyHost.setEnabled(useProxy);
-    proxyPort.setEnabled(useProxy);
-  }
-  
-  /**
-   * Returns the {@link Proxy} specified by the panel components.
-   */
-  public Proxy getProxy() {
-    LOGGER.debug("getProxy():  ProxyUsed = "+proxyUsed.getValue()+"\tProxyType = "+proxyType.getValue()+"\tHost = '"+proxyHost.getValue()+"'\tPort = "+proxyPort.getValue());
-    if ( !((Boolean)proxyUsed.getValue()) )
-      return Proxy.NO_PROXY;
-    Proxy.Type type = (Proxy.Type)proxyType.getValue();
-    String     host = (String)proxyHost.getValue();
-    Integer    port = (Integer)proxyPort.getValue();
-    if ( port == null )
-      port = 0;
-    
-    return IOUtil.createProxy(type, host, port);
-  }
-  
-  /**
-   * Sets the {@link Proxy} settings for the panel components.
-   */
-  public void setProxy(boolean used, Proxy.Type type, String host, int port) {
-//    LOGGER.debug("setProxy(.) method parameter:  ProxyUsed = "+used+"\tProxyType = "+type+"\tHost = '"+host+"'\tPort = "+port);
-    proxyUsed.setValue(used);
-    proxyType.setSelectedItem(type);
-    proxyHost.setValue(host);
-    proxyPort.setValue(String.valueOf(port));
-    updateComponentsEnabled();
-//    LOGGER.debug("setProxy(.) components after set:  ProxyUsed = "+proxyUsed.getValue()+"\tProxyType = "+proxyType.getValue()+"\tHost = '"+proxyHost.getValue()+"'\tPort = "+proxyPort.getValue());
-  }
-}

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/ManualInputOption.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/ManualInputOption.java	2012-05-17 14:37:55 UTC (rev 2002)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/ManualInputOption.java	2012-05-24 13:25:49 UTC (rev 2003)
@@ -294,7 +294,19 @@
 			return java.lang.Integer.parseInt(((JTextField) inpComp).getText());
 		}
 
-		/**
+	    /**
+	     * Setzt die aktuelle Eingabe im {@link JTextField}.
+	     * 
+	     * @param newValue kann vom Typ {@link String} oder {@link Number} sein
+	     */
+	    @Override
+	    protected boolean performSetValue(Object newValue) {
+	      if ( newValue instanceof Number )
+	        newValue = String.valueOf( ((Number)newValue).longValue() );
+	      return super.performSetValue(newValue);
+	    }
+
+	    /**
 		 * Prueft, ob ein gueltiger Integer-Wert im Feld eingegeben wurde.
 		 */
 		@Override
@@ -410,6 +422,18 @@
 			return convertCurrentValue();
 		}
 
+		/**
+         * Setzt die aktuelle Eingabe im {@link JTextField}.
+         * 
+         * @param newValue kann vom Typ {@link String} oder {@link Number} sein
+         */
+        @Override
+        protected boolean performSetValue(Object newValue) {
+          if ( newValue instanceof Number )
+            newValue = String.valueOf( ((Number)newValue).doubleValue() );
+          return super.performSetValue(newValue);
+        }
+
 		private java.lang.Double convertCurrentValue() {
           String doubleStr = ((JTextField)inpComp).getText();
           if ( DECIMAL_COMMA && doubleStr != null )

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2012-05-17 14:37:55 UTC (rev 2002)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle.properties	2012-05-24 13:25:49 UTC (rev 2003)
@@ -297,8 +297,11 @@
 
 WebFilesChooserPanel.InetNotAvailable=No internet connection available!
 
-ProxySettingsPanel.proxy.disabled=Direct internet connection
-ProxySettingsPanel.proxy.enabled=Use following proxy settings
-ProxySettingsPanel.proxy.type=Type of proxy server
-ProxySettingsPanel.proxy.host=Proxy server host
-ProxySettingsPanel.proxy.port=Port on proxy server
+ConnectionSettingsPanel.proxy.disabled=Direct internet connection
+ConnectionSettingsPanel.proxy.enabled=Use following proxy settings
+ConnectionSettingsPanel.proxy.type=Type of proxy server
+ConnectionSettingsPanel.proxy.host=Proxy server host
+ConnectionSettingsPanel.proxy.port=Port on proxy server
+ConnectionSettingsPanel.conn.timeout=Connection timeout (ms)
+ConnectionSettingsPanel.conn.readtimeout=Connection read timeout (ms)
+ConnectionSettingsPanel.conn.retries=Number of connection/download retries  

Modified: trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties
===================================================================
--- trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2012-05-17 14:37:55 UTC (rev 2002)
+++ trunk/schmitzm-core/src/main/resources/de/schmitzm/swing/resource/locales/SwingResourceBundle_de.properties	2012-05-24 13:25:49 UTC (rev 2003)
@@ -270,8 +270,11 @@
 
 WebFilesChooserPanel.InetNotAvailable=Keine Internet-Verbindung verfügbar!
 
-ProxySettingsPanel.proxy.disabled=Direkte Internet-Verbindung (ohne Proxy)
-ProxySettingsPanel.proxy.enabled=Die folgenden Proxy-Einstellungen verwenden
-ProxySettingsPanel.proxy.type=Art des Proxy-Servers
-ProxySettingsPanel.proxy.host=Hostname/IP des Proxy-Servers
-ProxySettingsPanel.proxy.port=Port des Proxy-Servers
+ConnectionSettingsPanel.proxy.disabled=Direkte Internet-Verbindung (ohne Proxy)
+ConnectionSettingsPanel.proxy.enabled=Die folgenden Proxy-Einstellungen verwenden
+ConnectionSettingsPanel.proxy.type=Art des Proxy-Servers
+ConnectionSettingsPanel.proxy.host=Hostname/IP des Proxy-Servers
+ConnectionSettingsPanel.proxy.port=Port des Proxy-Servers
+ConnectionSettingsPanel.conn.timeout=Verbindungs-Timeout (ms)
+ConnectionSettingsPanel.conn.readtimeout=Read-Timeout (ms)
+ConnectionSettingsPanel.conn.retries=Anzahl an Wiederhol-Versuchen für Verbindungsaufbau/Download 



More information about the Schmitzm-commits mailing list