com.sun.lwuit
Class MenuBar

java.lang.Object
  extended by com.sun.lwuit.Component
      extended by com.sun.lwuit.Container
          extended by com.sun.lwuit.MenuBar
All Implemented Interfaces:
Animation, ActionListener, StyleListener

public class MenuBar
extends Container
implements ActionListener

This class represents the Form MenuBar. This class is responsible to show the Form Commands and to handle device soft keys, back key, clear key, etc... This class can be overridden and replaced in the LookAndFeel

See Also:
LookAndFeel.setMenuBarClass(java.lang.Class)

Field Summary
 
Fields inherited from class com.sun.lwuit.Component
BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, LEFT, RIGHT, TOP
 
Constructor Summary
MenuBar()
          Empty Constructor
 
Method Summary
 void actionPerformed(ActionEvent evt)
          Invoked when a softbutton is pressed
 void addCommand(Command cmd)
          Adds a Command to the MenuBar
protected  void addCommand(Command cmd, int index)
          Add a Command to the MenuBar
protected  Dimension calcPreferredSize()
          Prevents scaling down of the menu when there is no text on the menu bar
protected  int calculateTouchCommandGridColumns(Container grid)
          Calculates the amount of columns to give to the touch commands within the grid
protected  Component createCommandComponent(java.util.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  List createCommandList(java.util.Vector commands)
          Creates the list component containing the commands within the given vector used for showing the menu dialog
protected  Command createMenuCancelCommand()
          Factory method that returns the Form Menu cancel Command.
protected  Command createMenuSelectCommand()
          Factory method that returns the Form Menu select Command.
protected  Command createSelectCommand()
          Factory method that returns the Form select Command.
protected  Button createSoftButton(java.lang.String uiid)
          Creates a soft button Component
protected  Button createTouchCommandButton(Command c)
          Creates a touch command for use as a touch menu item
 Command getBackCommand()
          Indicates the command that is defined as the back command out of this form.
protected  Command getCancelMenuItem()
          This method returns the cancel menu item, when a menu is opened
 Command getClearCommand()
          Indicates the command that is defined as the clear command in this form.
 Command getCommand(int index)
          Returns the command occupying the given index
 int getCommandCount()
          Returns number of commands
protected  java.util.Vector getCommands()
          This method returns a Vector of Command objects
 Command 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.
 Style getMenuStyle()
          Returns the Menu Dialog Style
 Command getSelectCommand()
          The selectCommand is the command to invoke when a Component has foucs in Third Soft Button state.
protected  Command getSelectMenuItem()
          This method returns the select menu item, when a menu is opened
 boolean handlesKeycode(int keyCode)
          This method returns true if the MenuBar should handle the given keycode.
protected  void initMenuBar(Form parent)
          Initialize the MenuBar
protected  void installMenuBar()
          Adds the MenuBar on the parent Form
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
 void keyPressed(int keyCode)
          If this Component is focused, the key pressed event will call this method
 void keyReleased(int keyCode)
          If this Component is focused, the key released event will call this method
 void refreshTheme()
          Makes sure the component is up to date with the current style object
protected  void removeAllCommands()
          Remove all commands from the menuBar
protected  void removeCommand(Command cmd)
          Removes a Command from the MenuBar
 void setBackCommand(Command backCommand)
          Indicates the command that is defined as the back command out of this form.
 void setClearCommand(Command clearCommand)
          Indicates the command that is defined as the clear command in this form.
 void setDefaultCommand(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.
 void setMenuCellRenderer(ListCellRenderer menuCellRenderer)
          The MenuBar default implementation shows the menu commands in a List contained in a Dialog.
 void setSelectCommand(Command selectCommand)
          Sets the select command
 void setTransitions(Transition transitionIn, Transition transitionOut)
          Sets the menu transitions for showing/hiding the menu, can be null...
 void setUnselectedStyle(Style style)
          Changes the Component Style by replacing the Component Style with the given Style
 void showMenu()
          This method shows the menu on the Form.
protected  Command showMenuDialog(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 ways
protected  void unInstallMenuBar()
          Removes the MenuBar from the parent Form
 
Methods inherited from class com.sun.lwuit.Container
addComponent, addComponent, addComponent, addComponent, animateLayout, animateLayoutAndWait, applyRTL, contains, dragInitiated, drop, findFirstFocusable, flushReplace, getBottomGap, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getScrollIncrement, getSideGap, invalidate, isEnabled, isScrollableX, isScrollableY, layoutContainer, paint, paintBackground, paintGlass, paramString, pointerHover, pointerPressed, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout
 
Methods inherited from class com.sun.lwuit.Component
addFocusListener, animate, calcScrollSize, contains, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, draggingOver, drawDraggedImage, fireClicked, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentForm, getDirtyRegion, getDisabledStyle, getDragImage, getHeight, getLabelForComponent, getName, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getParent, getPreferredH, getPreferredSize, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypes, getPropertyValue, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTensileLength, getUIID, getUnselectedStyle, getWidth, getVisibleBounds, getX, getY, growShrink, handlesInput, hasFocus, initComponent, initCustomStyle, installDefaultPainter, isAlwaysTensile, isDragActivated, isDragAndDropOperation, isDraggable, isDropTarget, isFlatten, isFocusable, isGrabsPointerEvents, isHideInPortrait, isInitialized, isRTL, isScrollable, isScrollVisible, isSelectableInteraction, isSmoothScrolling, isSnapToGrid, isTactileTouch, isTactileTouch, isTensileDragEnabled, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, paintBackgrounds, paintBorder, paintComponent, paintComponent, paintLock, paintLockRelease, paintScrollbars, paintScrollbarX, paintScrollbarY, pointerDragged, pointerDragged, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, removeFocusListener, repaint, repaint, requestFocus, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setDirtyRegion, setDisabledStyle, setDraggable, setDropTarget, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHideInPortrait, setInitialized, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setPreferredH, setPreferredSize, setPreferredW, setPressedStyle, setPropertyValue, setRTL, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTactileTouch, setTensileDragEnabled, setTensileLength, setUIID, setWidth, setVisible, setX, setY, styleChanged, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MenuBar

public MenuBar()
Empty Constructor

Method Detail

initMenuBar

protected void initMenuBar(Form parent)
Initialize the MenuBar

Parameters:
parent - the associated Form

setDefaultCommand

public void setDefaultCommand(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. Use with caution.

Parameters:
defaultCommand - the command to treat as default

getDefaultCommand

public Command 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

setClearCommand

public void setClearCommand(Command clearCommand)
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

getClearCommand

public Command 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

setBackCommand

public void setBackCommand(Command backCommand)
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

getBackCommand

public Command 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

getSelectCommand

public Command getSelectCommand()
The selectCommand is the command to invoke when a Component has foucs in Third Soft Button state.

Returns:
the select command

setSelectCommand

public void setSelectCommand(Command selectCommand)
Sets the select command

Parameters:
selectCommand -

actionPerformed

public void actionPerformed(ActionEvent evt)
Invoked when a softbutton is pressed

Specified by:
actionPerformed in interface ActionListener
Parameters:
evt - event object describing the source of the action as well as its trigger

createSoftButton

protected Button createSoftButton(java.lang.String uiid)
Creates a soft button Component

Returns:
the softbutton component

setUnselectedStyle

public void setUnselectedStyle(Style style)
Description copied from class: Component
Changes the Component Style by replacing the Component Style with the given Style

Overrides:
setUnselectedStyle in class Component
Parameters:
style - the component Style object

calcPreferredSize

protected Dimension calcPreferredSize()
Prevents scaling down of the menu when there is no text on the menu bar

Overrides:
calcPreferredSize in class Container
Returns:
the calculated preferred size based on component content

setTransitions

public void setTransitions(Transition transitionIn,
                           Transition transitionOut)
Sets the menu transitions for showing/hiding the menu, can be null...


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.


addCommand

public void addCommand(Command cmd)
Adds a Command to the MenuBar

Parameters:
cmd - Command to add

getCommand

public Command getCommand(int index)
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

protected void addCommand(Command cmd,
                          int index)
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

protected void removeCommand(Command cmd)
Removes a Command from the MenuBar

Parameters:
cmd - Command to remove

createSelectCommand

protected Command 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

protected 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

protected 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

public void setMenuCellRenderer(ListCellRenderer menuCellRenderer)
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

public Style 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:
true if the keycode is a MenuBar related keycode such as softkey, back button, clear button, ...

keyPressed

public void keyPressed(int keyCode)
Description copied from class: Component
If this Component is focused, the key pressed event will call this method

Overrides:
keyPressed in class Container
Parameters:
keyCode - the key code value to indicate a physical key.

keyReleased

public void keyReleased(int keyCode)
Description copied from class: Component
If this Component is focused, the key released event will call this method

Overrides:
keyReleased in class Container
Parameters:
keyCode - the key code value to indicate a physical key.

refreshTheme

public void refreshTheme()
Description copied from class: Component
Makes sure the component is up to date with the current style object

Overrides:
refreshTheme in class Container

showMenuDialog

protected Command showMenuDialog(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 ways

Parameters:
menu - a dialog containing menu options that can be customized
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

protected int calculateTouchCommandGridColumns(Container grid)
Calculates the amount of columns to give to the touch commands within the grid

Parameters:
grid - container that will be arranged in the grid containing the components
Returns:
an integer representing the touch command grid size

createTouchCommandButton

protected Button createTouchCommandButton(Command c)
Creates a touch command for use as a touch menu item

Parameters:
c - command to map into the returned button
Returns:
a button that would fire the touch command appropriately

createCommandComponent

protected Component createCommandComponent(java.util.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.

Parameters:
commands - list of command objects
Returns:
Component that will result in the parent menu dialog recieving a command event

getCommands

protected java.util.Vector getCommands()
This method returns a Vector of Command objects

Returns:
Vector of Command objects

createCommandList

protected List createCommandList(java.util.Vector commands)
Creates the list component containing the commands within the given vector used for showing the menu dialog

Parameters:
commands - list of command objects
Returns:
List object

getSelectMenuItem

protected Command getSelectMenuItem()
This method returns the select menu item, when a menu is opened

Returns:
select Command

getCancelMenuItem

protected Command getCancelMenuItem()
This method returns the cancel menu item, when a menu is opened

Returns:
cancel Command