KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lobobrowser > html > renderer > InputRadioControl


1 /*
2     GNU LESSER GENERAL PUBLIC LICENSE
3     Copyright (C) 2006 The Lobo Project
4
5     This library is free software; you can redistribute it and/or
6     modify it under the terms of the GNU Lesser General Public
7     License as published by the Free Software Foundation; either
8     version 2.1 of the License, or (at your option) any later version.
9
10     This library is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13     Lesser General Public License for more details.
14
15     You should have received a copy of the GNU Lesser General Public
16     License along with this library; if not, write to the Free Software
17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19     Contact info: xamjadmin@users.sourceforge.net
20 */

21 /*
22  * Created on Jan 15, 2006
23  */

24 package org.lobobrowser.html.renderer;
25
26 import org.lobobrowser.html.domimpl.*;
27 import org.lobobrowser.util.gui.WrapperLayout;
28 import javax.swing.*;
29
30 class InputRadioControl extends BaseInputControl {
31     private final JRadioButton widget;
32     
33     public InputRadioControl(HTMLBaseInputElement modelNode) {
34         super(modelNode);
35         this.setLayout(WrapperLayout.getInstance());
36         JRadioButton radio = new JRadioButton();
37         radio.setOpaque(false);
38         this.widget = radio;
39         this.add(radio);
40     }
41     
42     private ButtonGroup buttonGroup;
43     
44     public void reset(int availWidth, int availHeight) {
45         super.reset(availWidth, availHeight);
46         HTMLElementImpl controlElement = this.controlElement;
47         String JavaDoc name = controlElement.getAttribute("name");
48         JRadioButton radio = this.widget;
49         ButtonGroup prevGroup = this.buttonGroup;
50         if(prevGroup != null) {
51             prevGroup.remove(radio);
52         }
53         if(name != null) {
54             String JavaDoc key = "cobra.radio.group." + name;
55             ButtonGroup group = (ButtonGroup) controlElement.getDocumentItem(key);
56             if(group == null) {
57                 group = new ButtonGroup();
58                 controlElement.setDocumentItem(key, group);
59             }
60             group.add(radio);
61             this.buttonGroup = group;
62         }
63         else {
64             this.buttonGroup = null;
65         }
66         String JavaDoc checkedText = controlElement.getAttribute("checked");
67         radio.setSelected("checked".equalsIgnoreCase(checkedText));
68     }
69     
70     /* (non-Javadoc)
71      * @see org.xamjwg.html.domimpl.InputContext#click()
72      */

73     public void click() {
74         this.widget.doClick();
75     }
76
77     /* (non-Javadoc)
78      * @see org.xamjwg.html.domimpl.InputContext#getChecked()
79      */

80     public boolean getChecked() {
81         return this.widget.isSelected();
82     }
83
84     /* (non-Javadoc)
85      * @see org.xamjwg.html.domimpl.InputContext#setChecked(boolean)
86      */

87     public void setChecked(boolean checked) {
88         this.widget.setSelected(checked);
89     }
90
91     /* (non-Javadoc)
92      * @see org.xamjwg.html.domimpl.InputContext#setDisabled(boolean)
93      */

94     public void setDisabled(boolean disabled) {
95         super.setDisabled(disabled);
96         this.widget.setEnabled(!disabled);
97     }
98     
99     public void resetInput() {
100         String JavaDoc checkedText = controlElement.getAttribute("checked");
101         this.widget.setSelected("checked".equalsIgnoreCase(checkedText));
102     }
103     
104     public String JavaDoc getValue() {
105         return this.controlElement.getAttribute("value");
106     }
107 }
108
Popular Tags