org.apache.batik.util.gui.resource
Class MenuFactory

java.lang.Object
  |
  +--org.apache.batik.util.gui.resource.ResourceManager
        |
        +--org.apache.batik.util.gui.resource.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: mod+mod+...+X
   where mod is Shift, Meta, Alt or Ctrl
 '-' represents a separator
 
All entries are optional except the '.type' entry Consecutive RADIO items are put in a ButtonGroup


Fields inherited from class org.apache.batik.util.gui.resource.ResourceManager
bundle
 
Constructor Summary
MenuFactory(java.util.ResourceBundle rb, ActionMap am)
          Creates a new menu factory
 
Method Summary
 javax.swing.JCheckBoxMenuItem createJCheckBoxMenuItem(java.lang.String name)
          Creates and returns a new swing check box menu item
 javax.swing.JMenu createJMenu(java.lang.String name)
          Creates and returns a new swing menu
 javax.swing.JMenuBar createJMenuBar(java.lang.String name)
          Creates and returns a swing menu bar
protected  javax.swing.JComponent createJMenuComponent(java.lang.String name)
          Creates and returns a menu item or a separator
 javax.swing.JMenuItem createJMenuItem(java.lang.String name)
          Creates and returns a new swing menu item
 javax.swing.JRadioButtonMenuItem createJRadioButtonMenuItem(java.lang.String name)
          Creates and returns a new swing radio button menu item
protected  void initializeJMenuItem(javax.swing.JMenuItem item, java.lang.String name)
          Initializes a swing menu item
protected  javax.swing.KeyStroke toKeyStroke(java.lang.String str)
          Translate a string into a key stroke.
 
Methods inherited from class org.apache.batik.util.gui.resource.ResourceManager
getBoolean, getCharacter, getInteger, getString, getStringList, getStringList, getStringList
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuFactory

public MenuFactory(java.util.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

createJMenuBar

public javax.swing.JMenuBar createJMenuBar(java.lang.String name)
                                    throws java.util.MissingResourceException,
                                           ResourceFormatException,
                                           MissingListenerException
Creates and returns a swing menu bar
Parameters:
name - the name of the menu bar in the resource bundle
Throws:
java.util.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 javax.swing.JComponent createJMenuComponent(java.lang.String name)
                                               throws java.util.MissingResourceException,
                                                      ResourceFormatException,
                                                      MissingListenerException
Creates and returns a menu item or a separator
Parameters:
name - the name of the menu item or "-" to create a separator
Throws:
java.util.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

createJMenu

public javax.swing.JMenu createJMenu(java.lang.String name)
                              throws java.util.MissingResourceException,
                                     ResourceFormatException,
                                     MissingListenerException
Creates and returns a new swing menu
Parameters:
name - the name of the menu bar in the resource bundle
Throws:
java.util.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.

createJMenuItem

public javax.swing.JMenuItem createJMenuItem(java.lang.String name)
                                      throws java.util.MissingResourceException,
                                             ResourceFormatException,
                                             MissingListenerException
Creates and returns a new swing menu item
Parameters:
name - the name of the menu item
Throws:
java.util.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 javax.swing.JRadioButtonMenuItem createJRadioButtonMenuItem(java.lang.String name)
                                                            throws java.util.MissingResourceException,
                                                                   ResourceFormatException,
                                                                   MissingListenerException
Creates and returns a new swing radio button menu item
Parameters:
name - the name of the menu item
Throws:
java.util.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 javax.swing.JCheckBoxMenuItem createJCheckBoxMenuItem(java.lang.String name)
                                                      throws java.util.MissingResourceException,
                                                             ResourceFormatException,
                                                             MissingListenerException
Creates and returns a new swing check box menu item
Parameters:
name - the name of the menu item
Throws:
java.util.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.

initializeJMenuItem

protected void initializeJMenuItem(javax.swing.JMenuItem item,
                                   java.lang.String name)
                            throws ResourceFormatException,
                                   MissingListenerException
Initializes a swing menu item
Parameters:
item - the menu item to initialize
name - the name of the menu item
Throws:
ResourceFormatException - if the mnemonic is not a single character.
MissingListenerException - if then item action is not found in the action map.

toKeyStroke

protected javax.swing.KeyStroke toKeyStroke(java.lang.String str)
Translate a string into a key stroke. See the class comment for details
Parameters:
str - a string


Copyright © 2002 Apache Software Foundation. All Rights Reserved.