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

noreply at berlios.de noreply at berlios.de
Wed Mar 14 10:14:46 CET 2007


Author: vralev
Date: 2007-03-14 10:14:41 +0100 (Wed, 14 Mar 2007)
New Revision: 1784

Modified:
   izpack-src/trunk/Versions.txt
   izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
Log:
Dynamic control validation on radio and checkbox events

Modified: izpack-src/trunk/Versions.txt
===================================================================
--- izpack-src/trunk/Versions.txt	2007-03-13 17:05:28 UTC (rev 1783)
+++ izpack-src/trunk/Versions.txt	2007-03-14 09:14:41 UTC (rev 1784)
@@ -14,6 +14,7 @@
   (Michael Hagedorn via Julien Ponge)
 - Default path for JDKPathPanel will be got from Windows registry if possible (Klaus Bartz)  
 - New Farsi langpack (Parastou Kohvaei)
+- Dynamic control validation on radio and checkbox selection events (Vladimir Ralev)
 
   > 3.10.1 (build 2007.xx.xx)
 	

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java	2007-03-13 17:05:28 UTC (rev 1783)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/UserInputPanel.java	2007-03-14 09:14:41 UTC (rev 1784)
@@ -117,7 +117,7 @@
  * To Do: ------ * make sure all header documentation is complete and correct
  * --------------------------------------------------------------------------
  */
-public class UserInputPanel extends IzPanel
+public class UserInputPanel extends IzPanel implements ActionListener
 {
 
     // ------------------------------------------------------------------------
@@ -190,6 +190,10 @@
     private static final String SPEC = "spec";
 
     private static final String SET = "set";
+    
+    private static final String REVALIDATE = "revalidate";
+    
+    private static final String TOPBUFFER = "topBuffer";
 
     private static final String TRUE = "true";
 
@@ -395,15 +399,12 @@
 
     protected void init()
     {
+        
+        TwoColumnLayout layout;
         super.removeAll();
         uiElements.clear();
 
         // ----------------------------------------------------
-        // ----------------------------------------------------
-        TwoColumnLayout layout = new TwoColumnLayout(10, 5, 30, 25, TwoColumnLayout.LEFT);
-        setLayout(layout);
-
-        // ----------------------------------------------------
         // get a locale database
         // ----------------------------------------------------
         try
@@ -430,6 +431,24 @@
             exception.printStackTrace();
         }
 
+        // ----------------------------------------------------
+        // Set the topBuffer from the attribute. topBuffer=0 is useful
+        // if you don't want your panel to be moved up and down during
+        // dynamic validation (showing and hiding components within the
+        // same panel)
+        // ----------------------------------------------------
+        int topbuff = 25;
+        try
+        {
+           topbuff = Integer.parseInt(spec.getAttribute(TOPBUFFER));
+        }
+        catch(Exception ex){}
+        finally
+        {
+            layout = new TwoColumnLayout(10, 5, 30, topbuff, TwoColumnLayout.LEFT);
+        }
+        setLayout(layout);
+        
         if (!haveSpec)
         {
             // return if we could not read the spec. further
@@ -849,7 +868,9 @@
         // }
 
         buildUI();
-        // need a validation, else ui is scrambled
+        //need a validation, else ui is scrambled
+
+        this.setSize(this.getMaximumSize().width, this.getMaximumSize().height);
         validate();
         if (packsDefined)
         {
@@ -1787,11 +1808,19 @@
             {
                 JRadioButton choice = new JRadioButton();
                 choice.setText(getText((XMLElement) choices.elementAt(i)));
+                String causesValidataion = ((XMLElement) choices.elementAt(i)).getAttribute(REVALIDATE);
+                if(causesValidataion != null && causesValidataion.equals("yes"))
+                    choice.addActionListener(this);
                 value = (((XMLElement) choices.elementAt(i)).getAttribute(RADIO_VALUE));
 
                 group.add(choice);
 
                 String set = ((XMLElement) choices.elementAt(i)).getAttribute(SET);
+                // in order to properly initialize dependent controls
+                // we must set this variable now
+                if(idata.getVariable(variable) == null)
+                   if(set != null)
+                      idata.setVariable(variable, value);
                 if (set != null)
                 {
                     if (set != null && !"".equals(set))
@@ -2030,6 +2059,7 @@
         String trueValue = null;
         String falseValue = null;
         String variable = spec.getAttribute(VARIABLE);
+        String causesValidataion = null;
         XMLElement detail = spec.getFirstChildNamed(SPEC);
 
         if (variable == null) { return; }
@@ -2040,10 +2070,20 @@
             set = detail.getAttribute(SET);
             trueValue = detail.getAttribute(TRUE);
             falseValue = detail.getAttribute(FALSE);
+            causesValidataion = detail.getAttribute(REVALIDATE);
+            String value = idata.getVariable(variable);
+            if(value != null)
+            {
+                set = value;
+            }
         }
 
         JCheckBox checkbox = new JCheckBox(label);
-
+        
+        if(causesValidataion != null && causesValidataion.equals("yes"))
+           checkbox.addActionListener(this);
+        idata.setVariable(variable, set);
+        
         if (set != null)
         {
             if (set != null && !"".equals(set))
@@ -3349,6 +3389,12 @@
             }
         }
     }
+    
+    // Repaint all controls and validate them agains the current variables
+    public void actionPerformed(ActionEvent e) {
+       readInput();
+       panelActivate();
+   }
 
 } // public class UserInputPanel
 /*---------------------------------------------------------------------------*/




More information about the izpack-changes mailing list