2362N/A * Copyright (c) 1995, 2009, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * All items in a menu must belong to the class 0N/A * <code>MenuItem</code>, or one of its subclasses. 0N/A * The default <code>MenuItem</code> object embodies 0N/A * a simple labeled menu item. 0N/A * This picture of a menu bar shows five menu items: 0N/A * ALIGN=CENTER HSPACE=10 VSPACE=7> 0N/A * The first two items are simple menu items, labeled 0N/A * <code>"Basic"</code> and <code>"Simple"</code>. 0N/A * Following these two items is a separator, which is itself 0N/A * a menu item, created with the label <code>"-"</code>. 0N/A * Next is an instance of <code>CheckboxMenuItem</code> 0N/A * labeled <code>"Check"</code>. The final menu item is a 0N/A * submenu labeled <code>"More Examples"</code>, 0N/A * and this submenu is an instance of <code>Menu</code>. 0N/A * When a menu item is selected, AWT sends an action event to 0N/A * the menu item. Since the event is an 0N/A * instance of <code>ActionEvent</code>, the <code>processEvent</code> 0N/A * method examines the event and passes it along to 0N/A * <code>processActionEvent</code>. The latter method redirects the 0N/A * event to any <code>ActionListener</code> objects that have 0N/A * registered an interest in action events generated by this 0N/A * Note that the subclass <code>Menu</code> overrides this behavior and 0N/A * does not send any event to the frame until one of its subitems is 0N/A * @author Sami Shaio 0N/A /* ensure that the necessary native libraries are loaded */ 0N/A * A value to indicate whether a menu item is enabled 0N/A * or not. If it is enabled, <code>enabled</code> will 0N/A * be set to true. Else <code>enabled</code> will 0N/A * @see #setEnabled(boolean) 0N/A * <code>label</code> is the label of a menu item. 0N/A * It can be any string. 0N/A * @see #setLabel(String) 0N/A * This field indicates the command tha has been issued 0N/A * by a particular menu item. 0N/A * By default the <code>actionCommand</code> 0N/A * is the label of the menu item, unless it has been 0N/A * set using setActionCommand. 0N/A * @see #setActionCommand(String) 0N/A * @see #getActionCommand() 0N/A * The eventMask is ONLY set by subclasses via enableEvents. 0N/A * The mask should NOT be set when listeners are registered 0N/A * so that we can distinguish the difference between when 0N/A * listeners request events and subclasses request them. 0N/A * A sequence of key stokes that ia associated with 0N/A * Note :in 1.1.2 you must use setActionCommand() 0N/A * on a menu item in order for its shortcut to 0N/A * @see #getShortcut() 0N/A * @see #setShortcut(MenuShortcut) 0N/A * @see #deleteShortcut() 0N/A * JDK 1.1 serialVersionUID 0N/A * Constructs a new MenuItem with an empty label and no keyboard 0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless() 0N/A * @see java.awt.GraphicsEnvironment#isHeadless 0N/A * Constructs a new MenuItem with the specified label 0N/A * and no keyboard shortcut. Note that use of "-" in 0N/A * a label is reserved to indicate a separator between 0N/A * menu items. By default, all menu items except for 0N/A * separators are enabled. 0N/A * @param label the label for this menu item. 0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless() 0N/A * @see java.awt.GraphicsEnvironment#isHeadless 0N/A * Create a menu item with an associated keyboard shortcut. 0N/A * Note that use of "-" in a label is reserved to indicate 0N/A * a separator between menu items. By default, all menu 0N/A * items except for separators are enabled. 0N/A * @param label the label for this menu item. 0N/A * @param s the instance of <code>MenuShortcut</code> 0N/A * associated with this menu item. 0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless() 0N/A * @see java.awt.GraphicsEnvironment#isHeadless 0N/A * Construct a name for this MenuComponent. Called by getName() when 0N/A * Creates the menu item's peer. The peer allows us to modify the 0N/A * appearance of the menu item without changing its functionality. 0N/A * Gets the label for this menu item. 0N/A * @return the label of this menu item, or <code>null</code> 0N/A if this menu item has no label. 0N/A * @see java.awt.MenuItem#setLabel 0N/A * Sets the label for this menu item to the specified label. 0N/A * @param label the new label, or <code>null</code> for no label. 0N/A * @see java.awt.MenuItem#getLabel 0N/A * Checks whether this menu item is enabled. 0N/A * @see java.awt.MenuItem#setEnabled 0N/A * Sets whether or not this menu item can be chosen. 0N/A * @param b if <code>true</code>, enables this menu item; 0N/A * if <code>false</code>, disables it. 0N/A * @see java.awt.MenuItem#isEnabled 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>setEnabled(boolean)</code>. 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>setEnabled(boolean)</code>. 0N/A * @deprecated As of JDK version 1.1, 0N/A * replaced by <code>setEnabled(boolean)</code>. 0N/A * Get the <code>MenuShortcut</code> object associated with this 0N/A * @return the menu shortcut associated with this menu item, 0N/A * or <code>null</code> if none has been specified. 0N/A * @see java.awt.MenuItem#setShortcut 0N/A * Set the <code>MenuShortcut</code> object associated with this 0N/A * menu item. If a menu shortcut is already associated with 0N/A * this menu item, it is replaced. 0N/A * @param s the menu shortcut to associate 0N/A * with this menu item. 0N/A * @see java.awt.MenuItem#getShortcut 0N/A * Delete any <code>MenuShortcut</code> object associated 0N/A * with this menu item. 0N/A * Delete a matching MenuShortcut associated with this MenuItem. 0N/A * Used when iterating Menus. 0N/A * The main goal of this method is to post an appropriate event 0N/A * to the event queue when menu shortcut is pressed. However, 0N/A * in subclasses this method may do more than just posting 0N/A * Returns true if the item and all its ancestors are 0N/A * enabled, false otherwise 0N/A // Fix For 6185151: Menu shortcuts of all menuitems within a menu 0N/A // should be disabled when the menu itself is disabled 0N/A * Post an ActionEvent to the target (on 0N/A * keydown) and the item is enabled. 0N/A * Returns true if there is an associated shortcut. 0N/A // Fix For 6185151: Menu shortcuts of all menuitems within a menu 0N/A // should be disabled when the menu itself is disabled 0N/A // MenuShortcut match -- issue an event on keydown. 0N/A // silently eat key release. 0N/A * Enables event delivery to this menu item for events 0N/A * to be defined by the specified event mask parameter 0N/A * Since event types are automatically enabled when a listener for 0N/A * that type is added to the menu item, this method only needs 0N/A * to be invoked by subclasses of <code>MenuItem</code> which desire to 0N/A * have the specified event types delivered to <code>processEvent</code> 0N/A * regardless of whether a listener is registered. 0N/A * @param eventsToEnable the event mask defining the event types 0N/A * @see java.awt.MenuItem#processEvent 0N/A * @see java.awt.MenuItem#disableEvents 0N/A * @see java.awt.Component#enableEvents 0N/A * Disables event delivery to this menu item for events 0N/A * defined by the specified event mask parameter. 0N/A * @param eventsToDisable the event mask defining the event types 0N/A * @see java.awt.MenuItem#processEvent 0N/A * @see java.awt.MenuItem#enableEvents 0N/A * @see java.awt.Component#disableEvents 0N/A * Sets the command name of the action event that is fired 0N/A * by this menu item. 0N/A * By default, the action command is set to the label of 0N/A * @param command the action command to be set 0N/A * for this menu item. 0N/A * @see java.awt.MenuItem#getActionCommand 0N/A * Gets the command name of the action event that is fired 0N/A * by this menu item. 0N/A * @see java.awt.MenuItem#setActionCommand 0N/A // This is final so it can be called on the Toolkit thread. 0N/A * Adds the specified action listener to receive action events 0N/A * from this menu item. 0N/A * If l is null, no exception is thrown and no action is performed. 0N/A * >AWT Threading Issues</a> for details on AWT's threading model. 0N/A * @param l the action listener. 0N/A * @see #removeActionListener 0N/A * @see #getActionListeners 0N/A * @see java.awt.event.ActionEvent 0N/A * @see java.awt.event.ActionListener 0N/A * Removes the specified action listener so it no longer receives 0N/A * action events from this menu item. 0N/A * If l is null, no exception is thrown and no action is performed. 0N/A * >AWT Threading Issues</a> for details on AWT's threading model. 0N/A * @param l the action listener. 0N/A * @see #addActionListener 0N/A * @see #getActionListeners 0N/A * @see java.awt.event.ActionEvent 0N/A * @see java.awt.event.ActionListener 0N/A * Returns an array of all the action listeners 0N/A * registered on this menu item. 0N/A * @return all of this menu item's <code>ActionListener</code>s 0N/A * or an empty array if no action 0N/A * listeners are currently registered 0N/A * @see #addActionListener 0N/A * @see #removeActionListener 0N/A * @see java.awt.event.ActionEvent 0N/A * @see java.awt.event.ActionListener 0N/A * Returns an array of all the objects currently registered 0N/A * as <code><em>Foo</em>Listener</code>s 0N/A * upon this <code>MenuItem</code>. 0N/A * <code><em>Foo</em>Listener</code>s are registered using the 0N/A * <code>add<em>Foo</em>Listener</code> method. 0N/A * You can specify the <code>listenerType</code> argument 0N/A * with a class literal, such as 0N/A * <code><em>Foo</em>Listener.class</code>. 0N/A * For example, you can query a 0N/A * <code>MenuItem</code> <code>m</code> 0N/A * for its action listeners with the following code: 0N/A * <pre>ActionListener[] als = (ActionListener[])(m.getListeners(ActionListener.class));</pre> 0N/A * If no such listeners exist, this method returns an empty array. 0N/A * @param listenerType the type of listeners requested; this parameter 0N/A * should specify an interface that descends from 0N/A * <code>java.util.EventListener</code> 0N/A * @return an array of all objects registered as 0N/A * <code><em>Foo</em>Listener</code>s on this menu item, 0N/A * or an empty array if no such 0N/A * listeners have been added 0N/A * @exception ClassCastException if <code>listenerType</code> 0N/A * doesn't specify a class or interface that implements 0N/A * <code>java.util.EventListener</code> 0N/A * @see #getActionListeners 0N/A * Processes events on this menu item. If the event is an 0N/A * instance of <code>ActionEvent</code>, it invokes 0N/A * <code>processActionEvent</code>, another method 0N/A * defined by <code>MenuItem</code>. 0N/A * Currently, menu items only support action events. 0N/A * <p>Note that if the event parameter is <code>null</code> 0N/A * the behavior is unspecified and may result in an 0N/A * @param e the event 0N/A * @see java.awt.MenuItem#processActionEvent 0N/A // REMIND: remove when filtering is done at lower level 0N/A * Processes action events occurring on this menu item, 0N/A * by dispatching them to any registered 0N/A * <code>ActionListener</code> objects. 0N/A * This method is not called unless action events are 0N/A * enabled for this component. Action events are enabled 0N/A * when one of the following occurs: 0N/A * <li>An <code>ActionListener</code> object is registered 0N/A * via <code>addActionListener</code>. 0N/A * <li>Action events are enabled via <code>enableEvents</code>. 0N/A * <p>Note that if the event parameter is <code>null</code> 0N/A * the behavior is unspecified and may result in an 0N/A * @param e the action event 0N/A * @see java.awt.event.ActionEvent 0N/A * @see java.awt.event.ActionListener 0N/A * @see java.awt.MenuItem#enableEvents 0N/A * Returns a string representing the state of this <code>MenuItem</code>. 0N/A * This method is intended to be used only for debugging purposes, and the 0N/A * content and format of the returned string may vary between 0N/A * implementations. The returned string may be empty but may not be 0N/A * <code>null</code>. 0N/A * @return the parameter string of this menu item 0N/A /* Serialization support. 0N/A * Menu item serialized data version. 0N/A * Writes default serializable fields to stream. Writes 0N/A * a list of serializable <code>ActionListeners</code> 0N/A * as optional data. The non-serializable listeners are 0N/A * detected and no attempt is made to serialize them. 0N/A * @param s the <code>ObjectOutputStream</code> to write 0N/A * @serialData <code>null</code> terminated sequence of 0 0N/A * or more pairs; the pair consists of a <code>String</code> 0N/A * and an <code>Object</code>; the <code>String</code> 0N/A * indicates the type of object and is one of the following: 0N/A * <code>actionListenerK</code> indicating an 0N/A * <code>ActionListener</code> object 0N/A * @see AWTEventMulticaster#save(ObjectOutputStream, String, EventListener) 0N/A * @see #readObject(ObjectInputStream) 0N/A * Reads the <code>ObjectInputStream</code> and if it 0N/A * isn't <code>null</code> adds a listener to receive 0N/A * action events fired by the <code>Menu</code> Item. 0N/A * Unrecognized keys or values will be ignored. 0N/A * @param s the <code>ObjectInputStream</code> to read 0N/A * @exception HeadlessException if 0N/A * <code>GraphicsEnvironment.isHeadless</code> returns 0N/A * @see #removeActionListener(ActionListener) 0N/A * @see #addActionListener(ActionListener) 0N/A * @see #writeObject(ObjectOutputStream) 0N/A // HeadlessException will be thrown from MenuComponent's readObject 0N/A else // skip value for unrecognized key 0N/A * Initialize JNI field and method IDs 0N/A// Accessibility support 0N/A * Gets the AccessibleContext associated with this MenuItem. 0N/A * For menu items, the AccessibleContext takes the form of an 0N/A * AccessibleAWTMenuItem. 0N/A * A new AccessibleAWTMenuItem instance is created if necessary. 0N/A * @return an AccessibleAWTMenuItem that serves as the 0N/A * AccessibleContext of this MenuItem 0N/A * Inner class of MenuItem used to provide default support for 0N/A * accessibility. This class is not meant to be used directly by 0N/A * application developers, but is instead meant only to be 0N/A * subclassed by menu component developers. 0N/A * This class implements accessibility support for the 0N/A * <code>MenuItem</code> class. It provides an implementation of the 0N/A * Java Accessibility API appropriate to menu item user-interface elements. 0N/A * JDK 1.3 serialVersionUID 0N/A * Get the accessible name of this object. 0N/A * @return the localized name of the object -- can be null if this 0N/A * object does not have a name 0N/A * Get the role of this object. 0N/A * @return an instance of AccessibleRole describing the role of the 0N/A * Get the AccessibleAction associated with this object. In the 0N/A * implementation of the Java Accessibility API for this class, 0N/A * return this object, which is responsible for implementing the 0N/A * AccessibleAction interface on behalf of itself. 0N/A * @return this object 0N/A * Get the AccessibleValue associated with this object. In the 0N/A * implementation of the Java Accessibility API for this class, 0N/A * return this object, which is responsible for implementing the 0N/A * AccessibleValue interface on behalf of itself. 0N/A * @return this object 0N/A * Returns the number of Actions available in this object. The 0N/A * default behavior of a menu item is to have one action. 0N/A * @return 1, the number of Actions in this object 0N/A * Return a description of the specified action of the object. 0N/A * @param i zero-based index of the actions 0N/A // [[[PENDING: WDW -- need to provide a localized string]]] 0N/A * Perform the specified Action on the object 0N/A * @param i zero-based index of actions 0N/A * @return true if the action was performed; otherwise false. 0N/A // Simulate a button click 0N/A * Get the value of this object as a Number. 0N/A * @return An Integer of 0 if this isn't selected or an Integer of 1 if 0N/A * @see javax.swing.AbstractButton#isSelected() 0N/A * Set the value of this object as a Number. 0N/A * @return True if the value was set. 0N/A * Get the minimum value of this object as a Number. 0N/A * @return An Integer of 0. 0N/A * Get the maximum value of this object as a Number. 0N/A * @return An Integer of 0. 0N/A }
// class AccessibleAWTMenuItem