be.ugent.caagt.swirl.menus

Class MenuBuilder


public class MenuBuilder
extends java.lang.Object

Allows menus to be constructed from a configuration file.

The configuration file uses an XML-format, the DTD of which can be found here. The corresponding public identifier is "-//SWIRL//MenuBuilder configuration 1.0//EN".

More information can be found in the MenuBuilder tutorial.

Constructor Summary

MenuBuilder()
Create a new object of this type with a default action map.
MenuBuilder(ActionMap actionMap)
Create a new object of this type with the associated action map.

Method Summary

JMenuBar
createJMenuBar(String key)
Build a menu bar which corresponds to the root configuration element with the given key.
JPopupMenu
createJPopupMenu(String key)
Build a popup menu which corresponds to the menu configuration element with the given key.
JToolBar
createJToolBar(String key)
Build a tool bar which corresponds to the menu configuration element with the given key.
ActionMap
getActionMap()
The action map used by this builder
void
load(InputStream inputStream, String bundleName)
Load configuration information from the given input stream.
void
load(String resource, String bundleName)
Load configuration information from the given class path resource.
void
registerAction(String id, Action action)
Register an action this builder.
void
registerToggle(String id, ItemListener itemListener)
Register an item listener for a toggle.
void
removePredicate(String predicate)
Remove (unset) the predicate with the given name.
void
setPredicate(String predicate)
Set a predicate with the given name.

Constructor Details

MenuBuilder

public MenuBuilder()
Create a new object of this type with a default action map.

MenuBuilder

public MenuBuilder(ActionMap actionMap)
Create a new object of this type with the associated action map.

Method Details

createJMenuBar

public JMenuBar createJMenuBar(String key)
Build a menu bar which corresponds to the root configuration element with the given key. All actions, groups and toggles that occur in this menu must have been registered with the builder before this method is called.

createJPopupMenu

public JPopupMenu createJPopupMenu(String key)
Build a popup menu which corresponds to the menu configuration element with the given key.

createJToolBar

public JToolBar createJToolBar(String key)
Build a tool bar which corresponds to the menu configuration element with the given key. The menu element should not have any submenus.

getActionMap

public ActionMap getActionMap()
The action map used by this builder
Returns:
the cation map used by this builder

load

public void load(InputStream inputStream,
                 String bundleName)
            throws IOException
Load configuration information from the given input stream.
Parameters:
bundleName - Name of the resource bundle which will be used to resolve the various keys in the cnofiguration file

load

public void load(String resource,
                 String bundleName)
Load configuration information from the given class path resource.
Parameters:
bundleName - Name of the resource bundle which will be used to resolve the various keys in the cnofiguration file

registerAction

public void registerAction(String id,
                           Action action)
Register an action this builder.

Has the same effect as registering the action with the action map of this builder.

Parameters:
id - Identifier used in the configuration file for this action
action - Action object to be associated with this identifier

registerToggle

public void registerToggle(String id,
                           ItemListener itemListener)
Register an item listener for a toggle.
Parameters:
id - Identifier used for this toggle in the configuration file
itemListener - Item listener to be associated with this identifier

removePredicate

public void removePredicate(String predicate)
Remove (unset) the predicate with the given name.

setPredicate

public void setPredicate(String predicate)
Set a predicate with the given name. Predicates can influence which parts of a menu are built.