Class Menu


  extended by Object
      extended by Menu

public class Menu
extends Object

This class represents the Menus that are shown to user. Menu supports nesting and hiding/showing of individual menu items.

Methods are designed so that it's easy to create menu structures with method chaining:

Menu m = Menu()
   .add(CMD_OPEN, "Open")
   .add(CMD_REMOVE, "Remove")
   .add(CMD_ADD, "Add")
   .begin(CMD_MORE, "More")
     .add(CMD_SYNC, "Synchronize")
     .add(CMD_SETTINGS, "Settings")
   .end()
   .add(CMD_EXIT, "Exit")

 Menu getMenu(Shell shell, Component focused)
 {
   return m.reset().enable(CMD_OPEN, focused != null)
                   .enable(CMD_REMOVE, focused != null)
                   .enable(CMD_SYNC, isOnline());
 } 
 

The upper case references are to ids created in the script:

 const int CMD_OPEN = 0;
 const int CMD_REMOVE = 1;
 // etc...
 

These ids are given back in callback function arguments that are called when an action has happened: Script.actionPerformed(Shell, Component, int) or ActionCallback.actionPerformed(Shell, Component, int)

See Also:
MenuItem, Script.getMenu(Shell, Component), Script.getSoftKey(Shell, Component, int), Callbacks

Constructor Summary
Menu()
          Constructs a new Menu instance.
 
Method Summary
 Menu add(int id, String text)
          Creates a new MenuItem with specified action id and text.
 Menu begin(int id, String text)
          Creates a new MenuItem with sub menu.
 Menu enable(int id, boolean enabled)
          Enable or disable menu item with specified action id.
 Menu end()
          Closes sub menu and returns to parent menu.
 MenuItem get(int id)
          Returns MenuItem with specified action id.
 void open(Shell parent)
          Opens this menu.
 Menu reset()
          Resets the focus and sets all MenuItems visible.
 
Methods inherited from class Object
toString, equals, hashCode
 
Methods inherited from
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Menu

public Menu()
Constructs a new Menu instance.

Method Detail

add

public Menu add(int id,
                String text)
Creates a new MenuItem with specified action id and text.

Parameters:
id - An action id. It is passed to Script.actionPerformed(Shell, Component, int) when user selects this menu item. It can also be used to enable or disable this item.
text - Text to show
Returns:
this Menu instance

begin

public Menu begin(int id,
                  String text)
Creates a new MenuItem with sub menu. Sub menu is indicated with arrow at the right side of an item.

Parameters:
id - An action id. It can be used to enable or disable this item.
text - Text to show
Returns:
instance of sub Menu, use end() method to close sub menu and return parent menu

end

public Menu end()
Closes sub menu and returns to parent menu.

Returns:
parent menu

reset

public Menu reset()
Resets the focus and sets all MenuItems visible.

Returns:
this Menu instance

enable

public Menu enable(int id,
                   boolean enabled)
Enable or disable menu item with specified action id.

Parameters:
id - Action id of MenuItem to hide/show
enabled - if true item is shown, otherwise it is hidden
Returns:
this Menu instance

get

public MenuItem get(int id)
Returns MenuItem with specified action id.

Parameters:
id - Action id to search for
Returns:
MenuItem or null if no matching id was found.

open

public void open(Shell parent)
Opens this menu. Parent shell's action handler receives all the actions fired by the menu, or if action handler is not set then widget's global action handler. Parent can be just blank shell created by new Shell(null), it doesn't be visible or in the UI stack.

Parameters:
parent - Parent shell