danger.ui
Class BaseMenuWindow

java.lang.Object
  extended by danger.app.Listener
      extended by danger.ui.View
          extended by danger.ui.Container
              extended by danger.ui.Window
                  extended by danger.ui.BaseMenuWindow
All Implemented Interfaces:
ToolTipOwner
Direct Known Subclasses:
MenuWindow


public abstract class BaseMenuWindow
extends Window
implements ToolTipOwner

Base window type for the window that gets displayed for menus.


Field Summary
protected  MenuItem mAutoSelectItem
          Deprecated. Use setAutoSelectItem(danger.ui.MenuItem) and getAutoSelectItem() instead.
 
Fields inherited from class danger.ui.Window
mBusyPaintCount, mDefaultListener, STATE_AUTO_HIDE_IF_IDLE, STATE_DROP_ORPHANED_EVENTS, STATE_FULLSCREEN, STATE_UNUSED1
 
Fields inherited from class danger.ui.View
DEFAULT_SCROLL_FOCUS_MARGIN, FOCUS_DEFAULT, FOCUS_DOWNWARD, FOCUS_LEFTWARD, FOCUS_NONE, FOCUS_RIGHTWARD, FOCUS_UPWARD, mOriginX, mOriginY, mStyle, POSITION_ABOVE, POSITION_ALIGN_BASELINE, POSITION_ALIGN_BOTTOM, POSITION_ALIGN_HORIZONTALLY, POSITION_ALIGN_LEFT, POSITION_ALIGN_PARENT_BOTTOM, POSITION_ALIGN_PARENT_RIGHT, POSITION_ALIGN_RIGHT, POSITION_ALIGN_TOP, POSITION_ALIGN_VERTICALLY, POSITION_BELOW, POSITION_CENTER_HORIZONTALLY, POSITION_CENTER_VERTICALLY, POSITION_TO_LEFT, POSITION_TO_RIGHT, PREFER_DIRECTION_NONE, PREFER_HORIZONTAL_DIRECTION, PREFER_VERTICAL_DIRECTION, STATE_AT_AND_SPACE_PAGE, STATE_CAN_FOCUS, STATE_DEBUG_BOUNDS, STATE_ENABLED, STATE_FOCUSED, STATE_MAKE_DING, STATE_PARTIAL_FOCUS_OK, STATE_TRANSPARENT, STATE_VISIBLE, WIDTH_FILL_TO_RIGHT
 
Constructor Summary
BaseMenuWindow(BaseMenu inParentMenu)
          Create an instance.
 
Method Summary
protected  void advanceHilite(int count)
          Advance the selection by count menu items.
protected  void autoHide()
           
 boolean blocksChooser()
          Whether the window blocks from going to the chooser Some applications, such as security/passcode lock and registration block from going to the chooser when the JUMP button is pressed.
protected  void calcShortMenuHeight()
          Calculate the height of the menu window when it is displaying the bottommost menu items.
protected  void completelyCloseMenu()
          Close the menu window and any parent menu windows, as well.
protected  void drawMenuItem(Pen p, int left, int top, int right, int bottom, MenuItem item, int offset, boolean inEnabled, boolean inSelected)
          Draw the specified menu item, including text, shortcut, bitmap, etc.
protected  void drawMenuText(MenuItem item, CharSequence title, Pen p, int x, int y, int width, boolean selected)
          Draw the text of the specified menu item.
protected  void drawMenuText(MenuItem item, Pen p, int x, int y, int width, boolean selected)
          Draw the text of the specified menu item.
 void drawOpenMenuContents(Pen p, int width, int height)
          Draw the contents of the menu window.
 void drawOpenMenuFrame(Pen p, int width, int height)
          Draw the frame of the menu window.
 boolean eventKeyDown(char inChar, Event event)
          This method is called when the user presses a key.
 boolean eventKeyUp(char inChar, Event event)
          Processes key releases directed at this container.
 boolean eventShortcut(char shortcut, Event event)
          Handle a shortcut key.
 boolean eventWidgetDown(int inWhichWidget, Event event)
          Handle a button down event.
 boolean eventWidgetUp(int inWhichWidget, Event event)
          Handle the release of a device widget
protected  MenuItem getAutoSelectItem()
          Get the item to select when first displaying the menu.
protected  int getMaxHeight()
          Get the maximum height this menu window can be.
 BaseMenu getParentMenu()
          Returns the parent menu, as specified by setParentMenu(danger.ui.BaseMenu) or BaseMenuWindow(BaseMenu).
protected  MenuItem getSelectedItem()
          Get the currently selected menu item.
protected  int getTitleHeight()
          Get the height of the menu title.
 boolean getWrap()
          Determine whether menu items are wrapped, as specified by setWrap(boolean).
protected  void hideActiveMenu(boolean onlyIfOrphaned)
           
protected  void onHide()
          This method is called when this view is hidden, via the method View.hide().
protected  void onSelectionChanged()
          This method is called whenever the selection has changed to a different menu item.
protected  void onSelectionRectChanged()
          This method is called when the selection rect (the currently focused menu item) might have changed.
protected  void onShow()
          This method is called when this view is shown, via the method View.show().
protected  void pageDown()
           
protected  void pageUp()
           
 void paint(Pen p)
          Draw the contents of this View.
 boolean receiveEvent(Event event)
          Entry point for event processing.
protected  void reverseHilite(int count)
          Reverse the selection by count menu items.
 void setAlwaysSendEvents(boolean alwaysSendEvents)
          Specify that menu item events should always be sent when a menu item is executed.
protected  void setAutoSelectItem(MenuItem item)
          Specify the menu item to select when first displaying the menu window.
 void setEnablePrefixHilite(boolean inEnablePrefixHilite)
          Enable prefix highlighting.
 void setParentMenu(BaseMenu inParentMenu)
          Specify the parent menu, which determines what is displayed in the window.
protected  void setSelection(int selection)
          Select the specified menu item.
 void setWrap(boolean wrap)
          Specify whether to wrap the menu items.
 void show()
          Mark this view visible.
 void showToolTip()
          This method should be implemented to actually display the tool tip, probably via a call to ToolTipWindow.showToolTip(danger.ui.MenuItem, int, int, int, danger.ui.Window).
protected  void updateFirstVisibleEntry()
          Update which menu item is the topmost visible item on the screen.
 
Methods inherited from class danger.ui.Window
adjustActionMenuState, advanceFocus, autoHideIfIdle, autoHideIfIdle, blocksBackButton, blocksFloatingControls, blocksKeyGuard, blocksVolumeButtons, centerHorizontal, centerOnScreen, centerUnderTitleBar, centerVertical, disableControlWithID, dropOrphanedEvents, enableControlWithID, forwardQueuedEvents, getApplication, getDefaultFocus, getDescendantWithID, getIDOfChild, getListener, getTitle, getTitleSequence, getWindowBelow, hide, hideControlWithID, incrementMaxChildID, isActionMenuVisible, isFullScreen, isUnresponsive, onActivate, onDeactivate, onPeriodicPulse, onWindowPaint, receiveMessage, reverseFocus, setDefaultFocus, setDefaultListener, setEventArgForControlWithID, setEventForControlWithID, setFullScreen, setMaxChildID, setMaxControlID, setPosition, setSize, setTitle, setTitle, setTitled, setTitleFormatDate, setTitleFormatText, setTitleFormatText, setTitleFormatText, setTitleFormatText, setTitleFormatText, shouldDropEvent, showControlWithID, startQueueingEvents, wantsEndButton, wantsSendButton, willPassEventToWindow
 
Methods inherited from class danger.ui.Container
addChild, addChild, addChildAt, addChildAt, addFromContainerResource, addFromContainerResource, addFromContainerResource, addFromDialogResource, addFromDialogResource, advanceFocusInWindow, childCount, childIsOnScreen, disable, enable, eventKeyHeld, eventKeyRepeat, eventPeriodicPulse, eventRawKeyDown, eventRawKeyHeld, eventRawKeyRepeat, eventRawKeyUp, eventWidgetHeld, focusedDescendantIsValid, getBottomChild, getBottomChild, getChildAt, getChildIndex, getChildWithID, getControlWithID, getFirstChild, getFirstFocusableChild, getFocusableChildInWindow, getFocusedChild, getFocusedLeaf, getInterestingRect, getLastChild, getLastFocusableChild, getLeftMostChild, getNextFocusableChild, getNextFocusableChild, getPageHeight, getPrevFocusableChild, getPrevFocusableChild, getRightMostChild, getRightMostChild, handleButtonShortcut, hideAllChildren, isDescendant, keepRectInView, loseFocus, moveChildToIndex, onChildPositionChanged, onChildSizeChanged, onChildVisibilityChanged, pageToEnd, pageToHome, paintChildren, reflowChildren, removeAllChildren, removeChild, setFocusedChild, setFocusedChild, setFocusedChild, setFocusedDescendant, setFocusedDescendant, setFocusedDescendant, setFocusToFirstDescendant, setFormatDateForControlWithID, setFormatDateForTextControlWithID, setFormatTextForControlWithID, setFormatTextForControlWithID, setFormatTextForControlWithID, setFormatTextForControlWithID, setFormatTextForControlWithID, setFormatTextForTextControlWithID, setFormatTextForTextControlWithID, setFormatTextForTextControlWithID, setFormatTextForTextControlWithID, setFormatTextForTextControlWithID, setListenerForAllControls, setReflowAdjustHeight, setWindow, showAllChildren, snapHeightToChildren, snapHeightToChildren, snapToChildren, snapWidthToChildren, snapWidthToChildren, takeFocus, willFocusWithin, willFocusWithin
 
Methods inherited from class danger.ui.View
boundsIntersect, boundsIntersect, canLoseFocus, clear, clear, copyStyle, getAcceptFocus, getBackgroundColor, getBottom, getBounds, getBounds, getFocusTraversalDirection, getFocusTraversalFrom, getFocusTraversalPolicy, getFrame, getFrame, getGlobalBottom, getGlobalLeft, getGlobalRight, getGlobalTop, getHeight, getID, getInterestingRect, getLabelFont, getLabelFont, getLeft, getOrigin, getOrigin, getOriginX, getOriginY, getParent, getParentContainer, getPartialFocusOK, getRight, getScrollFocusMargin, getSibling, getState, getStyle, getStyleColor, getStyleFont, getTop, getWidth, getWindow, globalToLocal, globalToLocalH, globalToLocalV, invalidate, invalidate, invalidate, invalidateIndependentOfOrigin, invalidateIndependentOfOrigin, isEnabled, isFocusable, isFocused, isOnScreen, isTransparent, isVisible, isVisibleInHierarchy, isVisibleOnScreen, justSetVisible, localToGlobal, localToGlobal, localToGlobalH, localToGlobalV, localToWindow, moveBy, notifyWhenParentSizeChanges, notifyWhenPositionChanges, notifyWhenSizeChanges, offsetOrigin, offsetOrigin, onAddedToParent, onDecoded, onEnabledStateChanged, onPositionChanged, onRemovedFromParent, onShortcut, onShortcut, onShortcutConsumed, onSizeChanged, onStyleChanged, onViewPositionChanged, onViewSizeChanged, playLimitSound, receiveEventInternal, resetOrigin, sendEventToWindow, setAcceptFocus, setAtAndSpacePage, setBackground, setBackgroundColor, setBottom, setDebugBounds, setDynamicPosition, setDynamicWidth, setEnabled, setFocusTraversalDirection, setFocusTraversalFrom, setFocusTraversalPolicy, setFrame, setHeight, setKeyedValue, setLabelFont, setLeft, setMakeLimitNoise, setOrigin, setOrigin, setPartialFocusOK, setPreferredDirection, setRight, setScrollFocusMargin, setStyle, setStyleColor, setStyleFont, setStyleFrameColor, setTop, setTransparent, setVisible, setWidth, showContextMenu, styleIsDefault, swapStyleColors, windowToLocal
 
Methods inherited from class danger.app.Listener
cancelEvents, childEventPump, childEventPumpDone, eventProblem, isDispatchingThread, sendEvent, sendEvent, sendEvent, sendEvent, sendEvent, sendLowPriorityEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mAutoSelectItem

protected MenuItem mAutoSelectItem
Deprecated. Use setAutoSelectItem(danger.ui.MenuItem) and getAutoSelectItem() instead.
Constructor Detail

BaseMenuWindow

public BaseMenuWindow(BaseMenu inParentMenu)
Create an instance. The window populates the menu based on the parent menu.

Method Detail

onShow

protected void onShow()
Description copied from class: View
This method is called when this view is shown, via the method View.show(). It is called as the very last thing done by that method, and it is only ever called if the view was not already visible. Overriding this method is the recommended way to get special behavior when a view gets shown. The implementation in this class does nothin.

Overrides:
onShow in class View

setWrap

public void setWrap(boolean wrap)
Specify whether to wrap the menu items. By default, menu items are not wrapped, and are allocated a single line each. If menu items are wrapped, they may span multiple lines.

Since:
2.3

getWrap

public boolean getWrap()
Determine whether menu items are wrapped, as specified by setWrap(boolean).

Since:
2.3

setParentMenu

public void setParentMenu(BaseMenu inParentMenu)
Specify the parent menu, which determines what is displayed in the window. This should be called if the default constructor is used.


getParentMenu

public BaseMenu getParentMenu()
Returns the parent menu, as specified by setParentMenu(danger.ui.BaseMenu) or BaseMenuWindow(BaseMenu).


show

public void show()
Description copied from class: View
Mark this view visible. It will only be displayed if its parent is also displayed, or if it is a Window. If this view was not already visible, this method will call View.onShow() as the last thing it does before returning. If you wish to have special behavior when a view becomes visible, it is recommended that you override that method. In a future revision of the library, it is likely that this method will be final.

Overrides:
show in class Window

paint

public void paint(Pen p)
Description copied from class: View
Draw the contents of this View. This method is called by the graphics system when the View needs to be repainted. A Pen will be provided which is appropriately clipped and translated for drawing on this View.

The implementation of this method in this class will merely call clear() pen, if this View is opaque (not transparent), and will do nothing otherwise. If you don't need this behavior, then there is no point in calling super.paint() in an overriding method.

Overrides:
paint in class Container
Parameters:
p - non-null; the pen to use for drawing operations

onHide

protected void onHide()
Description copied from class: View
This method is called when this view is hidden, via the method View.hide(). It is called as the very last thing done by that method, and it is only ever called if the view was not already hidden. Overriding this method is the recommended way to get special behavior when a view gets hidden . The implementation in this class does nothin.

Overrides:
onHide in class View

drawOpenMenuFrame

public void drawOpenMenuFrame(Pen p,
                              int width,
                              int height)
Draw the frame of the menu window. This method is called automatically in paint(danger.ui.Pen).


onSelectionRectChanged

protected void onSelectionRectChanged()
This method is called when the selection rect (the currently focused menu item) might have changed.


drawMenuText

protected void drawMenuText(MenuItem item,
                            Pen p,
                            int x,
                            int y,
                            int width,
                            boolean selected)
Draw the text of the specified menu item.

Parameters:
item - the menu item to draw
p - the pen to use to draw the menu item
x - the x coordinate of the menu item text
y - the x coordinate of the menu item text
width - the width of the menu item text
selected - whether the menu item is currently selected

drawMenuText

protected void drawMenuText(MenuItem item,
                            CharSequence title,
                            Pen p,
                            int x,
                            int y,
                            int width,
                            boolean selected)
Draw the text of the specified menu item.

Parameters:
item - the menu item to draw
title - the text of the menu item to draw
p - the pen to use to draw the menu item
x - the x coordinate of the menu item text
y - the x coordinate of the menu item text
width - the width of the menu item text
selected - whether the menu item is currently selected

drawMenuItem

protected void drawMenuItem(Pen p,
                            int left,
                            int top,
                            int right,
                            int bottom,
                            MenuItem item,
                            int offset,
                            boolean inEnabled,
                            boolean inSelected)
Draw the specified menu item, including text, shortcut, bitmap, etc.

Parameters:
p - the pen to use to draw the menu item
left - the left coordinate of the menu item to draw
top - the top coordinate of the menu item to draw
right - the right coordinate of the menu item to draw
bottom - the bottom coordinate of the menu item to draw
item - the menu item to draw
offset - horizontal offset of the menu item bitmap
inEnabled - whether the menu item is enabled
inSelected - whether the menu item is currently selected

updateFirstVisibleEntry

protected void updateFirstVisibleEntry()
Update which menu item is the topmost visible item on the screen. This method is called automatically when necessary.


getTitleHeight

protected int getTitleHeight()
Get the height of the menu title. Returns 0 if there is no visible menu title.


drawOpenMenuContents

public void drawOpenMenuContents(Pen p,
                                 int width,
                                 int height)
Draw the contents of the menu window. This method is called automatically in paint(danger.ui.Pen).


getMaxHeight

protected int getMaxHeight()
Get the maximum height this menu window can be. If the menu window is to be centered in the parent window, then this method return the height of the parent window. Otherwise, it returns the height of the screen.


calcShortMenuHeight

protected void calcShortMenuHeight()
Calculate the height of the menu window when it is displaying the bottommost menu items. Implementations of BaseMenuWindow need to call this method.


receiveEvent

public boolean receiveEvent(Event event)
Description copied from class: Listener
Entry point for event processing. This method is called from a Dispatcher when it reads an Event in its queue that is targetted at this instance. The default behavior is to do nothing and return false. Subclasses are expected to override this method to do something more useful.

Overrides:
receiveEvent in class Container
Parameters:
event - non-null; the event to process
Returns:
whether (true) or not (false) this method actually handled the event to completion

eventWidgetDown

public boolean eventWidgetDown(int inWhichWidget,
                               Event event)
Description copied from class: Window
Handle a button down event.

Overrides:
eventWidgetDown in class Window
Parameters:
inWhichWidget - the widget that went up
Returns:
whether or not the event was consumed

eventWidgetUp

public boolean eventWidgetUp(int inWhichWidget,
                             Event event)
Description copied from class: Container
Handle the release of a device widget

Overrides:
eventWidgetUp in class Window
Parameters:
inWhichWidget - the widget that went down
Returns:
whether or not the event was consumed

eventKeyDown

public boolean eventKeyDown(char inChar,
                            Event event)
Description copied from class: View
This method is called when the user presses a key. The default implementation turns space and @ into page-down and page-up events if you have View.setAtAndSpacePage(boolean).

Overrides:
eventKeyDown in class Container

eventKeyUp

public boolean eventKeyUp(char inChar,
                          Event event)
Description copied from class: Container
Processes key releases directed at this container.

Overrides:
eventKeyUp in class Container
Parameters:
inChar - the character being released.

eventShortcut

public boolean eventShortcut(char shortcut,
                             Event event)
Description copied from class: View
Handle a shortcut key. Returns true if the shortcut was handled. Override this method if you want to handle this event yourself. event is currently always null. However, in a future release the actual event will be included so you can determine which modifier keys were held. The default View.eventShortcut handles the MENU+WHEEL shortcut for context menus. See ScreenWindow, DialogWindow, BaseMenuWindow.

Overrides:
eventShortcut in class Container
Parameters:
shortcut - the key that was pressed
event - the event associated with the key press
Returns:
true if the shortcut was handled

setEnablePrefixHilite

public final void setEnablePrefixHilite(boolean inEnablePrefixHilite)
Enable prefix highlighting. If enabled, users can type characters to quickly select menu items (this is different than menu shortcuts, which actually execute the the menu items). By default, prefix highlighting is disabled.


autoHide

protected void autoHide()
Overrides:
autoHide in class Window

pageUp

protected void pageUp()

pageDown

protected void pageDown()

advanceHilite

protected void advanceHilite(int count)
Advance the selection by count menu items.


reverseHilite

protected void reverseHilite(int count)
Reverse the selection by count menu items.


setSelection

protected void setSelection(int selection)
Select the specified menu item. selection is a 0-based index into the menu.


getSelectedItem

protected MenuItem getSelectedItem()
Get the currently selected menu item.


completelyCloseMenu

protected void completelyCloseMenu()
Close the menu window and any parent menu windows, as well.


onSelectionChanged

protected void onSelectionChanged()
This method is called whenever the selection has changed to a different menu item.


setAlwaysSendEvents

public void setAlwaysSendEvents(boolean alwaysSendEvents)
Specify that menu item events should always be sent when a menu item is executed. If disabled, then menu item events are only sent if the selection has changed. This method may be of use if you are using a PopupMenu and do not wish to receive an event if the user views the menu but does not change the selection. By default, this is enabled.


blocksChooser

public boolean blocksChooser()
Description copied from class: Window
Whether the window blocks from going to the chooser Some applications, such as security/passcode lock and registration block from going to the chooser when the JUMP button is pressed.

Overrides:
blocksChooser in class Window
Returns:
A boolean containing true if the application blocks the chooser.

hideActiveMenu

protected final void hideActiveMenu(boolean onlyIfOrphaned)
Overrides:
hideActiveMenu in class Window

setAutoSelectItem

protected void setAutoSelectItem(MenuItem item)
Specify the menu item to select when first displaying the menu window. If null (the default), then the topmost menu item is the first one selected.


getAutoSelectItem

protected final MenuItem getAutoSelectItem()
Get the item to select when first displaying the menu.

See Also:
setAutoSelectItem(danger.ui.MenuItem)

showToolTip

public void showToolTip()
Description copied from interface: ToolTipOwner
This method should be implemented to actually display the tool tip, probably via a call to ToolTipWindow.showToolTip(danger.ui.MenuItem, int, int, int, danger.ui.Window).

Specified by:
showToolTip in interface ToolTipOwner