Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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:

     String col0[] =
     {
       "Record",         // caption for the MenuBar
       "?NewEvent",      // checked item
       "Delete Event...",
       "Attach Note",
       "Delete Note...",
       "Purge...",
       "*Beam Event",    // disabled item
     };
     String col1[] =
     {
       "Edit",           // caption for the MenuBar
       "Undo",
       "Cut",
       "Copy",
       "Paste",
       "Select All",
       "-",              // a dotted line
       "Keyboard",
       "Graffiti Help",
     };
     String col2[] =
     {
       "Options",        // caption for the MenuBar
       "Font...",
       "Preferences...",
       "Display Options...",
       "Phone Lookup",
       "About Date Book",
     };
     setMenuBar(new MenuBar(new String[][]{col0,col1,col2}));

An WINDOW_CLOSED event will be thrown when the menu is closed. The menu can be closed by a click on a valid item or clicking outside of its bounds. To discover why it was closed, see method getSelectedMenuItem.

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

I know that storing things in String is very odd; I should create a class MenuItem and store things there; but this way is faster and uses less memory.

Field Summary
`static char` | `CHECKED`
`static char` | `DISABLED`
`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.
`static char` | `UNCHECKED`

Fields inherited from class waba.ui.Window
`beepIfOut, borderStyle, canDrag, eraseBackgroundNow, flicker, HIDE_STATE, 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_TOP, zStack`

Fields inherited from class waba.ui.Container
`BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, lastH, lastW, lastX, lastY, parentWindow, tail`

Fields inherited from class waba.ui.Control
`AFTER, appId, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, enabled, FILL, FIT, fm, fmH, focusLess, font, foreColor, foreDis, height, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, visible, width, x, x2, y, y2`

Constructor Summary
`MenuBar(String[][] items)` Create a MenuBar with the given items

Method Summary
`int` | `getSelectedMenuItem()` Returns the current menu item selected.
`boolean` | `isCheckable(int menuItem)` Returns true if a menu item is checkable
`boolean` | `isChecked(int menuItem)` Returns true if the given menu item in the xyy format is checked.
`boolean` | `isEnabled(int menuItem)` Returns the enabled state of the given menu item.
`protected void` | `loadBehindLastPopup(int ph)`
`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.
`void` | `setChecked(int menuItem, boolean check)` Put a check in the given menu item in the xyy format.
`void` | `setCursorColor(Color c)` Sets the cursor color.
`void` | `setEnabled(int menuItem, boolean enable)` Enable the given menu item.
`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
`protected void` | `switchTo(int index)`

Methods inherited from class waba.ui.Window
`_doPaint, _doPaint, _postEvent, damageRect, destroyZStack, dontSaveBehind, getClientRect, getFocus, getOffScreen, getPreferredHeight, getPreferredWidth, getTopMost, isTopMost, isVisible, loadBehind, makeUnmovable, onUnpop, paintTitle, popupBlockingModal, popupMenuBar, popupModal, postUnpop, pumpEvents, saveBehind, setBorderStyle, setDoubleBuffer, setFocus, setMenuBar, setStatePosition, setTitle, setTitleFont, swap, unpop`

Methods inherited from class waba.ui.Container
`add, add, add, broadcastEvent, findChild, getChildren, onStart, paintChildren, remove, setEnabled`

Methods inherited from class waba.ui.Control
`addTimer, 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`

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, toString, wait, wait`

Field Detail

### 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

### UNCHECKED

    public static final char UNCHECKED

### DISABLED

    public static final char DISABLED

Constructor Detail

### MenuBar

    public MenuBar(String[][] items)

  Create a MenuBar with the given items

Method Detail

### 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)

  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)

  Returns true if a menu item is checkable

### isEnabled

    public boolean isEnabled(int menuItem)

  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)

  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)

  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`

### 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`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD