O2Plib.gui
Class MenuSupport

java.lang.Object
  extended by O2Plib.gui.MenuSupport

public class MenuSupport
extends java.lang.Object

Class MenuSupport contains various Menu support functions for helping implement and support dynamic submenus of MenuItem or CheckboxMenuItem types. It tracks both entities in separate hash tables by either their associated command string or their MenuItem or CheckboxMenuItem instances. It supports radio groups using a common command name prefix ending in ':'. E.g., "Open:Sample:" with "Open:Sample:a1" "Open:Sample:a2" and "Open:Sample:a2" being in the same radio group. The event handler is in the parent calling these methods.

NOTE: event handlers are in the parent.

This work was produced by Peter Lemkin of the National Cancer Institute, an agency of the United States Government. As a work of the United States Government there is no associated copyright. It is offered as open source software under the Mozilla Public License (version 1.1) subject to the limitations noted in the accompanying LEGAL file. This notice must be included with the code. The Open2Dprot Mozilla and Legal files are available on http://open2dprot.sourceforge.net/

Version:
$Date: 2005/10/21 15:42:54 $ $Revision: 1.9 $
Author:
P. Lemkin (LECB/NCI), G. Thornwall (SAIC), Frederick, MD
See Also:
Open2Dprot Home

Nested Class Summary
(package private)  class MenuSupport.ChkBoxMenuData
           
(package private)  class MenuSupport.MenuCmdData
           
 
Field Summary
 java.util.Hashtable chkBoxMenuItemCmdHT
          Hashtable of ALL checkboxItem menu items.
 java.util.Hashtable chkBoxMenuItemDataHT
          Hashtable of ALL checkboxItem menu items.
static int MAX_CHKBOX_CMDS
          max number of menu checkbox items allowed
static int MAX_CMDS
          Initial max number of menu items allowed.
 int maxCheckboxMenuItems
          initial max number of menu checkbox items allowed
 int maxMenuItems
          Initial max number of menu items allowed.
 java.util.Hashtable menuItemCmdHT
          Hashtable of ALL menu items.
 java.util.Hashtable menuItemDataHT
          Hashtable of ALL menu items.
 java.lang.String name
          Name of this MenuSupport instance
 
Constructor Summary
MenuSupport()
          MenuSupport() - Constructor.
MenuSupport(java.lang.String name)
          MenuSupport() - Constructor.
MenuSupport(java.lang.String name, int maxMenuItems, int maxCheckboxMenuItems)
          MenuSupport() - Constructor.
 
Method Summary
 boolean clearSublistChkMenuItemStates(java.awt.CheckboxMenuItem cbmi)
          clearSublistChkMenuItemStates() - clear all of the checkbox menu items in the radio group.
 boolean clearSublistChkMenuItemStates(java.lang.String preface)
          clearSublistChkMenuItemStates() - clear all of the checkbox menu items in the radio group.
 java.lang.String[] getCmdListCBMIbyPreface(java.lang.String preface)
          getCmdListCBMIbyPreface() - get list of all of the commands in the checkbox menu items with a common command prefix ending with a ':'.
 java.lang.String[] getMenuLabelListCBMIbyPreface(java.lang.String preface)
          getMenuLabelListCBMIbyPreface() - get list of all of the menu labels in the checkbox menu items with a common command prefix endinting with a ':'.
 java.lang.String getRadioSublistChkMenuItemStates(java.awt.CheckboxMenuItem cbmi)
          getRadioSublistChkMenuItemStates() - Do radio function by clearing all of the checkbox menu items except the one mentioned which is set to true.
 void init(java.lang.String name, int maxMenuItems, int maxCheckboxMenuItems)
          init() - create empty hash tables.
 java.lang.String lookupChkboxMenuItem(java.awt.CheckboxMenuItem cbmi)
          lookupChkboxMenuItem() - lookup String command entry in checkbox menu item list by searching (key,value)=(CheckboxMenuItem,ChkBoxMenuData) and returning the command if found.
 java.awt.CheckboxMenuItem lookupChkboxMenuItem(java.lang.String sCmd)
          lookupChkboxMenuItem() - lookup CheckboxMenuItem entry in menu list by searching (key,value)=(cmd,ChkBoxMenuData) and returning the CheckboxMenuItem if found.
 java.lang.String lookupChkboxMenuItemLabel(java.lang.String sCmd)
          lookupChkboxMenuItemLabel() - lookup CheckboxMenuItem entry label in menu list by searching (key,value)=(cmd,ChkBoxMenuData) and returning the menu label if found.
 java.lang.String lookupMenuItem(java.awt.MenuItem mi)
          lookupMenuItem() - lookup MenuItem entry by MenuItem in menu list.
 java.awt.MenuItem lookupMenuItem(java.lang.String sCmd)
          lookupMenuItem() - lookup MenuItem entry in menu list.
 java.lang.String lookupMenuItemLabel(java.lang.String sCmd)
          lookupMenuItemLabel() - lookup CheckboxMenuItem entry label in menu list by searching (key,value)=(cmd,MenuCmdData) and returning the menu label if found.
 java.awt.CheckboxMenuItem makeChkBoxMenuItem(java.awt.Frame fm, java.awt.Menu pm, java.lang.String sLabel, java.lang.String sCmd, int shortcut, boolean value)
          makeChkBoxMenuItem() - make CheckboxMenuItem entry in popup menu list.
 java.awt.MenuItem makeMenuItem(java.awt.Frame fm, java.awt.Menu pm, java.lang.String sLabel, java.lang.String sCmd, int shortcut)
          makeMenuItem() - make menuItem entry in menu list.
 java.awt.Menu makeSubMenu(java.awt.Frame fm, java.awt.Menu pm, java.lang.String sLabel, java.lang.String sCmd, int shortcut)
          makeSubMenu() - make submenu entry in menu list.
 boolean rebuildChkBoxSubmenu(java.awt.Frame fm, java.awt.Menu submenu, java.lang.String preface, java.lang.String[] entryList, java.lang.String activeEntry)
          rebuildChkBoxSubmenu() - rebuild a submenu with a new entry list indicated by menu labels from entryList[], the commands are preface+entryList[].
 boolean setRadioSublistChkMenuItemStates(java.awt.CheckboxMenuItem cbmi)
          setRadioSublistChkMenuItemStates() - Do radio function by clearing all of the checkbox menu items except the one mentioned which is set to true.
 boolean setRadioSublistChkMenuItemStates(java.lang.String sCmd)
          setRadioSublistChkMenuItemStates() - Do radio function by clearing all of the checkbox menu items except the one mentioned which is set to true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_CMDS

public static final int MAX_CMDS
Initial max number of menu items allowed.

See Also:
Constant Field Values

MAX_CHKBOX_CMDS

public static final int MAX_CHKBOX_CMDS
max number of menu checkbox items allowed

See Also:
Constant Field Values

maxMenuItems

public int maxMenuItems
Initial max number of menu items allowed.


maxCheckboxMenuItems

public int maxCheckboxMenuItems
initial max number of menu checkbox items allowed


name

public java.lang.String name
Name of this MenuSupport instance


menuItemDataHT

public java.util.Hashtable menuItemDataHT
Hashtable of ALL menu items. The key is the MenuItem. The value is the MenuCmdData.


menuItemCmdHT

public java.util.Hashtable menuItemCmdHT
Hashtable of ALL menu items. The key is the command. The value is the MenuCmdData.


chkBoxMenuItemDataHT

public java.util.Hashtable chkBoxMenuItemDataHT
Hashtable of ALL checkboxItem menu items. The key is the CheckboxMenuItem. The value is the ChkBoxMenuData intance.


chkBoxMenuItemCmdHT

public java.util.Hashtable chkBoxMenuItemCmdHT
Hashtable of ALL checkboxItem menu items. The key is the command. The value is the ChkBoxMenuData intance.

Constructor Detail

MenuSupport

public MenuSupport()
MenuSupport() - Constructor. use default hash table sizes.


MenuSupport

public MenuSupport(java.lang.String name)
MenuSupport() - Constructor. use default hash table sizes.

Parameters:
name - of this menu support instance

MenuSupport

public MenuSupport(java.lang.String name,
                   int maxMenuItems,
                   int maxCheckboxMenuItems)
MenuSupport() - Constructor.

Parameters:
name - of this menu support instance
maxMenuItems - - initial maximum size of Menu Items in menubar
maxCheckboxMenuItems - - initial maximum size of Checkbox Menu Items in menubar
Method Detail

init

public void init(java.lang.String name,
                 int maxMenuItems,
                 int maxCheckboxMenuItems)
init() - create empty hash tables.

Parameters:
name - of this menu support instance
maxMenuItems - - initial maximum size of Menu Items in menubar
maxCheckboxMenuItems - - initial maximum size of Checkbox Menu Items in menubar

makeMenuItem

public java.awt.MenuItem makeMenuItem(java.awt.Frame fm,
                                      java.awt.Menu pm,
                                      java.lang.String sLabel,
                                      java.lang.String sCmd,
                                      int shortcut)
makeMenuItem() - make menuItem entry in menu list. Setup action command and listener call back. If the command name is null, set the command name to label name. if shortCut is <0, then gray-out the item. i.e. not available and do not add to event handler.

Parameters:
fm - is the frame that contains Action listener for this item
pm - is the menu to install new MenuItem
sLabel - is the visible label
sCmd - is the opt Cmd name (uses sLabel if null)
shortcut - is the opt short cut
Returns:
the menu item

makeSubMenu

public java.awt.Menu makeSubMenu(java.awt.Frame fm,
                                 java.awt.Menu pm,
                                 java.lang.String sLabel,
                                 java.lang.String sCmd,
                                 int shortcut)
makeSubMenu() - make submenu entry in menu list. Setup action command and listener call back. If the command name is null, set the command name to label name.

Parameters:
fm - is the frame
pm - is the menu to install new submenu in
sLabel - is the visible label
sCmd - is the opt Cmd name (uses sLabel if null)
shortcut - is the opt short cut

makeChkBoxMenuItem

public java.awt.CheckboxMenuItem makeChkBoxMenuItem(java.awt.Frame fm,
                                                    java.awt.Menu pm,
                                                    java.lang.String sLabel,
                                                    java.lang.String sCmd,
                                                    int shortcut,
                                                    boolean value)
makeChkBoxMenuItem() - make CheckboxMenuItem entry in popup menu list. Setup action command and listener call back. If the command name is null, set the command name to label name. if shortCut is <0, then gray-out the item. i.e. not available and do not add to event handler.

Parameters:
fm - is the frame that contains Item listener for this item
pm - is the menu to install new CheckboxMenuItem in
sLabel - is the visible label
sCmd - is the opt Cmd name (uses sLabel if null)
shortcut - is the opt short cut
value - is the initial value of the checkbox

lookupMenuItem

public java.awt.MenuItem lookupMenuItem(java.lang.String sCmd)
lookupMenuItem() - lookup MenuItem entry in menu list.

Parameters:
sCmd - is the opt Cmd name to search the hash table for (key,value)=(cmd,MenuCmdData) and returning the MenuItem if found.
Returns:
the MenuItem instance if found, else null

lookupMenuItem

public java.lang.String lookupMenuItem(java.awt.MenuItem mi)
lookupMenuItem() - lookup MenuItem entry by MenuItem in menu list.

Parameters:
mi - is the MenuItem instance to searching the hash table for (key,value)=(MenuItem,MenuCmdData) and returning the command if found.
miDataHT - is the hash table storing
Returns:
the menu item command name if found, else null

lookupChkboxMenuItem

public java.awt.CheckboxMenuItem lookupChkboxMenuItem(java.lang.String sCmd)
lookupChkboxMenuItem() - lookup CheckboxMenuItem entry in menu list by searching (key,value)=(cmd,ChkBoxMenuData) and returning the CheckboxMenuItem if found.

Parameters:
sCmd - is the opt Cmd name to search for
cbmiCmdHT - is the hash table storing
Returns:
the CheckboxMenuItem item instance if found, else null

lookupChkboxMenuItem

public java.lang.String lookupChkboxMenuItem(java.awt.CheckboxMenuItem cbmi)
lookupChkboxMenuItem() - lookup String command entry in checkbox menu item list by searching (key,value)=(CheckboxMenuItem,ChkBoxMenuData) and returning the command if found.

Parameters:
cbmi - is the CheckboxMenuItem to search for
Returns:
the string command name of the checkbox menu item if found, else null

lookupMenuItemLabel

public java.lang.String lookupMenuItemLabel(java.lang.String sCmd)
lookupMenuItemLabel() - lookup CheckboxMenuItem entry label in menu list by searching (key,value)=(cmd,MenuCmdData) and returning the menu label if found.

Parameters:
sCmd - is the opt Cmd name to search for
Returns:
the MenuItem item instance menu label if found, else null

lookupChkboxMenuItemLabel

public java.lang.String lookupChkboxMenuItemLabel(java.lang.String sCmd)
lookupChkboxMenuItemLabel() - lookup CheckboxMenuItem entry label in menu list by searching (key,value)=(cmd,ChkBoxMenuData) and returning the menu label if found.

Parameters:
sCmd - is the opt Cmd name to search for
Returns:
the CheckboxMenuItem item instance menu label if found, else null

clearSublistChkMenuItemStates

public boolean clearSublistChkMenuItemStates(java.lang.String preface)
clearSublistChkMenuItemStates() - clear all of the checkbox menu items in the radio group. The members of the radio group are determined by the command prefix up to the last ':' in the command name for the checkbox menu item.

Parameters:
cbmi - is the CheckboxMenuItem that is part of a radio group.
Returns:
true if succeed

clearSublistChkMenuItemStates

public boolean clearSublistChkMenuItemStates(java.awt.CheckboxMenuItem cbmi)
clearSublistChkMenuItemStates() - clear all of the checkbox menu items in the radio group. The members of the radio group are determined by the same command prefix up to the last ':' in the command name for the checkbox menu item.

Parameters:
cbmi - is the CheckboxMenuItem that is part of a radio group.
Returns:
true if succeed

setRadioSublistChkMenuItemStates

public boolean setRadioSublistChkMenuItemStates(java.lang.String sCmd)
setRadioSublistChkMenuItemStates() - Do radio function by clearing all of the checkbox menu items except the one mentioned which is set to true. The members of the radio group are determined by the same command prefix up to the last ':' in the command name for the checkbox menu item.

Parameters:
sCmd - is the command string for theCheckboxMenuItem that is part of a radio group.
Returns:
true if succeed

setRadioSublistChkMenuItemStates

public boolean setRadioSublistChkMenuItemStates(java.awt.CheckboxMenuItem cbmi)
setRadioSublistChkMenuItemStates() - Do radio function by clearing all of the checkbox menu items except the one mentioned which is set to true. The members of the radio group are determined by the same command prefix up to the last ':' in the command name for the checkbox menu item.

Parameters:
cbmi - is the CheckboxMenuItem that is part of a radio group.
Returns:
true if succeed

getRadioSublistChkMenuItemStates

public java.lang.String getRadioSublistChkMenuItemStates(java.awt.CheckboxMenuItem cbmi)
getRadioSublistChkMenuItemStates() - Do radio function by clearing all of the checkbox menu items except the one mentioned which is set to true. The members of the radio group are determined by the command prefix up to the last ':' in the command name for the same checkbox menu item. It returns the command for the checkbox.

Parameters:
cbmi - is the CheckboxMenuItem that is part of a radio group.
Returns:
command of the checkbox item, null if a problem

getCmdListCBMIbyPreface

public java.lang.String[] getCmdListCBMIbyPreface(java.lang.String preface)
getCmdListCBMIbyPreface() - get list of all of the commands in the checkbox menu items with a common command prefix ending with a ':'.

Parameters:
cbmi - is the CheckboxMenuItem that is part of a radio group.
Returns:
true if succeed

getMenuLabelListCBMIbyPreface

public java.lang.String[] getMenuLabelListCBMIbyPreface(java.lang.String preface)
getMenuLabelListCBMIbyPreface() - get list of all of the menu labels in the checkbox menu items with a common command prefix endinting with a ':'.

Parameters:
cbmi - is the CheckboxMenuItem that is part of a radio group.
Returns:
true if succeed

rebuildChkBoxSubmenu

public boolean rebuildChkBoxSubmenu(java.awt.Frame fm,
                                    java.awt.Menu submenu,
                                    java.lang.String preface,
                                    java.lang.String[] entryList,
                                    java.lang.String activeEntry)
rebuildChkBoxSubmenu() - rebuild a submenu with a new entry list indicated by menu labels from entryList[], the commands are preface+entryList[]. First all entries are removed from the subMenu before new entries being added. Then the new entries are added. It also maintains the hash tables.

Parameters:
fm - is the frame that contains this submenu
submenu - to change contents
preface - is added to each entry's command string
entryList - of entries menu labels to add
activeEntry - (if not null) to set true
Returns:
true if suceed