jewl
Class MenuItem

java.lang.Object
  extended byjewl.Window
      extended byjewl.Control
          extended byjewl.TextControl
              extended byjewl.BooleanControl
                  extended byjewl.MenuItem

public class MenuItem
extends BooleanControl

An item that can be attached to a menu. Menu items generate a command code (a character) when they are selected. They are Boolean controls, and can be set to display a checkmark next to the item when the menu is displayed. Like other Boolean controls, the program can get or set the state of a menu item (checked or unchecked) and the text associated with it.

Since menus are not containers, the menu item's parent window will actually be the frame that the menu belongs to.


Field Summary
 
Fields inherited from class jewl.TextControl
CENTER, CENTRE, LEFT, RIGHT
 
Constructor Summary
MenuItem(Menu parent, java.lang.String text, char action)
          Construct a new menu item attached to a specified menu which will generate a specified command code (a character) when selected.
 
Method Summary
 void activate()
          Activate this menu item as if it was selected by a mouse click.
 void setAlignment(int align)
          Set the alignment of this menu item's text within its allocated area.
 void setLocation(int left, int top)
          Set the location of this menu item within the parent window.
 void setMenuKey(char key)
          Set a menu accelerator key.
 void setSize(int width, int height)
          Set the size of this menu item.
 
Methods inherited from class jewl.BooleanControl
getState, setState, toggle
 
Methods inherited from class jewl.TextControl
getAlignment, getText, setKey, setText
 
Methods inherited from class jewl.Control
disable, enable, enable, getToolTip, isEnabled, setToolTip
 
Methods inherited from class jewl.Window
addEventListener, commandAvailable, getCommand, getFont, getHeight, getID, getLeft, getScreenHeight, getScreenWidth, getSource, getTop, getWidth, hide, init, isVisible, nextCommand, parent, root, setFont, setID, show, show
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuItem

public MenuItem(Menu parent,
                java.lang.String text,
                char action)
Construct a new menu item attached to a specified menu which will generate a specified command code (a character) when selected.

Parameters:
parent - the menu item's parent menu.
text - the initial text displayed by the menu item.
action - the command code generated when the menu item is selected.
Method Detail

activate

public void activate()
Activate this menu item as if it was selected by a mouse click. This generates the command code associated with the menu item.


setSize

public void setSize(int width,
                    int height)
Set the size of this menu item. Menu items cannot be resized, so this method does nothing.

Overrides:
setSize in class Window
Parameters:
width - ignored.
height - ignored.

setLocation

public void setLocation(int left,
                        int top)
Set the location of this menu item within the parent window. Menu items cannot be moved, so this method does nothing.

Overrides:
setLocation in class Window
Parameters:
left - ignored.
top - ignored.

setAlignment

public void setAlignment(int align)
Set the alignment of this menu item's text within its allocated area. Menu items cannot be aligned, so this method does nothing.

Overrides:
setAlignment in class TextControl
Parameters:
align - the desired alignment, specified using one of the values LEFT, RIGHT, CENTRE or CENTER.

setMenuKey

public void setMenuKey(char key)
Set a menu accelerator key. The possible accelerators are Ctrl-A to Ctrl-Z, and Ctrl-0 to Ctrl-9. Pressing the designated key will have the same effect as pulling down the menu and selecting the item using the mouse. The accelerator will be displayed next to the menu item. This is separate from the mnemonic key set by setKey, and a menu item can have both a mnemonic key and an accelerator key associated with it.

Parameters:
key - a letter or digit which will activate the menu item when pressed together with the Control key. Anything other than a letter or digit will be ignored.