waba.ui
Class MenuBar

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.Container
              |
              +--waba.ui.Window
                    |
                    +--waba.ui.MenuBar

public class MenuBar
extends Window

Constructs a Menu with the given items. The Menu supports disabled and checked items. Here is an example of how to build the menu for the DateBook:

 MenuItem miBeamEvent,miNewEvent,miDeleteEvent;
 MenuItem col0[] =
 {
   new MenuItem("Record"),                               // caption for the MenuBar
   miNewEvent = new MenuItem("NewEvent",false),          // checked item, starting unchecked
   miDeleteEvent = new MenuItem("Delete Event...",true), // checked item, starting checked
   new MenuItem("Attach Note"),
   new MenuItem("Delete Note..."),
   new MenuItem("Purge..."),
   beamEvent = new MenuItem("Beam Event"),   
 };
 MenuItem col1[] =
 {
   new MenuItem("Edit"),           // caption for the MenuBar
   new MenuItem("Undo"),
   new MenuItem("Cut"),
   new MenuItem("Copy"),
   new MenuItem("Paste"),
   new MenuItem("Select All"),
   new MenuItem(),                 // a separator
   new MenuItem("Keyboard"),
   new MenuItem("Graffiti Help"),
 };
 MenuItem col2[] =
 {
   new MenuItem("Options"),        // caption for the MenuBar
   new MenuItem("Font..."),
   new MenuItem("Preferences..."),
   new MenuItem("Display Options..."),
   new MenuItem("Phone Lookup"),
   new MenuItem("About Date Book"),
 };
 setMenuBar(new MenuBar(new MenuItem[][]{col0,col1,col2}));
 beamEvent.isEnabled = false;
 ...
 // at later time, disable the "new event" and enable the "delete event"
 miNewEvent.isChecked = true;
 miDeleteEvent.isChecked = false;
 
The menu can be closed by a click on a valid item or clicking outside of its bounds. A PRESSED event will be thrown when the menu is closed and a menu item was selected. To discover which item was selected, see method getSelectedMenuItem, which returns -1 if none, or the matrix index otherwise.

Note that the separator dotted line doesn't generate events.

To convert the old menu form (using a string matrix) into the new form using a MenuItem matrix, you can use this idea:
Old format:

 // the string arrays menuArq, menuUtil and menuSobre are initialized somewhere else
 setMenuBar(mbar = new MenuBar(new String[][]{menuArq,menuUtil,menuSobre})); 
 mbar.setChecked(106,true);
 mbar.setEnabled(106,false);
 mbar.setChecked(4, true);
 
New format:
 // declare these as global variables:
 MenuItem mi4, mi106;
 
 // at onStart 
 setMenuBar(mbar = new MenuBar(MenuBar.strings2items(new String[][]{menuArq,menuUtil,menuSobre})));
 MenuItem[][] mis = mbar.getMenuItems();
 mi4 = mis[0][4];
 mi106 = mis[1][6];
 mi106.isChecked = true;
 mi106.isEnabled = false;
 mi4.isChecked = true;
 
Note that, after changing the isChecked and isEnabled states, there's no need to call repaint, bacause they will show up only the next time the menu bar opens.


Field Summary
static char CHECKED
          Deprecated. Use the new MenuBar.Item properties instead.
static char DISABLED
          Deprecated. Use the new MenuBar.Item properties instead.
 int gap
          Note: if you want to change the spacement between the menu items (maybe to make more items fit in the row), change this gap value.
protected  MenuItem[][] items
           
static char UNCHECKED
          Deprecated. Use the new MenuBar.Item properties instead.
 
Fields inherited from class waba.ui.Window
_controlEvent, _focus, _keyEvent, _penEvent, beepIfOut, blockingCount, borderStyle, canDrag, eraseBackgroundNow, flicker, HIDE_STATE, highlighted, highResPrepared, imgCovered, lastSwappedContainer, mainSwapContainer, menubar, needsPaint, NO_BORDER, RECT_BORDER, ROUND_BORDER, TAB_BORDER, TAB_ONLY_BORDER, title, titleFont, topMost, VK_BOTTOM, VK_HIDE, VK_SHOW, VK_TOP, zStack
 
Fields inherited from class waba.ui.Container
BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, lastH, lastW, lastX, lastY, parentWindow, started, tabOrder, tail
 
Fields inherited from class waba.ui.Control
AFTER, appId, appObj, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, clearValueInt, clearValueStr, enabled, FILL, FIT, fm, fmH, focusLess, focusTraversable, font, foreColor, foreDis, height, highlightRectsCount, isHighlighting, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, uiCE, uiFlat, uiPalm, uiVista, visible, width, x, x2, y, y2
 
Constructor Summary
MenuBar(MenuItem[][] items)
          Create a MenuBar with the given menu items.
MenuBar(java.lang.String[][] items)
          Deprecated. Use MenuBar(MenuItem[][]).
 
Method Summary
 java.lang.String[][] getItems()
          Deprecated. Use the method getMenuItems instead.
 MenuItem[][] getMenuItems()
           
 int getSelectedMenuItem()
          Returns the current menu item selected.
protected  boolean handleFocusChangeKeys(KeyEvent ke)
          Called by the main event handler to handle the focus change keys.
 boolean isCheckable(int menuItem)
          Deprecated. Store a reference to the desired MenuItem and call the isCheckable method.
 boolean isChecked(int menuItem)
          Deprecated. Store a reference to the desired MenuItem and change its isChecked property directly. See MenuItem for more details.
 boolean isEnabled(int menuItem)
          Deprecated. Store a reference to the desired MenuItem and check the isEnabled property.
protected  void loadBehindLastPopup(int ph)
           
 void moveBy(int i)
           
protected  boolean onClickedOutside(int x, int y)
          Close the popup list with a click outside its bounds
protected  void onColorsChanged(boolean colorsChanged)
          Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.
 void onEvent(Event event)
          Called to process key, pen, control and other posted events.
protected  void onFontChanged()
          Change the font and recompute some parameters
 void onPaint(Graphics g)
          Draws the border (if any).
protected  void onPopup()
          Setup some important variables
protected  void popupClosed(PopupMenu pop)
          called from menu to tell that it is being closed
protected  void postPopup()
          Placeholder called after the popup is done and after the repaint of this window. the default implementation does nothing.
protected  void postUnpop()
          Placeholder called after the unpop is done and after the repaint of the other window. the default implementation does nothing.
 void setChecked(int menuItem, boolean check)
          Deprecated. Store a reference to the desired MenuItem and set the isChecked property.
 void setCursorColor(Color c)
          Sets the cursor color.
 void setEnabled(int menuItem, boolean enable)
          Deprecated. Store a reference to the desired MenuItem and set the isEnabled property.
 void setItems(java.lang.String[][] items)
          Deprecated. Don't change the items of a MenuBar. Create a new MenuBar with the new items instead.
 void setPopColors(Color back, Color fore, Color cursor)
          Set the colors for the popup windows.
 void setVisible(boolean b)
          Called by the Window class to popup this MenuBar
static MenuItem[][] strings2items(java.lang.String[][] items)
          Converts a String matrix into a MenuItem matrix.
protected  void switchTo(int index)
           
 
Methods inherited from class waba.ui.Window
_doPaint, _doPaint, _postEvent, _postSoundEvent, damageRect, destroyZStack, dontSaveBehind, drawHighlight, getClientRect, getClientRect, getFocus, getHighlighted, getOffScreen, getPreferredHeight, getPreferredWidth, getTopMost, isTopMost, isVisible, loadBehind, makeUnmovable, onUnpop, paintTitle, popupBlockingModal, popupMenuBar, popupModal, postPressedEvent, pumpEvents, saveBehind, setBorderStyle, setDoubleBuffer, setFocus, setHighlighted, setMenuBar, setStatePosition, setTitle, setTitleFont, swap, swapFocus, unpop, updateScreen, validate
 
Methods inherited from class waba.ui.Container
add, add, add, broadcastEvent, clear, findChild, getChildren, onAdd, onRemove, onStart, paintChildren, remove, setEnabled, setHighlighting, swapToTopmostWindow
 
Methods inherited from class waba.ui.Control
addTimer, changeHighlighted, contains, createGraphics, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getRect, getSize, isDisplayed, isEnabled, onBoundsChanged, onWindowPaintFinished, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, translateFromOrigin, uiStyleChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

items

protected MenuItem[][] items

gap

public int gap
Note: if you want to change the spacement between the menu items (maybe to make more items fit in the row), change this gap value. Default is 3 (3 pixels at left and 3 at right).

CHECKED

public static final char CHECKED
Deprecated. Use the new MenuBar.Item properties instead.


UNCHECKED

public static final char UNCHECKED
Deprecated. Use the new MenuBar.Item properties instead.


DISABLED

public static final char DISABLED
Deprecated. Use the new MenuBar.Item properties instead.

Constructor Detail

MenuBar

public MenuBar(java.lang.String[][] items)
Deprecated. Use MenuBar(MenuItem[][]).

Create a MenuBar with the given items.

MenuBar

public MenuBar(MenuItem[][] items)
Create a MenuBar with the given menu items.
Method Detail

strings2items

public static MenuItem[][] strings2items(java.lang.String[][] items)
Converts a String matrix into a MenuItem matrix.

setItems

public void setItems(java.lang.String[][] items)
Deprecated. Don't change the items of a MenuBar. Create a new MenuBar with the new items instead.

Sets the current Menu items.

getItems

public java.lang.String[][] getItems()
Deprecated. Use the method getMenuItems instead.

Gets the current Menu items.

getMenuItems

public MenuItem[][] getMenuItems()

setPopColors

public void setPopColors(Color back,
                         Color fore,
                         Color cursor)
Set the colors for the popup windows. You can pass null to any parameter to keep the current settings.

setCursorColor

public void setCursorColor(Color c)
Sets the cursor color. By default, it is based in the background color

setVisible

public void setVisible(boolean b)
Called by the Window class to popup this MenuBar
Overrides:
setVisible in class Control

onFontChanged

protected void onFontChanged()
Change the font and recompute some parameters
Overrides:
onFontChanged in class Control

getSelectedMenuItem

public int getSelectedMenuItem()
Returns the current menu item selected.
Returns:
-1 if no item was selected, or a number with format xyy, where x is the index of the item selected at the MenuBar and yy is the index+1 ( = the index of the String array that defines the items) of the item selected in the PopupMenu. EG: suppose that the col1/"Cut" of the example at the top of this page was clicked, then 102 is returned.

isChecked

public boolean isChecked(int menuItem)
Deprecated. Store a reference to the desired MenuItem and change its isChecked property directly. See MenuItem for more details.

Returns true if the given menu item in the xyy format is checked. To make an item checkable at the constructor, prefix it with a ?. When it is selected, the ? is replaced by a !.

isCheckable

public boolean isCheckable(int menuItem)
Deprecated. Store a reference to the desired MenuItem and call the isCheckable method.

Returns true if a menu item is checkable.

isEnabled

public boolean isEnabled(int menuItem)
Deprecated. Store a reference to the desired MenuItem and check the isEnabled property.

Returns the enabled state of the given menu item. To disable an item, use method setEnabled or prefix it with a * at the constructor.

setChecked

public void setChecked(int menuItem,
                       boolean check)
Deprecated. Store a reference to the desired MenuItem and set the isChecked property.

Put a check in the given menu item in the xyy format. To make an item checkable, at the constructor you must prefix it with a ?. When a checkable item is selected, the ? is replaced by a !.

Note: the items at the MenuBar cannot be checkable.


setEnabled

public void setEnabled(int menuItem,
                       boolean enable)
Deprecated. Store a reference to the desired MenuItem and set the isEnabled property.

Enable the given menu item.

onPopup

protected void onPopup()
Setup some important variables
Overrides:
onPopup in class Window

onClickedOutside

protected boolean onClickedOutside(int x,
                                   int y)
Close the popup list with a click outside its bounds
Overrides:
onClickedOutside in class Window

onEvent

public void onEvent(Event event)
Description copied from class: Control
Called to process key, pen, control and other posted events.
Overrides:
onEvent in class Control
Tags copied from class: Control
Parameters:
event - the event to process
See Also:
Event, KeyEvent, PenEvent

postUnpop

protected void postUnpop()
Description copied from class: Window
Placeholder called after the unpop is done and after the repaint of the other window. the default implementation does nothing.
Overrides:
postUnpop in class Window

postPopup

protected void postPopup()
Description copied from class: Window
Placeholder called after the popup is done and after the repaint of this window. the default implementation does nothing.
Overrides:
postPopup in class Window

popupClosed

protected void popupClosed(PopupMenu pop)
called from menu to tell that it is being closed

loadBehindLastPopup

protected void loadBehindLastPopup(int ph)

switchTo

protected void switchTo(int index)

onColorsChanged

protected void onColorsChanged(boolean colorsChanged)
Description copied from class: Control
Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
Overrides:
onColorsChanged in class Container

onPaint

public void onPaint(Graphics g)
Description copied from class: Container
Draws the border (if any). If you override this method, be sure to call super.onPaint(g);, or the border will not be drawn.
Overrides:
onPaint in class Container
Tags copied from class: Control
Parameters:
g - the graphics object for drawing
See Also:
Graphics

moveBy

public void moveBy(int i)

handleFocusChangeKeys

protected boolean handleFocusChangeKeys(KeyEvent ke)
Description copied from class: Window
Called by the main event handler to handle the focus change keys. Only called when Settings.keyboardFocusNavigation is true.
Overrides:
handleFocusChangeKeys in class Window