Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / javax / swing / JRadioButtonMenuItem.java
blob0d7c1d1053355b287829dc28c224ae6c9a392c61
1 /* JRadioButtonMenuItem.java --
2 Copyright (C) 2002, 2004, 2006, 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.Accessible;
42 import javax.accessibility.AccessibleContext;
43 import javax.accessibility.AccessibleRole;
45 /**
46 * This class represents JRadioButtonMenuItem. Its behaviour is very similar
47 * to JRadioButton. Just like JRadioButton, user can check and uncheck this
48 * menu item by clicking on it. JRadioButtonMenuItem uses ToggleButtonModel
49 * to keep track of its selection. If the JRadioButtonMenuItem is included in
50 * the button group, then only one JRadioButtonMenuItem can be selected at
51 * one time.
53 public class JRadioButtonMenuItem extends JMenuItem implements Accessible
55 private static final long serialVersionUID = 8482658191548521743L;
57 /** name for the UI delegate for this radio button menu item. */
58 private static final String uiClassID = "RadioButtonMenuItemUI";
60 /**
61 * Creates a new JRadioButtonMenuItem object.
63 public JRadioButtonMenuItem()
65 this(null, null);
68 /**
69 * Creates a new JRadioButtonMenuItem with specified icon
71 * @param icon Icon to be used for this menu item
73 public JRadioButtonMenuItem(Icon icon)
75 this(null, icon);
78 /**
79 * Creates a new JRadioButtonMenuItem with specified label
81 * @param text Label for this menu item
83 public JRadioButtonMenuItem(String text)
85 this(text, null);
88 /**
89 * Creates a new JRadioButtonMenuItem using specified action
91 * @param action Action for this menu item
93 public JRadioButtonMenuItem(Action action)
95 this();
96 setAction(action);
99 /**
100 * Creates a new JRadioButtonMenuItem with specified label and icon
102 * @param text Label for this menu item
103 * @param icon Icon for this menu item
105 public JRadioButtonMenuItem(String text, Icon icon)
107 this(text, icon, false);
111 * Creates a new JRadioButtonMenuItem with specified label
112 * and marked selected if 'selected' is true.
114 * @param text Text for this menu item
115 * @param selected Selected state of this menu item
117 public JRadioButtonMenuItem(String text, boolean selected)
119 this(text, null, selected);
123 * Creates a new JRadioButtonMenuItem with specified icon
124 * and given selected state
126 * @param icon Icon for this menu item
127 * @param selected Selected state for this menu item
129 public JRadioButtonMenuItem(Icon icon, boolean selected)
131 this(null, icon, selected);
135 * Creates a new JRadioButtonMenuItem with specified label,
136 * icon and selected state.
138 * @param text Label for this menu item
139 * @param icon Icon to be use for this menu item
140 * @param selected selected state of this menu item
142 public JRadioButtonMenuItem(String text, Icon icon, boolean selected)
144 super(text, icon);
145 setModel(new JToggleButton.ToggleButtonModel());
146 model.setSelected(selected);
150 * This method returns a name to identify which look and feel class will be
151 * the UI delegate for the menuItem.
153 * @return The Look and Feel classID. "JRadioButtonMenuItemUI"
155 public String getUIClassID()
157 return uiClassID;
161 * This method overrides JComponent.requestFocus with an empty
162 * implementation, since JRadioButtonMenuItems should not
163 * receve focus in general.
165 public void requestFocus()
167 // Should do nothing here
171 * Returns a string describing the attributes for the
172 * <code>JRadioButtonMenuItem</code> component, for use in debugging. The
173 * return value is guaranteed to be non-<code>null</code>, but the format of
174 * the string may vary between implementations.
176 * @return A string describing the attributes of the
177 * <code>JRadioButtonMenuItem</code>.
179 protected String paramString()
181 // calling super seems to be sufficient here...
182 return super.paramString();
186 * Returns the object that provides accessibility features for this
187 * <code>JRadioButtonMenuItem</code> component.
189 * @return The accessible context (an instance of
190 * {@link AccessibleJRadioButtonMenuItem}).
192 public AccessibleContext getAccessibleContext()
194 if (accessibleContext == null)
195 accessibleContext = new AccessibleJRadioButtonMenuItem();
197 return accessibleContext;
201 * Provides the accessibility features for the
202 * <code>JRadioButtonMenuItem</code> component.
204 * @see JRadioButtonMenuItem#getAccessibleContext()
206 protected class AccessibleJRadioButtonMenuItem extends AccessibleJMenuItem
208 private static final long serialVersionUID = 4381471510145292179L;
211 * Creates a new <code>AccessibleJRadioButtonMenuItem</code> instance.
213 protected AccessibleJRadioButtonMenuItem()
215 // Nothing to do here.
219 * Returns the accessible role for the <code>JRadioButtonMenuItem</code>
220 * component.
222 * @return {@link AccessibleRole#RADIO_BUTTON}.
224 public AccessibleRole getAccessibleRole()
226 return AccessibleRole.RADIO_BUTTON;