org.apache.batik.util.gui.resource

Class MenuFactory

public class MenuFactory extends ResourceManager

This class represents a menu factory which builds menubars and menus from the content of a resource file.
The resource entries format is (for a menubar named 'MenuBar'):
   MenuBar           = Menu1 Menu2 ...

   Menu1.type        = RADIO | CHECK | MENU | ITEM
   Menu1             = Item1 Item2 - Item3 ...
   Menu1.text        = text
   Menu1.icon        = icon_name
   Menu1.mnemonic    = mnemonic
   Menu1.accelerator = accelerator
   Menu1.action      = action_name
   Menu1.selected    = true | false
   Menu1.enabled     = true | false
   ...
 mnemonic is a single character
 accelerator is of the form described in {@link javax.swing.KeyStroke#getKeyStroke(String)}.
 '-' represents a separator
 
All entries are optional except the '.type' entry Consecutive RADIO items are put in a ButtonGroup
Constructor Summary
MenuFactory(ResourceBundle rb, ActionMap am)
Creates a new menu factory
Method Summary
JCheckBoxMenuItemcreateJCheckBoxMenuItem(String name)
Creates and returns a new swing check box menu item
JCheckBoxMenuItemcreateJCheckBoxMenuItem(String name, String specialization)
Creates and returns a new swing check box menu item
JMenucreateJMenu(String name)
Creates and returns a new swing menu
JMenucreateJMenu(String name, String specialization)
Creates and returns a new swing menu
JMenuBarcreateJMenuBar(String name)
Creates and returns a swing menu bar
JMenuBarcreateJMenuBar(String name, String specialization)
Creates and returns a swing menu bar
protected JComponentcreateJMenuComponent(String name, String specialization)
Creates and returns a menu item or a separator
JMenuItemcreateJMenuItem(String name)
Creates and returns a new swing menu item
JMenuItemcreateJMenuItem(String name, String specialization)
Creates and returns a new swing menu item
JRadioButtonMenuItemcreateJRadioButtonMenuItem(String name)
Creates and returns a new swing radio button menu item
JRadioButtonMenuItemcreateJRadioButtonMenuItem(String name, String specialization)
Creates and returns a new swing radio button menu item
protected booleangetSpecializedBoolean(String name, String specialization)
Gets a possibly specialized resource boolean.
protected StringgetSpecializedString(String name, String specialization)
Gets a possibly specialized resource string.
protected ListgetSpecializedStringList(String name, String specialization)
Gets a possibly specialized resource string list.
protected voidinitializeJMenuItem(JMenuItem item, String name, String specialization)
Initializes a swing menu item

Constructor Detail

MenuFactory

public MenuFactory(ResourceBundle rb, ActionMap am)
Creates a new menu factory

Parameters: rb the resource bundle that contains the menu bar description. am the actions to add to menu items

Method Detail

createJCheckBoxMenuItem

public JCheckBoxMenuItem createJCheckBoxMenuItem(String name)
Creates and returns a new swing check box menu item

Parameters: name the name of the menu item

Throws: MissingResourceException if one of the keys that compose the menu item is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character. MissingListenerException if then item action is not found in the action map.

createJCheckBoxMenuItem

public JCheckBoxMenuItem createJCheckBoxMenuItem(String name, String specialization)
Creates and returns a new swing check box menu item

Parameters: name the name of the menu item specialization the name of the specialization to look for

Throws: MissingResourceException if one of the keys that compose the menu item is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character. MissingListenerException if then item action is not found in the action map.

createJMenu

public JMenu createJMenu(String name)
Creates and returns a new swing menu

Parameters: name the name of the menu bar in the resource bundle

Throws: MissingResourceException if one of the keys that compose the menu is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character. MissingListenerException if a item action is not found in the action map.

createJMenu

public JMenu createJMenu(String name, String specialization)
Creates and returns a new swing menu

Parameters: name the name of the menu bar in the resource bundle specialization the name of the specialization to look for

Throws: MissingResourceException if one of the keys that compose the menu is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character. MissingListenerException if a item action is not found in the action map.

createJMenuBar

public JMenuBar createJMenuBar(String name)
Creates and returns a swing menu bar

Parameters: name the name of the menu bar in the resource bundle

Throws: MissingResourceException if one of the keys that compose the menu is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character and if the accelerator is malformed MissingListenerException if an item action is not found in the action map

createJMenuBar

public JMenuBar createJMenuBar(String name, String specialization)
Creates and returns a swing menu bar

Parameters: name the name of the menu bar in the resource bundle specialization the name of the specialization to look for

Throws: MissingResourceException if one of the keys that compose the menu is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character and if the accelerator is malformed MissingListenerException if an item action is not found in the action map

createJMenuComponent

protected JComponent createJMenuComponent(String name, String specialization)
Creates and returns a menu item or a separator

Parameters: name the name of the menu item or "-" to create a separator specialization the name of the specialization to look for

Throws: MissingResourceException if key is not the name of a menu item. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException in case of malformed entry MissingListenerException if an item action is not found in the action map

createJMenuItem

public JMenuItem createJMenuItem(String name)
Creates and returns a new swing menu item

Parameters: name the name of the menu item

Throws: MissingResourceException if one of the keys that compose the menu item is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character. MissingListenerException if then item action is not found in the action map.

createJMenuItem

public JMenuItem createJMenuItem(String name, String specialization)
Creates and returns a new swing menu item

Parameters: name the name of the menu item specialization the name of the specialization to look for

Throws: MissingResourceException if one of the keys that compose the menu item is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character. MissingListenerException if then item action is not found in the action map.

createJRadioButtonMenuItem

public JRadioButtonMenuItem createJRadioButtonMenuItem(String name)
Creates and returns a new swing radio button menu item

Parameters: name the name of the menu item

Throws: MissingResourceException if one of the keys that compose the menu item is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character. MissingListenerException if then item action is not found in the action map.

createJRadioButtonMenuItem

public JRadioButtonMenuItem createJRadioButtonMenuItem(String name, String specialization)
Creates and returns a new swing radio button menu item

Parameters: name the name of the menu item specialization the name of the specialization to look for

Throws: MissingResourceException if one of the keys that compose the menu item is missing. It is not thrown if the mnemonic, the accelerator and the action keys are missing ResourceFormatException if the mnemonic is not a single character. MissingListenerException if then item action is not found in the action map.

getSpecializedBoolean

protected boolean getSpecializedBoolean(String name, String specialization)
Gets a possibly specialized resource boolean. This will first look for name + '.' + specialization, and if that resource doesn't exist, name.

getSpecializedString

protected String getSpecializedString(String name, String specialization)
Gets a possibly specialized resource string. This will first look for name + '.' + specialization, and if that resource doesn't exist, name.

getSpecializedStringList

protected List getSpecializedStringList(String name, String specialization)
Gets a possibly specialized resource string list. This will first look for name + '.' + specialization, and if that resource doesn't exist, name.

initializeJMenuItem

protected void initializeJMenuItem(JMenuItem item, String name, String specialization)
Initializes a swing menu item

Parameters: item the menu item to initialize name the name of the menu item specialization the name of the specialization to look for

Throws: ResourceFormatException if the mnemonic is not a single character. MissingListenerException if then item action is not found in the action map.

Copyright B) 2007 Apache Software Foundation. All Rights Reserved.