public class ActionContainerFactory extends Object
For a menu or submenu, the first element in the action-list represents a menu and subsequent elements represent menu items or separators (if null).
This class can be used as a general component factory which will construct
components from Actions if the create<comp>(Action,...)
methods are used.
ActionManager
Modifier and Type | Field and Description |
---|---|
private Map<Integer,ButtonGroup> |
groupMap |
private ActionMap |
manager |
private static Insets |
TOOLBAR_BUTTON_MARGIN
Standard margin for toolbar buttons to improve their look
|
Constructor and Description |
---|
ActionContainerFactory()
Constructs an container factory which uses the default
ActionManager.
|
ActionContainerFactory(ActionMap manager)
Constructs an container factory which uses managed actions.
|
Modifier and Type | Method and Description |
---|---|
void |
configureButton(JToggleButton button,
AbstractActionExt a,
ButtonGroup group) |
protected void |
configureButtonFromExtActionProperties(AbstractButton button,
Action action)
This method will be called after buttons created from an action.
|
protected void |
configureMenuItemFromExtActionProperties(JMenuItem menuItem,
Action action)
This method will be called after menu items are created.
|
void |
configureSelectableButton(AbstractButton button,
AbstractActionExt a,
ButtonGroup group)
method to configure a "selectable" button from the given AbstractActionExt.
|
AbstractButton |
createButton(Action action)
Creates a button based on the attributes of the action.
|
AbstractButton |
createButton(Action action,
JComponent container)
Creates a button based on the attributes of the action.
|
AbstractButton |
createButton(Object id,
JComponent container)
Creates, configures and returns an AbstractButton.
|
private JCheckBoxMenuItem |
createCheckBoxMenuItem(AbstractActionExt a)
Helper method to add a checkbox menu item.
|
JMenu |
createMenu(List<?> list)
Creates and returns a menu from a List which represents actions, separators
and sub-menus.
|
JMenu |
createMenu(Object[] actionIds)
Creates and returns a menu from a List which represents actions, separators
and sub-menus.
|
JMenuBar |
createMenuBar(List<?> list)
Constructs a menu tree from a list of actions or lists of lists or actions.
|
JMenuBar |
createMenuBar(Object[] actionIds)
Constructs a menu tree from a list of actions or lists of lists or actions.
|
JMenuItem |
createMenuItem(Action action)
Creates a menu item based on the attributes of the action.
|
private JMenuItem |
createMenuItem(Action action,
JComponent container)
Creates a menu item based on the attributes of the action element.
|
private JMenuItem |
createMenuItem(Object id,
JComponent container)
Creates a menu item based on the attributes of the action element.
|
JPopupMenu |
createPopup(List<?> list)
Constructs a popup menu from a list of action ids.
|
JPopupMenu |
createPopup(Object[] list)
Constructs a popup menu from an array of action ids.
|
private JRadioButtonMenuItem |
createRadioButtonMenuItem(ButtonGroup group,
AbstractActionExt a)
Helper method to add a radio button menu item.
|
private JToggleButton |
createToggleButton(AbstractActionExt a)
Adds and configures a toggle button.
|
private JToggleButton |
createToggleButton(AbstractActionExt a,
ButtonGroup group)
Adds and configures a toggle button.
|
JToolBar |
createToolBar(List<?> list)
Constructs a toolbar from an action-list id.
|
JToolBar |
createToolBar(Object[] list)
Constructs a toolbar from an action-list id.
|
private Action |
getAction(Object id)
Convenience method to get the action from an ActionManager.
|
ActionMap |
getActionManager()
Gets the ActionManager instance.
|
private ButtonGroup |
getGroup(String groupid,
JComponent container)
Returns the button group corresponding to the groupid
|
void |
setActionManager(ActionMap manager)
Sets the ActionManager instance that will be used by this
ActionContainerFactory
|
private static Insets TOOLBAR_BUTTON_MARGIN
private Map<Integer,ButtonGroup> groupMap
public ActionContainerFactory()
public ActionContainerFactory(ActionMap manager)
manager
- use the actions managed with this manager for
constructing ui componenents.public ActionMap getActionManager()
setActionManager(javax.swing.ActionMap)
public void setActionManager(ActionMap manager)
public JToolBar createToolBar(Object[] list)
list
- a list of action ids used to construct the toolbar.public JToolBar createToolBar(List<?> list)
list
- a list of action ids used to construct the toolbar.public JPopupMenu createPopup(Object[] list)
list
- an array of action ids used to construct the popup.public JPopupMenu createPopup(List<?> list)
list
- a list of action ids used to construct the popup.public JMenuBar createMenuBar(Object[] actionIds)
actionIds
- an array which represents the root item.public JMenuBar createMenuBar(List<?> list)
list
- a list which represents the root item.public JMenu createMenu(Object[] actionIds)
actionIds
- an array of action ids used to construct the menu and menu items.
the first element represents the action used for the menu,public JMenu createMenu(List<?> list)
list
- a list of action ids used to construct the menu and menu items.
the first element represents the action used for the menu,private Action getAction(Object id)
private ButtonGroup getGroup(String groupid, JComponent container)
groupid
- the value of the groupid attribute for the action elementcontainer
- a container which will further identify the ButtonGroupprivate JMenuItem createMenuItem(Object id, JComponent container)
private JMenuItem createMenuItem(Action action, JComponent container)
action
- a managed Actioncontainer
- the parent container may be null for non-group actions.public JMenuItem createMenuItem(Action action)
action
- an action used to create the menu itempublic AbstractButton createButton(Object id, JComponent container)
id
- the identifiercontainer
- the JComponent which parents the group, if any.public AbstractButton createButton(Action action, JComponent container)
action
- an action used to create the buttoncontainer
- the parent container to uniquely identify
grouped components or nullpublic AbstractButton createButton(Action action)
action
- an action used to create the buttonprivate JToggleButton createToggleButton(AbstractActionExt a)
a
- an abstraction of a toggle action.private JToggleButton createToggleButton(AbstractActionExt a, ButtonGroup group)
a
- an abstraction of a toggle action.group
- the group to add the toggle button or nullpublic void configureButton(JToggleButton button, AbstractActionExt a, ButtonGroup group)
button
- a
- group
- public void configureSelectableButton(AbstractButton button, AbstractActionExt a, ButtonGroup group)
It's up to the client to only pass in button's where selected and/or the group property makes sense. PENDING: the group properties are yet untested. PENDING: think about automated unconfig.
button
- where selected makes sensea
- group
- the button should be added to.IllegalArgumentException
- if the given action doesn't have the state flag set.protected void configureButtonFromExtActionProperties(AbstractButton button, Action action)
button
- the button to be configuredaction
- the action used to construct the menu item.protected void configureMenuItemFromExtActionProperties(JMenuItem menuItem, Action action)
menuItem
- the menu item to be configuredaction
- the action used to construct the menu item.private JCheckBoxMenuItem createCheckBoxMenuItem(AbstractActionExt a)
private JRadioButtonMenuItem createRadioButtonMenuItem(ButtonGroup group, AbstractActionExt a)
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses