com.ibm.as400.ui.framework.java
Class MenuManager

java.lang.Object
  extended by com.ibm.as400.ui.framework.java.MenuManager
Direct Known Subclasses:
ContextMenuManager

public class MenuManager
extends Object

Creates a menu defined using the Panel Definition Markup Language (PDML).

MenuManager performs the following processing on behalf of the application:

To locate a menu definition, MenuManager needs three pieces of information:

The framework first searches the specified location for a file with a name matching the menu name, and an extension of .pdml.ser. If the serialized menu definition is not found, an attempt will be made to load a ResourceBundle and a PDML file which correspond to the specified resource name. If the resources cannot be located a DisplayManagerException will be thrown.

Examples

Assume that the menu MyMenu is defined in the file TestPanels.pdml, and that a properties file TestPanels.properties is associated with the menu definition. Both files reside in the directory com/ourCompany/ourPackage, which is accessible from a directory defined in the classpath, or from a ZIP or JAR file defined in the classpath. The following code creates the menu and adds it to the menu bar for an application's dialog window:

 import com.ibm.as400.ui.framework.java.*;
  
 // Create the menu manager. Parameters:
 // 1. Resource name of the menu definition
 // 2. Name of menu
 // 3. Pane manager not needed
  
 MenuManager mm = null;
 try {
 mm = new MenuManager("com.ourCompany.ourPackage.TestPanels",
                      "Mymenu",
                      null);
 }
 catch (DisplayManagerException e) {
 e.displayUserMessage(null);
 System.exit(-1);
 }
  
 // Add the menu to a menu bar
 JMenuBar jmb = new JMenuBar();
 jmb.add(mm.getMenu());
 

Command Line Interface

The command line interface may be used to display newly-defined menus, or to serialize PDML menu definitions.
 java com.ibm.as400.ui.framework.java.MenuManager
     [-serialize]
     [-locale <language code>_<country or region code>_<variant>]
     <resource name>
     <menu name>
 
Options:
-serialize
Parses the PDML menu definition and creates a serialized version of the menu. The name of the serialized file will match the menu name, and the file extension will be .pdml.ser. If this option is specified the menu will not be displayed on the screen.

-locale <language code>_<country or region code>_<variant>
Identifies the locale which should be used to locate the menu definition. The locale string should consist of a two-letter lowercase ISO Language Code, a two-letter uppercase ISO country or region code, and an optional variant string, each delimited by an underscore ("_") character. If this parameter is omitted the default locale will be used. If resources for the default locale cannot be found, an attempt will be made to use the base resources for the menu.

<resource name>
The fully-qualified resource name of the PDML document/resource bundle combination which defines the menu specification.

<menu name>
The name of the menu, as specified on the menu tag in the PDML document.

Examples:

Test a base sample menu:

java com.ibm.as400.ui.framework.java.MenuManager com.ourCompany.ourPackage.TestPanels MyMenu

Serialize the base menu:

java com.ibm.as400.ui.framework.java.MenuManager -serialize com.ourCompany.ourPackage.TestPanels MyMenu

Test the UK version:

java com.ibm.as400.ui.framework.java.MenuManager -locale en_UK com.ourCompany.ourPackage.TestPanels MyMenu

Serialize the UK version:

java com.ibm.as400.ui.framework.java.MenuManager -serialize -locale en_UK com.ourCompany.ourPackage.TestPanels MyMenu

Since:
v4r5m0
Version:
1.0, 03/05/99
Author:
D. Petty
See Also:
DisplayManagerException

Constructor Summary
Constructor and Description
MenuManager(String baseName, Locale locale, String menuName)
          Constructs a MenuManager object for the specified menu, and then serializes the menu definition.
MenuManager(String baseName, Locale locale, String menuName, PaneManager pm)
          Constructs a MenuManager for the specified menu.
MenuManager(String baseName, String menuName, PaneManager pm)
          Constructs a MenuManager for the specified menu.
 
Method Summary
Modifier and Type Method and Description
 void addMenuItem(JMenuItem mi)
          Adds a MenuItem to this MenuManager The MenuItem must have a non-null name
 void addSeparator()
          Adds a Seperator to this MenuManager
 void enableAllMenuItems(boolean b)
          Enables or Disables all Menu Items contained in this MenuManager
 void enableMenuItem(String name, boolean b)
          Enables or Disables a MenuItem contained in this MenuManager
 Action[] getActions()
          Returns a list of Actions for the items in this menu.
 JMenu getMenu()
          Returns the root JMenu for this menu.
 JMenuItem getMenuItem(String name)
          Returns the menu item identified by name.
 String getName()
          Returns the this Menu Manager's name
 PaneManager getPaneManager()
          Returns the PaneManager with which this menu is associated.
static void main(String[] args)
          Provides a command line interface to MenuManager.
 void removeMenuItem(String name)
          Removes a MenuItem
 void serialize()
          Serializes the menu definition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MenuManager

public MenuManager(String baseName,
                   String menuName,
                   PaneManager pm)
            throws DisplayManagerException
Constructs a MenuManager for the specified menu.

The default locale will be used to load the menu definition.

Parameters:
baseName - the resource name of the PDML document/resource bundle combination which defines the menu specification
menuName - the name of the menu, as specified on the MENU tag in the PDML
the - PaneManager with which this menu is associated (may be null)
Throws:
DisplayManagerException - if an error was encountered accessing the menu definition
Since:
v4r5m0
See Also:
PaneManager, DisplayManagerException

MenuManager

public MenuManager(String baseName,
                   Locale locale,
                   String menuName,
                   PaneManager pm)
            throws DisplayManagerException
Constructs a MenuManager for the specified menu.

Parameters:
baseName - the resource name of the PDML document/resource bundle combination which defines the menu specification
locale - the desired locale to be used to load the menu definition
menuName - the name of the menu, as specified on the MENU tag in the PDML
the - PaneManager with which this menu is associated (may be null)
Throws:
DisplayManagerException - if an error was encountered accessing the menu definition
Since:
v4r5m0
See Also:
PaneManager, DisplayManagerException

MenuManager

public MenuManager(String baseName,
                   Locale locale,
                   String menuName)
            throws DisplayManagerException
Constructs a MenuManager object for the specified menu, and then serializes the menu definition. This constructor cannot be used to display the menu.

If a null locale is specified, the default locale will be used to load the menu definition. If resources for the default locale cannot be found, an attempt will be made to use the base resources for the menu.

Parameters:
baseName - the resource name of the PDML document/resource bundle combination which define the menu specification
locale - the desired locale to be used to load the menu definition (may be null)
menuName - the name of the menu, as specified on the MENU tag in the PDML
Throws:
DisplayManagerException - if an error was encountered accessing or serializing the menu definition
Since:
v4r5m0
See Also:
DisplayManagerException, serialize()
Method Detail

main

public static void main(String[] args)
Provides a command line interface to MenuManager. See the class description.

Since:
v4r5m0

serialize

public void serialize()
               throws IOException
Serializes the menu definition. The filename of the serialized file will be of the form
 <menu name>_<locale string>.pdml.ser
 
where <menu name> is the name of the menu as specified on the MENU tag in the PDML, and <locale string> consists of the ISO Language Code, ISO country or region code, and optional variant codes, each delimited by an underscore ("_") character.

Throws:
IOException - if serialized file cannot be written
Since:
v4r5m0

getMenu

public JMenu getMenu()
Returns the root JMenu for this menu.

Returns:
a JMenu for this menu
Since:
v4r5m0

getMenuItem

public JMenuItem getMenuItem(String name)
Returns the menu item identified by name.

Parameters:
name - the name of the menu item as specified in the menu definition
Returns:
a JMenuItem corresponding to the specified menu item
Since:
v4r5m0

enableAllMenuItems

public void enableAllMenuItems(boolean b)
Enables or Disables all Menu Items contained in this MenuManager

Parameters:
b - true to enable the menu item
Since:
v5r1m0

enableMenuItem

public void enableMenuItem(String name,
                           boolean b)
Enables or Disables a MenuItem contained in this MenuManager

Parameters:
name - the name of the menu item be enabled
b - true to enable the menu item
Since:
v5r1m0

addMenuItem

public void addMenuItem(JMenuItem mi)
Adds a MenuItem to this MenuManager The MenuItem must have a non-null name

Parameters:
mi - a named JMenuItem
Since:
v5r1m0

addSeparator

public void addSeparator()
Adds a Seperator to this MenuManager

Since:
v5r1m0

removeMenuItem

public void removeMenuItem(String name)
Removes a MenuItem

Parameters:
name - the name of the MenuItem to be removed
Since:
v5r1m0

getActions

public Action[] getActions()
Returns a list of Actions for the items in this menu.

Returns:
an array of Actions for the menu items
Since:
v4r5m0

getPaneManager

public PaneManager getPaneManager()
Returns the PaneManager with which this menu is associated.

Returns:
the PaneManager with which this menu is associated (may be null)
Since:
v4r5m0
See Also:
PaneManager

getName

public String getName()
Returns the this Menu Manager's name

Returns:
the name of this Menu Manager
Since:
v4r5m0