/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import javax.accessibility.*;
/**
* 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.
* <p>
* 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>.
* <p>
* For further documentation and for examples, see
* <a
href="http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html">How to Use Menus</a>
* in <em>The Java Tutorial.</em>
* <p>
* <strong>Warning:</strong> Swing is not thread safe. For more
* information see <a
* href="package-summary.html#threading">Swing's Threading
* Policy</a>.
* <p>
* <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.
* Please see {@link java.beans.XMLEncoder}.
*
* @beaninfo
* attribute: isContainer false
* description: An item which can be selected in a menu.
*
* @author Georges Saab
* @author David Karlton
* @see JPopupMenu
* @see JMenu
* @see JCheckBoxMenuItem
* @see JRadioButtonMenuItem
*/
/**
* @see #getUIClassID
* @see #readObject
*/
/* diagnostic aids -- should be false for production builds. */
private boolean isMouseDragged = false;
/**
* Creates a <code>JMenuItem</code> with no set text or icon.
*/
public JMenuItem() {
}
/**
* 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>
* @since 1.3
*/
this();
setAction(a);
}
/**
* 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>
*/
setModel(new DefaultButtonModel());
}
/**
* Creates a <code>JMenuItem</code> with the specified text and
* keyboard mnemonic.
*
* @param text the text of the <code>JMenuItem</code>
* @param mnemonic the keyboard mnemonic for the <code>JMenuItem</code>
*/
setModel(new DefaultButtonModel());
}
/**
* {@inheritDoc}
*/
if(newModel instanceof DefaultButtonModel) {
}
}
/**
* 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
* this.
*/
void initFocusability() {
setFocusable(false);
}
/**
* 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
setFocusPainted(false);
updateUI();
}
// When focus is lost, repaint if
// the focus information is painted
if(mi.isFocusPainted()) {
}
}
}
/**
* Sets the look and feel object that renders this component.
*
* @param ui the <code>JMenuItemUI</code> L&F object
* @see UIDefaults#getUI
* @beaninfo
* bound: true
* hidden: true
* 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
*/
public void updateUI() {
}
/**
* Returns the suffix used to construct the name of the L&F class used to
* render this component.
*
* @return the string "MenuItemUI"
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
*/
return uiClassID;
}
/**
* 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
* @beaninfo
* description: Mouse release will fire an action event
* hidden: true
*/
public void setArmed(boolean b) {
}
}
/**
* Returns whether the menu item is "armed".
*
* @return true if the menu item is armed, and it can be selected
* @see #setArmed
*/
public boolean isArmed() {
}
/**
* Enables or disables the menu item.
*
* @param b true to enable the item
* @beaninfo
* description: Does the component react to user interaction
* bound: true
* preferred: true
*/
public void setEnabled(boolean b) {
// Make sure we aren't armed!
setArmed(false);
}
super.setEnabled(b);
}
/**
* 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.
*/
// package private
boolean alwaysOnTop() {
// Fix for bug #4482165
null) {
return false;
}
return true;
}
/* 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
* @beaninfo
* description: The keystroke combination which will invoke the
* JMenuItem's actionlisteners without navigating the
* menu hierarchy
* bound: true
* preferred: true
*/
this.accelerator = keyStroke;
repaint();
revalidate();
}
/**
* Returns the <code>KeyStroke</code> which serves as an accelerator
* for the menu item.
* @return a <code>KeyStroke</code> object identifying the
* accelerator key
*/
return this.accelerator;
}
/**
* {@inheritDoc}
*
* @since 1.3
*/
super.configurePropertiesFromAction(a);
}
if (a != null) {
}
}
}
}
}
/**
* {@inheritDoc}
* @since 1.6
*/
}
else {
}
}
/**
* 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.
* <p>
* 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>
*/
e.getWhen(),
e.getXOnScreen(), e.getYOnScreen(),
e.getClickCount(), e.isPopupTrigger(),
}
/**
* Processes a key event forwarded from the
* <code>MenuSelectionManager</code> and changes the menu selection,
* if necessary, by using <code>MenuSelectionManager</code>'s API.
* <p>
* 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>
*/
if (DEBUG) {
}
e.getWhen(), e.getModifiers(),
e.getKeyCode(), e.getKeyChar(),
if (mke.isConsumed()) {
e.consume();
}
}
/**
* Handles mouse drag in a menu.
*
* @param e a <code>MenuDragMouseEvent</code> object
*/
switch (e.getID()) {
case MouseEvent.MOUSE_ENTERED:
isMouseDragged = false; fireMenuDragMouseEntered(e); break;
case MouseEvent.MOUSE_EXITED:
isMouseDragged = false; fireMenuDragMouseExited(e); break;
case MouseEvent.MOUSE_DRAGGED:
isMouseDragged = true; fireMenuDragMouseDragged(e); break;
case MouseEvent.MOUSE_RELEASED:
if(isMouseDragged) fireMenuDragMouseReleased(e); break;
default:
break;
}
}
/**
* Handles a keystroke in a menu.
*
* @param e a <code>MenuKeyEvent</code> object
*/
if (DEBUG) {
}
switch (e.getID()) {
case KeyEvent.KEY_PRESSED:
fireMenuKeyPressed(e); break;
case KeyEvent.KEY_RELEASED:
fireMenuKeyReleased(e); break;
fireMenuKeyTyped(e); break;
default:
break;
}
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type.
*
* @param event a <code>MenuMouseDragEvent</code>
* @see EventListenerList
*/
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuDragMouseListener.class) {
// Lazily create the event:
}
}
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type.
*
* @param event a <code>MenuDragMouseEvent</code>
* @see EventListenerList
*/
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuDragMouseListener.class) {
// Lazily create the event:
}
}
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type.
*
* @param event a <code>MenuDragMouseEvent</code>
* @see EventListenerList
*/
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuDragMouseListener.class) {
// Lazily create the event:
}
}
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type.
*
* @param event a <code>MenuDragMouseEvent</code>
* @see EventListenerList
*/
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuDragMouseListener.class) {
// Lazily create the event:
}
}
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type.
*
* @param event a <code>MenuKeyEvent</code>
* @see EventListenerList
*/
if (DEBUG) {
}
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuKeyListener.class) {
// Lazily create the event:
}
}
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type.
*
* @param event a <code>MenuKeyEvent</code>
* @see EventListenerList
*/
if (DEBUG) {
}
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuKeyListener.class) {
// Lazily create the event:
}
}
}
/**
* Notifies all listeners that have registered interest for
* notification on this event type.
*
* @param event a <code>MenuKeyEvent</code>
* @see EventListenerList
*/
if (DEBUG) {
}
// Guaranteed to return a non-null array
// Process the listeners last to first, notifying
// those that are interested in this event
if (listeners[i]==MenuKeyListener.class) {
// 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
*/
return new MenuElement[0];
}
/**
* 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
*/
return this;
}
/**
* 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
* @since 1.4
*/
}
/**
* 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
* @since 1.4
*/
}
/**
* See JComponent.readObject() for information about serialization
* in Swing.
*/
throws IOException, ClassNotFoundException
{
s.defaultReadObject();
updateUI();
}
}
s.defaultWriteObject();
}
}
}
/**
* 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
* be <code>null</code>.
*
* @return a string representation of this <code>JMenuItem</code>
*/
return super.paramString();
}
/////////////////
// Accessibility support
////////////////
/**
* 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>
*/
if (accessibleContext == null) {
accessibleContext = new AccessibleJMenuItem();
}
return accessibleContext;
}
/**
* 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
* elements.
* <p>
* <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.
* Please see {@link java.beans.XMLEncoder}.
*/
private boolean isArmed = false;
private boolean hasFocus = false;
private boolean isPressed = false;
private boolean isSelected = false;
super();
JMenuItem.this.addChangeListener(this);
}
/**
* Get the role of this object.
*
* @return an instance of AccessibleRole describing the role of the
* object
*/
return AccessibleRole.MENU_ITEM;
}
MenuElement [] path =
}
}
}
/**
* Supports the change listener interface and fires property changes.
*/
if (!isArmed) {
isArmed = true;
// 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]
}
} else {
if (isArmed) {
isArmed = false;
}
}
if (JMenuItem.this.isFocusOwner()) {
if (!hasFocus) {
hasFocus = true;
}
} else {
if (hasFocus) {
hasFocus = false;
}
}
if (!isPressed) {
isPressed = true;
}
} else {
if (isPressed) {
isPressed = false;
}
}
if (!isSelected) {
isSelected = true;
// 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]
}
} else {
if (isSelected) {
isSelected = false;
}
}
}
} // inner class AccessibleJMenuItem
}