Class MenuBar
- All Implemented Interfaces:
Animation, Editable, ActionListener, StyleListener, Iterable<Component>
- Direct Known Subclasses:
SideMenuBar
-
Field Summary
Fields inherited from class Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInvoked when a softbutton is pressedvoidaddCommand(Command cmd) Adds a Command to the MenuBarprotected voidaddCommand(Command cmd, int index) Add a Command to the MenuBarprotected DimensionPrevents scaling down of the menu when there is no text on the menu barprotected intCalculates the amount of columns to give to the touch commands within the gridprotected Buttonprotected ComponentcreateCommandComponent(Vector commands) Creates the component containing the commands within the given vector used for showing the menu dialog, this method calls the createCommandList method by default however it allows more elaborate menu creation.protected ListcreateCommandList(Vector commands) Creates the list component containing the commands within the given vector used for showing the menu dialogprotected CommandFactory method that returns the Form Menu cancel Command.protected CommandFactory method that returns the Form Menu select Command.protected CommandFactory method that returns the Form select Command.protected ButtoncreateSoftButton(String uiid) Creates a soft button Componentprotected ButtonCreates a touch command for use as a touch menu itemFind the command component instance if such an instance existsIndicates the command that is defined as the back command out of this form.protected CommandThis method returns the cancel menu item, when a menu is openedIndicates the command that is defined as the clear command in this form.getCommand(int index) Returns the command occupying the given indexintintReturns number of commandsprotected VectorThis method returns a Vector of Command objectsDefault command is invoked when a user presses fire, this functionality works well in some situations but might collide with elements such as navigation and combo boxes.protected intgetDragRegionStatus(int x, int y) Indicates if the section within the X/Y area is a "drag region" where we expect people to drag or press in which case we can instantly start dragging making perceived performance faster.Returns the Menu Dialog StyleThe selectCommand is the command to invoke when a Component has foucs in Third Soft Button state.protected CommandThis method returns the select menu item, when a menu is openedprotected ContainerReturns the parent Form title areaprotected ComponentGets the Form titleComponentbooleanhandlesKeycode(int keyCode) This method returns true if the MenuBar should handle the given keycode.protected voidinitMenuBar(Form parent) Initialize the MenuBarprotected voidAdds the MenuBar on the parent FormbooleanThis method will return true if the menu dialog is currently displayingbooleanWhen set to true the physical back button will minimize the applicationprotected booleanAllows an individual form to reverse the layout direction of the softbuttons, this method is RTL sensitive and might reverse the result based on RTL statevoidkeyPressed(int keyCode) If this Component is focused, the key pressed event will call this methodvoidkeyReleased(int keyCode) If this Component is focused, the key released event will call this methodvoidrefreshTheme(boolean merge) Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!protected voidRemove all commands from the menuBarprotected voidremoveCommand(Command cmd) Removes a Command from the MenuBarvoidThis method removes empty J2ME softbuttons that don't have a commandvoidsetBackCommand(Command backCommand) Indicates the command that is defined as the back command out of this form.voidsetClearCommand(Command clearCommand) Indicates the command that is defined as the clear command in this form.voidsetCommandUIID(Command cmd, String uiid) Sets the command UIID to the given UIID, notice that this won't work for all menu types since some menu types might be implemented natively or as a list in which case the UIID won't apply!voidsetDefaultCommand(Command defaultCommand) Default command is invoked when a user presses fire, this functionality works well in some situations but might collide with elements such as navigation and combo boxes.voidsetMenuCellRenderer(ListCellRenderer menuCellRenderer) The MenuBar default implementation shows the menu commands in a List contained in a Dialog.voidsetMinimizeOnBack(boolean minimizeOnBack) When set to true the physical back button will minimize the applicationvoidsetSelectCommand(Command selectCommand) Sets the select commandvoidsetTransitions(Transition transitionIn, Transition transitionOut) Sets the menu transitions for showing/hiding the menu, can be null...voidsetUnselectedStyle(Style style) Changes the Component Style by replacing the Component Style with the given StylevoidshowMenu()This method shows the menu on the Form.protected CommandshowMenuDialog(Dialog menu) A menu is implemented as a dialog, this method allows you to override dialog display in order to customize the dialog menu in various waysprotected voidRemoves the MenuBar from the parent FormMethods inherited from class Container
add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndicesMethods inherited from class Component
addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initComponent, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContainsMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
MenuBar
public MenuBar()
-
-
Method Details
-
initMenuBar
Initialize the MenuBar
Parameters
parent: the associated Form
-
removeEmptySoftbuttons
public void removeEmptySoftbuttons()This method removes empty J2ME softbuttons that don't have a command -
getCommandBehavior
public int getCommandBehavior() -
getDefaultCommand
Default command is invoked when a user presses fire, this functionality works well in some situations but might collide with elements such as navigation and combo boxes. Use with caution.
Returns
the command to treat as default
-
setDefaultCommand
Default command is invoked when a user presses fire, this functionality works well in some situations but might collide with elements such as navigation and combo boxes. Use with caution.
Parameters
defaultCommand: the command to treat as default
-
getClearCommand
Indicates the command that is defined as the clear command in this form. A clear command can be used both to map to a "clear" hardware button if such a button exists.
Returns
the command to treat as the clear Command
-
setClearCommand
Indicates the command that is defined as the clear command in this form. A clear command can be used both to map to a "clear" hardware button if such a button exists.
Parameters
clearCommand: the command to treat as the clear Command
-
findCommandComponent
-
getBackCommand
Indicates the command that is defined as the back command out of this form. A back command can be used both to map to a hardware button (e.g. on the Sony Ericsson devices) and by elements such as transitions etc. to change the behavior based on direction (e.g. slide to the left to enter screen and slide to the right to exit with back).
Returns
the command to treat as the back Command
-
setBackCommand
Indicates the command that is defined as the back command out of this form. A back command can be used both to map to a hardware button (e.g. on the Sony Ericsson devices) and by elements such as transitions etc. to change the behavior based on direction (e.g. slide to the left to enter screen and slide to the right to exit with back).
Parameters
backCommand: the command to treat as the back Command
-
getSelectCommand
The selectCommand is the command to invoke when a Component has foucs in Third Soft Button state.
Returns
the select command
-
setSelectCommand
Sets the select command
Parameters
selectCommand
-
actionPerformed
Invoked when a softbutton is pressed- Specified by:
actionPerformedin interfaceActionListener
-
createSoftButton
-
setUnselectedStyle
Changes the Component Style by replacing the Component Style with the given Style
Parameters
style: the component Style object
- Overrides:
setUnselectedStylein classComponent
-
calcPreferredSize
Prevents scaling down of the menu when there is no text on the menu bar- Overrides:
calcPreferredSizein classContainer
-
setTransitions
Sets the menu transitions for showing/hiding the menu, can be null... -
isMenuShowing
public boolean isMenuShowing()This method will return true if the menu dialog is currently displaying
Returns
true of the menu dialog is displaying
-
showMenu
public void showMenu()This method shows the menu on the Form. The method creates a Dialog with the commands and calls showMenuDialog. The method blocks until the user dispose the dialog. -
createBackCommandButton
-
addCommand
Adds a Command to the MenuBar
Parameters
cmd: Command to add
-
getCommand
Returns the command occupying the given index
Parameters
index: offset of the command
Returns
the command at the given index
-
getCommandCount
public int getCommandCount()Returns number of commands
Returns
number of commands
-
addCommand
Add a Command to the MenuBar
Parameters
-
cmd: Command to Add -
index: determines the order of the added commands
-
-
installMenuBar
protected void installMenuBar()Adds the MenuBar on the parent Form -
unInstallMenuBar
protected void unInstallMenuBar()Removes the MenuBar from the parent Form -
removeAllCommands
protected void removeAllCommands()Remove all commands from the menuBar -
removeCommand
Removes a Command from the MenuBar
Parameters
cmd: Command to remove
-
createSelectCommand
Factory method that returns the Form select Command. This Command is used when Display.getInstance().isThirdSoftButton() returns true. This method can be overridden to customize the Command on the Form.
Returns
Command
-
createMenuSelectCommand
Factory method that returns the Form Menu select Command. This method can be overridden to customize the Command on the Form.
Returns
Command
-
createMenuCancelCommand
Factory method that returns the Form Menu cancel Command. This method can be overridden to customize the Command on the Form.
Returns
Command
-
setMenuCellRenderer
The MenuBar default implementation shows the menu commands in a List contained in a Dialog. This method replaces the menu ListCellRenderer of the Menu List.
Parameters
menuCellRenderer
-
getMenuStyle
Returns the Menu Dialog Style
Returns
Menu Dialog Style
-
handlesKeycode
public boolean handlesKeycode(int keyCode) This method returns true if the MenuBar should handle the given keycode.
Parameters
keyCode: to determine if the MenuBar is responsible for.
Returns
- Returns:
- true if the keycode is a MenuBar related keycode such as softkey, back button, clear button, ...
-
keyPressed
public void keyPressed(int keyCode) If this Component is focused, the key pressed event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyPressedin classContainer
-
keyReleased
public void keyReleased(int keyCode) If this Component is focused, the key released event will call this method
Parameters
keyCode: the key code value to indicate a physical key.
- Overrides:
keyReleasedin classContainer
-
refreshTheme
public void refreshTheme(boolean merge) Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!
Parameters
merge: indicates if the current styles should be merged with the new styles
- Overrides:
refreshThemein classContainer
-
showMenuDialog
A menu is implemented as a dialog, this method allows you to override dialog display in order to customize the dialog menu in various ways
Parameters
menu: a dialog containing menu options that can be customized
Returns
- Returns:
- the command selected by the user in the dialog (not menu) Select or Cancel
-
isReverseSoftButtons
protected boolean isReverseSoftButtons()Allows an individual form to reverse the layout direction of the softbuttons, this method is RTL sensitive and might reverse the result based on RTL state
Returns
The value of UIManager.getInstance().getLookAndFeel().isReverseSoftButtons()
-
calculateTouchCommandGridColumns
Calculates the amount of columns to give to the touch commands within the grid
Parameters
grid: @param grid container that will be arranged in the grid containing the components
Returns
an integer representing the touch command grid size
-
setCommandUIID
Sets the command UIID to the given UIID, notice that this won't work for all menu types since some menu types might be implemented natively or as a list in which case the UIID won't apply!
Parameters
-
cmd: the command -
uiid: the uiid for the given command
-
-
createTouchCommandButton
-
createCommandComponent
Creates the component containing the commands within the given vector used for showing the menu dialog, this method calls the createCommandList method by default however it allows more elaborate menu creation.
Parameters
commands: list of command objects
Returns
Component that will result in the parent menu dialog recieving a command event
-
getCommands
This method returns a Vector of Command objects
Returns
Vector of Command objects
-
createCommandList
-
getSelectMenuItem
This method returns the select menu item, when a menu is opened
Returns
select Command
-
getCancelMenuItem
This method returns the cancel menu item, when a menu is opened
Returns
cancel Command
-
isMinimizeOnBack
public boolean isMinimizeOnBack()When set to true the physical back button will minimize the application
Returns
the minimizeOnBack
-
setMinimizeOnBack
public void setMinimizeOnBack(boolean minimizeOnBack) When set to true the physical back button will minimize the application
Parameters
minimizeOnBack: the minimizeOnBack to set
-
getDragRegionStatus
protected int getDragRegionStatus(int x, int y) Indicates if the section within the X/Y area is a "drag region" where we expect people to drag or press in which case we can instantly start dragging making perceived performance faster. This is invoked by the implementation code to optimize drag start behavior
Parameters
-
x: x location for the touch -
y: y location for the touch
Returns
one of the DRAG_REGION_* values
- Overrides:
getDragRegionStatusin classComponent
-
-
getTitleAreaContainer
Returns the parent Form title area
Returns
the title area Container
-
getTitleComponent
Gets the Form titleComponent
Returns
titleComponent
-