OSDN Git Service

パネルのスクロールバーを表示するよう変更.
authorAkihiro Ono <akihiro@ase.co.jp>
Fri, 27 Nov 2009 10:30:57 +0000 (19:30 +0900)
committerAkihiro Ono <akihiro@ase.co.jp>
Fri, 27 Nov 2009 10:30:57 +0000 (19:30 +0900)
specの属性 childVariable, setChildValueWhenParentIsUnchecked を追加.

installer/IzPack/src/lib/com/izforge/izpack/panels/UserInputPanel.java

index 308941f..83b5d6c 100644 (file)
@@ -20,6 +20,7 @@
 
 package com.izforge.izpack.panels;
 
+import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.event.ActionEvent;
@@ -52,7 +53,9 @@ import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPasswordField;
 import javax.swing.JRadioButton;
+import javax.swing.JScrollPane;
 import javax.swing.JTextField;
+import javax.swing.border.Border;
 import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import javax.swing.filechooser.FileFilter;
@@ -122,6 +125,10 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
 
     private static final String REVALIDATE = "revalidate";
 
+    private static final String CHILD_VARIABLE = "childVariable";
+
+    private static final String SET_CHILD_VALUE_WHEN_PARENT_IS_UNCHECKED = "setChildValueWhenParentIsUnchecked";
+
     private static final String TOPBUFFER = "topBuffer";
 
     private static final String TRUE = "true";
@@ -314,6 +321,8 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
 
     private Vector<UIElement> elements = new Vector<UIElement>();
 
+    private JPanel panel;
+
     /*--------------------------------------------------------------------------*/
     // This method can be used to search for layout problems. If this class is
     // compiled with this method uncommented, the layout guides will be shown
@@ -409,7 +418,10 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
         {
             layout = new TwoColumnLayout(10, 5, 30, topbuff, TwoColumnLayout.LEFT);
         }
-        setLayout(layout);
+        setLayout(new BorderLayout());
+
+        panel = new JPanel();
+        panel.setLayout(layout);
 
         if (!haveSpec)
         {
@@ -1101,7 +1113,7 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
                 if (!element.isDisplayed())
                 {
                     element.setDisplayed(true);
-                    add(element.getComponent(), element.getConstraints());
+                    panel.add(element.getComponent(), element.getConstraints());
                 }
             }
             else
@@ -1109,10 +1121,16 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
                 if (element.isDisplayed())
                 {
                     element.setDisplayed(false);
-                    remove(element.getComponent());
+                    panel.remove(element.getComponent());
                 }
             }
         }
+        JScrollPane scroller = new JScrollPane(panel);
+        Border emptyBorder = BorderFactory.createEmptyBorder();
+        scroller.setViewportBorder(emptyBorder);
+        scroller.getVerticalScrollBar().setBorder(emptyBorder);
+        scroller.getHorizontalScrollBar().setBorder(emptyBorder);
+        add(scroller, BorderLayout.CENTER);
     }
 
     /*--------------------------------------------------------------------------*/
@@ -1184,7 +1202,8 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
         try
         {
             FileInputField panel = (FileInputField) field.getComponent();
-            result = panel.validateField();
+            //result = panel.validateField();
+            result = !validating || panel.validateField();
             if (result)
             {
                 idata.setVariable(field.getAssociatedVariable(), panel.getSelectedFile()
@@ -1209,7 +1228,8 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
         try
         {
             FileInputField input = (FileInputField) field.getComponent();
-            result = input.validateField();
+            //result = input.validateField();
+            result = !validating || input.validateField();
             if (result)
             {
                 idata.setVariable(field.getAssociatedVariable(), input.getSelectedFile()
@@ -1234,7 +1254,8 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
         try
         {
             MultipleFileInputField input = (MultipleFileInputField) field.getComponent();
-            result = input.validateField();
+            //result = input.validateField();
+            result = !validating || input.validateField();
             if (result)
             {
                 List<String> files = input.getSelectedFiles();
@@ -1406,7 +1427,7 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
             constraints.align = justify;
             constraints.position = TwoColumnConstraints.NORTH;
 
-            add(label, constraints);
+            panel.add(label, constraints);
         }
     }
 
@@ -1822,7 +1843,8 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
 
         // validate the input
         Debug.trace("Validating text field");
-        boolean success = textField.validateContents();
+        //boolean success = textField.validateContents();
+        boolean success = !validating || textField.validateContents();
         if (!success)
         {
             Debug.trace("Validation did not pass, message: " + message);
@@ -2439,6 +2461,9 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
         String falseValue = null;
         String variable = spec.getAttribute(VARIABLE);
         String causesValidataion = null;
+        String childVariable = null;
+        String childCheckBoxVariable = null;
+        String setChildValueWhenParentIsUnchecked = null;
         IXMLElement detail = spec.getFirstChildNamed(SPEC);
 
         if (variable == null) { return; }
@@ -2450,6 +2475,11 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
             trueValue = detail.getAttribute(TRUE);
             falseValue = detail.getAttribute(FALSE);
             causesValidataion = detail.getAttribute(REVALIDATE);
+            childVariable =  detail.getAttribute(CHILD_VARIABLE);
+            if(childVariable != null) {
+               childCheckBoxVariable = idata.getVariable(childVariable);
+            }
+            setChildValueWhenParentIsUnchecked =  detail.getAttribute(SET_CHILD_VALUE_WHEN_PARENT_IS_UNCHECKED);
             String value = idata.getVariable(variable);
             Debug.trace("check: value: " + value + ", set: " + set);
             if (value != null)
@@ -2466,6 +2496,11 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
         // What are we doing here anyway??? BDA 20090518
         //checkbox.addItemListener(this);
 
+        if(("0".equals(idata.getVariable(variable)) || "false".equals(idata.getVariable(variable))) && ("1".equals(childCheckBoxVariable) || "true".equals(childCheckBoxVariable))) {
+            // 自分自身のチェックボックスがオフ(0 or false)になるときに、子供のチェックがオン(1 or true)であれば、子供のチェックをsetChildValueWhenParentIsUncheckedの値にする
+            idata.setVariable(childVariable, setChildValueWhenParentIsUnchecked);
+        }
+
         if (causesValidataion != null && causesValidataion.equals("yes"))
         {
             checkbox.addActionListener(this);
@@ -3897,7 +3932,11 @@ public class UserInputPanel extends IzPanel implements ActionListener, ItemListe
         // readInput();
         // panelActivate();
         // validating = true;
+        Debug.trace("Setting validating to false");
+        validating=false;
         updateDialog();
+        Debug.trace("Setting validating back to true");
+        validating=true;
     }
 
     /*--------------------------------------------------------------------------*/