|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--waba.ui.Control
|
+--waba.ui.Container
|
+--waba.ui.Window
|
+--waba.ui.MenuBar
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 |
protected MenuItem[][] items
public int gap
public static final char CHECKED
public static final char UNCHECKED
public static final char DISABLED
| Constructor Detail |
public MenuBar(java.lang.String[][] items)
public MenuBar(MenuItem[][] items)
| Method Detail |
public static MenuItem[][] strings2items(java.lang.String[][] items)
public void setItems(java.lang.String[][] items)
public java.lang.String[][] getItems()
public MenuItem[][] getMenuItems()
public void setPopColors(Color back,
Color fore,
Color cursor)
null
to any parameter to keep the current settings.public void setCursorColor(Color c)
public void setVisible(boolean b)
protected void onFontChanged()
public int getSelectedMenuItem()
public boolean isChecked(int menuItem)
public boolean isCheckable(int menuItem)
public boolean isEnabled(int menuItem)
public void setChecked(int menuItem,
boolean check)
Note: the items at the MenuBar cannot be checkable.
public void setEnabled(int menuItem,
boolean enable)
protected void onPopup()
protected boolean onClickedOutside(int x,
int y)
public void onEvent(Event event)
event - the event to processEvent,
KeyEvent,
PenEventprotected void postUnpop()
protected void postPopup()
protected void popupClosed(PopupMenu pop)
protected void loadBehindLastPopup(int ph)
protected void switchTo(int index)
protected void onColorsChanged(boolean colorsChanged)
public void onPaint(Graphics g)
super.onPaint(g);, or the border will not be drawn.g - the graphics object for drawingGraphicspublic void moveBy(int i)
protected boolean handleFocusChangeKeys(KeyEvent ke)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||