2004-08-12 Janis Johnson <janis187@us.ibm.com>
[official-gcc.git] / libjava / javax / swing / JRadioButtonMenuItem.java
blob4ced1a595f513507684578fc652b0945d7d95f35
1 /* JRadioButtonMenuItem.java --
2 Copyright (C) 2002, 2004 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. */
38 package javax.swing;
40 import java.io.IOException;
41 import java.io.ObjectOutputStream;
42 import javax.accessibility.Accessible;
43 import javax.accessibility.AccessibleContext;
44 import javax.accessibility.AccessibleRole;
45 import javax.swing.event.ChangeEvent;
46 import javax.swing.event.ChangeListener;
49 /**
50 * This class represents JRadioButtonMenuItem. Its behaviour is very similar
51 * to JRadioButton. Just like JRadioButton, user can check and uncheck this
52 * menu item by clicking on it. JRadioButtonMenuItem uses ToggleButtonModel
53 * to keep track of its selection. If the JRadioButtonMenuItem is included in
54 * the button group, then only one JRadioButtonMenuItem can be selected at
55 * one time.
57 public class JRadioButtonMenuItem extends JMenuItem implements Accessible
59 private static final long serialVersionUID = 8482658191548521743L;
61 /** name for the UI delegate for this radio button menu item. */
62 private static final String uiClassID = "RadioButtonMenuItemUI";
64 /**
65 * Creates a new JRadioButtonMenuItem object.
67 public JRadioButtonMenuItem()
69 this(null, null);
72 /**
73 * Creates a new JRadioButtonMenuItem with specified icon
75 * @param icon Icon to be used for this menu item
77 public JRadioButtonMenuItem(Icon icon)
79 this(null, icon);
82 /**
83 * Creates a new JRadioButtonMenuItem with specified label
85 * @param text Label for this menu item
87 public JRadioButtonMenuItem(String text)
89 this(text, null);
92 /**
93 * Creates a new JRadioButtonMenuItem using specified action
95 * @param action Action for this menu item
97 public JRadioButtonMenuItem(Action action)
99 this();
100 setAction(action);
104 * Creates a new JRadioButtonMenuItem with specified label and icon
106 * @param text Label for this menu item
107 * @param icon Icon for this menu item
109 public JRadioButtonMenuItem(String text, Icon icon)
111 this(text, icon, false);
115 * Creates a new JRadioButtonMenuItem with specified label
116 * and marked selected if 'selected' is true.
118 * @param text Text for this menu item
119 * @param selected Selected state of this menu item
121 public JRadioButtonMenuItem(String text, boolean selected)
123 this(text, null, selected);
127 * Creates a new JRadioButtonMenuItem with specified icon
128 * and given selected state
130 * @param icon Icon for this menu item
131 * @param selected Selected state for this menu item
133 public JRadioButtonMenuItem(Icon icon, boolean selected)
135 this(null, icon, selected);
139 * Creates a new JRadioButtonMenuItem with specified label,
140 * icon and selected state.
142 * @param text Label for this menu item
143 * @param icon Icon to be use for this menu item
144 * @param selected selected state of this menu item
146 public JRadioButtonMenuItem(String text, Icon icon, boolean selected)
148 super(text, icon);
149 setModel(new JToggleButton.ToggleButtonModel());
150 model.setSelected(selected);
153 private void writeObject(ObjectOutputStream stream) throws IOException
158 * This method returns a name to identify which look and feel class will be
159 * the UI delegate for the menuItem.
161 * @return The Look and Feel classID. "JRadioButtonMenuItemUI"
163 public String getUIClassID()
165 return uiClassID;
169 * This method overrides JComponent.requestFocus with an empty
170 * implementation, since JRadioButtonMenuItems should not
171 * receve focus in general.
173 public void requestFocus()
175 // Should do nothing here
179 * A string that describes this JRadioButtonMenuItem. Normally only used
180 * for debugging.
182 * @return A string describing this JRadioButtonMenuItem
184 protected String paramString()
186 return "JRadioButtonMenuItem";
189 public AccessibleContext getAccessibleContext()
191 if (accessibleContext == null)
192 accessibleContext = new AccessibleJRadioButtonMenuItem();
194 return accessibleContext;
197 protected class AccessibleJRadioButtonMenuItem extends AccessibleJMenuItem
199 private static final long serialVersionUID = 4381471510145292179L;
202 * Creates a new AccessibleJRadioButtonMenuItem object.
204 protected AccessibleJRadioButtonMenuItem()
208 public AccessibleRole getAccessibleRole()
210 return AccessibleRole.RADIO_BUTTON;