aboutsummaryrefslogtreecommitdiff
path: root/libjava/javax/swing/JRadioButton.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/javax/swing/JRadioButton.java')
-rw-r--r--libjava/javax/swing/JRadioButton.java191
1 files changed, 170 insertions, 21 deletions
diff --git a/libjava/javax/swing/JRadioButton.java b/libjava/javax/swing/JRadioButton.java
index b1f733a..fc06d15 100644
--- a/libjava/javax/swing/JRadioButton.java
+++ b/libjava/javax/swing/JRadioButton.java
@@ -39,70 +39,219 @@ exception statement from your version. */
package javax.swing;
import javax.accessibility.AccessibleContext;
+import javax.accessibility.AccessibleRole;
+import javax.swing.plaf.ButtonUI;
+/**
+ * The <code>JRadioButton</code> component provides a visually selectable
+ * button with mutually exclusive behaviour within a <code>ButtonGroup</code>.
+ * A series of radio buttons can be used to provide options to the user,
+ * where the user can only select one of the available options. The state
+ * of the button is provided by the superclass, <code>JToggleButton</code>.
+ * <code>JRadioButton</code> adds the additional behaviour, that if two
+ * or more radio buttons are grouped together, the selection of one implies
+ * the deselection of the other buttons within the group.
+ * <p>
+ *
+ * Buttons are grouped by adding each instance to a <code>ButtonGroup</code>.
+ * The existence of such a grouping is not reflected visually, so other means
+ * should be used to denote this. For instance, the grouped buttons can be placed
+ * within the same panel, possibly with an appropriate border to denote
+ * the connection between the components.
+ *
+ * @author Michael Koch <konqueror@gmx.de>
+ * @author Graydon Hoare <graydon@redhat.com>
+ * @author Andrew John Hughes <gnu_andrew@member.fsf.org>
+ * @see JToggleButton
+ * @see ButtonGroup
+ * @since 1.2
+ */
public class JRadioButton extends JToggleButton
{
+ /**
+ * Compatible with Sun's JDK.
+ */
private static final long serialVersionUID = 7751949583255506856L;
+ /**
+ * This class provides accessibility support for the toggle button.
+ */
+ protected class AccessibleJRadioButton
+ extends AccessibleJToggleButton
+ {
+
+ /**
+ * Constructor for the accessible toggle button.
+ */
+ protected AccessibleJRadioButton()
+ {
+ /* Call the superclass to register for events */
+ super();
+ }
+
+ /**
+ * Returns the accessible role for the toggle button.
+ *
+ * @return An instance of <code>AccessibleRole</code>, describing
+ * the role of the toggle button.
+ */
+ public AccessibleRole getAccessibleRole()
+ {
+ return AccessibleRole.RADIO_BUTTON;
+ }
+
+ }
+
+ /**
+ * Constructs an unselected radio button with no text or icon.
+ */
public JRadioButton()
{
- this(null, null);
+ this(null, null, false);
}
+ /**
+ * Constructs a radio button using the labelling, state
+ * and icon specified by the supplied action.
+ *
+ * @param a the action to use to define the properties of the button.
+ */
public JRadioButton(Action a)
{
this();
setAction(a);
}
+ /**
+ * Constructs an unselected radio button with the supplied icon
+ * and no text.
+ *
+ * @param icon the icon to use.
+ */
public JRadioButton(Icon icon)
{
- this(null, icon);
+ this(null, icon, false);
}
+ /**
+ * Constructs a radio button with the supplied icon and state.
+ *
+ * @param icon the icon to use.
+ * @param selected if true, the radio button is initially in the
+ * selected state. Otherwise, the button is unselected.
+ */
public JRadioButton(Icon icon, boolean selected)
{
this(null, icon, selected);
}
+ /**
+ * Constructs an unselected radio button using the supplied text
+ * and no icon.
+ *
+ * @param text the text to use.
+ */
public JRadioButton(String text)
{
- this(text, null);
+ this(text, null, false);
}
+ /**
+ * Constructs a radio button with the supplied text and state.
+ *
+ * @param text the text to use.
+ * @param selected if true, the radio button is initially in the
+ * selected state. Otherwise, the button is unselected.
+ */
public JRadioButton(String text, boolean selected)
{
this(text, null, selected);
}
+ /**
+ * Constructs an unselected radio button with the supplied text
+ * and icon.
+ *
+ * @param text the text to use.
+ * @param icon the icon to use.
+ */
public JRadioButton(String text, Icon icon)
{
- super(text, icon);
+ this(text, icon, false);
+ }
+
+ /**
+ * Constructs a radio button with the supplied text, icon and state.
+ *
+ * @param text the text to use.
+ * @param icon the icon to use.
+ * @param selected if true, the radio button is initially in the
+ * selected state. Otherwise, the button is unselected.
+ */
+ public JRadioButton(String text, Icon icon, boolean selected)
+ {
+ super(text, icon, selected);
borderPainted = false;
contentAreaFilled = false;
}
- public JRadioButton(String text, Icon icon, boolean selected)
+ /**
+ * Returns the accessible context for this <code>JRadioButton</code>,
+ * in the form of an instance of <code>AccessibleJRadioButton</code>.
+ * The context is created, if necessary.
+ *
+ * @return the associated context
+ */
+ public AccessibleContext getAccessibleContext()
{
+ /* Create the context if this is the first request */
+ if (accessibleContext == null)
+ {
+ /* Create the context */
+ accessibleContext = new AccessibleJRadioButton();
+ }
+ return accessibleContext;
}
-
- public AccessibleContext getAccessibleContext()
- {
- //Gets the AccessibleContext associated with this JRadioButton.
- return null;
- }
- public String getUIClassID()
- {
- //Returns a string that specifies the name of the Look and Feel
- //class that renders this component.
- return "RadioButtonUI";
- }
+ /**
+ * Returns a string specifying the name of the Look and Feel UI class
+ * that renders this component.
+ *
+ * @return the Look and Feel UI class for <code>JRadioButton</code>s
+ * as a <code>String</code>.
+ */
+ public String getUIClassID()
+ {
+ return "RadioButtonUI";
+ }
- protected String paramString()
- {
- return "JRadioButton";
- }
+ /**
+ * Returns a string representation of this component for debugging use.
+ * Users should not depend on anything as regards the content or formatting
+ * of this string, except for the fact that the returned string may never be
+ * null (only empty).
+ *
+ * @return the component in <code>String</code> form for debugging.
+ */
+ protected String paramString()
+ {
+ return "JRadioButton";
+ }
+
+ /**
+ * This method resets the radio button's UI delegate to the default UI for
+ * the current look and feel.
+ */
+ public void updateUI()
+ {
+ /*
+ I can't see any difference between this and the superclass one,
+ but Sun reimplements it... there is no RadioButtonUI class for it
+ to be cast to.
+ */
+ setUI((ButtonUI) UIManager.getUI(this));
+ }
+
}