| 1 | /* MenuItem.java -- An item in a menu
|
|---|
| 2 | Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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.
|
|---|
| 20 |
|
|---|
| 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.
|
|---|
| 25 |
|
|---|
| 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. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.awt;
|
|---|
| 40 |
|
|---|
| 41 | import java.awt.peer.MenuItemPeer;
|
|---|
| 42 | import java.awt.peer.MenuComponentPeer;
|
|---|
| 43 | import java.awt.event.ActionEvent;
|
|---|
| 44 | import java.awt.event.ActionListener;
|
|---|
| 45 | import java.lang.reflect.Array;
|
|---|
| 46 | import java.util.EventListener;
|
|---|
| 47 |
|
|---|
| 48 | /**
|
|---|
| 49 | * This class represents an item in a menu.
|
|---|
| 50 | *
|
|---|
| 51 | * @author Aaron M. Renn ([email protected])
|
|---|
| 52 | */
|
|---|
| 53 | public 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
|
|---|
| 63 | private 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 | */
|
|---|
| 74 | private String actionCommand;
|
|---|
| 75 |
|
|---|
| 76 | /**
|
|---|
| 77 | * @serial Indicates whether or not this menu item is enabled.
|
|---|
| 78 | */
|
|---|
| 79 | private boolean enabled;
|
|---|
| 80 |
|
|---|
| 81 | /**
|
|---|
| 82 | * @serial The mask of events that are enabled for this menu item.
|
|---|
| 83 | */
|
|---|
| 84 | long eventMask;
|
|---|
| 85 |
|
|---|
| 86 | /**
|
|---|
| 87 | * @serial This menu item's label
|
|---|
| 88 | */
|
|---|
| 89 | private String label;
|
|---|
| 90 |
|
|---|
| 91 | /**
|
|---|
| 92 | * @serial The shortcut for this menu item, if any
|
|---|
| 93 | */
|
|---|
| 94 | private MenuShortcut shortcut;
|
|---|
| 95 |
|
|---|
| 96 | // The list of action listeners for this menu item.
|
|---|
| 97 | private 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 | */
|
|---|
| 109 | public
|
|---|
| 110 | MenuItem()
|
|---|
| 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 | */
|
|---|
| 122 | public
|
|---|
| 123 | MenuItem(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 | */
|
|---|
| 137 | public
|
|---|
| 138 | MenuItem(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 | */
|
|---|
| 155 | public String
|
|---|
| 156 | getLabel()
|
|---|
| 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 | */
|
|---|
| 168 | public synchronized void
|
|---|
| 169 | setLabel(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 | */
|
|---|
| 187 | public boolean
|
|---|
| 188 | isEnabled()
|
|---|
| 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 | */
|
|---|
| 201 | public synchronized void
|
|---|
| 202 | setEnabled(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 | */
|
|---|
| 225 | public void
|
|---|
| 226 | enable(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 | */
|
|---|
| 238 | public void
|
|---|
| 239 | enable()
|
|---|
| 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 | */
|
|---|
| 251 | public void
|
|---|
| 252 | disable()
|
|---|
| 253 | {
|
|---|
| 254 | setEnabled(false);
|
|---|
| 255 | }
|
|---|
| 256 |
|
|---|
| 257 | /*************************************************************************/
|
|---|
| 258 |
|
|---|
|
|---|