[Schmitzm-commits] r1952 - in trunk/schmitzm-core/src/main/java/de/schmitzm: io swing swing/input

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Mon Apr 16 13:17:04 CEST 2012


Author: mojays
Date: 2012-04-16 13:17:04 +0200 (Mon, 16 Apr 2012)
New Revision: 1952

Added:
   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/WebAndLocalFilesChooser.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooser.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooserPanel.java
   trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java
Log:
IOUtil/WebFilesChooser: handle proxy in several methods
SelectionInputOption.Radio: bugfix with action/change listener
new ProxySettingsPanel/Dialog


Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2012-04-15 23:36:29 UTC (rev 1951)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/io/IOUtil.java	2012-04-16 11:17:04 UTC (rev 1952)
@@ -49,6 +49,9 @@
 import java.io.Writer;
 import java.net.InetAddress;
 import java.net.MalformedURLException;
+import java.net.Proxy;
+import java.net.Proxy.Type;
+import java.net.SocketAddress;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLConnection;
@@ -547,10 +550,24 @@
      * @param timeout connection timeout in ms
      */
     public static File downloadUrlToFile(URL url, File file, int timeout) throws IOException {
+      return downloadUrlToFile(url, null, file, timeout);
+    }
+    
+    /**
+     * 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 timeout connection timeout in ms
+     */
+    public static File downloadUrlToFile(URL url, Proxy proxy, File file, int timeout) throws IOException {
       if ( file == null ) {
         file = File.createTempFile("java-schmitzm-",null);
         file.deleteOnExit();
       }
+      if ( proxy == null )
+        proxy = Proxy.NO_PROXY;
       
       OutputStream output = null;
       InputStream  input = null;
@@ -558,7 +575,7 @@
         // Prepare output
         output = new FileOutputStream(file);
         // Prepare input from URL
-        URLConnection urlconn = url.openConnection();
+        URLConnection urlconn = url.openConnection(proxy);
         if ( timeout >= 0 )
           urlconn.setConnectTimeout(timeout);
         urlconn.setDoOutput(true);
@@ -1281,15 +1298,47 @@
 	
 	
 	/**
+	 * Creates a {@link Proxy} for given host and port.
+	 * @param proxyType type of proxy (if {@code null} {@link Proxy#NO_PROXY}
+	 *                  is returned)
+	 * @param host host address
+	 * @param port proxy port
+	 * @return {@link Proxy#NO_PROXY} if {@code host} is {@code null}
+	 */
+	public static Proxy createProxy(Type proxyType, String host, int port) {
+	  if ( proxyType == null )
+	    proxyType = Type.DIRECT;
+
+	  if ( host == null || proxyType.equals(Type.DIRECT) )
+	    return Proxy.NO_PROXY;
+	  // Create socket address for proxy
+	  SocketAddress proxySocket = new InetSocketAddress(host, port);
+	  return new Proxy(proxyType, proxySocket);
+	}
+	
+	
+    /**
+     * Extracts all links (href tags) from website document.
+     * @param url URL of a website
+     * @return an empty list, if {@code null} URL is given
+     */
+    public static List<String> extractLinksFromURL(URL url) throws IOException {
+      return extractLinksFromURL(url, null);
+    }
+    
+	/**
 	 * Extracts all links (href tags) from website document.
 	 * @param url URL of a website
+	 * @param proxy proxy to use for connection
 	 * @return an empty list, if {@code null} URL is given
 	 */
-	public static List<String> extractLinksFromURL(URL url) throws IOException {
+	public static List<String> extractLinksFromURL(URL url, Proxy proxy) throws IOException {
 	  if ( url == null )
 	    return new ArrayList<String>();
+	  if ( proxy == null )
+	    proxy = Proxy.NO_PROXY;
 	  // load document from URL
-	  URLConnection conn = url.openConnection();
+	  URLConnection conn = url.openConnection(proxy);
 	  conn.setConnectTimeout(1000);
 	  conn.setReadTimeout(1000);
 	  String str = IOUtil.convertStreamToString(conn.getInputStream()); 
@@ -1320,12 +1369,13 @@
      * web server without any index.html (or something like that).
      * Otherwise (e.g. if URL specifies a website) this method might have an unexpected result!
      * @param url URL of a webserver directory
+     * @param proxy proxy server to use for connection (can be {@code null})
      */
-    public static List<URL> listFilesFromURL(URL url) throws IOException {
+    public static List<URL> listFilesFromURL(URL url, Proxy proxy) throws IOException {
       // #### TODO: improve this workaround method! ####
 
       List<URL> files = new ArrayList<URL>();
-      listFilesAndDirectoriesFromURL(url, files, null);
+      listFilesAndDirectoriesFromURL(url, proxy, files, null);
       return files;
     }
 
@@ -1336,12 +1386,13 @@
      * web server without any index.html (or something like that).
      * Otherwise (e.g. if URL specifies a website) this method might have an unexpected result!
      * @param url URL of a webserver directory
+     * @param proxy proxy server to use for connection (can be {@code null})
      */
-    public static List<URL> listDirectoriesFromURL(URL url) throws IOException {
+    public static List<URL> listDirectoriesFromURL(URL url, Proxy proxy) throws IOException {
       // #### TODO: improve this workaround method! ####
 
       List<URL> dirs = new ArrayList<URL>();
-      listFilesAndDirectoriesFromURL(url, null, dirs);
+      listFilesAndDirectoriesFromURL(url, proxy, null, dirs);
       return dirs;
     }
 
@@ -1352,14 +1403,15 @@
      * web server without any index.html (or something like that).
      * Otherwise (e.g. if URL specifies a website) this method might have an unexpected result!
      * @param url URL of a webserver directory
+     * @param proxy proxy server to use for connection (can be {@code null})
      * @param files destination list to store the file urls in
      * @param dirs  destination list to store the directory urls in
      */
-    public static void listFilesAndDirectoriesFromURL(URL url,  Collection<URL> files,  Collection<URL> dirs) throws IOException {
+    public static void listFilesAndDirectoriesFromURL(URL url,  Proxy proxy, Collection<URL> files,  Collection<URL> dirs) throws IOException {
       // #### TODO: improve this workaround method! ####
 
       // extract links from URL
-      List<String> fileNames = extractLinksFromURL(url);
+      List<String> fileNames = extractLinksFromURL(url,proxy);
       // combine file names with source URL
       for (String fileName : fileNames) {
         URL fileURL = new URL(url,fileName);
@@ -1874,8 +1926,19 @@
 		return new CharacterDevice(reader, writer);
 	}
 	
-	
-	public static boolean isInetConnectionAvailable() {
+	/**
+	 * Tests whether an internet connection is available.
+	 */
+    public static boolean isInetConnectionAvailable() {
+      return isInetConnectionAvailable(null);
+    }
+    
+    /**
+     * Tests whether an internet connection is available.
+     */
+	public static boolean isInetConnectionAvailable(Proxy proxy) {
+	  if ( proxy == null )
+	    proxy = Proxy.NO_PROXY;
 	  final int      timeoutMillis  = 300;
 	  final String[] addressesToTry = new String[] {"google.com",
 	                                                "heise.de"
@@ -1894,7 +1957,7 @@
       for (String addrStr : addressesToTry)
         try {
           final URL url = new URL("http",addrStr,"");
-          final URLConnection conn = url.openConnection();
+          final URLConnection conn = url.openConnection(proxy);
           final InputStream input = conn.getInputStream();
           input.close();
           return true;

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsDialog.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsDialog.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsDialog.java	2012-04-16 11:17:04 UTC (rev 1952)
@@ -0,0 +1,98 @@
+/**
+ * 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.Dimension;
+import java.awt.Frame;
+import java.net.Proxy;
+import java.net.URL;
+import java.util.List;
+
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
+
+/**
+ * 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;
+  }
+
+}

Added: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsPanel.java	                        (rev 0)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/ProxySettingsPanel.java	2012-04-16 11:17:04 UTC (rev 1952)
@@ -0,0 +1,120 @@
+/**
+ * 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 de.schmitzm.io.IOUtil;
+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 {
+
+  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[] {"Direct internet connection","Use following proxy settings"} );
+    proxyUsed.addInputOptionListener( new InputOptionAdapter() {
+      @Override
+      public <E> void optionChanged(InputOption<E> inputOption, E oldValue, E newValue) {
+        updateComponentsEnabled();
+      }
+    });
+    proxyTypeCaption = new JLabel("Type of proxy server:");
+    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("Proxy server host:");
+    proxyHost = new ManualInputOption.Text(null,false);
+    proxyPortCaption = new JLabel("Port on proxy server:");
+    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() {
+    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();
+    
+    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) {
+    proxyUsed.setValue(used);
+    proxyType.setSelectedItem(type);
+    proxyHost.setValue(host);
+    proxyPort.setValue(String.valueOf(port));
+    updateComponentsEnabled();
+  }
+}

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebAndLocalFilesChooser.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebAndLocalFilesChooser.java	2012-04-15 23:36:29 UTC (rev 1951)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebAndLocalFilesChooser.java	2012-04-16 11:17:04 UTC (rev 1952)
@@ -36,6 +36,7 @@
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
+import java.net.Proxy;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -272,6 +273,20 @@
   }
 
   /**
+   * Returns the proxy server used for url connection.
+   */
+  public Proxy getProxy() {
+    return webFilesChooser.getProxy();
+  }
+
+  /**
+   * Sets the proxy server used for url connection.
+   */
+  public void setProxy(Proxy proxy) {
+    webFilesChooser.setProxy(proxy);
+  }
+
+  /**
    * Sets the directory for the local files chooser tab.
    */
   public void setCurrentDirectory(String directory) {

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooser.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooser.java	2012-04-15 23:36:29 UTC (rev 1951)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooser.java	2012-04-16 11:17:04 UTC (rev 1952)
@@ -33,6 +33,7 @@
 import java.awt.Dialog;
 import java.awt.Dimension;
 import java.awt.Frame;
+import java.net.Proxy;
 import java.net.URL;
 import java.util.List;
 
@@ -174,6 +175,20 @@
   }
 
   /**
+   * Returns the proxy server used for url connection.
+   */
+  public Proxy getProxy() {
+    return filesChooserPanel.getProxy();
+  }
+
+  /**
+   * Sets the proxy server used for url connection.
+   */
+  public void setProxy(Proxy proxy) {
+    filesChooserPanel.setProxy(proxy);
+  }
+
+  /**
    * Returns the selected files.
    * @return {@code null} if dialog was not closed by OK 
    */

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooserPanel.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooserPanel.java	2012-04-15 23:36:29 UTC (rev 1951)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/WebFilesChooserPanel.java	2012-04-16 11:17:04 UTC (rev 1952)
@@ -35,6 +35,7 @@
 import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.io.IOException;
+import java.net.Proxy;
 import java.net.SocketTimeoutException;
 import java.net.URL;
 import java.util.ArrayList;
@@ -215,7 +216,7 @@
   public void setBaseURL(String baseURL) {
     try {
       SwingUtil.setWaitCursor(this);
-      if ( !IOUtil.isInetConnectionAvailable() ) {
+      if ( !IOUtil.isInetConnectionAvailable(getProxy()) ) {
         baseUrl.setText( SwingUtil.R("WebFilesChooserPanel.InetNotAvailable") );
         setEnabled(false);
         return;
@@ -238,6 +239,20 @@
   }
 
   /**
+   * Returns the proxy server used for url connection.
+   */
+  public Proxy getProxy() {
+    return baseUrl.getProxy();
+  }
+
+  /**
+   * Sets the proxy server used for url connection.
+   */
+  public void setProxy(Proxy proxy) {
+    baseUrl.setProxy(proxy);
+  }
+
+  /**
    * Returns the selected files.
    * @return
    */
@@ -252,6 +267,9 @@
    *
    */
   private class UpdateURLAddressPanel extends URLAddressPanel {
+    /** Proxy used for url connection. */
+    protected Proxy proxy = Proxy.NO_PROXY;
+
     /**
      * Creates a new text field.
      */
@@ -261,6 +279,20 @@
     }
 
     /**
+     * @return the proxy
+     */
+    public Proxy getProxy() {
+      return proxy;
+    }
+
+    /**
+     * @param proxy the proxy to set
+     */
+    public void setProxy(Proxy proxy) {
+      this.proxy = proxy;
+    }
+
+    /**
      * Initializes the panel. Called by the constructor.
      * @param buttonText text for action on button or in menu (if icon
      *                   is specified, the button shows only the icon!)
@@ -288,7 +320,7 @@
         URL baseURL = IOUtil.createURL(destAddr,"http");
         TreeSet<URL> files = new TreeSet<URL>(FILENAME_COMPARATOR); // sorted by filename
         TreeSet<URL> dirs = new TreeSet<URL>(FILENAME_COMPARATOR); // sorted by filename
-        IOUtil.listFilesAndDirectoriesFromURL(baseURL,files,dirs);
+        IOUtil.listFilesAndDirectoriesFromURL(baseURL,getProxy(),files,dirs);
         filesTable.setFiles(new ArrayList<URL>(files));
         dirsTable.setFiles(new ArrayList<URL>(dirs));
         setText( baseURL != null ? baseURL.toExternalForm() : "" );

Modified: trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java
===================================================================
--- trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java	2012-04-15 23:36:29 UTC (rev 1951)
+++ trunk/schmitzm-core/src/main/java/de/schmitzm/swing/input/SelectionInputOption.java	2012-04-16 11:17:04 UTC (rev 1952)
@@ -470,17 +470,20 @@
     /** Liste der Buttons. */
     protected Vector<JRadioButton> buttonList;
 
+//    /** ActionListener, der auf die Button-Klicks reagiert und ggf. Events
+//     *  feuert. */
+//    private ActionListener actionListener = new ActionListener() {
+//      public void actionPerformed(ActionEvent e) {
+//        Object newValue = getValue();
+//        if ( lastSelection != newValue )
+//          fireOptionChanged(lastSelection,newValue);
+//        lastSelection = newValue;
+//      }
+//    };
     /** ActionListener, der auf die Button-Klicks reagiert und ggf. Events
      *  feuert. */
-    private ActionListener actionListener = new ActionListener() {
-      public void actionPerformed(ActionEvent e) {
-        Object newValue = getValue();
-        if ( lastSelection != newValue )
-          fireOptionChanged(lastSelection,newValue);
-        lastSelection = newValue;
-      }
-    };
-
+    private ActionListener actionListener;
+    
     /**
      * Erzeugt eine neue Auswahl-Option.
      * @param label       Beschreibung
@@ -559,6 +562,15 @@
      * angeordnet werden.
      */
     protected JPanel createInputComponent() {
+      actionListener = new ActionListener() {
+        public void actionPerformed(ActionEvent e) {
+          Object newValue = getValue();
+          if ( lastSelection != newValue )
+            fireOptionChanged(lastSelection,newValue);
+          lastSelection = newValue;
+        }
+      };
+      
       this.buttonGroup = new ButtonGroup();
       this.buttonList  = new Vector<JRadioButton>();
       JPanel panel = new JPanel();
@@ -608,15 +620,16 @@
      */
     public void setSelectedIndex(int idx) {
 // Event wird - glaube ich - bereits durch den ActionListener
-// des RadioButtons realisiert!
-//      Object oldValue = getValue();
+// des RadioButtons realisiert! >> DEM IST NICHT SO!
+      Object oldValue = getValue();
       if ( idx == -1 || idx >= buttonList.size() )
         buttonGroup.setUnselected();
       else
         buttonList.elementAt(idx).setSelected(true);
-//      Object newValue = getValue();
-//      if ( oldValue != newValue || oldValue!=null && !oldValue.equals( getValue() ) )
-//        fireOptionChanged(oldValue,newValue);
+      Object newValue = getValue();
+      if ( oldValue != newValue || oldValue!=null && !oldValue.equals( getValue() ) )
+        fireOptionChanged(oldValue,newValue);
+      lastSelection = newValue;
     }
   }
 



More information about the Schmitzm-commits mailing list