Methods Summary |
---|
public synchronized void | addActionListener(java.awt.event.ActionListener l)Adds the specified action listener to receive action events
from this menu item.
If l is null, no exception is thrown and no action is performed.
Refer to AWT Threading Issues for details on AWT's threading model.
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.add(actionListener, l);
newEventsOnly = true;
|
public void | addNotify()Creates the menu item's peer. The peer allows us to modify the
appearance of the menu item without changing its functionality.
synchronized (getTreeLock()) {
if (peer == null)
peer = Toolkit.getDefaultToolkit().createMenuItem(this);
}
|
java.lang.String | constructComponentName()Construct a name for this MenuComponent. Called by getName() when
the name is null.
synchronized (getClass()) {
return base + nameCounter++;
}
|
public void | deleteShortcut()Delete any MenuShortcut object associated
with this menu item.
shortcut = null;
MenuItemPeer peer = (MenuItemPeer)this.peer;
if (peer != null) {
peer.setLabel(label);
}
|
void | deleteShortcut(java.awt.MenuShortcut s)
if (s.equals(shortcut)) {
shortcut = null;
MenuItemPeer peer = (MenuItemPeer)this.peer;
if (peer != null) {
peer.setLabel(label);
}
}
|
public synchronized void | disable()
enabled = false;
MenuItemPeer peer = (MenuItemPeer)this.peer;
if (peer != null) {
peer.disable();
}
|
protected final void | disableEvents(long eventsToDisable)Disables event delivery to this menu item for events
defined by the specified event mask parameter.
eventMask &= ~eventsToDisable;
|
void | doMenuEvent(long when, int modifiers)
Toolkit.getEventQueue().postEvent(
new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
getActionCommand(), when, modifiers));
|
public synchronized void | enable()
enabled = true;
MenuItemPeer peer = (MenuItemPeer)this.peer;
if (peer != null) {
peer.enable();
}
|
public void | enable(boolean b)
if (b) {
enable();
} else {
disable();
}
|
protected final void | enableEvents(long eventsToEnable)Enables event delivery to this menu item for events
to be defined by the specified event mask parameter
Since event types are automatically enabled when a listener for
that type is added to the menu item, this method only needs
to be invoked by subclasses of MenuItem which desire to
have the specified event types delivered to processEvent
regardless of whether a listener is registered.
eventMask |= eventsToEnable;
newEventsOnly = true;
|
boolean | eventEnabled(java.awt.AWTEvent e)
if (e.id == ActionEvent.ACTION_PERFORMED) {
if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 ||
actionListener != null) {
return true;
}
return false;
}
return super.eventEnabled(e);
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this MenuItem.
For menu items, the AccessibleContext takes the form of an
AccessibleAWTMenuItem.
A new AccessibleAWTMenuItem instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTMenuItem();
}
return accessibleContext;
|
public java.lang.String | getActionCommand()Gets the command name of the action event that is fired
by this menu item.
return getActionCommandImpl();
|
final java.lang.String | getActionCommandImpl()
return (actionCommand == null? label : actionCommand);
|
public synchronized java.awt.event.ActionListener[] | getActionListeners()Returns an array of all the action listeners
registered on this menu item.
return (ActionListener[])(getListeners(ActionListener.class));
|
public java.lang.String | getLabel()Gets the label for this menu item.
return label;
|
public T[] | getListeners(java.lang.Class listenerType)Returns an array of all the objects currently registered
as FooListener s
upon this MenuItem .
FooListener s are registered using the
addFooListener method.
You can specify the listenerType argument
with a class literal, such as
FooListener.class .
For example, you can query a
MenuItem m
for its action listeners with the following code:
ActionListener[] als = (ActionListener[])(m.getListeners(ActionListener.class));
If no such listeners exist, this method returns an empty array.
EventListener l = null;
if (listenerType == ActionListener.class) {
l = actionListener;
}
return AWTEventMulticaster.getListeners(l, listenerType);
|
public java.awt.MenuShortcut | getShortcut()Get the MenuShortcut object associated with this
menu item,
return shortcut;
|
java.awt.MenuItem | getShortcutMenuItem(java.awt.MenuShortcut s)
return (s.equals(shortcut)) ? this : null;
|
boolean | handleShortcut(java.awt.event.KeyEvent e)
MenuShortcut s = new MenuShortcut(e.getKeyCode(),
(e.getModifiers() & InputEvent.SHIFT_MASK) > 0);
// Fix For 6185151: Menu shortcuts of all menuitems within a menu
// should be disabled when the menu itself is disabled
if (s.equals(shortcut) && isItemEnabled()) {
// MenuShortcut match -- issue an event on keydown.
if (e.getID() == KeyEvent.KEY_PRESSED) {
doMenuEvent(e.getWhen(), e.getModifiers());
} else {
// silently eat key release.
}
return true;
}
return false;
|
private static native void | initIDs()Initialize JNI field and method IDs
|
public boolean | isEnabled()Checks whether this menu item is enabled.
return enabled;
|
private final boolean | isItemEnabled()
// Fix For 6185151: Menu shortcuts of all menuitems within a menu
// should be disabled when the menu itself is disabled
if (!isEnabled()) {
return false;
}
MenuContainer container = getParent_NoClientCode();
do {
if (!(container instanceof Menu)) {
return true;
}
Menu menu = (Menu)container;
if (!menu.isEnabled()) {
return false;
}
container = menu.getParent_NoClientCode();
} while (container != null);
return true;
|
public java.lang.String | paramString()Returns a string representing the state of this MenuItem .
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
null .
String str = ",label=" + label;
if (shortcut != null) {
str += ",shortcut=" + shortcut;
}
return super.paramString() + str;
|
protected void | processActionEvent(java.awt.event.ActionEvent e)Processes action events occurring on this menu item,
by dispatching them to any registered
ActionListener objects.
This method is not called unless action events are
enabled for this component. Action events are enabled
when one of the following occurs:
- An
ActionListener object is registered
via addActionListener .
- Action events are enabled via
enableEvents .
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
ActionListener listener = actionListener;
if (listener != null) {
listener.actionPerformed(e);
}
|
protected void | processEvent(java.awt.AWTEvent e)Processes events on this menu item. If the event is an
instance of ActionEvent , it invokes
processActionEvent , another method
defined by MenuItem .
Currently, menu items only support action events.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
if (e instanceof ActionEvent) {
processActionEvent((ActionEvent)e);
}
|
private void | readObject(java.io.ObjectInputStream s)Reads the ObjectInputStream and if it
isn't null adds a listener to receive
action events fired by the Menu Item.
Unrecognized keys or values will be ignored.
// HeadlessException will be thrown from MenuComponent's readObject
s.defaultReadObject();
Object keyOrNull;
while(null != (keyOrNull = s.readObject())) {
String key = ((String)keyOrNull).intern();
if (actionListenerK == key)
addActionListener((ActionListener)(s.readObject()));
else // skip value for unrecognized key
s.readObject();
}
|
public synchronized void | removeActionListener(java.awt.event.ActionListener l)Removes the specified action listener so it no longer receives
action events from this menu item.
If l is null, no exception is thrown and no action is performed.
Refer to AWT Threading Issues for details on AWT's threading model.
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.remove(actionListener, l);
|
public void | setActionCommand(java.lang.String command)Sets the command name of the action event that is fired
by this menu item.
By default, the action command is set to the label of
the menu item.
actionCommand = command;
|
public synchronized void | setEnabled(boolean b)Sets whether or not this menu item can be chosen.
enable(b);
|
public synchronized void | setLabel(java.lang.String label)Sets the label for this menu item to the specified label.
this.label = label;
MenuItemPeer peer = (MenuItemPeer)this.peer;
if (peer != null) {
peer.setLabel(label);
}
|
public void | setShortcut(java.awt.MenuShortcut s)Set the MenuShortcut object associated with this
menu item. If a menu shortcut is already associated with
this menu item, it is replaced.
shortcut = s;
MenuItemPeer peer = (MenuItemPeer)this.peer;
if (peer != null) {
peer.setLabel(label);
}
|
private void | writeObject(java.io.ObjectOutputStream s)Writes default serializable fields to stream. Writes
a list of serializable ActionListeners
as optional data. The non-serializable listeners are
detected and no attempt is made to serialize them.
s.defaultWriteObject();
AWTEventMulticaster.save(s, actionListenerK, actionListener);
s.writeObject(null);
|