JMenuItem.java revision 625
3980N/A * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 3980N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3980N/A * This code is free software; you can redistribute it and/or modify it 3980N/A * under the terms of the GNU General Public License version 2 only, as 3980N/A * published by the Free Software Foundation. Sun designates this 3980N/A * particular file as subject to the "Classpath" exception as provided 3980N/A * by Sun in the LICENSE file that accompanied this code. 3980N/A * This code is distributed in the hope that it will be useful, but WITHOUT 3980N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6015N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6015N/A * version 2 for more details (a copy is included in the LICENSE file that 6015N/A * You should have received a copy of the GNU General Public License version 6015N/A * 2 along with this work; if not, write to the Free Software Foundation, 3980N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * An implementation of an item in a menu. A menu item is essentially a button * sitting in a list. When the user selects the "button", the action * associated with the menu item is performed. A <code>JMenuItem</code> * contained in a <code>JPopupMenu</code> performs exactly that function. * Menu items can be configured, and to some degree controlled, by * <code><a href="Action.html">Action</a></code>s. Using an * <code>Action</code> with a menu item has many benefits beyond directly * configuring a menu item. Refer to <a href="Action.html#buttonActions"> * Swing Components Supporting <code>Action</code></a> for more * details, and you can find more information in <a * to Use Actions</a>, a section in <em>The Java Tutorial</em>. * For further documentation and for examples, see * in <em>The Java Tutorial.</em> * <strong>Warning:</strong> Swing is not thread safe. For more * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * attribute: isContainer false * description: An item which can be selected in a menu. * @see JRadioButtonMenuItem /* diagnostic aids -- should be false for production builds. */ private static final boolean TRACE =
false;
// trace creates and disposes private static final boolean DEBUG =
false;
// show bad params, misc. * Creates a <code>JMenuItem</code> with no set text or icon. * Creates a <code>JMenuItem</code> with the specified icon. * @param icon the icon of the <code>JMenuItem</code> * Creates a <code>JMenuItem</code> with the specified text. * @param text the text of the <code>JMenuItem</code> * Creates a menu item whose properties are taken from the * specified <code>Action</code>. * @param a the action of the <code>JMenuItem</code> * Creates a <code>JMenuItem</code> with the specified text and icon. * @param text the text of the <code>JMenuItem</code> * @param icon the icon of the <code>JMenuItem</code> * Creates a <code>JMenuItem</code> with the specified text and * @param text the text of the <code>JMenuItem</code> * @param mnemonic the keyboard mnemonic for the <code>JMenuItem</code> * Inititalizes the focusability of the the <code>JMenuItem</code>. * <code>JMenuItem</code>'s are focusable, but subclasses may * want to be, this provides them the opportunity to override this * and invoke something else, or nothing at all. Refer to * {@link javax.swing.JMenu#initFocusability} for the motivation of * Initializes the menu item with the specified text and icon. * @param text the text of the <code>JMenuItem</code> * @param icon the icon of the <code>JMenuItem</code> // Listen for Focus events // When focus is lost, repaint if // the focus information is painted * Sets the look and feel object that renders this component. * @param ui the <code>JMenuItemUI</code> L&F object * attribute: visualUpdate true * description: The UI object that implements the Component's LookAndFeel. * Resets the UI property with a value from the current look and feel. * @see JComponent#updateUI * Returns the suffix used to construct the name of the L&F class used to * @return the string "MenuItemUI" * @see JComponent#getUIClassID * Identifies the menu item as "armed". If the mouse button is * released while it is over this item, the menu's action event * will fire. If the mouse button is released elsewhere, the * event will not fire and the menu item will be disarmed. * @param b true to arm the menu item so it can be selected * description: Mouse release will fire an action event * Returns whether the menu item is "armed". * @return true if the menu item is armed, and it can be selected * Enables or disables the menu item. * @param b true to enable the item * description: Does the component react to user interaction // Make sure we aren't armed! * Returns true since <code>Menu</code>s, by definition, * should always be on top of all other windows. If the menu is * in an internal frame false is returned due to the rollover effect * for windows laf where the menu is not always on top. /* The keystroke which acts as the menu item's accelerator * Sets the key combination which invokes the menu item's * action listeners without navigating the menu hierarchy. It is the * UI's responsibility to install the correct action. Note that * when the keyboard accelerator is typed, it will work whether or * not the menu is currently displayed. * @param keyStroke the <code>KeyStroke</code> which will * serve as an accelerator * description: The keystroke combination which will invoke the * JMenuItem's actionlisteners without navigating the * Returns the <code>KeyStroke</code> which serves as an accelerator * @return a <code>KeyStroke</code> object identifying the * Processes a mouse event forwarded from the * <code>MenuSelectionManager</code> and changes the menu * selection, if necessary, by using the * <code>MenuSelectionManager</code>'s API. * Note: you do not have to forward the event to sub-components. * This is done automatically by the <code>MenuSelectionManager</code>. * @param e a <code>MouseEvent</code> * @param path the <code>MenuElement</code> path array * @param manager the <code>MenuSelectionManager</code> * Processes a key event forwarded from the * <code>MenuSelectionManager</code> and changes the menu selection, * if necessary, by using <code>MenuSelectionManager</code>'s API. * Note: you do not have to forward the event to sub-components. * This is done automatically by the <code>MenuSelectionManager</code>. * @param e a <code>KeyEvent</code> * @param path the <code>MenuElement</code> path array * @param manager the <code>MenuSelectionManager</code> * Handles mouse drag in a menu. * @param e a <code>MenuDragMouseEvent</code> object * Handles a keystroke in a menu. * @param e a <code>MenuKeyEvent</code> object * Notifies all listeners that have registered interest for * notification on this event type. * @param event a <code>MenuMouseDragEvent</code> // Guaranteed to return a non-null array // Process the listeners last to first, notifying // those that are interested in this event // Lazily create the event: * Notifies all listeners that have registered interest for * notification on this event type. * @param event a <code>MenuDragMouseEvent</code> // Guaranteed to return a non-null array // Process the listeners last to first, notifying // those that are interested in this event // Lazily create the event: * Notifies all listeners that have registered interest for * notification on this event type. * @param event a <code>MenuDragMouseEvent</code> // Guaranteed to return a non-null array // Process the listeners last to first, notifying // those that are interested in this event // Lazily create the event: * Notifies all listeners that have registered interest for * notification on this event type. * @param event a <code>MenuDragMouseEvent</code> // Guaranteed to return a non-null array // Process the listeners last to first, notifying // those that are interested in this event // Lazily create the event: * Notifies all listeners that have registered interest for * notification on this event type. * @param event a <code>MenuKeyEvent</code> // Guaranteed to return a non-null array // Process the listeners last to first, notifying // those that are interested in this event // Lazily create the event: * Notifies all listeners that have registered interest for * notification on this event type. * @param event a <code>MenuKeyEvent</code> // Guaranteed to return a non-null array // Process the listeners last to first, notifying // those that are interested in this event // Lazily create the event: * Notifies all listeners that have registered interest for * notification on this event type. * @param event a <code>MenuKeyEvent</code> // Guaranteed to return a non-null array // Process the listeners last to first, notifying // those that are interested in this event // Lazily create the event: * Called by the <code>MenuSelectionManager</code> when the * <code>MenuElement</code> is selected or unselected. * @param isIncluded true if this menu item is on the part of the menu * path that changed, false if this menu is part of the * a menu path that changed, but this particular part of * that path is still the same * @see MenuSelectionManager#setSelectedPath(MenuElement[]) * This method returns an array containing the sub-menu * components for this menu component. * @return an array of <code>MenuElement</code>s * Returns the <code>java.awt.Component</code> used to paint * this object. The returned component will be used to convert * events and detect if an event is inside a menu component. * @return the <code>Component</code> that paints this menu item * Adds a <code>MenuDragMouseListener</code> to the menu item. * @param l the <code>MenuDragMouseListener</code> to be added * Removes a <code>MenuDragMouseListener</code> from the menu item. * @param l the <code>MenuDragMouseListener</code> to be removed * Returns an array of all the <code>MenuDragMouseListener</code>s added * to this JMenuItem with addMenuDragMouseListener(). * @return all of the <code>MenuDragMouseListener</code>s added or an empty * array if no listeners have been added * Adds a <code>MenuKeyListener</code> to the menu item. * @param l the <code>MenuKeyListener</code> to be added * Removes a <code>MenuKeyListener</code> from the menu item. * @param l the <code>MenuKeyListener</code> to be removed * Returns an array of all the <code>MenuKeyListener</code>s added * to this JMenuItem with addMenuKeyListener(). * @return all of the <code>MenuKeyListener</code>s added or an empty * array if no listeners have been added * See JComponent.readObject() for information about serialization * Returns a string representation of this <code>JMenuItem</code>. * This method is intended to be used only for debugging purposes, * and the content and format of the returned string may vary between * implementations. The returned string may be empty but may not * @return a string representation of this <code>JMenuItem</code> * Returns the <code>AccessibleContext</code> associated with this * <code>JMenuItem</code>. For <code>JMenuItem</code>s, * the <code>AccessibleContext</code> takes the form of an * <code>AccessibleJMenuItem</code>. * A new AccessibleJMenuItme instance is created if necessary. * @return an <code>AccessibleJMenuItem</code> that serves as the * <code>AccessibleContext</code> of this <code>JMenuItem</code> * This class implements accessibility support for the * <code>JMenuItem</code> class. It provides an implementation of the * Java Accessibility API appropriate to menu item user-interface * <strong>Warning:</strong> * Serialized objects of this class will not be compatible with * future Swing releases. The current serialization support is * appropriate for short term storage or RMI between applications running * the same version of Swing. As of 1.4, support for long term storage * of all JavaBeans<sup><font size="-2">TM</font></sup> * has been added to the <code>java.beans</code> package. * Get the role of this object. * @return an instance of AccessibleRole describing the role of the * Supports the change listener interface and fires property changes. // Fix for 4848220 moved here to avoid major memory leak // Here we will fire the event in case of JMenuItem // See bug 4910323 for details [zav] // Fix for 4848220 moved here to avoid major memory leak // Here we will fire the event in case of JMenu // See bug 4910323 for details [zav] }
// inner class AccessibleJMenuItem