Class JMenuLoader
java.lang.Object
|
+----JMenuLoader
- class JMenuLoader
- extends Object
Builds up a Swing menu by reading the settings from a resource file. It's
intended to use this class for loading menu's created with Magic Menu.
-
ACCEL_SUFFIX
- Suffix applied to the key used in resource file
lookups for a accelerator.
-
ACTION_SUFFIX
- Suffix applied to the key used in resource file
lookups for an action.
-
commands
-
-
defaultAction
-
-
eventClass
- A reference to the java.awt.event.InputEvent class.
-
IMAGE_SUFFIX
- Suffix applied to the key used in resource file
lookups for an image.
-
keyEventClass
- A reference to the java.awt.event.KeyEvent class.
-
LABEL_SUFFIX
- Suffix applied to the key used in resource file
lookups for a label.
-
MNEMONIC_ESCAPE
- The escape character to identify a mnemonic in a label.
-
resources
-
-
TYPE_CHECKBOX
- Type identifier of a checkbox menu item.
-
TYPE_ITEM
- Type identifier of a menu item.
-
TYPE_MENU
- Type identifier of a submenu.
-
TYPE_SUFFIX
- Suffix applied to the key used in resource file
lookups for the type of a menu item.
-
JMenuLoader(ResourceBundle)
- Create a new JMenuLoader object.
-
()
-
-
createMenu(String)
- Create a menu.
-
createMenuBar(String)
- Create the menubar for the specified key.
-
createMenuItem(String)
- This is the hook through which all menu items are created.
-
filterMnemonic(String, char[])
- Filters the mnemonic identifiers out of a label string.
-
getAction(String)
- Return the Action with name cmd stored in the command hashtable.
-
getCommands()
- Returns a hashtable containing the menu commands.
-
getDefaultActionListener()
- Return the default action listener.
-
getResource(String)
- Read the name of an image from the resource bundle and convert
if to an URL.
-
getResourceString(String)
- Read a string from the resource bundle containing the menu
definition.
-
loadImageIcon(URL)
- Hook through which ImageIcons are loaded.
-
reportError(String)
- This method will be called, if some errors occur.
-
setCommands(Hashtable)
- Set the hashtable containing the menu commands.
-
setDefaultActionListener(ActionListener)
- Set the default action listener.
-
tokenize(String)
- Take the given string and chop it up into a series
of strings on whitespace boundries.
IMAGE_SUFFIX
public static final String IMAGE_SUFFIX
- Suffix applied to the key used in resource file
lookups for an image.
LABEL_SUFFIX
public static final String LABEL_SUFFIX
- Suffix applied to the key used in resource file
lookups for a label.
ACCEL_SUFFIX
public static final String ACCEL_SUFFIX
- Suffix applied to the key used in resource file
lookups for a accelerator.
ACTION_SUFFIX
public static final String ACTION_SUFFIX
- Suffix applied to the key used in resource file
lookups for an action.
TYPE_SUFFIX
public static final String TYPE_SUFFIX
- Suffix applied to the key used in resource file
lookups for the type of a menu item.
TYPE_ITEM
public static final String TYPE_ITEM
- Type identifier of a menu item.
TYPE_MENU
public static final String TYPE_MENU
- Type identifier of a submenu.
TYPE_CHECKBOX
public static final String TYPE_CHECKBOX
- Type identifier of a checkbox menu item.
MNEMONIC_ESCAPE
public static final char MNEMONIC_ESCAPE
- The escape character to identify a mnemonic in a label.
eventClass
private static Class eventClass
- A reference to the java.awt.event.InputEvent class.
keyEventClass
private static Class keyEventClass
- A reference to the java.awt.event.KeyEvent class.
resources
private ResourceBundle resources
commands
private Hashtable commands
defaultAction
private ActionListener defaultAction
JMenuLoader
JMenuLoader(ResourceBundle resources)
- Create a new JMenuLoader object.
- Parameters:
- resources - A resources bundle containing the menu settings.
static void ()
filterMnemonic
private static String filterMnemonic(String label,
char ch[])
- Filters the mnemonic identifiers out of a label string.
getCommands
public Hashtable getCommands()
- Returns a hashtable containing the menu commands. The hashtable
contains pairs of action name and Action object.
setCommands
public void setCommands(Hashtable commands)
- Set the hashtable containing the menu commands. This hashtable should
contain pairs of action name and Action object. If a commands hashtable
is set, this should be done before the first call to createMenuBar,
createMenu or createMenuItem.
- See Also:
- createMenuBar, createMenu, createMenuItem
getDefaultActionListener
public ActionListener getDefaultActionListener()
- Return the default action listener. This action listener is registered
at every menu item, which has no associated command in the commands
hashtable.
setDefaultActionListener
public void setDefaultActionListener(ActionListener al)
- Set the default action listener. This action listener is registered at
every menu item,which has no associated command in the commands
hashtable. If a ActionListener is set, this should be done before the
first call to createMenuBar, createMenu or createMenuItem.
- See Also:
- createMenuBar, createMenu, createMenuItem
createMenuItem
public JMenuItem createMenuItem(String key)
- This is the hook through which all menu items are created.
getAction
protected ActionListener getAction(String cmd)
- Return the Action with name cmd stored in the command hashtable.
If it doesn't exist, return the default action listener.
- Parameters:
- cmd - The action command of the associated menu item.
getResourceString
protected String getResourceString(String key)
- Read a string from the resource bundle containing the menu
definition.
getResource
protected URL getResource(String key)
- Read the name of an image from the resource bundle and convert
if to an URL. The name in the resource bundle must be a relative
path. It's relative to the location of this class. This method is
only available, if the checkbox
Display Images im Menu Items
was selected at creation time of this class.
tokenize
protected String[] tokenize(String input)
- Take the given string and chop it up into a series
of strings on whitespace boundries. This is useful
for trying to get an array of strings out of the
resource file.
createMenuBar
protected JMenuBar createMenuBar(String key)
- Create the menubar for the specified key. This pulls the
definition of the menu from the associated resource bundle.
createMenu
protected JMenu createMenu(String key)
- Create a menu. This pulls the definition
of the menu from the associated resource file.
loadImageIcon
protected ImageIcon loadImageIcon(URL url)
- Hook through which ImageIcons are loaded. If some kind of
image cache should be implemented, this method can be
overwritten. This method is only available, if the checkbox
Display Images im Menu Items
was selected at
creation time of this class.
reportError
protected void reportError(String text)
- This method will be called, if some errors occur. By default this
will cause an output to stderr.