public class MenuBar extends Widget implements PopupListener, HasAnimation, HasCloseHandlers<PopupPanel>
Scheduler.ScheduledCommand
or
open a cascaded menu bar.
MenuBar elements in UiBinder template files can have a vertical
boolean attribute (which defaults to false), and may have only MenuItem
elements as children. MenuItems may contain HTML and MenuBars.
For example:
<g:MenuBar> <g:MenuItem>Higgledy <g:MenuBar vertical="true"> <g:MenuItem>able</g:MenuItem> <g:MenuItem>baker</g:MenuItem> <g:MenuItem>charlie</g:MenuItem> </g:MenuBar> </g:MenuItem> <g:MenuItem>Piggledy <g:MenuBar vertical="true"> <g:MenuItem>foo</g:MenuItem> <g:MenuItem>bar</g:MenuItem> <g:MenuItem>baz</g:MenuItem> </g:MenuBar> </g:MenuItem> <g:MenuItem><b>Pop!</b> <g:MenuBar vertical="true"> <g:MenuItem>uno</g:MenuItem> <g:MenuItem>dos</g:MenuItem> <g:MenuItem>tres</g:MenuItem> </g:MenuBar> </g:MenuItem> </g:MenuBar>
Modifier and Type | Class and Description |
---|---|
static interface |
MenuBar.MenuBarImages
Deprecated.
replaced by
MenuBar.Resources |
static interface |
MenuBar.Resources
A ClientBundle that contains the default resources for this widget.
|
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
DEBUG_ID_PREFIX
Constructor and Description |
---|
MenuBar()
Creates an empty horizontal menu bar.
|
MenuBar(boolean vertical)
Creates an empty menu bar.
|
MenuBar(boolean vertical,
MenuBar.MenuBarImages images)
Deprecated.
replaced by
MenuBar(boolean, Resources) |
MenuBar(boolean vertical,
MenuBar.Resources resources)
Creates an empty menu bar that uses the specified ClientBundle for menu
images.
|
MenuBar(MenuBar.MenuBarImages images)
Deprecated.
replaced by
MenuBar(Resources) |
MenuBar(MenuBar.Resources resources)
Creates an empty horizontal menu bar that uses the specified ClientBundle
for menu images.
|
Modifier and Type | Method and Description |
---|---|
HandlerRegistration |
addCloseHandler(CloseHandler<PopupPanel> handler)
Adds a
CloseEvent handler. |
MenuItem |
addItem(MenuItem item)
Adds a menu item to the bar.
|
MenuItem |
addItem(SafeHtml html,
MenuBar popup)
Adds a menu item to the bar, that will open the specified menu when it is
selected.
|
MenuItem |
addItem(SafeHtml html,
Scheduler.ScheduledCommand cmd)
Adds a menu item to the bar containing SafeHtml, that will fire the given
command when it is selected.
|
MenuItem |
addItem(String text,
boolean asHTML,
MenuBar popup)
Adds a menu item to the bar, that will open the specified menu when it is
selected.
|
MenuItem |
addItem(String text,
boolean asHTML,
Scheduler.ScheduledCommand cmd)
Adds a menu item to the bar, that will fire the given command when it is
selected.
|
MenuItem |
addItem(String text,
MenuBar popup)
Adds a menu item to the bar, that will open the specified menu when it is
selected.
|
MenuItem |
addItem(String text,
Scheduler.ScheduledCommand cmd)
Adds a menu item to the bar, that will fire the given command when it is
selected.
|
MenuItemSeparator |
addSeparator()
|
MenuItemSeparator |
addSeparator(MenuItemSeparator separator)
|
void |
clearItems()
Removes all menu items from this menu bar.
|
void |
closeAllChildren(boolean focus)
Closes this menu and all child menu popups.
|
void |
focus()
Give this MenuBar focus.
|
boolean |
getAutoOpen()
Gets whether this menu bar's child menus will open when the mouse is moved
over it.
|
int |
getItemIndex(MenuItem item)
Get the index of a
MenuItem . |
protected List<MenuItem> |
getItems()
Returns a list containing the
MenuItem objects in the menu
bar. |
protected MenuItem |
getSelectedItem()
Returns the
MenuItem that is currently selected (highlighted)
by the user. |
int |
getSeparatorIndex(MenuItemSeparator item)
Get the index of a
MenuItemSeparator . |
MenuItem |
insertItem(MenuItem item,
int beforeIndex)
Adds a menu item to the bar at a specific index.
|
MenuItemSeparator |
insertSeparator(int beforeIndex)
|
MenuItemSeparator |
insertSeparator(MenuItemSeparator separator,
int beforeIndex)
|
boolean |
isAnimationEnabled()
Returns true if animations are enabled, false if not.
|
boolean |
isFocusOnHoverEnabled()
Check whether or not this widget will steal keyboard focus when the mouse
hovers over it.
|
void |
moveSelectionDown()
Moves the menu selection down to the next item.
|
void |
moveSelectionUp()
Moves the menu selection up to the previous item.
|
void |
onBrowserEvent(Event event)
Fired whenever a browser event is received.
|
protected void |
onDetach()
This method is called when a widget is detached from the browser's
document.
|
protected void |
onEnsureDebugId(String baseID)
Affected Elements:
-item# = the
MenuItem at the specified index.
|
void |
onPopupClosed(PopupPanel sender,
boolean autoClosed)
Deprecated.
Use
addCloseHandler(CloseHandler) instead |
void |
removeItem(MenuItem item)
Removes the specified menu item from the bar.
|
void |
removeSeparator(MenuItemSeparator separator)
Removes the specified
MenuItemSeparator from the bar. |
void |
selectItem(MenuItem item)
Select the given MenuItem, which must be a direct child of this MenuBar.
|
void |
setAnimationEnabled(boolean enable)
Enable or disable animations.
|
void |
setAutoOpen(boolean autoOpen)
Sets whether this menu bar's child menus will open when the mouse is moved
over it.
|
void |
setFocusOnHoverEnabled(boolean enabled)
Enable or disable auto focus when the mouse hovers over the MenuBar.
|
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
fireEvent
public MenuBar()
public MenuBar(boolean vertical)
vertical
- true
to orient the menu bar vertically@Deprecated public MenuBar(boolean vertical, MenuBar.MenuBarImages images)
MenuBar(boolean, Resources)
vertical
- true
to orient the menu bar verticallyimages
- a bundle that provides images for this menupublic MenuBar(boolean vertical, MenuBar.Resources resources)
vertical
- true
to orient the menu bar verticallyresources
- a bundle that provides images for this menu@Deprecated public MenuBar(MenuBar.MenuBarImages images)
MenuBar(Resources)
images
- a bundle that provides images for this menupublic MenuBar(MenuBar.Resources resources)
resources
- a bundle that provides images for this menupublic HandlerRegistration addCloseHandler(CloseHandler<PopupPanel> handler)
HasCloseHandlers
CloseEvent
handler.addCloseHandler
in interface HasCloseHandlers<PopupPanel>
handler
- the handlerpublic MenuItem addItem(MenuItem item)
item
- the item to be addedMenuItem
objectpublic MenuItem addItem(SafeHtml html, Scheduler.ScheduledCommand cmd)
html
- the item's html textcmd
- the command to be firedMenuItem
object createdpublic MenuItem addItem(String text, boolean asHTML, Scheduler.ScheduledCommand cmd)
text
- the item's textasHTML
- true
to treat the specified text as htmlcmd
- the command to be firedMenuItem
object createdpublic MenuItem addItem(SafeHtml html, MenuBar popup)
html
- the item's html textpopup
- the menu to be cascaded from itMenuItem
object createdpublic MenuItem addItem(String text, boolean asHTML, MenuBar popup)
text
- the item's textasHTML
- true
to treat the specified text as htmlpopup
- the menu to be cascaded from itMenuItem
object createdpublic MenuItem addItem(String text, Scheduler.ScheduledCommand cmd)
text
- the item's textcmd
- the command to be firedMenuItem
object createdpublic MenuItem addItem(String text, MenuBar popup)
text
- the item's textpopup
- the menu to be cascaded from itMenuItem
object createdpublic MenuItemSeparator addSeparator()
MenuItemSeparator
object createdpublic MenuItemSeparator addSeparator(MenuItemSeparator separator)
separator
- the MenuItemSeparator
to be addedMenuItemSeparator
objectpublic void clearItems()
public void closeAllChildren(boolean focus)
focus
- true to move focus to the parentpublic void focus()
public boolean getAutoOpen()
true
if child menus will auto-openpublic int getItemIndex(MenuItem item)
MenuItem
.public int getSeparatorIndex(MenuItemSeparator item)
MenuItemSeparator
.public MenuItem insertItem(MenuItem item, int beforeIndex) throws IndexOutOfBoundsException
item
- the item to be insertedbeforeIndex
- the index where the item should be insertedMenuItem
objectIndexOutOfBoundsException
- if beforeIndex
is out of
rangepublic MenuItemSeparator insertSeparator(int beforeIndex)
beforeIndex
- the index where the separator should be insertedMenuItemSeparator
objectIndexOutOfBoundsException
- if beforeIndex
is out of
rangepublic MenuItemSeparator insertSeparator(MenuItemSeparator separator, int beforeIndex) throws IndexOutOfBoundsException
separator
- the MenuItemSeparator
to be insertedbeforeIndex
- the index where the separator should be insertedMenuItemSeparator
objectIndexOutOfBoundsException
- if beforeIndex
is out of
rangepublic boolean isAnimationEnabled()
HasAnimation
isAnimationEnabled
in interface HasAnimation
public boolean isFocusOnHoverEnabled()
public void moveSelectionDown()
public void moveSelectionUp()
public void onBrowserEvent(Event event)
EventListener
onBrowserEvent
in interface EventListener
onBrowserEvent
in class Widget
event
- the event received@Deprecated public void onPopupClosed(PopupPanel sender, boolean autoClosed)
addCloseHandler(CloseHandler)
insteadonPopupClosed
in interface PopupListener
sender
- popup being closed.autoClosed
- true
if the popup was automatically closed;
false
if it was closed programmatically.public void removeItem(MenuItem item)
item
- the item to be removedpublic void removeSeparator(MenuItemSeparator separator)
MenuItemSeparator
from the bar.separator
- the separator to be removedpublic void selectItem(MenuItem item)
item
- the MenuItem to select, or null to clear selectionpublic void setAnimationEnabled(boolean enable)
HasAnimation
setAnimationEnabled
in interface HasAnimation
enable
- true to enable, false to disablepublic void setAutoOpen(boolean autoOpen)
autoOpen
- true
to cause child menus to auto-openpublic void setFocusOnHoverEnabled(boolean enabled)
enabled
- true to enable, false to disableprotected List<MenuItem> getItems()
MenuItem
objects in the menu
bar. If there are no items in the menu bar, then an empty List
object will be returned.MenuItem
objects in the menu barprotected MenuItem getSelectedItem()
MenuItem
that is currently selected (highlighted)
by the user. If none of the items in the menu are currently selected, then
null
will be returned.MenuItem
that is currently selected, or
null
if no items are currently selectedprotected void onDetach()
Widget
This method is called when a widget is detached from the browser's
document. To receive notification before a Widget is removed from the
document, override the Widget.onUnload()
method or use Widget.addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler)
.
It is strongly recommended that you override Widget.onUnload()
or
Widget.doDetachChildren()
instead of this method to avoid inconsistencies
between logical and physical attachment states.
Subclasses that override this method must call
super.onDetach()
to ensure that the Widget has been detached
from the underlying Element. Failure to do so will result in application
memory leaks due to circular references between DOM Elements and JavaScript
objects.
onDetach
in class Widget
Widget.onUnload()
,
Widget.doDetachChildren()
protected void onEnsureDebugId(String baseID)
MenuItem
at the specified index.onEnsureDebugId
in class UIObject
baseID
- the base ID used by the main elementUIObject.onEnsureDebugId(String)
Copyright © 2018. All rights reserved.