buoy.widget
Class BMenuItem

java.lang.Object
  extended by buoy.event.EventSource
      extended by buoy.widget.Widget
          extended by buoy.widget.BMenuItem
All Implemented Interfaces:
MenuWidget
Direct Known Subclasses:
BCheckBoxMenuItem, BRadioButtonMenuItem

public class BMenuItem
extends Widget
implements MenuWidget

A BMenuItem is a Widget corresponding to an item in a pulldown menu. Each menu item typically represents a different command, which the user can issue by selecting it with the mouse.

It also is possible to select a menu item with the keyboard. There are, in fact, two different ways of doing this. First, a menu item may have a Shortcut associated with it. This is a particular combination of keys, usually including a platform specific modifier key such as Control or Meta. Whenever that combination of keys is pressed, the corresponding menu item is immediately selected.

Second, many platforms allow keyboard navigation of menus and menu items. Typically, a user enters keyboard navigation mode by pressing a particular key. They can then use arrow keys to select a desired menu item, and Enter or Space to activate it. Keyboard navigation can be accelerated by assigning a mnemonic to each menu and menu item. When the user is in keyboard navigation mode, pressing the mnemonic key for a particular menu item will immediately select that item.

In addition to the event types generated by all Widgets, BMenuItems generate the following event types:

Author:
Peter Eastman

Constructor Summary
BMenuItem()
          Create a new BMenuItem with no label.
BMenuItem(java.lang.String text)
          Create a new BMenuItem.
BMenuItem(java.lang.String text, javax.swing.Icon image)
          Create a new BMenuItem.
BMenuItem(java.lang.String text, Shortcut shortcut)
          Create a new BMenuItem.
BMenuItem(java.lang.String text, Shortcut shortcut, javax.swing.Icon image)
          Create a new BMenuItem.
 
Method Summary
 java.lang.String getActionCommand()
          Get the "action command" which will be sent in a CommandEvent when this menu item is selected.
 javax.swing.JMenuItem getComponent()
          Get the java.awt.Component corresponding to this Widget.
 javax.swing.Icon getIcon()
          Get the image which appears next to this menu item.
 int getMnemonic()
          Get the mnemonic which can be used to activate this menu item in keyboard navigation mode.
 Shortcut getShortcut()
          Get the keyboard shortcut for this menu item.
 java.lang.String getText()
          Get the text which appears on this menu item.
 void setActionCommand(java.lang.String command)
          Set the "action command" which will be sent in a CommandEvent when this menu item is selected.
 void setIcon(javax.swing.Icon image)
          Set the image which appears next to this menu item.
 void setMnemonic(int key)
          Set the mnemonic which can be used to activate this menu item in keyboard navigation mode.
 void setShortcut(Shortcut shortcut)
          Set the keyboard shortcut for this menu item.
 void setText(java.lang.String title)
          Set the text which appears on this menu item.
 
Methods inherited from class buoy.widget.Widget
addEventLink, dispatchEvent, getBackground, getBounds, getCursor, getFont, getMaximumSize, getMinimumSize, getName, getParent, getPreferredSize, hasFocus, isEnabled, isFocusable, isVisible, repaint, requestFocus, setBackground, setCursor, setEnabled, setFocusable, setFont, setName, setVisible
 
Methods inherited from class buoy.event.EventSource
addEventLink, addEventLink, removeEventLink
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BMenuItem

public BMenuItem()
Create a new BMenuItem with no label.


BMenuItem

public BMenuItem(java.lang.String text)
Create a new BMenuItem.

Parameters:
text - the text to display on the BMenuItem

BMenuItem

public BMenuItem(java.lang.String text,
                 javax.swing.Icon image)
Create a new BMenuItem.

Parameters:
text - the text to display on the BMenuItem
image - the image to display next to the menu item

BMenuItem

public BMenuItem(java.lang.String text,
                 Shortcut shortcut)
Create a new BMenuItem.

Parameters:
text - the text to display on the BMenuItem
shortcut - a keyboard shortcut which will activate this menu item

BMenuItem

public BMenuItem(java.lang.String text,
                 Shortcut shortcut,
                 javax.swing.Icon image)
Create a new BMenuItem.

Parameters:
text - the text to display on the BMenuItem
shortcut - a keyboard shortcut which will activate this menu item
image - the image to display next to the menu item
Method Detail

getComponent

public javax.swing.JMenuItem getComponent()
Description copied from class: Widget
Get the java.awt.Component corresponding to this Widget.

Overrides:
getComponent in class Widget

getText

public java.lang.String getText()
Get the text which appears on this menu item.


setText

public void setText(java.lang.String title)
Set the text which appears on this menu item.


getActionCommand

public java.lang.String getActionCommand()
Get the "action command" which will be sent in a CommandEvent when this menu item is selected.


setActionCommand

public void setActionCommand(java.lang.String command)
Set the "action command" which will be sent in a CommandEvent when this menu item is selected.


getShortcut

public Shortcut getShortcut()
Get the keyboard shortcut for this menu item.


setShortcut

public void setShortcut(Shortcut shortcut)
Set the keyboard shortcut for this menu item.


getMnemonic

public int getMnemonic()
Get the mnemonic which can be used to activate this menu item in keyboard navigation mode.

Returns:
the key code (defined by the KeyEvent class) which activates this menu item

setMnemonic

public void setMnemonic(int key)
Set the mnemonic which can be used to activate this menu item in keyboard navigation mode.

Parameters:
key - the key code (defined by the KeyEvent class) which activates this menu item

getIcon

public javax.swing.Icon getIcon()
Get the image which appears next to this menu item.


setIcon

public void setIcon(javax.swing.Icon image)
Set the image which appears next to this menu item.



Written by Peter Eastman.