Class MenuLoader

java.lang.Object
  |
  +--MenuLoader

public class MenuLoader
extends java.lang.Object

Builds up a AWT menu by reading the settings from a resource file. It's intended to use this class for loading menu's created with Magic Menu. The class can create Panels that look and behave like menubars with the method createMenuPanel. This menu panels can be used to realize menubars in applets for browsers supporting Java 1.1. Open the project HelloW.prj in the subdirectory example and run HelloW.html to see a demonstration of this.


Inner Class Summary
(package private)  class MenuLoader.ActionAdapter
          Converts an item event to an action event.
(package private)  class MenuLoader.PopupLabel
          A label that looks and behaves like a menu.
 
Field Summary
static java.lang.String ACCEL_SUFFIX
          Suffix applied to the key used in resource file lookups for a accelerator.
static java.lang.String ACTION_SUFFIX
          Suffix applied to the key used in resource file lookups for an action.
static java.lang.String LABEL_SUFFIX
          Suffix applied to the key used in resource file lookups for a label.
static char MNEMONIC_ESCAPE
          The escape character to identify a mnemonic in a label.
static java.lang.String TYPE_CHECKBOX
          Type identifier of a checkbox menu item.
static java.lang.String TYPE_ITEM
          Type identifier of a menu item.
static java.lang.String TYPE_MENU
          Type identifier of a submenu.
static java.lang.String TYPE_SUFFIX
          Suffix applied to the key used in resource file lookups for the type of a menu item.
 
Constructor Summary
MenuLoader(java.util.Properties properties)
          Create a new JMenuLoader object.
MenuLoader(java.util.ResourceBundle resources)
          Create a new JMenuLoader object.
 
Method Summary
(package private) static void ()
           
protected  java.awt.Menu createMenu(java.lang.String key)
          Create a menu.
 java.awt.MenuBar createMenuBar(java.lang.String key)
          Create the menubar for the specified key.
 java.awt.MenuItem createMenuItem(java.lang.String key)
          This is the hook through which all menu items are created.
 java.awt.Panel createMenuPanel(java.lang.String key)
          Create a panel of popup menu labels for the specified key.
protected  MenuLoader.PopupLabel createPopupLabel(java.lang.String key, boolean[] pressed)
          Create a label with popup menu.
protected  java.awt.event.ActionListener getAction(java.lang.String cmd)
          Return the default action listener.
 java.awt.event.ActionListener getDefaultActionListener()
          Returns the default action listener.
protected  java.lang.String getResourceString(java.lang.String key)
          Read a string from the resource bundle containing the menu definition.
protected  void reportError(java.lang.String text)
          This method will be called, if some errors occur.
 void setDefaultActionListener(java.awt.event.ActionListener al)
          Set the default action listener.
protected  java.lang.String[] tokenize(java.lang.String input)
          Take the given string and chop it up into a series of strings on whitespace boundries.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LABEL_SUFFIX

public static final java.lang.String LABEL_SUFFIX
Suffix applied to the key used in resource file lookups for a label.

ACCEL_SUFFIX

public static final java.lang.String ACCEL_SUFFIX
Suffix applied to the key used in resource file lookups for a accelerator.

ACTION_SUFFIX

public static final java.lang.String ACTION_SUFFIX
Suffix applied to the key used in resource file lookups for an action.

TYPE_SUFFIX

public static final java.lang.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 java.lang.String TYPE_ITEM
Type identifier of a menu item.

TYPE_MENU

public static final java.lang.String TYPE_MENU
Type identifier of a submenu.

TYPE_CHECKBOX

public static final java.lang.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.
Constructor Detail

MenuLoader

public MenuLoader(java.util.ResourceBundle resources)
Create a new JMenuLoader object.
Parameters:
resources - A resources bundle containing the menu settings.

MenuLoader

public MenuLoader(java.util.Properties properties)
Create a new JMenuLoader object.
Parameters:
properties - Properties containing the menu settings.
Method Detail

static void ()

getDefaultActionListener

public java.awt.event.ActionListener getDefaultActionListener()
Returns the default action listener. This ActionListener is registered at every menu item.

setDefaultActionListener

public void setDefaultActionListener(java.awt.event.ActionListener al)
Set the default action listener. This action listener is registered at every menu item. If a ActionListener is set, this should be done before the first call to createMenuBar, createMenu or createMenuItem.
See Also:
createMenuBar(java.lang.String), createMenu(java.lang.String), createMenuItem(java.lang.String)

createMenuItem

public java.awt.MenuItem createMenuItem(java.lang.String key)
This is the hook through which all menu items are created. CheckbBoxMenuItems are connected by a special adapter class, which ensures compatibility to the ActionListener interface.

getAction

protected java.awt.event.ActionListener getAction(java.lang.String cmd)
Return the default action listener. This Method should be overwritten, if not all menu items should register the same action listener.
Parameters:
cmd - The action command of the associated menu item.

getResourceString

protected java.lang.String getResourceString(java.lang.String key)
Read a string from the resource bundle containing the menu definition.

tokenize

protected java.lang.String[] tokenize(java.lang.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

public java.awt.MenuBar createMenuBar(java.lang.String key)
Create the menubar for the specified key. This pulls the definition of the menu from the associated resource file.

createMenuPanel

public java.awt.Panel createMenuPanel(java.lang.String key)
Create a panel of popup menu labels for the specified key. This pulls the definition of the menu from the associated resource file. Only available, if 'Applet enabled' is checked.

createMenu

protected java.awt.Menu createMenu(java.lang.String key)
Create a menu. This pulls the definition of the menu from the associated resource file.

createPopupLabel

protected MenuLoader.PopupLabel createPopupLabel(java.lang.String key,
                                                 boolean[] pressed)
Create a label with popup menu. The definition of the popup menu is pulled from the associated resource file. Only available, if 'Applet enabled' is checked.

reportError

protected void reportError(java.lang.String text)
This method will be called, if some errors occur. By default this will cause an output to stderr.