Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libjava / javax / swing / JRadioButton.java
blobda8c8395a24e015400dde562789f47dc8c137bb6
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., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 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
83 /**
84 * Constructor for the accessible toggle button.
86 protected AccessibleJRadioButton()
88 /* Call the superclass to register for events */
89 super();
92 /**
93 * Returns the accessible role for the toggle button.
95 * @return An instance of <code>AccessibleRole</code>, describing
96 * the role of the toggle button.
98 public AccessibleRole getAccessibleRole()
100 return AccessibleRole.RADIO_BUTTON;
106 * Constructs an unselected radio button with no text or icon.
108 public JRadioButton()
110 this(null, null, false);
114 * Constructs a radio button using the labelling, state
115 * and icon specified by the supplied action.
117 * @param a the action to use to define the properties of the button.
119 public JRadioButton(Action a)
121 this();
122 setAction(a);
126 * Constructs an unselected radio button with the supplied icon
127 * and no text.
129 * @param icon the icon to use.
131 public JRadioButton(Icon icon)
133 this(null, icon, false);
137 * Constructs a radio button with the supplied icon and state.
139 * @param icon the icon to use.
140 * @param selected if true, the radio button is initially in the
141 * selected state. Otherwise, the button is unselected.
143 public JRadioButton(Icon icon, boolean selected)
145 this(null, icon, selected);
149 * Constructs an unselected radio button using the supplied text
150 * and no icon.
152 * @param text the text to use.
154 public JRadioButton(String text)
156 this(text, null, false);
160 * Constructs a radio button with the supplied text and state.
162 * @param text the text to use.
163 * @param selected if true, the radio button is initially in the
164 * selected state. Otherwise, the button is unselected.
166 public JRadioButton(String text, boolean selected)
168 this(text, null, selected);
172 * Constructs an unselected radio button with the supplied text
173 * and icon.
175 * @param text the text to use.
176 * @param icon the icon to use.
178 public JRadioButton(String text, Icon icon)
180 this(text, icon, false);
184 * Constructs a radio button with the supplied text, icon and state.
186 * @param text the text to use.
187 * @param icon the icon to use.
188 * @param selected if true, the radio button is initially in the
189 * selected state. Otherwise, the button is unselected.
191 public JRadioButton(String text, Icon icon, boolean selected)
193 super(text, icon, selected);
194 borderPainted = false;
195 contentAreaFilled = false;
199 * Returns the accessible context for this <code>JRadioButton</code>,
200 * in the form of an instance of <code>AccessibleJRadioButton</code>.
201 * The context is created, if necessary.
203 * @return the associated context
205 public AccessibleContext getAccessibleContext()
207 /* Create the context if this is the first request */
208 if (accessibleContext == null)
210 /* Create the context */
211 accessibleContext = new AccessibleJRadioButton();
213 return accessibleContext;
217 * Returns a string specifying the name of the Look and Feel UI class
218 * that renders this component.
220 * @return the Look and Feel UI class for <code>JRadioButton</code>s
221 * as a <code>String</code>.
223 public String getUIClassID()
225 return "RadioButtonUI";
229 * Returns a string representation of this component for debugging use.
230 * Users should not depend on anything as regards the content or formatting
231 * of this string, except for the fact that the returned string may never be
232 * null (only empty).
234 * @return the component in <code>String</code> form for debugging.
236 protected String paramString()
238 return "JRadioButton";
242 * This method resets the radio button's UI delegate to the default UI for
243 * the current look and feel.
245 public void updateUI()
248 I can't see any difference between this and the superclass one,
249 but Sun reimplements it... there is no RadioButtonUI class for it
250 to be cast to.
252 setUI((ButtonUI) UIManager.getUI(this));