001: /*
002: * Copyright 2007 Google Inc.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy of
006: * the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations under
014: * the License.
015: */
016: package com.google.gwt.user.client.ui;
017:
018: import com.google.gwt.user.client.DOM;
019:
020: /**
021: * A mutually-exclusive selection radio button widget.
022: *
023: * <p>
024: * <img class='gallery' src='RadioButton.png'/>
025: * </p>
026: *
027: * <h3>CSS Style Rules</h3>
028: * <ul class='css'>
029: * <li>.gwt-RadioButton { }</li>
030: * </ul>
031: *
032: * <p>
033: * <h3>Example</h3> {@example com.google.gwt.examples.RadioButtonExample}
034: * </p>
035: */
036: public class RadioButton extends CheckBox {
037:
038: /**
039: * Creates a new radio associated with a particular group name. All radio
040: * buttons associated with the same group name belong to a mutually-exclusive
041: * set.
042: *
043: * Radio buttons are grouped by their name attribute, so changing their
044: * name using the setName() method will also change their associated
045: * group.
046: *
047: * @param name the group name with which to associate the radio button
048: */
049: public RadioButton(String name) {
050: super (DOM.createInputRadio(name));
051: setStyleName("gwt-RadioButton");
052: }
053:
054: /**
055: * Creates a new radio associated with a particular group, and initialized
056: * with the given HTML label. All radio buttons associated with the same group
057: * name belong to a mutually-exclusive set.
058: *
059: * Radio buttons are grouped by their name attribute, so changing their
060: * name using the setName() method will also change their associated
061: * group.
062: *
063: * @param name the group name with which to associate the radio button
064: * @param label this radio button's label
065: */
066: public RadioButton(String name, String label) {
067: this (name);
068: setText(label);
069: }
070:
071: /**
072: * Creates a new radio button associated with a particular group, and
073: * initialized with the given label (optionally treated as HTML). All radio
074: * buttons associated with the same group name belong to a mutually-exclusive
075: * set.
076: *
077: * Radio buttons are grouped by their name attribute, so changing their
078: * name using the setName() method will also change their associated
079: * group.
080: *
081: * @param name name the group with which to associate the radio button
082: * @param label this radio button's label
083: * @param asHTML <code>true</code> to treat the specified label as HTML
084: */
085: public RadioButton(String name, String label, boolean asHTML) {
086: this (name);
087: if (asHTML) {
088: setHTML(label);
089: } else {
090: setText(label);
091: }
092: }
093:
094: /**
095: * Change the group name of this radio button.
096: *
097: * Radio buttons are grouped by their name attribute, so changing their
098: * name using the setName() method will also change their associated
099: * group.
100: *
101: * If changing this group name results in a new radio group with
102: * multiple radio buttons selected, this radio button will remain
103: * selected and the other radio buttons will be unselected.
104: *
105: * @param name name the group with which to associate the radio button
106: */
107: @Override
108: public void setName(String name) {
109: super.replaceInputElement(DOM.createInputRadio(name));
110: }
111: }
|