/hg/icedtea-web: Remove need for MiddleClickListener.java.

asu at icedtea.classpath.org asu at icedtea.classpath.org
Tue Dec 21 13:48:48 PST 2010


changeset 7ddab63cf8fe in /hg/icedtea-web
details: http://icedtea.classpath.org/hg/icedtea-web?cmd=changeset;node=7ddab63cf8fe
author: Andrew Su <asu at redhat.com>
date: Tue Dec 21 16:48:12 2010 -0500

	Remove need for MiddleClickListener.java.


diffstat:

5 files changed, 128 insertions(+), 150 deletions(-)
ChangeLog                                                             |   10 
netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java |   77 +------
netx/net/sourceforge/jnlp/controlpanel/DocumentAdapter.java           |  102 ++++++++++
netx/net/sourceforge/jnlp/controlpanel/MiddleClickListener.java       |   64 ------
netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java      |   25 --

diffs (350 lines):

diff -r bbbe02c58ddc -r 7ddab63cf8fe ChangeLog
--- a/ChangeLog	Mon Dec 20 13:37:59 2010 -0500
+++ b/ChangeLog	Tue Dec 21 16:48:12 2010 -0500
@@ -1,3 +1,13 @@ 2010-12-20  Andrew Su  <asu at redhat.com>
+2010-12-21  Andrew Su  <asu at redhat.com>
+
+	* netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java,
+	netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java:
+	(addComponents): Replaced key listeners and mouse listeners for text
+	fields with document adapter.
+	* netx/net/sourceforge/jnlp/controlpanel/DocumentAdapter.java: New class.
+	* netx/net/sourceforge/jnlp/controlpanel/MiddleClickListener.java:
+	Removed.
+
 2010-12-20  Andrew Su  <asu at redhat.com>
 
 	Added a cache viewer for the control panel.
diff -r bbbe02c58ddc -r 7ddab63cf8fe netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java
--- a/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java	Mon Dec 20 13:37:59 2010 -0500
+++ b/netx/net/sourceforge/jnlp/controlpanel/AdvancedProxySettingsPane.java	Tue Dec 21 16:48:12 2010 -0500
@@ -100,9 +100,7 @@ public class AdvancedProxySettingsPane e
     }
 
     /**
-     * Add the components to the panel. FIXME: We should probably refactor the
-     * listeners and do them in a more generic way. Also can change this from
-     * using textfield to using a table.
+     * Add the components to the panel.
      */
     private void addComponents() {
         JPanel topPanel = new JPanel(new GridBagLayout());
@@ -119,77 +117,29 @@ public class AdvancedProxySettingsPane e
         JLabel http = new JLabel(Translator.R("APSLabelHTTP") + ":");
         final JTextField httpAddressField = new JTextField(fields[0]);
         final JTextField httpPortField = new JTextField(fields[1]);
-        httpAddressField.addKeyListener(new KeyAdapter() {
-            @Override
-            public void keyReleased(KeyEvent e) {
-                fields[0] = httpAddressField.getText();
-            }
-        });
-        httpPortField.addKeyListener(new KeyAdapter() {
-            @Override
-            public void keyReleased(KeyEvent e) {
-                fields[1] = httpPortField.getText();
-            }
-        });
-        httpAddressField.addMouseListener(new MiddleClickListener(this.config, properties[0]));
-        httpPortField.addMouseListener(new MiddleClickListener(this.config, properties[1]));
+        httpAddressField.getDocument().addDocumentListener(new DocumentAdapter(fields, 0));
+        httpPortField.getDocument().addDocumentListener(new DocumentAdapter(fields, 1));
 
         // This addresses the HTTPS proxy settings.
         JLabel secure = new JLabel(Translator.R("APSLabelSecure") + ":");
         final JTextField secureAddressField = new JTextField(fields[2]);
         final JTextField securePortField = new JTextField(fields[3]);
-        secureAddressField.addKeyListener(new KeyAdapter() {
-            @Override
-            public void keyReleased(KeyEvent e) {
-                fields[2] = secureAddressField.getText();
-            }
-        });
-        securePortField.addKeyListener(new KeyAdapter() {
-            @Override
-            public void keyReleased(KeyEvent e) {
-                fields[3] = securePortField.getText();
-            }
-        });
-        secureAddressField.addMouseListener(new MiddleClickListener(this.config, properties[2]));
-        securePortField.addMouseListener(new MiddleClickListener(this.config, properties[3]));
+        secureAddressField.getDocument().addDocumentListener(new DocumentAdapter(fields, 2));
+        securePortField.getDocument().addDocumentListener(new DocumentAdapter(fields, 3));
 
         // This addresses the FTP proxy settings.
         JLabel ftp = new JLabel(Translator.R("APSLabelFTP") + ":");
         final JTextField ftpAddressField = new JTextField(fields[4]);
         final JTextField ftpPortField = new JTextField(fields[5]);
-        ftpAddressField.addKeyListener(new KeyAdapter() {
-            @Override
-            public void keyReleased(KeyEvent e) {
-                fields[4] = ftpAddressField.getText();
-            }
-        });
-        ftpPortField.addKeyListener(new KeyAdapter() {
-            @Override
-            public void keyReleased(KeyEvent e) {
-                fields[5] = ftpPortField.getText();
-            }
-        });
-        ftpAddressField.addMouseListener(new MiddleClickListener(this.config, properties[4]));
-        ftpPortField.addMouseListener(new MiddleClickListener(this.config, properties[5]));
+        ftpAddressField.getDocument().addDocumentListener(new DocumentAdapter(fields, 4));
+        ftpPortField.getDocument().addDocumentListener(new DocumentAdapter(fields, 5));
 
         // This addresses the Socks proxy settings.
         JLabel socks = new JLabel(Translator.R("APSLabelSocks") + ":");
         final JTextField socksAddressField = new JTextField(fields[6]);
         final JTextField socksPortField = new JTextField(fields[7]);
-        socksAddressField.addKeyListener(new KeyAdapter() {
-            @Override
-            public void keyReleased(KeyEvent e) {
-                fields[6] = socksAddressField.getText();
-            }
-        });
-        socksPortField.addKeyListener(new KeyAdapter() {
-            @Override
-            public void keyReleased(KeyEvent e) {
-                fields[7] = socksPortField.getText();
-            }
-        });
-        socksAddressField.addMouseListener(new MiddleClickListener(this.config, properties[6]));
-        socksPortField.addMouseListener(new MiddleClickListener(this.config, properties[7]));
+        socksAddressField.getDocument().addDocumentListener(new DocumentAdapter(fields, 6));
+        socksPortField.getDocument().addDocumentListener(new DocumentAdapter(fields, 7));
 
         JCheckBox sameProxyForAll = new JCheckBox(Translator.R("APSSameProxyForAllProtocols"), Boolean.parseBoolean(fields[8]));
         sameProxyForAll.addItemListener(new ItemListener() {
@@ -235,13 +185,8 @@ public class AdvancedProxySettingsPane e
         final JTextArea exceptionListArea = new JTextArea();
         exceptionListArea.setLineWrap(true);
         exceptionListArea.setText(fields[9]);
-        exceptionListArea.addKeyListener(new KeyAdapter() {
-            @Override
-            public void keyReleased(KeyEvent e) {
-                fields[9] = exceptionListArea.getText();
-            }
-        });
-        exceptionListArea.addMouseListener(new MiddleClickListener(this.config, fields[9]));
+        exceptionListArea.getDocument().addDocumentListener(new DocumentAdapter(fields, 9));
+
         JLabel exceptionFormat = new JLabel(Translator.R("APSExceptionInstruction"));
         JScrollPane exceptionScroll = new JScrollPane(exceptionListArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
         exceptions.add(exceptionDescription, BorderLayout.NORTH);
diff -r bbbe02c58ddc -r 7ddab63cf8fe netx/net/sourceforge/jnlp/controlpanel/DocumentAdapter.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/netx/net/sourceforge/jnlp/controlpanel/DocumentAdapter.java	Tue Dec 21 16:48:12 2010 -0500
@@ -0,0 +1,102 @@
+/* DocumentAdapter.java -- Updates properties.
+Copyright (C) 2010 Red Hat
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 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 General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.jnlp.controlpanel;
+
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
+
+import net.sourceforge.jnlp.config.DeploymentConfiguration;
+
+/**
+ * Updates the property as it happens.
+ * 
+ * @author Andrew Su (asu at redhat.com, andrew.su at utoronto.ca)
+ *
+ */
+public class DocumentAdapter implements DocumentListener {
+
+    String[] fields;
+    int index;
+    String property;
+    DeploymentConfiguration config;
+    int mode;
+
+    /**
+     * This creates a new instance of DocumentAdapter.
+     * 
+     * @param fields The list of property.
+     * @param index Location of property to modify.
+     */
+    public DocumentAdapter(String[] fields, int index) {
+        this.fields = fields;
+        this.index = index;
+        mode = 1;
+    }
+
+    /**
+     * This creates a new instance of DocumentAdapter. This allows modifying 
+     * the configuration directly.
+     * 
+     * @param config ConfigurationFile containing the properties.
+     * @param property Name of property to modify.
+     */
+    public DocumentAdapter(DeploymentConfiguration config, String property) {
+        this.property = property;
+        this.config = config;
+        mode = 2;
+    }
+
+    @Override
+    public void insertUpdate(DocumentEvent e) {
+        update(e);
+    }
+
+    @Override
+    public void removeUpdate(DocumentEvent e) {
+        update(e);
+    }
+
+    @Override
+    public void changedUpdate(DocumentEvent e) {
+
+    }
+
+    /**
+     * Update the property as on the appropriate items.
+     * 
+     * @param e The event that caused the call.
+     */
+    private void update(DocumentEvent e) {
+        Document d = e.getDocument();
+        try {
+            String value = d.getText(0, d.getLength()).trim();
+            value = (value.length() == 0) ? null : value;
+            if (mode == 1) {
+                fields[index] = value;
+            } else if (mode == 2) {
+                config.setProperty(property, value);
+            }
+        } catch (BadLocationException e1) {
+            // TODO Auto-generated catch block
+            e1.printStackTrace();
+        }
+    }
+
+}
diff -r bbbe02c58ddc -r 7ddab63cf8fe netx/net/sourceforge/jnlp/controlpanel/MiddleClickListener.java
--- a/netx/net/sourceforge/jnlp/controlpanel/MiddleClickListener.java	Mon Dec 20 13:37:59 2010 -0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-/* MiddleClickListener.java -- Update configuration when pasting with middle click.
-Copyright (C) 2010 Red Hat
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 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 General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package net.sourceforge.jnlp.controlpanel;
-
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-
-import javax.swing.JTextArea;
-import javax.swing.JTextField;
-
-import net.sourceforge.jnlp.config.DeploymentConfiguration;
-
-/**
- * When middle click pastes to the textboxes it doesn't register it... This is
- * to fix that problem. Not needed in Windows.
- * 
- * @author Andrew Su <asu at redhat.com, andrew.su at utoronto.ca>
- * 
- */
-class MiddleClickListener extends MouseAdapter {
-
-    DeploymentConfiguration config;
-    private String property;
-
-    /**
-     * Creates a new instance of middle-click listener.
-     * 
-     * @param config
-     *            Loaded DeploymentConfiguration file.
-     * @param property
-     *            the property in configuration file to edit.
-     */
-    public MiddleClickListener(DeploymentConfiguration config, String property) {
-        this.config = config;
-        this.property = property;
-    }
-
-    @Override
-    public void mouseClicked(MouseEvent e) {
-        Object obj = e.getSource();
-        String result = null;
-        if (obj instanceof JTextField)
-            result = ((JTextField) obj).getText();
-        else if (obj instanceof JTextArea)
-            result = ((JTextArea) obj).getText();
-
-        config.setProperty(property, result);
-    }
-}
diff -r bbbe02c58ddc -r 7ddab63cf8fe netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java
--- a/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java	Mon Dec 20 13:37:59 2010 -0500
+++ b/netx/net/sourceforge/jnlp/controlpanel/NetworkSettingsPanel.java	Tue Dec 21 16:48:12 2010 -0500
@@ -114,19 +114,11 @@ public class NetworkSettingsPanel extend
         JLabel addressLabel = new JLabel(Translator.R("NSAddress") + ":");
         JLabel portLabel = new JLabel(Translator.R("NSPort") + ":");
         final JTextField addressField = new JTextField(config.getProperty(properties[1]), 10);
-        addressField.addKeyListener(new KeyAdapter() {
-            public void keyReleased(KeyEvent e) {
-                config.setProperty(properties[1], addressField.getText());
-            }
-        });
-
-        addressField.addMouseListener(new MiddleClickListener(this.config, properties[1]));
+        addressField.getDocument().addDocumentListener(new DocumentAdapter(config, properties[1]));
+        
         final JTextField portField = new JTextField(config.getProperty(properties[2]), 3);
-        portField.addKeyListener(new KeyAdapter() {
-            public void keyReleased(KeyEvent e) {
-                config.setProperty(properties[2], portField.getText());
-            }
-        });
+        portField.getDocument().addDocumentListener(new DocumentAdapter(config, properties[1]));
+        
         // Create the button which allows setting of other types of proxy.
         JButton advancedProxyButton = new JButton(Translator.R("NSAdvanced") + "...");
         advancedProxyButton.addActionListener(new ActionListener() {
@@ -187,14 +179,7 @@ public class NetworkSettingsPanel extend
         JPanel proxyAutoPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
         JLabel locationLabel = new JLabel(Translator.R("NSScriptLocation") + ":");
         final JTextField locationField = new JTextField(config.getProperty(properties[4]), 20);
-        locationField.addKeyListener(new KeyAdapter() {
-            public void keyReleased(KeyEvent e) {
-                String value = locationField.getText();
-                if (value.trim().equals(""))
-                    value = null;
-                config.setProperty(properties[4], value);
-            }
-        });
+        locationField.getDocument().addDocumentListener(new DocumentAdapter(config, properties[4]));
 
         proxyAutoPanel.add(Box.createRigidArea(new Dimension(13, 0)));
         proxyAutoPanel.add(locationLabel);



More information about the distro-pkg-dev mailing list