From 93b8643ec02f2f7d3da57f784241da3cfec98afb Mon Sep 17 00:00:00 2001
From: Andrew Su <asu@redhat.com>
Date: Tue, 21 Dec 2010 16:48:12 -0500
Subject: Remove need for MiddleClickListener.java.

---
 .../jnlp/controlpanel/DocumentAdapter.java         | 102 +++++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100644 netx/net/sourceforge/jnlp/controlpanel/DocumentAdapter.java

(limited to 'netx/net/sourceforge/jnlp/controlpanel/DocumentAdapter.java')

diff --git a/netx/net/sourceforge/jnlp/controlpanel/DocumentAdapter.java b/netx/net/sourceforge/jnlp/controlpanel/DocumentAdapter.java
new file mode 100644
index 0000000..2bcb0c2
--- /dev/null
+++ b/netx/net/sourceforge/jnlp/controlpanel/DocumentAdapter.java
@@ -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@redhat.com, andrew.su@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();
+        }
+    }
+
+}
-- 
cgit v1.2.3