be.ugent.caagt.swirl.menus
Class MenuBuilder

java.lang.Object
  extended by be.ugent.caagt.swirl.menus.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(javax.swing.ActionMap actionMap)
          Create a new object of this type with the associated action map.
 
Method Summary
 javax.swing.JMenuBar createJMenuBar(java.lang.String key)
          Build a menu bar which corresponds to the root configuration element with the given key.
 javax.swing.JPopupMenu createJPopupMenu(java.lang.String key)
          Build a popup menu which corresponds to the menu configuration element with the given key.
 javax.swing.JToolBar createJToolBar(java.lang.String key)
          Build a tool bar which corresponds to the menu configuration element with the given key.
 javax.swing.ActionMap getActionMap()
          The action map used by this builder
 void load(java.io.InputStream inputStream, java.lang.String bundleName)
          Load configuration information from the given input stream.
 void load(java.lang.String resource, java.lang.String bundleName)
          Load configuration information from the given class path resource.
 void registerAction(java.lang.String id, javax.swing.Action action)
          Register an action this builder.
<E> void
registerGroup(java.lang.String id, GenericSelectionModel<E> model, java.lang.Object... namesAndConstants)
          Register a selection group
 void registerToggle(java.lang.String id, java.awt.event.ItemListener itemListener)
          Register an item listener for a toggle.
 void removePredicate(java.lang.String predicate)
          Remove (unset) the predicate with the given name.
 void setPredicate(java.lang.String predicate)
          Set a predicate with the given name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuBuilder

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


MenuBuilder

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

Method Detail

getActionMap

public javax.swing.ActionMap getActionMap()
The action map used by this builder

Returns:
the cation map used by this builder

setPredicate

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


removePredicate

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

See Also:
setPredicate(java.lang.String)

registerAction

public void registerAction(java.lang.String id,
                           javax.swing.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(java.lang.String id,
                           java.awt.event.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

registerGroup

public <E> void registerGroup(java.lang.String id,
                              GenericSelectionModel<E> model,
                              java.lang.Object... namesAndConstants)
Register a selection group

Parameters:
id - Identifier used for this group in the configuration file
model - Selection model to be associated with this group
namesAndConstants - List of names and constants for the buttons in this group

load

public void load(java.lang.String resource,
                 java.lang.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

load

public void load(java.io.InputStream inputStream,
                 java.lang.String bundleName)
          throws java.io.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
Throws:
java.io.IOException

createJMenuBar

public javax.swing.JMenuBar createJMenuBar(java.lang.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.

See Also:
registerAction(java.lang.String, javax.swing.Action), registerToggle(java.lang.String, java.awt.event.ItemListener), registerGroup(java.lang.String, be.ugent.caagt.swirl.GenericSelectionModel, java.lang.Object...)

createJPopupMenu

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

See Also:
registerAction(java.lang.String, javax.swing.Action), registerToggle(java.lang.String, java.awt.event.ItemListener), registerGroup(java.lang.String, be.ugent.caagt.swirl.GenericSelectionModel, java.lang.Object...)

createJToolBar

public javax.swing.JToolBar createJToolBar(java.lang.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.

See Also:
registerAction(java.lang.String, javax.swing.Action), registerToggle(java.lang.String, java.awt.event.ItemListener), registerGroup(java.lang.String, be.ugent.caagt.swirl.GenericSelectionModel, java.lang.Object...)