public interface PopupMenuBuilder
A builder interface for creating popup menus.
Using the methods defined in this interface arbitrary complex popup menus can
be created. A popup menu consists of an arbitrary number of
objects plus optional separators and sub
menus. The basic usage pattern is to invoke the several FormAction
add()
methods for defining the menu's content. Finally the create()
method must be called, which will actually create the menu.
This interface provides a platform-independent view on popup menus. There will be concrete implementations for the GUI libraries supported. These implementations take care of creating the correct, platform-specific menu objects.
As is common practice for builder-like structures this interface supports method chaining, i.e. most methods return a reference to the builder itself, which can be used for immediately adding the next element. The following example fragment shows how a popup menu with some items and a sub menu can be constructed. It assumes that the references to the actions involved are defined somewhere else:
PopupMenuBuilder builder = ... // obtain the builder Object popup = builder .addAction(actionOpen) .addAction(actionSave) .addAction(actionSaveAs) .addSeparator() .addSubMenu(builder.subMenuBuilder(tiMenuEdit) .addAction(actionCopy) .addAction(actionCut) .addAction(actionPaste) .create()) .addSeparator() .addAction(actionExit) .create();
Modifier and Type | Method and Description |
---|---|
PopupMenuBuilder |
addAction(FormAction action)
Adds an action to the current menu.
|
PopupMenuBuilder |
addSeparator()
Adds a separator to the current menu.
|
PopupMenuBuilder |
addSubMenu(Object subMenu)
Adds a sub menu to the current menu.
|
Object |
create()
Creates the menu and returns a reference to it.
|
PopupMenuBuilder |
subMenuBuilder(ActionData menuDesc)
Returns a builder for creating a sub menu.
|
PopupMenuBuilder addAction(FormAction action)
action
- the action to be added (must not be null)IllegalArgumentException
- if the action is nullPopupMenuBuilder addSeparator()
PopupMenuBuilder addSubMenu(Object subMenu)
subMenu
- the sub menu to add (must not be null)IllegalArgumentException
- if the sub menu is nullsubMenuBuilder(ActionData)
PopupMenuBuilder subMenuBuilder(ActionData menuDesc)
create()
method
returns the menu created. The passed in ActionData
object
contains the definition of the menu as it will be displayed in the parent
menu (i.e. its text, icon, etc.).menuDesc
- an ActionData
object with the properties of
the sub menu (must not be null)IllegalArgumentException
- if the menu description is nullObject create()
Copyright © 2016 The JGUIraffe Team. All rights reserved.