Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / javax / swing / JRadioButton.java
blobe0593f3a5012b5446442a534b9cfba5ce64be236
1 /* JRadioButton.java --
2 Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax.swing;
41 import javax.accessibility.AccessibleContext;
42 import javax.accessibility.AccessibleRole;
43 import javax.swing.plaf.ButtonUI;
45 /**
46 * The <code>JRadioButton</code> component provides a visually selectable
47 * button with mutually exclusive behaviour within a <code>ButtonGroup</code>.
48 * A series of radio buttons can be used to provide options to the user,
49 * where the user can only select one of the available options. The state
50 * of the button is provided by the superclass, <code>JToggleButton</code>.
51 * <code>JRadioButton</code> adds the additional behaviour, that if two
52 * or more radio buttons are grouped together, the selection of one implies
53 * the deselection of the other buttons within the group.
54 * <p>
56 * Buttons are grouped by adding each instance to a <code>ButtonGroup</code>.
57 * The existence of such a grouping is not reflected visually, so other means
58 * should be used to denote this. For instance, the grouped buttons can be placed
59 * within the same panel, possibly with an appropriate border to denote
60 * the connection between the components.
62 * @author Michael Koch (konqueror@gmx.de)
63 * @author Graydon Hoare (graydon@redhat.com)
64 * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
65 * @see JToggleButton
66 * @see ButtonGroup
67 * @since 1.2
69 public class JRadioButton extends JToggleButton
71 /**
72 * Compatible with Sun's JDK.
74 private static final long serialVersionUID = 7751949583255506856L;
76 /**
77 * This class provides accessibility support for the toggle button.
79 protected class AccessibleJRadioButton
80 extends AccessibleJToggleButton
82 private static final long serialVersionUID = 4850967637026120674L;
84 /**
85 * Constructor for the accessible toggle button.
87 protected AccessibleJRadioButton()
89 /* Call the superclass to register for events */
90 super();
93 /**
94 * Returns the accessible role for the toggle button.
96 * @return An instance of <code>AccessibleRole</code>, describing
97 * the role of the toggle button.
99 public AccessibleRole getAccessibleRole()
101 return AccessibleRole.RADIO_BUTTON;
107 * Constructs an unselected radio button with no text or icon.
109 public JRadioButton()
111 this(null, null, false);
115 * Constructs a radio button using the labelling, state
116 * and icon specified by the supplied action.
118 * @param a the action to use to define the properties of the button.
120 public JRadioButton(Action a)
122 this();
123 setAction(a);
127 * Constructs an unselected radio button with the supplied icon
128 * and no text.
130 * @param icon the icon to use.
132 public JRadioButton(Icon icon)
134 this(null, icon, false);
138 * Constructs a radio button with the supplied icon and state.
140 * @param icon the icon to use.
141 * @param selected if true, the radio button is initially in the
142 * selected state. Otherwise, the button is unselected.
144 public JRadioButton(Icon icon, boolean selected)
146 this(null, icon, selected);
150 * Constructs an unselected radio button using the supplied text
151 * and no icon.
153 * @param text the text to use.
155 public JRadioButton(String text)
157 this(text, null, false);
161 * Constructs a radio button with the supplied text and state.
163 * @param text the text to use.
164 * @param selected if true, the radio button is initially in the
165 * selected state. Otherwise, the button is unselected.
167 public JRadioButton(String text, boolean selected)
169 this(text, null, selected);
173 * Constructs an unselected radio button with the supplied text
174 * and icon.
176 * @param text the text to use.
177 * @param icon the icon to use.
179 public JRadioButton(String text, Icon icon)
181 this(text, icon, false);
185 * Constructs a radio button with the supplied text, icon and state.
187 * @param text the text to use.
188 * @param icon the icon to use.
189 * @param selected if true, the radio button is initially in the
190 * selected state. Otherwise, the button is unselected.
192 public JRadioButton(String text, Icon icon, boolean selected)
194 super(text, icon, selected);
195 setBorderPainted(false);
196 setHorizontalAlignment(LEADING);
200 * Returns the accessible context for this <code>JRadioButton</code>,
201 * in the form of an instance of <code>AccessibleJRadioButton</code>.
202 * The context is created, if necessary.
204 * @return the associated context
206 public AccessibleContext getAccessibleContext()
208 /* Create the context if this is the first request */
209 if (accessibleContext == null)
211 /* Create the context */
212 accessibleContext = new AccessibleJRadioButton();
214 return accessibleContext;
218 * Returns a string specifying the name of the Look and Feel UI class
219 * that renders this component.
221 * @return the Look and Feel UI class for <code>JRadioButton</code>s
222 * as a <code>String</code>.
224 public String getUIClassID()
226 return "RadioButtonUI";
230 * Returns a string representation of this component for debugging use.
231 * Users should not depend on anything as regards the content or formatting
232 * of this string, except for the fact that the returned string may never be
233 * null (only empty).
235 * @return the component in <code>String</code> form for debugging.
237 protected String paramString()
239 return super.paramString();
243 * This method resets the radio button's UI delegate to the default UI for
244 * the current look and feel.
246 public void updateUI()
249 I can't see any difference between this and the superclass one,
250 but Sun reimplements it... there is no RadioButtonUI class for it
251 to be cast to.
253 setUI((ButtonUI) UIManager.getUI(this));