public abstract class Menu<O extends OutputManager<?>> extends AbstractContainer<O> implements WidgetWithConfig<MenuConfig>
Menu
client abstract implementation class.Modifier and Type | Class and Description |
---|---|
static class |
Menu.PopupKeyListener
Key listener, intended to show pop-up menu.
|
Modifier and Type | Field and Description |
---|---|
private MenuConfig |
config
Menu attribute container.
|
private java.lang.Runnable |
menuClosed
Executed when a menu item is selected
|
location, mousePtr, nativeInsets, physicalLocation
Constructor and Description |
---|
Menu(WidgetId id,
MenuConfig cfg)
Special constructor used to restore component using given configuration.
|
Modifier and Type | Method and Description |
---|---|
void |
afterConfigUpdate(MenuConfig beforeUpdate)
The method is called after the configuration associated with
the implementor changes.
|
MenuConfig |
config()
Provide access to the attributes stored in the widget.
|
void |
destroy()
Destroy this widget.
|
protected void |
doShowPopup(Widget<O> src,
NativePoint location,
java.lang.Runnable dismissHandler)
The abstract portion of the logic making pop-up menu shown.
|
private MenuItem<O> |
findMenuItem(int accelCode,
AbstractContainer<O> menu)
Find MENU-ITEM by specified accelerator key code in specified MENU (SUB-MENU) recursively.
|
protected void |
focusWorker(boolean direction)
Search for the next or previous focusable widget in the container and
set focus on it.
|
abstract Widget<O> |
getFirstEnabledWidget()
Looks up the very first enabled widget.
|
static Menu<?> |
getMenu(MenuElement<?> mel)
Get menu widget from menu-item or sub-menu.
|
boolean |
hasFocus()
Check if widget has focus.
|
static boolean |
hasMenuFocus(MenuStructure element)
Checks whether the menu of the passed in menu element has focus, i.e.
|
void |
initialize(WidgetId id,
MenuConfig cfg)
Replacement API for the logic which should exist in the widget's c'tor, but the logic
can't be executed as it depends on the widget being registered into the official registry.
|
boolean |
isDisplayed()
Check if widget is displayed.
|
static boolean |
isMenubarElement(Widget<?> item)
Check if this menu-item is right inside MENUBAR (first level)
|
void |
leaveMenu()
Close all opened bodies and remove focus from the menu.
|
protected boolean |
processAccelerator(KeyInput event,
MenuItem<?> m)
Process accelerator event.
|
void |
processKeyAccelerator(KeyInput event)
Processes menu key accelerator event.
|
void |
processKeyEvent(KeyInput event)
Process key event.
|
void |
setDisplayed(boolean displayed)
Set displayed flag of this menu.
|
void |
setMenuClosedHandler(java.lang.Runnable menuClosed)
Sets a handler that will be executed when a menu item is selected.
|
void |
setVisible(boolean visible)
Hide/show widget.
|
void |
showPopup(Widget<O> src,
NativePoint location,
java.lang.Runnable dismissHandler)
Shows this pop-up menu.
|
void |
triggerMenuClosed()
Triggers the menu-closed event handler.
|
add, add, add, addContainerStateListener, addDirectly, belongsTo, checkWidget, childrenLocation, clipping, clipRectangle, copyState, currentFocus, currentFocus, cycleFocus, defaultFocus, detach, dimension, doLayout, draw, dumpCurrentWidgets, dumpWidgets, endSizeChange, findMouseSource, firstFocus, focus, focusTraversable, formatDump, get, getClipRect, getEffectiveScrollableSize, getFocusInt, getIgnoreFocus, getLayout, getScrollableSize, getTabItemList, hasFocusable, height, insets, lastFocus, minimumSize, moveAfterTabItem, moveBeforeTabItem, moveToBottom, moveToBottomInClass, moveToTop, moveToTopInClass, moveToZpos, nextFocus, normalizeZOrder, onWidgetAdded, onWidgetRemoved, prepareWidgets, prevFocus, reflectAncestorChange, reflectLocationChange, remove, removeContainerStateListener, repaint, replace, requestFocus, setFocus, setFocusInt, setHeight, setIgnoreFocus, setInsets, setLayout, setSize, setSize, setTabItemList, setWidth, startSizeChange, triggerContainerStateRedrawEnabled, unrealize, updateSizeWorker, widgets, widgetsAsList, width
_setHidden, _setVisible, activateDirectManipulation, addFocusListener, addKeyListener, afterConfigUpdateBase, ancestor, ancestorId, autoResize, bounds, clear, clearWidget, clipRectangle, clipRectangle, clipWith, copyColors, createMouseHoverAction, deactivateDirectManipulation, debug, disable, displayPhysicalLocation, drawCaret, enable, enclosingFrame, forceCursorOnFocus, forceVisibility, getActualBounds, getAndResetBitmap, getAndSetBitmap, getBitmapCopy, getCachedScreenLocation, getCachedScreenPhysicalLocation, getCustomMousePointer, getDefaultEvent, getEffectiveMousePointer, getId, getLoadedMousePointer, getMenuMouse, getMouseActions, getPortableMouseEventCoordinates, getSelectedText, getState, getTextHeight, getTextHeightNative, getTextWidth, getTextWidth, getTextWidthNative, getTextWidthNative, getVisiblePart, getZOrderClass, hidden, hide, highlighted, ignoreAction, isCurrent, isDirectManipulationCapable, isDirectManipulationRequired, isEnabled, isFocusable, isHeader, isRealized, isRepaintDisabled, isRMBEntrySupported, isScreenLocationCached, isTabStop, isThreeD, isTotallyObscured, isVisible, isVisible, location, manageSystemActions, mouseActions, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, mouseReleased, mouseWheelMoved, moveToBottom, moveToTop, name, navigable, parent, parent, parentObject, parentOrSelf, parentOrSelfObject, physicalBounds, physicalDimension, physicalLocation, postprocessConfig, prepParentLocation, processDirectManipulationEvent, processEvent, processFocusEvent, processKeyListeners, processMnemonic, processMnemonicImpl, processSystemKey, raiseLegacyMouseEvents, refresh, registerWidgetStateListener, repaint, requestSync, resetBitmap, resizeTo, resolveFont, resolvePopupMenuId, resolveTitleFont, screen, screenDimension, screenHeight, screenLocation, screenPhysicalLocation, screenWidth, setBitmap, setCachedScreenLocation, setCachedScreenPhysicalLocation, setEnabled, setHidden, setHighlighted, setLocation, setLocation, setMousePointer, setParent, setPhysicalLocation, setState, show, showPopupMenu, supportsCustomMousePointer, sync, topLevelWindow, toString, translate, window
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addFocusListener, addKeyListener, ancestor, ancestorId, bounds, clearWidget, defaultMousePtr, displayPhysicalLocation, drawCaret, enclosingFrame, enforceDefaultMousePtr, forceCursorOnFocus, forceVisibility, getActualBounds, getCustomMousePointer, getEffectiveMousePointer, getId, getLegacyWidget, getLoadedMousePointer, getMenuMouse, getMouseActions, getSelectedText, getState, getVisiblePart, getZOrderClass, hidden, hide, highlighted, isCurrent, isDirectManipulable, isDroppable, isEnabled, isFocusable, isHeader, isRealized, isRepaintDisabled, isRMBEntrySupported, isTabStop, isThreeD, isTotallyObscured, isVisible, isVisible, location, maySwitchFocus, moveToBottom, moveToTop, name, navigable, parent, parent, parentObject, parentOrSelf, parentOrSelfObject, physicalBounds, physicalDimension, physicalLocation, postprocessConfig, processDirectManipulationEvent, processEvent, processFocusEvent, processKeyListeners, processMnemonic, raiseLegacyMouseEvents, repaint, requestFocus, requestSync, resizeTo, resolvePopupMenuId, screen, screenLocation, screenPhysicalLocation, setEnabled, setHidden, setHighlighted, setLocation, setLocation, setMousePointer, setParent, setPhysicalLocation, setState, show, supportsCustomMousePointer, topLevelWindow, window
private java.lang.Runnable menuClosed
private MenuConfig config
public Menu(WidgetId id, MenuConfig cfg)
id
- The widget's ID.cfg
- Configuration data.public static boolean isMenubarElement(Widget<?> item)
public static boolean hasMenuFocus(MenuStructure element)
element
- A menu element.true
if the menu has focus.public final void showPopup(Widget<O> src, NativePoint location, java.lang.Runnable dismissHandler)
src
- Source widget.location
- The popup location.dismissHandler
- When not null, the runnable instance is executed when the popup menu is dismissed, regardless
whether an item is chosen or not.public static Menu<?> getMenu(MenuElement<?> mel)
public abstract Widget<O> getFirstEnabledWidget()
null
public void initialize(WidgetId id, MenuConfig cfg)
This API is called after the widget is created and added to the registry.
initialize
in interface WidgetWithConfig<MenuConfig>
id
- The widget's ID.cfg
- The config used to initialize this widget.public MenuConfig config()
config
in interface Widget<O extends OutputManager<?>>
config
in interface ConfigOwner<MenuConfig>
config
in class AbstractWidget<O extends OutputManager<?>>
public void afterConfigUpdate(MenuConfig beforeUpdate)
afterConfigUpdate
in interface ConfigOwner<MenuConfig>
beforeUpdate
- public void setDisplayed(boolean displayed)
displayed
- true
means that menu is dropped down,
false
otherwise.public boolean isDisplayed()
isDisplayed
in interface Widget<O extends OutputManager<?>>
isDisplayed
in class AbstractWidget<O extends OutputManager<?>>
true
if widget is displayed.public void setVisible(boolean visible)
If the menu is being shown and not yet attached to a window, attached it to the default window.
setVisible
in interface Widget<O extends OutputManager<?>>
setVisible
in class AbstractWidget<O extends OutputManager<?>>
visible
- New visible state.public boolean hasFocus()
hasFocus
in interface Widget<O extends OutputManager<?>>
hasFocus
in class AbstractWidget<O extends OutputManager<?>>
true
if widget has focus.public void processKeyEvent(KeyInput event)
processKeyEvent
in interface Widget<O extends OutputManager<?>>
processKeyEvent
in class AbstractContainer<O extends OutputManager<?>>
event
- Key event to process.public void processKeyAccelerator(KeyInput event)
event
- The key event.public void leaveMenu()
protected boolean processAccelerator(KeyInput event, MenuItem<?> m)
event
- KeyInput object, related to key event.m
- Target accelerator source menu-item.true
means accelerator was processed.
false
means accelerator was ignored.public void destroy()
destroy
in interface Widget<O extends OutputManager<?>>
destroy
in class AbstractContainer<O extends OutputManager<?>>
public void setMenuClosedHandler(java.lang.Runnable menuClosed)
menuClosed
- May be null
.public void triggerMenuClosed()
protected void focusWorker(boolean direction)
focusWorker
in class AbstractContainer<O extends OutputManager<?>>
direction
- Widget search direction.protected void doShowPopup(Widget<O> src, NativePoint location, java.lang.Runnable dismissHandler)
src
- Source widget.location
- The popup location.dismissHandler
- When not null, the runnable instance is executed when the popup menu is dismissed, regardless
whether an item is chosen or not.private MenuItem<O> findMenuItem(int accelCode, AbstractContainer<O> menu)
accelCode
- Key code of accelerator.menu
- Current menu or sub-menunull