source: trunk/gcc/libjava/java/awt/MenuItem.java@ 3148

Last change on this file since 3148 was 1392, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 11.1 KB
Line 
1/* MenuItem.java -- An item in a menu
2 Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.awt;
40
41import java.awt.peer.MenuItemPeer;
42import java.awt.peer.MenuComponentPeer;
43import java.awt.event.ActionEvent;
44import java.awt.event.ActionListener;
45import java.lang.reflect.Array;
46import java.util.EventListener;
47
48/**
49 * This class represents an item in a menu.
50 *
51 * @author Aaron M. Renn ([email protected])
52 */
53public class MenuItem extends MenuComponent implements java.io.Serializable
54{
55
56// FIXME: The enabled event mask is not used at this time.
57
58/*
59 * Static Variables
60 */
61
62// Serialization Constant
63private static final long serialVersionUID = -21757335363267194L;
64
65/*************************************************************************/
66
67/*
68 * Instance Variables
69 */
70
71/**
72 * @serial The name of the action command generated by this item.
73 */
74private String actionCommand;
75
76/**
77 * @serial Indicates whether or not this menu item is enabled.
78 */
79private boolean enabled;
80
81/**
82 * @serial The mask of events that are enabled for this menu item.
83 */
84long eventMask;
85
86/**
87 * @serial This menu item's label
88 */
89private String label;
90
91/**
92 * @serial The shortcut for this menu item, if any
93 */
94private MenuShortcut shortcut;
95
96// The list of action listeners for this menu item.
97private transient ActionListener action_listeners;
98
99/*************************************************************************/
100
101/*
102 * Constructors
103 */
104
105/**
106 * Initializes a new instance of <code>MenuItem</code> with no label
107 * and no shortcut.
108 */
109public
110MenuItem()
111{
112}
113
114/*************************************************************************/
115
116/**
117 * Initializes a new instance of <code>MenuItem</code> with the specified
118 * label and no shortcut.
119 *
120 * @param label The label for this menu item.
121 */
122public
123MenuItem(String label)
124{
125 this.label = label;
126}
127
128/*************************************************************************/
129
130/**
131 * Initializes a new instance of <code>MenuItem</code> with the specified
132 * label and shortcut.
133 *
134 * @param label The label for this menu item.
135 * @param shortcut The shortcut for this menu item.
136 */
137public
138MenuItem(String label, MenuShortcut shortcut)
139{
140 this.label = label;
141 this.shortcut = shortcut;
142}
143
144/*************************************************************************/
145
146/*
147 * Instance Methods
148 */
149
150/**
151 * Returns the label for this menu item, which may be <code>null</code>.
152 *
153 * @return The label for this menu item.
154 */
155public String
156getLabel()
157{
158 return(label);
159}
160
161/*************************************************************************/
162
163/**
164 * This method sets the label for this menu to the specified value.
165 *
166 * @param label The new label for this menu item.
167 */
168public synchronized void
169setLabel(String label)
170{
171 this.label = label;
172 if (peer != null)
173 {
174 MenuItemPeer mp = (MenuItemPeer) peer;
175 mp.setLabel (label);
176 }
177}
178
179/*************************************************************************/
180
181/**
182 * Tests whether or not this menu item is enabled.
183 *
184 * @return <code>true</code> if this menu item is enabled, <code>false</code>
185 * otherwise.
186 */
187public boolean
188isEnabled()
189{
190 return(enabled);
191}
192
193/*************************************************************************/
194
195/**
196 * Sets the enabled status of this menu item.
197 *
198 * @param enabled <code>true</code> to enable this menu item,
199 * <code>false</code> otherwise.
200 */
201public synchronized void
202setEnabled(boolean enabled)
203{
204 if (enabled == this.enabled)
205 return;
206
207 this.enabled = enabled;
208 if (peer != null)
209 {
210 MenuItemPeer mp = (MenuItemPeer) peer;
211 mp.setEnabled (enabled);
212 }
213}
214
215/*************************************************************************/
216
217/**
218 * Sets the enabled status of this menu item.
219 *
220 * @param enabled <code>true</code> to enable this menu item,
221 * <code>false</code> otherwise.
222 *
223 * @deprecated This method is deprecated in favor of <code>setEnabled()</code>.
224 */
225public void
226enable(boolean enabled)
227{
228 setEnabled(enabled);
229}
230
231/*************************************************************************/
232
233/**
234 * Enables this menu item.
235 *
236 * @deprecated This method is deprecated in favor of <code>setEnabled()</code>.
237 */
238public void
239enable()
240{
241 setEnabled(true);
242}
243
244/*************************************************************************/
245
246/**
247 * Disables this menu item.
248 *
249 * @deprecated This method is deprecated in favor of <code>setEnabled()</code>.
250 */
251public void
252disable()
253{
254 setEnabled(false);
255}
256
257/*************************************************************************/
258