[izpack-changes] r1759 - in izpack-src/trunk: . src/lib/com/izforge/izpack/installer src/lib/com/izforge/izpack/panels

noreply at berlios.de noreply at berlios.de
Sat Feb 24 11:53:47 CET 2007


Author: jponge
Date: 2007-02-24 11:53:22 +0100 (Sat, 24 Feb 2007)
New Revision: 1759

Modified:
   izpack-src/trunk/Versions.txt
   izpack-src/trunk/src/lib/com/izforge/izpack/installer/InstallerFrame.java
   izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
Log:
UserInputPanel: force users to select an existing directory or file
  (Michael Hagedorn via Julien Ponge)


Modified: izpack-src/trunk/Versions.txt
===================================================================
--- izpack-src/trunk/Versions.txt	2007-02-21 08:36:30 UTC (rev 1758)
+++ izpack-src/trunk/Versions.txt	2007-02-24 10:53:22 UTC (rev 1759)
@@ -10,6 +10,8 @@
 - Added file and dir fields in UserInputPanel (Dennis Reil)
 - Modifications to keep original file dates and times in _dist directory and in the installer jar
   (Ari Voutilainen via Julien Ponge)
+- UserInputPanel: force users to select an existing directory or file
+  (Michael Hagedorn via Julien Ponge)
 
 	> 3.10.1 (build 2007.xx.xx)
 	

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/installer/InstallerFrame.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/installer/InstallerFrame.java	2007-02-21 08:36:30 UTC (rev 1758)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/installer/InstallerFrame.java	2007-02-24 10:53:22 UTC (rev 1759)
@@ -1363,8 +1363,18 @@
      */
     public void unlockNextButton()
     {
+        unlockNextButton(true);
+    }
+
+    /**
+     * Unlocks the 'next' button.
+     * @param requestFocus if <code>true</code> focus goes to <code>nextButton</code> 
+     */
+    public void unlockNextButton(boolean requestFocus)
+    {
         nextButton.setEnabled(true);
-        nextButton.requestFocus();
+        if (requestFocus)
+            nextButton.requestFocus();
     }
 
     /**

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java	2007-02-21 08:36:30 UTC (rev 1758)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java	2007-02-24 10:53:22 UTC (rev 1759)
@@ -45,6 +45,10 @@
 import javax.swing.JPasswordField;
 import javax.swing.JRadioButton;
 import javax.swing.JTextField;
+import javax.swing.event.DocumentEvent;
+import javax.swing.event.DocumentListener;
+import javax.swing.text.BadLocationException;
+import javax.swing.text.Document;
 import javax.swing.filechooser.FileFilter;
 
 import net.n3.nanoxml.NonValidator;
@@ -3001,8 +3005,44 @@
             this.autodetectButton.addActionListener(this);
             this.browseButton.addActionListener(this);
 
+            /*
+             * add DocumentListener to manage nextButton if user enters input
+             */
+            ((JTextField)this.pathComboBox.getEditor().getEditorComponent()).getDocument().addDocumentListener(new DocumentListener()
+            {
+                public void changedUpdate(DocumentEvent e)
+                {
+                    checkNextButtonState();
+                }
+                public void insertUpdate(DocumentEvent e)
+                {
+                    checkNextButtonState();
+                }
+                public void removeUpdate(DocumentEvent e)
+                {
+                    checkNextButtonState();
+                }
+                private void checkNextButtonState()
+                {
+                    Document doc = ((JTextField)pathComboBox.getEditor().getEditorComponent()).getDocument();
+                    try {
+                        if (pathMatches(doc.getText(0, doc.getLength())))
+                            getInstallerFrame().unlockNextButton(false);
+                        else    
+                            getInstallerFrame().lockNextButton();
+                    } catch (BadLocationException e) {/*ignore, it not happens*/}
+                }
+            });
+
             autodetect();
         }
+        
+        /**
+         * convenient method
+         */
+        private InstallerFrame getInstallerFrame() {
+            return parent;
+        }
 
         /**
          * Check whether the given combobox belongs to this searchfield. This is used when reading
@@ -3061,7 +3101,10 @@
              * Check if the user has entered data into the ComboBox and add it to the Itemlist
              */
             String selected = (String) this.pathComboBox.getSelectedItem();
-            if (selected == null) { return false; }
+            if (selected == null) {
+                parent.lockNextButton();
+                return false;
+            }
             boolean found = false;
             for (int x = 0; x < this.pathComboBox.getItemCount(); x++)
             {
@@ -3130,14 +3173,19 @@
                 if (this.pathMatches(path))
                 {
                     this.pathComboBox.setSelectedIndex(i);
+                    parent.unlockNextButton();
                     return true;
                 }
 
             }
 
             // if the user entered something else, it's not listed as an item
-            return this.pathMatches((String) this.pathComboBox.getSelectedItem());
-
+            if (this.pathMatches((String) this.pathComboBox.getSelectedItem())) {
+                parent.unlockNextButton();
+                return true;
+            }
+            parent.lockNextButton();
+            return false;
         }
 
         /*--------------------------------------------------------------------------*/




More information about the izpack-changes mailing list