]> source.dussan.org Git - vaadin-framework.git/commitdiff
Cleaned Button & CheckBox code, now ensures button has initial value false.
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 30 Oct 2008 08:21:39 +0000 (08:21 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Thu, 30 Oct 2008 08:21:39 +0000 (08:21 +0000)
svn changeset:5767/svn branch:trunk

src/com/itmill/toolkit/ui/Button.java
src/com/itmill/toolkit/ui/CheckBox.java

index 9e51b81576340a36a3ae854ae5af8741be425ba3..0812f261fffb9b7307b986cf172a4d1c898cfb76 100644 (file)
@@ -32,6 +32,7 @@ public class Button extends AbstractField {
      * 
      */
     public Button() {
+        setValue(new Boolean(false));
         setSwitchMode(false);
     }
 
@@ -45,8 +46,8 @@ public class Button extends AbstractField {
      *            the Button caption.
      */
     public Button(String caption) {
+        this();
         setCaption(caption);
-        setSwitchMode(false);
     }
 
     /**
@@ -134,14 +135,7 @@ public class Button extends AbstractField {
         if (isSwitchMode()) {
             target.addAttribute("type", "switch");
         }
-        boolean state;
-        try {
-            state = ((Boolean) getValue()).booleanValue();
-        } catch (final NullPointerException e) {
-            state = false;
-        }
-        target.addVariable(this, "state", state);
-
+        target.addVariable(this, "state", booleanValue());
     }
 
     /**
@@ -203,7 +197,9 @@ public class Button extends AbstractField {
         this.switchMode = switchMode;
         if (!switchMode) {
             setImmediate(true);
-            setValue(new Boolean(false));
+            if (booleanValue()) {
+                setValue(new Boolean(false));
+            }
         }
     }
 
@@ -213,7 +209,13 @@ public class Button extends AbstractField {
      * @return True iff the button is pressed down or checked.
      */
     public boolean booleanValue() {
-        return ((Boolean) getValue()).booleanValue();
+        boolean state;
+        try {
+            state = ((Boolean) getValue()).booleanValue();
+        } catch (final NullPointerException e) {
+            state = false;
+        }
+        return state;
     }
 
     /**
index 58855c9a62c1d7aa8dd16b4aa1248cd42e234968..cd488b403a8bfa6b5d5035296b810611a8e947bc 100644 (file)
@@ -25,9 +25,7 @@ public class CheckBox extends Button {
      *            the initial state of the switch button
      */
     public CheckBox(String caption, boolean initialState) {
-        setCaption(caption);
-        setValue(new Boolean(initialState));
-        setSwitchMode(true);
+        super(caption, initialState);
     }
 
     /**
@@ -39,8 +37,7 @@ public class CheckBox extends Button {
      *            the click listener
      */
     public CheckBox(String caption, ClickListener listener) {
-        setCaption(caption);
-        addListener(listener);
+        super(caption, listener);
         setSwitchMode(true);
     }
 
@@ -62,8 +59,7 @@ public class CheckBox extends Button {
      *            click events.
      */
     public CheckBox(String caption, Object target, String methodName) {
-        setCaption(caption);
-        addListener(ClickEvent.class, target, methodName);
+        super(caption, target, methodName);
         setSwitchMode(true);
     }
 
@@ -75,8 +71,7 @@ public class CheckBox extends Button {
      * @param dataSource
      */
     public CheckBox(String caption, Property dataSource) {
-        setCaption(caption);
-        setPropertyDataSource(dataSource);
+        super(caption, dataSource);
         setSwitchMode(true);
     }
 
@@ -91,8 +86,7 @@ public class CheckBox extends Button {
      */
 
     public CheckBox(String caption) {
-        setCaption(caption);
-        setSwitchMode(true);
+        super(caption, false);
     }
 
     public void setSwitchMode(boolean switchMode)
@@ -101,7 +95,7 @@ public class CheckBox extends Button {
             throw new UnsupportedOperationException(
                     "CheckBox is always in switch mode (consider using a Button)");
         }
-        this.switchMode = true;
+        super.setSwitchMode(true);
     }
 
 }