2362N/A * Copyright (c) 1997, 2008, 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 * An implementation of an item in a menu. A menu item is essentially a button 0N/A * sitting in a list. When the user selects the "button", the action 0N/A * associated with the menu item is performed. A <code>JMenuItem</code> 0N/A * contained in a <code>JPopupMenu</code> performs exactly that function. 0N/A * Menu items can be configured, and to some degree controlled, by 0N/A * <code>Action</code> with a menu item has many benefits beyond directly 0N/A * configuring a menu item. Refer to <a href="Action.html#buttonActions"> 0N/A * Swing Components Supporting <code>Action</code></a> for more 0N/A * details, and you can find more information in <a 0N/A * to Use Actions</a>, a section in <em>The Java Tutorial</em>. 0N/A * For further documentation and for examples, see 0N/A * in <em>The Java Tutorial.</em> 0N/A * <strong>Warning:</strong> Swing is not thread safe. For more 0N/A * information see <a 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * attribute: isContainer false 0N/A * description: An item which can be selected in a menu. 0N/A * @author Georges Saab 0N/A * @author David Karlton 0N/A * @see JCheckBoxMenuItem 0N/A * @see JRadioButtonMenuItem 0N/A * @see #getUIClassID 0N/A /* diagnostic aids -- should be false for production builds. */ 0N/A private static final boolean TRACE =
false;
// trace creates and disposes 0N/A private static final boolean DEBUG =
false;
// show bad params, misc. 0N/A * Creates a <code>JMenuItem</code> with no set text or icon. 0N/A * Creates a <code>JMenuItem</code> with the specified icon. 0N/A * @param icon the icon of the <code>JMenuItem</code> 0N/A * Creates a <code>JMenuItem</code> with the specified text. 0N/A * @param text the text of the <code>JMenuItem</code> 0N/A * Creates a menu item whose properties are taken from the 0N/A * specified <code>Action</code>. 0N/A * @param a the action of the <code>JMenuItem</code> 0N/A * Creates a <code>JMenuItem</code> with the specified text and icon. 0N/A * @param text the text of the <code>JMenuItem</code> 0N/A * @param icon the icon of the <code>JMenuItem</code> 0N/A * Creates a <code>JMenuItem</code> with the specified text and 0N/A * keyboard mnemonic. 0N/A * @param text the text of the <code>JMenuItem</code> 0N/A * @param mnemonic the keyboard mnemonic for the <code>JMenuItem</code> 0N/A * Inititalizes the focusability of the the <code>JMenuItem</code>. 0N/A * <code>JMenuItem</code>'s are focusable, but subclasses may 0N/A * want to be, this provides them the opportunity to override this 0N/A * and invoke something else, or nothing at all. Refer to 0N/A * {@link javax.swing.JMenu#initFocusability} for the motivation of 0N/A * Initializes the menu item with the specified text and icon. 0N/A * @param text the text of the <code>JMenuItem</code> 0N/A * @param icon the icon of the <code>JMenuItem</code> 0N/A // Listen for Focus events 0N/A // When focus is lost, repaint if 0N/A // the focus information is painted 0N/A * Sets the look and feel object that renders this component. 0N/A * @param ui the <code>JMenuItemUI</code> L&F object 0N/A * @see UIDefaults#getUI 0N/A * attribute: visualUpdate true 0N/A * description: The UI object that implements the Component's LookAndFeel. 0N/A * Resets the UI property with a value from the current look and feel. 0N/A * @see JComponent#updateUI 0N/A * Returns the suffix used to construct the name of the L&F class used to 0N/A * render this component. 0N/A * @return the string "MenuItemUI" 0N/A * @see JComponent#getUIClassID 0N/A * @see UIDefaults#getUI 0N/A * Identifies the menu item as "armed". If the mouse button is 0N/A * released while it is over this item, the menu's action event 0N/A * will fire. If the mouse button is released elsewhere, the 0N/A * event will not fire and the menu item will be disarmed. 0N/A * @param b true to arm the menu item so it can be selected 0N/A * description: Mouse release will fire an action event 0N/A * Returns whether the menu item is "armed". 0N/A * @return true if the menu item is armed, and it can be selected 0N/A * Enables or disables the menu item. 0N/A * @param b true to enable the item 0N/A * description: Does the component react to user interaction 0N/A // Make sure we aren't armed! 0N/A * Returns true since <code>Menu</code>s, by definition, 0N/A * should always be on top of all other windows. If the menu is 0N/A * in an internal frame false is returned due to the rollover effect 0N/A * for windows laf where the menu is not always on top. 0N/A // Fix for bug #4482165 0N/A /* The keystroke which acts as the menu item's accelerator 0N/A * Sets the key combination which invokes the menu item's 0N/A * action listeners without navigating the menu hierarchy. It is the 0N/A * UI's responsibility to install the correct action. Note that 0N/A * when the keyboard accelerator is typed, it will work whether or 0N/A * not the menu is currently displayed. 0N/A * @param keyStroke the <code>KeyStroke</code> which will 0N/A * serve as an accelerator 0N/A * description: The keystroke combination which will invoke the 0N/A * JMenuItem's actionlisteners without navigating the 0N/A * Returns the <code>KeyStroke</code> which serves as an accelerator 0N/A * for the menu item. 0N/A * @return a <code>KeyStroke</code> object identifying the 0N/A * Processes a mouse event forwarded from the 0N/A * <code>MenuSelectionManager</code> and changes the menu 0N/A * selection, if necessary, by using the 0N/A * <code>MenuSelectionManager</code>'s API. 0N/A * Note: you do not have to forward the event to sub-components. 0N/A * This is done automatically by the <code>MenuSelectionManager</code>. 0N/A * @param e a <code>MouseEvent</code> 0N/A * @param path the <code>MenuElement</code> path array 0N/A * @param manager the <code>MenuSelectionManager</code> 0N/A * Processes a key event forwarded from the 0N/A * <code>MenuSelectionManager</code> and changes the menu selection, 0N/A * if necessary, by using <code>MenuSelectionManager</code>'s API. 0N/A * Note: you do not have to forward the event to sub-components. 0N/A * This is done automatically by the <code>MenuSelectionManager</code>. 0N/A * @param e a <code>KeyEvent</code> 0N/A * @param path the <code>MenuElement</code> path array 0N/A * @param manager the <code>MenuSelectionManager</code> 0N/A * Handles mouse drag in a menu. 0N/A * @param e a <code>MenuDragMouseEvent</code> object 0N/A * Handles a keystroke in a menu. 0N/A * @param e a <code>MenuKeyEvent</code> object 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. 0N/A * @param event a <code>MenuMouseDragEvent</code> 0N/A * @see EventListenerList 0N/A // Guaranteed to return a non-null array 0N/A // Process the listeners last to first, notifying 0N/A // those that are interested in this event 0N/A // Lazily create the event: 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. 0N/A * @param event a <code>MenuDragMouseEvent</code> 0N/A * @see EventListenerList 0N/A // Guaranteed to return a non-null array 0N/A // Process the listeners last to first, notifying 0N/A // those that are interested in this event 0N/A // Lazily create the event: 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. 0N/A * @param event a <code>MenuDragMouseEvent</code> 0N/A * @see EventListenerList 0N/A // Guaranteed to return a non-null array 0N/A // Process the listeners last to first, notifying 0N/A // those that are interested in this event 0N/A // Lazily create the event: 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. 0N/A * @param event a <code>MenuDragMouseEvent</code> 0N/A * @see EventListenerList 0N/A // Guaranteed to return a non-null array 0N/A // Process the listeners last to first, notifying 0N/A // those that are interested in this event 0N/A // Lazily create the event: 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. 0N/A * @param event a <code>MenuKeyEvent</code> 0N/A * @see EventListenerList 0N/A // Guaranteed to return a non-null array 0N/A // Process the listeners last to first, notifying 0N/A // those that are interested in this event 0N/A // Lazily create the event: 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. 0N/A * @param event a <code>MenuKeyEvent</code> 0N/A * @see EventListenerList 0N/A // Guaranteed to return a non-null array 0N/A // Process the listeners last to first, notifying 0N/A // those that are interested in this event 0N/A // Lazily create the event: 0N/A * Notifies all listeners that have registered interest for 0N/A * notification on this event type. 0N/A * @param event a <code>MenuKeyEvent</code> 0N/A * @see EventListenerList 0N/A // Guaranteed to return a non-null array 0N/A // Process the listeners last to first, notifying 0N/A // those that are interested in this event 0N/A // Lazily create the event: 0N/A * Called by the <code>MenuSelectionManager</code> when the 0N/A * <code>MenuElement</code> is selected or unselected. 0N/A * @param isIncluded true if this menu item is on the part of the menu 0N/A * path that changed, false if this menu is part of the 0N/A * a menu path that changed, but this particular part of 0N/A * that path is still the same 0N/A * @see MenuSelectionManager#setSelectedPath(MenuElement[]) 0N/A * This method returns an array containing the sub-menu 0N/A * components for this menu component. 0N/A * @return an array of <code>MenuElement</code>s 0N/A * Returns the <code>java.awt.Component</code> used to paint 0N/A * this object. The returned component will be used to convert 0N/A * events and detect if an event is inside a menu component. 0N/A * @return the <code>Component</code> that paints this menu item 0N/A * Adds a <code>MenuDragMouseListener</code> to the menu item. 0N/A * @param l the <code>MenuDragMouseListener</code> to be added 0N/A * Removes a <code>MenuDragMouseListener</code> from the menu item. 0N/A * @param l the <code>MenuDragMouseListener</code> to be removed 0N/A * Returns an array of all the <code>MenuDragMouseListener</code>s added 0N/A * to this JMenuItem with addMenuDragMouseListener(). 0N/A * @return all of the <code>MenuDragMouseListener</code>s added or an empty 0N/A * array if no listeners have been added 0N/A * Adds a <code>MenuKeyListener</code> to the menu item. 0N/A * @param l the <code>MenuKeyListener</code> to be added 0N/A * Removes a <code>MenuKeyListener</code> from the menu item. 0N/A * @param l the <code>MenuKeyListener</code> to be removed 0N/A * Returns an array of all the <code>MenuKeyListener</code>s added 0N/A * to this JMenuItem with addMenuKeyListener(). 0N/A * @return all of the <code>MenuKeyListener</code>s added or an empty 0N/A * array if no listeners have been added 0N/A * See JComponent.readObject() for information about serialization 0N/A * Returns a string representation of this <code>JMenuItem</code>. 0N/A * This method is intended to be used only for debugging purposes, 0N/A * and the content and format of the returned string may vary between 0N/A * implementations. The returned string may be empty but may not 0N/A * be <code>null</code>. 0N/A * @return a string representation of this <code>JMenuItem</code> 0N/A// Accessibility support 0N/A * Returns the <code>AccessibleContext</code> associated with this 0N/A * <code>JMenuItem</code>. For <code>JMenuItem</code>s, 0N/A * the <code>AccessibleContext</code> takes the form of an 0N/A * <code>AccessibleJMenuItem</code>. 0N/A * A new AccessibleJMenuItme instance is created if necessary. 0N/A * @return an <code>AccessibleJMenuItem</code> that serves as the 0N/A * <code>AccessibleContext</code> of this <code>JMenuItem</code> 0N/A * This class implements accessibility support for the 0N/A * <code>JMenuItem</code> class. It provides an implementation of the 0N/A * Java Accessibility API appropriate to menu item user-interface 0N/A * <strong>Warning:</strong> 0N/A * Serialized objects of this class will not be compatible with 0N/A * future Swing releases. The current serialization support is 0N/A * appropriate for short term storage or RMI between applications running 0N/A * the same version of Swing. As of 1.4, support for long term storage 0N/A * of all JavaBeans<sup><font size="-2">TM</font></sup> 0N/A * has been added to the <code>java.beans</code> package. 0N/A * Get the role of this object. 0N/A * @return an instance of AccessibleRole describing the role of the 0N/A * Supports the change listener interface and fires property changes. 0N/A // Fix for 4848220 moved here to avoid major memory leak 0N/A // Here we will fire the event in case of JMenuItem 0N/A // See bug 4910323 for details [zav] 0N/A // Fix for 4848220 moved here to avoid major memory leak 0N/A // Here we will fire the event in case of JMenu 0N/A // See bug 4910323 for details [zav] 0N/A }
// inner class AccessibleJMenuItem