KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jdesktop > swing > binding > RadioBinding


1 /*
2  * $Id: RadioBinding.java,v 1.2 2004/07/28 21:21:16 aim Exp $
3  *
4  * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5  * Santa Clara, California 95054, U.S.A. All rights reserved.
6  */

7
8 package org.jdesktop.swing.binding;
9
10 import org.jdesktop.swing.data.DataModel;
11 import org.jdesktop.swing.data.MetaData;
12
13 import org.jdesktop.swing.JXRadioGroup;
14
15 import java.awt.event.ActionEvent JavaDoc;
16 import java.awt.event.ActionListener JavaDoc;
17
18 import javax.swing.JComponent JavaDoc;
19
20
21 /**
22  * Class which binds a component that supports setting a one-of-many
23  * value (JXRadioGroup) to a data model field which is may be an arbitrary type.
24  * @author Amy Fowler
25  * @version 1.0
26  */

27 public class RadioBinding extends AbstractBinding {
28     private JXRadioGroup radioGroup;
29
30     public RadioBinding(JXRadioGroup radioGroup,
31                            DataModel dataModel, String JavaDoc fieldName) {
32         super(radioGroup, dataModel, fieldName, Binding.AUTO_VALIDATE_NONE);
33     }
34
35     public JComponent JavaDoc getComponent() {
36         return radioGroup;
37     }
38
39     protected void setComponent(JComponent JavaDoc component) {
40         radioGroup = (JXRadioGroup) component;
41         radioGroup.addActionListener(new ActionListener JavaDoc() {
42             public void actionPerformed(ActionEvent JavaDoc e) {
43                 if (!pulling) {
44                     setModified(true);
45                 }
46             }
47         });
48     }
49
50     protected Object JavaDoc getComponentValue(){
51         return radioGroup.getSelectedValue();
52     }
53
54     protected void setComponentValue(Object JavaDoc value) {
55         radioGroup.setSelectedValue(value);
56     }
57
58 }
59
Popular Tags