Revision: 1319
Author:   mathiasbr
Date:     2006-08-19 16:42:24 -0700 (Sat, 19 Aug 2006)
ViewCVS:  http://svn.sourceforge.net/spring-rich-c/?rev=1319&view=rev

Log Message:
-----------
binding support for toggle button
CheckBoxBinder now uses toggle button binding
ComponentFactory can now create toggle buttons
Test case for ToggleButtonBinding

Modified Paths:
--------------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/ComponentFactory.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultComponentFactory.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/CheckBoxBinder.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/SwingBinderSelectionStrategy.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/SwingBindingFactory.java
    
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
    
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/BindingAbstractTests.java

Added Paths:
-----------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinder.java
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinding.java
    
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/ToggleButtonBindingTests.java

Removed Paths:
-------------
    
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/CheckBoxBinding.java
Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/ComponentFactory.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/ComponentFactory.java
  2006-08-19 22:56:58 UTC (rev 1318)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/ComponentFactory.java
  2006-08-19 23:42:24 UTC (rev 1319)
@@ -33,6 +33,7 @@
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
 import javax.swing.JScrollPane;
+import javax.swing.JToggleButton;
 import javax.swing.JFormattedTextField.AbstractFormatterFactory;
 import javax.swing.table.TableModel;
 
@@ -263,6 +264,26 @@
     public JCheckBox createCheckBox(String[] labelKeys);
 
     /**
+     * Create a configured toggle button.
+     * 
+     * @param labelKey
+     *            The label message code; may also be the label text if no
+     *            message source is configured.
+     * @return The toggle button.
+     */
+    public JToggleButton createToggleButton(String labelKey);
+
+    /**
+     * Create a configured toggle button.
+     * 
+     * @param labelKeys
+     *            The label message codes; may also be the label text if no
+     *            message source is configured.
+     * @return The toggle button.
+     */
+    public JToggleButton createToggleButton(String[] labelKeys);
+
+    /**
      * Create a formatted text field using this component factory.
      * 
      * @param formatterFactory
@@ -386,4 +407,5 @@
      * @return new table instance
      */
     public JTable createTable(TableModel model);
+
 }
\ No newline at end of file

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultComponentFactory.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultComponentFactory.java
   2006-08-19 22:56:58 UTC (rev 1318)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/factory/DefaultComponentFactory.java
   2006-08-19 23:42:24 UTC (rev 1319)
@@ -22,6 +22,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 
+import javax.swing.AbstractButton;
 import javax.swing.BorderFactory;
 import javax.swing.Icon;
 import javax.swing.JButton;
@@ -39,6 +40,7 @@
 import javax.swing.JTable;
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
+import javax.swing.JToggleButton;
 import javax.swing.JFormattedTextField.AbstractFormatterFactory;
 import javax.swing.table.TableModel;
 
@@ -278,6 +280,18 @@
         return new JCheckBox();
     }
 
+    public JToggleButton createToggleButton(String labelKey) {
+        return 
(JToggleButton)getButtonLabelInfo(getRequiredMessage(labelKey)).configure(createNewToggleButton());
+    }
+
+    public JToggleButton createToggleButton(String[] labelKeys) {
+        return 
(JToggleButton)getButtonLabelInfo(getRequiredMessage(labelKeys)).configure(createNewToggleButton());
+    }
+
+    protected AbstractButton createNewToggleButton() {
+        return new JToggleButton();
+    }
+
     public JMenuItem createMenuItem(String labelKey) {
         return 
(JMenuItem)getButtonLabelInfo(getRequiredMessage(labelKey)).configure(getMenuFactory().createMenuItem());
     }

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/CheckBoxBinder.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/CheckBoxBinder.java
 2006-08-19 22:56:58 UTC (rev 1318)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/CheckBoxBinder.java
 2006-08-19 23:42:24 UTC (rev 1319)
@@ -17,28 +17,29 @@
 
 import java.util.Map;
 
-import javax.swing.JCheckBox;
 import javax.swing.JComponent;
 
-import org.springframework.binding.form.FormModel;
-import org.springframework.richclient.form.binding.Binding;
-import org.springframework.richclient.form.binding.support.AbstractBinder;
-import org.springframework.util.Assert;
-
 /**
  * @author Oliver Hutchison
  */
-public class CheckBoxBinder extends AbstractBinder  {
+public class CheckBoxBinder extends ToggleButtonBinder {
 
     public CheckBoxBinder() {
-        super(null);
+        super();
     }
 
-    protected Binding doBind(JComponent control, FormModel formModel, String 
formPropertyPath, Map context) {
-        Assert.isTrue(control instanceof JCheckBox, "Control must be an 
instance of JCheckBox.");
-        return new CheckBoxBinding((JCheckBox) control, formModel, 
formPropertyPath);
+    protected CheckBoxBinder(Class requiredSourceClass, String[] 
supportedContextKeys) {
+        super(requiredSourceClass, supportedContextKeys);
     }
 
+    protected CheckBoxBinder(Class requiredSourceClass) {
+        super(requiredSourceClass);
+    }
+
+    protected CheckBoxBinder(String[] supportedContextKeys) {
+        super(supportedContextKeys);
+    }
+
     protected JComponent createControl(Map context) {
         return getComponentFactory().createCheckBox("");
     }

Deleted: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/CheckBoxBinding.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/CheckBoxBinding.java
        2006-08-19 22:56:58 UTC (rev 1318)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/CheckBoxBinding.java
        2006-08-19 23:42:24 UTC (rev 1319)
@@ -1,52 +0,0 @@
-/*
- * Copyright 2002-2004 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.springframework.richclient.form.binding.swing;
-
-import javax.swing.JCheckBox;
-import javax.swing.JComponent;
-
-import org.springframework.binding.form.FormModel;
-import org.springframework.binding.value.ValueModel;
-import org.springframework.binding.value.swing.SelectableButtonModelAdapter;
-import org.springframework.richclient.form.binding.support.AbstractBinding;
-
-/**
- * @author Oliver Hutchison
- */
-public class CheckBoxBinding extends AbstractBinding {
-    
-    private final JCheckBox checkBox;    
-    
-    public CheckBoxBinding(JCheckBox checkBox, FormModel formModel, String 
formPropertyPath) {
-        super(formModel, formPropertyPath, Boolean.class);
-        this.checkBox = checkBox;
-    }
-    
-    protected JComponent doBindControl() {
-        final ValueModel valueModel = getValueModel();
-        checkBox.setText(getFieldFace().getDescription());
-        checkBox.setModel(new SelectableButtonModelAdapter(valueModel));
-        return checkBox;
-    }
-    
-    protected void readOnlyChanged() {
-        checkBox.setEnabled(isEnabled() && ! isReadOnly());    
-    }
-
-    protected void enabledChanged() {
-        checkBox.setEnabled(isEnabled() && ! isReadOnly());        
-    }
-}
\ No newline at end of file

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/SwingBinderSelectionStrategy.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/SwingBinderSelectionStrategy.java
   2006-08-19 22:56:58 UTC (rev 1318)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/SwingBinderSelectionStrategy.java
   2006-08-19 23:42:24 UTC (rev 1319)
@@ -23,6 +23,7 @@
 import javax.swing.JScrollPane;
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
+import javax.swing.JToggleButton;
 import javax.swing.text.JTextComponent;
 
 import org.springframework.core.enums.LabeledEnum;
@@ -45,6 +46,7 @@
         registerBinderForControlType(JTextComponent.class, new 
TextComponentBinder());
         registerBinderForControlType(JFormattedTextField.class, new 
FormattedTextFieldBinder(null));
         registerBinderForControlType(JTextArea.class, new TextAreaBinder());
+        registerBinderForControlType(JToggleButton.class, new 
ToggleButtonBinder());
         registerBinderForControlType(JCheckBox.class, new CheckBoxBinder());
         registerBinderForControlType(JComboBox.class, new ComboBoxBinder());
         registerBinderForControlType(JList.class, new ListBinder());

Modified: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/SwingBindingFactory.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/SwingBindingFactory.java
    2006-08-19 22:56:58 UTC (rev 1318)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/SwingBindingFactory.java
    2006-08-19 23:42:24 UTC (rev 1319)
@@ -28,6 +28,7 @@
 import javax.swing.JSpinner;
 import javax.swing.JTextArea;
 import javax.swing.JTextField;
+import javax.swing.JToggleButton;
 import javax.swing.JFormattedTextField.AbstractFormatterFactory;
 
 import org.springframework.beans.support.PropertyComparator;
@@ -89,6 +90,10 @@
         return createBinding(JLabel.class, formProperty);
     }
 
+    public Binding createBoundToggleButton(String formProperty) {
+        return createBinding(JToggleButton.class, formProperty);
+    }
+
     public Binding createBoundCheckBox(String formProperty) {
         return createBinding(JCheckBox.class, formProperty);
     }

Added: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinder.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinder.java
                             (rev 0)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinder.java
     2006-08-19 23:42:24 UTC (rev 1319)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy 
of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.springframework.richclient.form.binding.swing;
+
+import java.util.Map;
+
+import javax.swing.JComponent;
+import javax.swing.JToggleButton;
+
+import org.springframework.binding.form.FormModel;
+import org.springframework.richclient.form.binding.Binding;
+import org.springframework.richclient.form.binding.support.AbstractBinder;
+import org.springframework.util.Assert;
+
+/**
+ * @author Mathias Broekelmann
+ * 
+ */
+public class ToggleButtonBinder extends AbstractBinder {
+
+    public ToggleButtonBinder() {
+        this(Boolean.class);
+    }
+
+    protected ToggleButtonBinder(String[] supportedContextKeys) {
+        super(Boolean.class, supportedContextKeys);
+    }
+
+    protected ToggleButtonBinder(Class requiredSourceClass) {
+        super(requiredSourceClass);
+    }
+
+    protected ToggleButtonBinder(Class requiredSourceClass, String[] 
supportedContextKeys) {
+        super(requiredSourceClass, supportedContextKeys);
+    }
+
+    protected Binding doBind(JComponent control, FormModel formModel, String 
formPropertyPath, Map context) {
+        Assert.isTrue(control instanceof JToggleButton, "Control must be an 
instance of JToggleButton.");
+        return new ToggleButtonBinding((JToggleButton) control, formModel, 
formPropertyPath);
+    }
+
+    protected JComponent createControl(Map context) {
+        return getComponentFactory().createToggleButton("");
+    }
+
+}


Property changes on: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinder.java
___________________________________________________________________
Name: svn:keywords
   + Revision Author Date Id
Name: svn:eol-style
   + native

Added: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinding.java
===================================================================
--- 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinding.java
                            (rev 0)
+++ 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinding.java
    2006-08-19 23:42:24 UTC (rev 1319)
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy 
of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.springframework.richclient.form.binding.swing;
+
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.JComponent;
+import javax.swing.JToggleButton;
+
+import org.springframework.binding.form.FormModel;
+import org.springframework.richclient.form.binding.support.CustomBinding;
+
+/**
+ * @author Mathias Broekelmann
+ * 
+ */
+public class ToggleButtonBinding extends CustomBinding {
+
+    private final JToggleButton toggleButton;
+
+    private ItemListener selectionListener = new SelectionListener();
+
+    public ToggleButtonBinding(JToggleButton toggleButton, FormModel 
formModel, String formPropertyPath) {
+        super(formModel, formPropertyPath, Boolean.class);
+        this.toggleButton = toggleButton;
+    }
+
+    protected JComponent doBindControl() {
+        getFieldFace().configure(toggleButton);
+        toggleButton.getModel().addItemListener(selectionListener);
+        return toggleButton;
+    }
+
+    protected void readOnlyChanged() {
+        toggleButton.setEnabled(isEnabled() && !isReadOnly());
+    }
+
+    protected void enabledChanged() {
+        toggleButton.setEnabled(isEnabled() && !isReadOnly());
+    }
+
+    protected void valueModelChanged(Object newValue) {
+        toggleButton.setSelected(Boolean.TRUE.equals(newValue));
+    }
+
+    protected class SelectionListener implements ItemListener {
+
+        public void itemStateChanged(ItemEvent e) {
+            controlValueChanged(Boolean.valueOf(toggleButton.isSelected()));
+        }
+
+    }
+}


Property changes on: 
trunk/spring-richclient/support/src/main/java/org/springframework/richclient/form/binding/swing/ToggleButtonBinding.java
___________________________________________________________________
Name: svn:keywords
   + Revision Author Date Id
Name: svn:eol-style
   + native

Modified: 
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
===================================================================
--- 
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
     2006-08-19 22:56:58 UTC (rev 1318)
+++ 
trunk/spring-richclient/support/src/test/java/org/springframework/binding/support/TestBean.java
     2006-08-19 23:42:24 UTC (rev 1319)
@@ -46,6 +46,8 @@
     public Object writeOnly;
 
     public Number numberProperty;
+    
+    private boolean booleanProperty;
 
     public Number getNumberProperty() {
         return numberProperty;
@@ -127,4 +129,12 @@
         this.arrayProperty = arrayProperty;
     }
 
+    public boolean isBooleanProperty() {
+        return booleanProperty;
+    }
+
+    public void setBooleanProperty(boolean booleanProperty) {
+        this.booleanProperty = booleanProperty;
+    }
+
 }
\ No newline at end of file

Modified: 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/BindingAbstractTests.java
===================================================================
--- 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/BindingAbstractTests.java
   2006-08-19 22:56:58 UTC (rev 1318)
+++ 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/BindingAbstractTests.java
   2006-08-19 23:42:24 UTC (rev 1319)
@@ -27,9 +27,11 @@
 
     protected ValueModel vm;
 
+    protected String property;
+
     public void doSetUp() {
         fm = new DefaultFormModel(createTestBean());        
-        String property = setUpBinding();
+        property = setUpBinding();
         vm = fm.getValueModel(property);
     }
 

Added: 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/ToggleButtonBindingTests.java
===================================================================
--- 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/ToggleButtonBindingTests.java
                               (rev 0)
+++ 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/ToggleButtonBindingTests.java
       2006-08-19 23:42:24 UTC (rev 1319)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2002-2006 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy 
of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.springframework.richclient.form.binding.swing;
+
+import javax.swing.JToggleButton;
+
+import org.springframework.binding.form.FieldMetadata;
+
+/**
+ * @author Mathias Broekelmann
+ * 
+ */
+public class ToggleButtonBindingTests extends BindingAbstractTests {
+
+    private JToggleButton tb;
+
+    private ToggleButtonBinding tbb;
+
+    protected String setUpBinding() {
+        tbb = new ToggleButtonBinding(new JToggleButton(), fm, 
"booleanProperty");
+        tb = (JToggleButton) tbb.getControl();
+        return "booleanProperty";
+    }
+
+    public void testComponentTracksEnabledChanges() {
+        assertEquals(true, tb.isEnabled());
+        fm.setEnabled(false);
+        assertEquals(false, tb.isEnabled());
+        fm.setEnabled(true);
+        assertEquals(true, tb.isEnabled());
+    }
+
+    public void testComponentTracksReadOnlyChanges() {
+        FieldMetadata state = fm.getFieldMetadata(property);
+        assertEquals(true, tb.isEnabled());
+        state.setReadOnly(true);
+        assertEquals(false, tb.isEnabled());
+        state.setReadOnly(false);
+        assertEquals(true, tb.isEnabled());
+    }
+
+    public void testComponentUpdatesValueModel() {
+        tb.setSelected(true);
+        assertEquals(Boolean.TRUE, vm.getValue());
+        tb.setSelected(false);
+        assertEquals(Boolean.FALSE, vm.getValue());
+        tb.setSelected(true);
+        assertEquals(Boolean.TRUE, vm.getValue());
+    }
+
+    public void testValueModelUpdatesComponent() {
+        vm.setValue(Boolean.TRUE);
+        assertTrue(tb.isSelected());
+        vm.setValue(Boolean.FALSE);
+        assertFalse(tb.isSelected());
+        vm.setValue(Boolean.TRUE);
+        assertTrue(tb.isSelected());
+    }
+
+}


Property changes on: 
trunk/spring-richclient/support/src/test/java/org/springframework/richclient/form/binding/swing/ToggleButtonBindingTests.java
___________________________________________________________________
Name: svn:keywords
   + Revision Author Date Id
Name: svn:eol-style
   + native


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
spring-rich-c-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spring-rich-c-cvs

Reply via email to