Class WPopupMenu
- java.lang.Object
-
- eu.webtoolkit.jwt.WObject
-
- eu.webtoolkit.jwt.WWidget
-
- eu.webtoolkit.jwt.WCompositeWidget
-
- eu.webtoolkit.jwt.WMenu
-
- eu.webtoolkit.jwt.WPopupMenu
-
public class WPopupMenu extends WMenu
A menu presented in a popup window.The menu implements a typical context menu, with support for submenu's. It is a specialized
WMenufrom which it inherits most of the API.When initially created, the menu is invisible, until
popup()or exec() is called. Then, the menu will remain visible until an item is selected, or the user cancels the menu (by hitting Escape or clicking elsewhere).The implementation assumes availability of JavaScript to position the menu at the current mouse position and provide feed-back of the currently selected item.
As with
WDialog, there are two ways of using the menu. The simplest way is to use one of the synchronous exec() methods, which starts a reentrant event loop and waits until the user cancelled the popup menu (by hitting Escape or clicking elsewhere), or selected an item.Alternatively, you can use one of the
popup()methods to show the menu and listen to thetriggered()signal where you read thegetResult(), or associate the menu with a button usingWPushButton#setMenu().You have several options to react to the selection of an item:
- Either you use the
WMenuItemitself to identify the action, perhaps by specialization or simply by binding custom data usingWMenuItem#setData(). - You can bind a separate method to each item's
WMenuItem.triggered()signal.
Usage example:
// Create a menu with some items WPopupMenu popup = new WPopupMenu(); popup.addItem("icons/item1.gif", "Item 1"); popup.addItem("Item 2").setCheckable(true); popup.addItem("Item 3"); popup.addSeparator(); popup.addItem("Item 4"); popup.addSeparator(); popup.addItem("Item 5"); popup.addItem("Item 6"); popup.addSeparator(); WPopupMenu subMenu = new WPopupMenu(); subMenu.addItem("Sub Item 1"); subMenu.addItem("Sub Item 2"); popup.addMenu("Item 7", subMenu); WMenuItem item = popup.exec(event); if (item != null) { // ... do associated action. }A snapshot of the
WPopupMenu:
WPopupMenu example (default)
WPopupMenu example (polished)
- See Also:
WMenuItem
- Either you use the
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWPopupMenu.AutoHideBehaviourEnumeration of auto-hide options.-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
-
Field Summary
-
Fields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS
-
-
Constructor Summary
Constructors Constructor Description WPopupMenu()Creates a new popup menu.WPopupMenu(WStackedWidget contentsStack)Creates a new popup menu.WPopupMenu(WStackedWidget contentsStack, WContainerWidget parentContainer)Creates a new popup menu.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SignalaboutToHide()Signal emitted when the popup is hidden.WMenuItemexec(WMouseEvent e)Executes the the popup at the location of a mouse event.WMenuItemexec(WPoint p)Executes the the popup at a position.WMenuItemexec(WWidget location)Executes the popup besides a widget.WMenuItemexec(WWidget location, Orientation orientation)Executes the popup besides a widget.java.util.EnumSet<Orientation>getAdjust()Returns in which orientations this popup widget can adjust its coordinates on popup.WPopupMenu.AutoHideBehaviourgetAutoHideBehaviour()Returns the auto-hide behaviour.WMenuItemgetResult()Returns the last triggered menu item.booleanisHideOnSelect()Returns whether this popup menu should hide when an item is selected.voidpopup(WMouseEvent e)Shows the the popup at the location of a mouse event.voidpopup(WPoint p)Shows the the popup at a position.voidpopup(WWidget location)Shows the popup besides a widget.voidpopup(WWidget location, Orientation orientation)Shows the popup besides a widget.voidremove()Destructor.protected voidrender(java.util.EnumSet<RenderFlag> flags)Renders the widget.protected voidrenderSelected(WMenuItem item, boolean selected)voidsetAdjust(Orientation adjustOrientation, Orientation... adjustOrientations)Sets in which direction this popup menu can adjust its coordinates on popup.voidsetAdjust(java.util.EnumSet<Orientation> adjustOrientations)Sets in which direction this popup menu can adjust its coordinates on popup.voidsetAutoHide(boolean enabled)Configure auto-hide when the mouse leaves the menu.voidsetAutoHide(boolean enabled, int autoHideDelay)Configure auto-hide when the mouse leaves the menu.voidsetAutoHideBehaviour(WPopupMenu.AutoHideBehaviour behaviour)Configures auto-hide behaviour.voidsetButton(WInteractWidget button)protected voidsetCurrent(int index)voidsetHidden(boolean hidden, WAnimation animation)Hides or shows the widget.voidsetHideOnSelect()Set whether this popup menu should hide when an item is selected.voidsetHideOnSelect(boolean enabled)Set whether this popup menu should hide when an item is selected.voidsetMaximumSize(WLength width, WLength height)Sets a maximum size.voidsetMinimumSize(WLength width, WLength height)Sets a minimum size.Signal1<WMenuItem>triggered()Signal emitted when an item is selected.-
Methods inherited from class eu.webtoolkit.jwt.WMenu
addItem, addItem, addItem, addItem, addItem, addItem, addItem, addMenu, addMenu, addSectionHeader, addSeparator, close, close, getContentsStack, getCount, getCurrentIndex, getCurrentItem, getInternalBasePath, getItems, getParentItem, getUl, indexOf, insertItem, insertItem, insertItem, insertItem, insertItem, insertItem, insertItem, insertMenu, insertMenu, isInternalPathEnabled, isItemDisabled, isItemDisabled, isItemHidden, isItemHidden, itemAt, itemClosed, itemSelected, itemSelectRendered, load, moveItem, moveItem, nextAfterHide, removeItem, select, select, setInternalBasePath, setInternalPathEnabled, setInternalPathEnabled, setItemDisabled, setItemDisabled, setItemHidden, setItemHidden
-
Methods inherited from class eu.webtoolkit.jwt.WCompositeWidget
addStyleClass, boxBorder, boxPadding, callJavaScriptMember, doJavaScript, enableAjax, find, findById, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getId, getImplementation, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getObjectName, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getTakeImplementation, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isEnabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, propagateSetEnabled, propagateSetVisible, refresh, removeStyleClass, removeWidget, resize, scrollVisibilityChanged, setAttributeValue, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFloatSide, setFocus, setHiddenKeepsGeometry, setId, setImplementation, setInline, setJavaScriptMember, setLineHeight, setMargin, setObjectName, setOffsets, setParentWidget, setPopup, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment
-
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, isRendered, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
-
Methods inherited from class eu.webtoolkit.jwt.WObject
setFormData
-
-
-
-
Constructor Detail
-
WPopupMenu
public WPopupMenu(WStackedWidget contentsStack, WContainerWidget parentContainer)
Creates a new popup menu.The menu is hidden, by default, and must be shown using
popup()or exec().
-
WPopupMenu
public WPopupMenu()
Creates a new popup menu.
-
WPopupMenu
public WPopupMenu(WStackedWidget contentsStack)
Creates a new popup menu.
-
-
Method Detail
-
remove
public void remove()
Description copied from class:WMenuDestructor.- Overrides:
removein classWMenu- See Also:
WWidget.removeWidget(WWidget widget)
-
popup
public void popup(WPoint p)
Shows the the popup at a position.Displays the popup at a point with document coordinates
point. The positions intelligent, and will chose one of the four menu corners to correspond to this point so that the popup menu is completely visible within the window.
-
popup
public void popup(WMouseEvent e)
Shows the the popup at the location of a mouse event.This is a convenience method for
popup()that uses the event's document coordinates.- See Also:
popup(WPoint p),WMouseEvent.getDocument()
-
setButton
public void setButton(WInteractWidget button)
-
popup
public void popup(WWidget location, Orientation orientation)
Shows the popup besides a widget.
-
popup
public final void popup(WWidget location)
Shows the popup besides a widget.
-
exec
public WMenuItem exec(WPoint p)
Executes the the popup at a position.Displays the popup at a point with document coordinates
p, usingpopup(), and the waits until a menu item is selected, or the menu is cancelled.Returns the selected menu (or sub-menu) item, or
nullif the user cancelled the menu.- See Also:
popup(WPoint p)
-
exec
public WMenuItem exec(WMouseEvent e)
Executes the the popup at the location of a mouse event.This is a convenience method for
exec()that uses the event's document coordinates.- See Also:
exec(WPoint p)
-
exec
public WMenuItem exec(WWidget location, Orientation orientation)
Executes the popup besides a widget.
-
getResult
public WMenuItem getResult()
Returns the last triggered menu item.The result is
nullwhen the user cancelled the popup menu.
-
setHidden
public void setHidden(boolean hidden, WAnimation animation)Description copied from class:WWidgetHides or shows the widget.Hides or show the widget (including all its descendant widgets). When setting
hidden=false, this widget and all descendant widgets that are not hidden will be shown. A widget is only visible if it and all its ancestors in the widget tree are visible, which may be checked usingisVisible().- Overrides:
setHiddenin classWCompositeWidget
-
setMaximumSize
public void setMaximumSize(WLength width, WLength height)
Description copied from class:WWidgetSets a maximum size.Specifies a maximum size for this widget, setting CSS
max-widthandmax-heightproperties.The default the maximum width and height are
WLength.Auto, indicating no maximum size. ALengthUnit.Percentagesize should not be used, as this is (in virtually all cases) undefined behaviour.When the widget is a container widget that contains a layout manager, then setting a maximum size will have the effect of letting the size of the container to reflect the preferred size of the contents (rather than constraining the size of the children based on the size of the container), up to the specified maximum size.
- Overrides:
setMaximumSizein classWCompositeWidget- See Also:
WWidget.resize(WLength width, WLength height),WWidget.setMinimumSize(WLength width, WLength height)
-
setMinimumSize
public void setMinimumSize(WLength width, WLength height)
Description copied from class:WWidgetSets a minimum size.Specifies a minimum size for this widget, setting CSS
min-widthandmin-heightproperties.The default minimum width and height is 0. The special value
WLength.Autoindicates that the initial width is used as minimum size. ALengthUnit.Percentagesize should not be used, as this is (in virtually all cases) undefined behaviour.When the widget is inserted in a layout manager, then the minimum size will be taken into account.
- Overrides:
setMinimumSizein classWCompositeWidget- See Also:
WWidget.resize(WLength width, WLength height),WWidget.getMinimumWidth(),WWidget.getMinimumHeight()
-
aboutToHide
public Signal aboutToHide()
Signal emitted when the popup is hidden.Unlike the
WMenu.itemSelected()signal,aboutToHide()is only emitted by the toplevel popup menu (and not by submenus), and is also emitted when no item was selected.You can use
getResult()to get the selected item, which may benull.- See Also:
triggered(),WMenu.itemSelected()
-
triggered
public Signal1<WMenuItem> triggered()
Signal emitted when an item is selected.Unlike the
WMenu.itemSelected()signal,triggered()is only emitted by the toplevel popup menu (and not by submenus).- See Also:
aboutToHide(),WMenu.itemSelected()
-
setAutoHide
public void setAutoHide(boolean enabled, int autoHideDelay)Configure auto-hide when the mouse leaves the menu.If
enabled, The popup menu will be hidden when the mouse leaves the menu, its submenus or its parent menu, for longer thanautoHideDelay(milliseconds).It is possible to configure how this affects its submenus and parents menus using
setAutoHideBehaviour().If the top-level menu is automatically hidden, its
getResult()will be anull, as if the user cancelled.By default, this option is disabled.
-
setAutoHide
public final void setAutoHide(boolean enabled)
Configure auto-hide when the mouse leaves the menu.Calls
setAutoHide(enabled, 0)
-
setAutoHideBehaviour
public void setAutoHideBehaviour(WPopupMenu.AutoHideBehaviour behaviour)
Configures auto-hide behaviour.Defines how auto-hide behaves in this popup menu.
This setting can only be set on the top-level popup menu. Setting it on a submenu has no effect.
By default, the behaviour is
HideAllEnabled.
-
getAutoHideBehaviour
public WPopupMenu.AutoHideBehaviour getAutoHideBehaviour()
Returns the auto-hide behaviour.
-
setHideOnSelect
public void setHideOnSelect(boolean enabled)
Set whether this popup menu should hide when an item is selected.Defaults to true.
- See Also:
isHideOnSelect()
-
setHideOnSelect
public final void setHideOnSelect()
Set whether this popup menu should hide when an item is selected.Calls
setHideOnSelect(true)
-
isHideOnSelect
public boolean isHideOnSelect()
Returns whether this popup menu should hide when an item is selected.- See Also:
setHideOnSelect(boolean enabled)
-
setAdjust
public void setAdjust(java.util.EnumSet<Orientation> adjustOrientations)
Sets in which direction this popup menu can adjust its coordinates on popup.This sets in which orientations the popup menu can adjust its position in order to be fully visible in the window, potentially hiding the widget (or point) from which it popped up. @see WWidget#positionAt(WWidget widget, Orientation orientation, EnumSet adjustOrientations)
By default, it can adjust in both orientations.
-
setAdjust
public final void setAdjust(Orientation adjustOrientation, Orientation... adjustOrientations)
Sets in which direction this popup menu can adjust its coordinates on popup.Calls
setAdjust(EnumSet.of(adjustOrientation, adjustOrientations))
-
getAdjust
public java.util.EnumSet<Orientation> getAdjust()
Returns in which orientations this popup widget can adjust its coordinates on popup.- See Also:
setAdjust(EnumSet adjustOrientations)
-
renderSelected
protected void renderSelected(WMenuItem item, boolean selected)
- Overrides:
renderSelectedin classWMenu
-
setCurrent
protected void setCurrent(int index)
- Overrides:
setCurrentin classWMenu
-
render
protected void render(java.util.EnumSet<RenderFlag> flags)
Description copied from class:WWidgetRenders the widget.This function renders the widget (or an update for the widget), after this has been scheduled using
scheduleRender().The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
-
-