jigcell.compare.ui
Class MenuBuilder

java.lang.Object
  extended by jigcell.compare.ui.MenuBuilder

public class MenuBuilder
extends java.lang.Object

Generates and manages menus and popups for another component.

This code is licensed under the DARPA BioCOMP Open Source License. See LICENSE for more details.

Author:
Nicholas Allen

Nested Class Summary
protected static class MenuBuilder.Builder
          Builder for creating the item scripts.
protected  class MenuBuilder.ScriptActionTrampoline
          Handles and dispatches menu events to handlers.
 
Field Summary
protected  MenuBuilder.Builder builder
          Menu builder
protected static java.util.Map BUILDERS
          Known menu builders
protected  java.util.Map commandIndex
          Map from commands to menu elements if indexing is enabled
protected  java.lang.String global
          Global handler
static javax.swing.Icon ICON_BLANK
          Blank image for popup and menu entries without icons
static java.lang.String MENUITEM_SEPARATOR
          Special menu separator
protected  java.lang.Object target
          Target of event actions
 
Constructor Summary
MenuBuilder(java.lang.Object target)
          Creates a new manager for menus.
MenuBuilder(java.lang.Object target, boolean index)
          Creates a new manager for menus.
 
Method Summary
 void clearCommandIndex()
          Clears the command index for menu elements.
static javax.swing.JCheckBoxMenuItem createCheckBoxMenuItem(java.lang.String entry, java.lang.String command, javax.swing.KeyStroke accelerator, java.awt.event.ActionListener listener)
          A single checkbox menu item for a view.
static javax.swing.JMenu createMenu(java.lang.String name, java.lang.String command, javax.swing.Icon icon, java.awt.event.ActionListener listener)
          A single menu for a view.
static javax.swing.JMenuItem createMenuItem(java.lang.String entry, java.lang.String command, javax.swing.Icon icon, javax.swing.KeyStroke accelerator, java.awt.event.ActionListener listener)
          A single menu item for a view.
 javax.swing.JMenu[] createMenus(java.lang.String name)
          Creates menus for a menu bar.
static javax.swing.JMenu[] createMenus(java.lang.String[] headers, java.lang.String[][] entries, java.lang.String[][] commands, javax.swing.Icon[][] icons, javax.swing.KeyStroke[][] accelerators, java.awt.event.ActionListener listener)
          A list of menus for a view.
 javax.swing.JPopupMenu createPopup(java.lang.String name)
          Creates a popup menu
static javax.swing.JPopupMenu createPopup(java.lang.String[] entries, java.lang.String[] commands, javax.swing.Icon[] icons, java.awt.event.ActionListener listener)
          Creates a context menu for a view.
static javax.swing.JRadioButtonMenuItem createRadioButtonMenuItem(java.lang.String entry, java.lang.String command, javax.swing.KeyStroke accelerator, java.awt.event.ActionListener listener, javax.swing.ButtonGroup group)
          A single radio button menu item for a view.
static javax.swing.JButton[] createToolbar(java.lang.String[] entries, java.lang.String[] commands, javax.swing.Icon[] icons, java.awt.event.ActionListener listener)
          Creates a collection of toolbar buttons.
 javax.swing.JButton[] createTools(java.lang.String name)
          Creates buttons for a tool bar.
static javax.swing.JButton findButton(javax.swing.JButton[] tools, java.lang.String action)
          Returns a JButton with the given action command or returns null to indicate that no such button exists.
static javax.swing.JMenuItem findMenuItem(javax.swing.MenuElement[] elements, java.lang.String action, boolean checkMenus)
          Returns an item with the given action command or returns null to indicate that no such menu item exists.
static javax.swing.JMenuItem findMenuItem(javax.swing.MenuElement element, java.lang.String action, boolean checkMenus)
          Returns an item with the given action command or returns null to indicate that no such menu item exists.
static javax.swing.JMenu findParentMenu(javax.swing.MenuElement[] elements, java.lang.String action, boolean checkMenus)
          Returns an item with the given action command or returns null to indicate that no such menu item exists.
static javax.swing.JMenu findParentMenu(javax.swing.MenuElement element, java.lang.String action, boolean checkMenus)
          Returns a menu containing an item with the given action command or returns null to indicate that no such menu exists.
protected static javax.swing.MenuElement findParentMenuElement(javax.swing.MenuElement element, java.lang.String action, boolean checkMenus)
          Returns a menu containing an item with the given action command or returns null to indicate that no such menu exists.
protected  void indexCommand(javax.swing.AbstractButton button)
          Indexes the command from a button.
protected  void indexCommands(javax.swing.AbstractButton[] buttons)
          Indexes the commands from a set of buttons.
protected  void indexCommands(javax.swing.MenuElement[] elements)
          Indexes the commands from a set of menu elements.
 void setCommandEnabled(java.lang.String command, boolean enabled)
          Enables or disables all of the menu elements with a given action command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ICON_BLANK

public static final javax.swing.Icon ICON_BLANK
Blank image for popup and menu entries without icons


MENUITEM_SEPARATOR

public static final java.lang.String MENUITEM_SEPARATOR
Special menu separator

See Also:
Constant Field Values

BUILDERS

protected static final java.util.Map BUILDERS
Known menu builders


builder

protected MenuBuilder.Builder builder
Menu builder


commandIndex

protected java.util.Map commandIndex
Map from commands to menu elements if indexing is enabled


target

protected java.lang.Object target
Target of event actions


global

protected java.lang.String global
Global handler

Constructor Detail

MenuBuilder

public MenuBuilder(java.lang.Object target)
Creates a new manager for menus.

Parameters:
target - Owner

MenuBuilder

public MenuBuilder(java.lang.Object target,
                   boolean index)
Creates a new manager for menus.

Parameters:
target - Owner
index - Whether to create an index of the generated menus
Method Detail

createCheckBoxMenuItem

public static javax.swing.JCheckBoxMenuItem createCheckBoxMenuItem(java.lang.String entry,
                                                                   java.lang.String command,
                                                                   javax.swing.KeyStroke accelerator,
                                                                   java.awt.event.ActionListener listener)
A single checkbox menu item for a view.

Parameters:
entry - Menu entry
command - Menu action command (optional)
accelerator - Menu key accelerator (optional)
listener - Listener for menu actions

createMenu

public static javax.swing.JMenu createMenu(java.lang.String name,
                                           java.lang.String command,
                                           javax.swing.Icon icon,
                                           java.awt.event.ActionListener listener)
A single menu for a view.

Parameters:
name - Menu name
command - Menu action command (optional)
icon - Menu icon which must be 16x16 in size (optional)
listener - Listener for menu actions (optional)

createMenuItem

public static javax.swing.JMenuItem createMenuItem(java.lang.String entry,
                                                   java.lang.String command,
                                                   javax.swing.Icon icon,
                                                   javax.swing.KeyStroke accelerator,
                                                   java.awt.event.ActionListener listener)
A single menu item for a view.

Parameters:
entry - Menu entry
command - Menu action command (optional)
icon - Menu icon which must be 16x16 in size (optional)
accelerator - Menu key accelerator (optional)
listener - Listener for menu actions

createMenus

public static javax.swing.JMenu[] createMenus(java.lang.String[] headers,
                                              java.lang.String[][] entries,
                                              java.lang.String[][] commands,
                                              javax.swing.Icon[][] icons,
                                              javax.swing.KeyStroke[][] accelerators,
                                              java.awt.event.ActionListener listener)
A list of menus for a view.

Parameters:
headers - Menu headers
entries - Menu entries
commands - Menu action commands
icons - Menu icons which must be 16x16 in size (optional)
accelerators - Menu key accelerators (optional)
listener - Listener for menu actions

createPopup

public static javax.swing.JPopupMenu createPopup(java.lang.String[] entries,
                                                 java.lang.String[] commands,
                                                 javax.swing.Icon[] icons,
                                                 java.awt.event.ActionListener listener)
Creates a context menu for a view.

Parameters:
entries - Menu entries
commands - Menu action commands
icons - Menu icons which must be 16x16 in size (optional)
listener - Listener for menu actions

createRadioButtonMenuItem

public static javax.swing.JRadioButtonMenuItem createRadioButtonMenuItem(java.lang.String entry,
                                                                         java.lang.String command,
                                                                         javax.swing.KeyStroke accelerator,
                                                                         java.awt.event.ActionListener listener,
                                                                         javax.swing.ButtonGroup group)
A single radio button menu item for a view. This method cannot be used to create menu separators.

Parameters:
entry - Menu entry
command - Menu action command (optional)
accelerator - Menu key accelerator (optional)
listener - Listener for menu actions
group - Button group

createToolbar

public static javax.swing.JButton[] createToolbar(java.lang.String[] entries,
                                                  java.lang.String[] commands,
                                                  javax.swing.Icon[] icons,
                                                  java.awt.event.ActionListener listener)
Creates a collection of toolbar buttons.

Parameters:
entries - Toolbar action commands
commands - Toolbar action commands
icons - Toolbar icons which must be 24x24 in size
listener - Listener for button actions

findButton

public static javax.swing.JButton findButton(javax.swing.JButton[] tools,
                                             java.lang.String action)
Returns a JButton with the given action command or returns null to indicate that no such button exists.

Parameters:
tools - Toolbar
action - Action command

findMenuItem

public static javax.swing.JMenuItem findMenuItem(javax.swing.MenuElement element,
                                                 java.lang.String action,
                                                 boolean checkMenus)
Returns an item with the given action command or returns null to indicate that no such menu item exists.

Parameters:
element - Menu element to start search from
action - Action command
checkMenus - Whether to check menus as well as menu items for the command

findMenuItem

public static javax.swing.JMenuItem findMenuItem(javax.swing.MenuElement[] elements,
                                                 java.lang.String action,
                                                 boolean checkMenus)
Returns an item with the given action command or returns null to indicate that no such menu item exists.

Parameters:
elements - Menu elements to start search from
action - Action command
checkMenus - Whether to check menus as well as menu items for the command

findParentMenu

public static javax.swing.JMenu findParentMenu(javax.swing.MenuElement element,
                                               java.lang.String action,
                                               boolean checkMenus)
Returns a menu containing an item with the given action command or returns null to indicate that no such menu exists.

Parameters:
element - Menu element to start search from
action - Action command
checkMenus - Whether to check menus as well as menu items for the command

findParentMenu

public static javax.swing.JMenu findParentMenu(javax.swing.MenuElement[] elements,
                                               java.lang.String action,
                                               boolean checkMenus)
Returns an item with the given action command or returns null to indicate that no such menu item exists.

Parameters:
elements - Menu elements to start search from
action - Action command
checkMenus - Whether to check menus as well as menu items for the command

findParentMenuElement

protected static javax.swing.MenuElement findParentMenuElement(javax.swing.MenuElement element,
                                                               java.lang.String action,
                                                               boolean checkMenus)
Returns a menu containing an item with the given action command or returns null to indicate that no such menu exists.

Parameters:
element - Menu element to start search from
action - Action command
checkMenus - Whether to check menus as well as menu items for the command

clearCommandIndex

public void clearCommandIndex()
Clears the command index for menu elements. After performing this operation, indexing will be disabled.


createMenus

public javax.swing.JMenu[] createMenus(java.lang.String name)
Creates menus for a menu bar.

Parameters:
name - Menu bar name

createPopup

public javax.swing.JPopupMenu createPopup(java.lang.String name)
Creates a popup menu

Parameters:
name - Menu name

createTools

public javax.swing.JButton[] createTools(java.lang.String name)
Creates buttons for a tool bar.

Parameters:
name - Tool bar name

setCommandEnabled

public void setCommandEnabled(java.lang.String command,
                              boolean enabled)
Enables or disables all of the menu elements with a given action command. Indexing must be enabled for this to work.

Parameters:
command - Command
enabled - State for menu elements

indexCommand

protected void indexCommand(javax.swing.AbstractButton button)
Indexes the command from a button.

Parameters:
button - Button

indexCommands

protected void indexCommands(javax.swing.AbstractButton[] buttons)
Indexes the commands from a set of buttons.

Parameters:
buttons - Button set

indexCommands

protected void indexCommands(javax.swing.MenuElement[] elements)
Indexes the commands from a set of menu elements.

Parameters:
elements - Menu elements