org.moyoman.client.reference.util
Class ActionManager

java.lang.Object
  |
  +--org.moyoman.client.reference.util.ActionManager

public class ActionManager
extends Object

Provides a factory for creating and caching Swing actions.

Since:
v0.01
Version:
v0.03
Author:
Jeffrey M. Thompson

Field Summary
private  Map _actions
          Map which contains all actions, stored by name.
private  Map _buttons
          Map which contains all buttons created by this, stored by action.
private  Map _checkBoxes
          Map which contains all check boxes created by this, stored by action.
private  Map _checkBoxMenuItems
          Map which contains all check box menu items created by this, stored by action.
private  boolean _isMacApp
          Flag which indicates if the items should be created in the Macintosh style or not.
private  Map _menuItems
          Map which contains all menu items created by this, stored by action.
private  Map _menus
          Map which contains all menus created by this, stored by action.
private  Object _owner
          The owner.
private  Class _ownerClass
          The class of the owner.
private  Map _radioButtonMenuItems
          Map which contains all radio button menu items created by this, stored by action.
private  Map _radioButtons
          Map which contains all radio buttons created by this, stored by action.
private  Map _toggleButtons
          Map which contains all toggle buttons created by this, stored by action.
private static Class[] ACTION_EVENT_CLASS_ARRAY
           
static String CALLBACK_PROPERTY_NAME
           
 
Constructor Summary
ActionManager(Object owner)
          Construct the manager.
 
Method Summary
private static void addToMap(Map map, Action action, AbstractButton button)
          Add the given button to the given map under the given action.
 void clear()
          Clear all contents.
 AbstractButton configureAbstractButton(AbstractButton abstractButton, Action action)
          Configure the given abstract button using the given action.
 JMenuItem configureMenuItem(JMenuItem menuItem, Action action)
          Configure the given menu item using the given action.
 JButton createButton(Action action)
          Create a button from the given action.
 JButton createButton(String actionName, boolean useIcon, boolean useText, String defaultText, int mnemonic)
          Create a button from the given action parameters.
 JCheckBox createCheckBox(Action action)
          Create a check box from the given action.
 JCheckBox createCheckBox(String actionName, boolean useIcon, boolean useText, String defaultText, int mnemonic, KeyStroke accelerator)
          Create a check box from the given action parameters.
 JCheckBoxMenuItem createCheckBoxMenuItem(Action action)
          Create a check box menu item from the given action.
 JCheckBoxMenuItem createCheckBoxMenuItem(String actionName, boolean useIcon, boolean useText, String defaultText, int mnemonic, KeyStroke accelerator)
          Create a check box menu item from the given action parameters.
 JMenu createMenu(Action action)
          Create a menu from the given action.
 JMenu createMenu(String actionName, boolean useIcon, boolean useText, String defaultText, int mnemonic)
          Create a menu from the given action parameters.
 JMenuItem createMenuItem(Action action)
          Create a menu item from the given action.
 JMenuItem createMenuItem(String actionName, boolean useIcon, boolean useText, String defaultText, int mnemonic, KeyStroke accelerator)
          Create a menu item from the given action parameters.
 JRadioButton createRadioButton(Action action)
          Create a radio button from the given action.
 JRadioButton createRadioButton(String actionName, boolean useIcon, boolean useText, String defaultText, int mnemonic, KeyStroke accelerator)
          Create a radio button from the given action parameters.
 JRadioButtonMenuItem createRadioButtonMenuItem(Action action)
          Create a radio button menu item from the given action.
 JRadioButtonMenuItem createRadioButtonMenuItem(String actionName, boolean useIcon, boolean useText, String defaultText, int mnemonic, KeyStroke accelerator)
          Create a radio button menu item from the given action parameters.
 JToggleButton createToggleButton(Action action)
          Create a toggle button from the given action.
 JToggleButton createToggleButton(String actionName, boolean useIcon, boolean useText, String defaultText, int mnemonic)
          Create a button from the given action parameters.
 Action getAction(String name)
          Return an action for the given name, creating it if necessary.
 Action getAction(String name, boolean useIcon)
          Return an action for the given name, creating it if necessary.
 Action getAction(String name, boolean useIcon, boolean useText)
          Return an action for the given name, creating it if necessary.
 Action getAction(String name, boolean useIcon, boolean useText, String defaultText)
          Return an action for the given name, creating it if necessary.
 Action getAction(String name, boolean useIcon, boolean useText, String defaultText, int mnemonic)
          Return an action for the given name, creating it if necessary.
 Action getAction(String name, boolean useIcon, boolean useText, String defaultText, int mnemonic, KeyStroke accelerator)
          Return an action for the given name, creating it if necessary.
 JButton getButton(Action action)
          Return the first entry in the buttons list corresponding to the given action.
private  Map getButtons()
          Return the buttons map, creating it if necessary.
 List getButtons(Action action)
          Return the buttons list corresponding to the given action.
 JCheckBox getCheckBox(Action action)
          Return the first entry in the check boxes list corresponding to the given action.
private  Map getCheckBoxes()
          Return the check boxes map, creating it if necessary.
 List getCheckBoxes(Action action)
          Return the check boxes list corresponding to the given action.
 JCheckBoxMenuItem getCheckBoxMenuItem(Action action)
          Return the first entry in the check box menu items list corresponding to the given action.
private  Map getCheckBoxMenuItems()
          Return the check box menu items map, creating it if necessary.
 List getCheckBoxMenuItems(Action action)
          Return the check box menu items list corresponding to the given action.
private  Object getFirstInList(List list)
          Return the first entry in the given list.
private  List getList(Map map, Action action)
          Return the list from the given map corresponding to the given action.
 JMenu getMenu(Action action)
          Return the first entry in the menus list corresponding to the given action.
 JMenuItem getMenuItem(Action action)
          Return the first entry in the menu items list corresponding to the given action.
private  Map getMenuItems()
          Return the menu items map, creating it if necessary.
 List getMenuItems(Action action)
          Return the menu items list corresponding to the given action.
private  Map getMenus()
          Return the menu map, creating it if necessary.
 List getMenus(Action action)
          Return the menus list corresponding to the given action.
 JRadioButton getRadioButton(Action action)
          Return the first entry in the radio buttons list corresponding to the given action.
 JRadioButtonMenuItem getRadioButtonMenuItem(Action action)
          Return the first entry in the radio button menu items list corresponding to the given action.
private  Map getRadioButtonMenuItems()
          Return the radio button menu items map, creating it if necessary.
 List getRadioButtonMenuItems(Action action)
          Return the radio button menu items list corresponding to the given action.
private  Map getRadioButtons()
          Return the radio buttons map, creating it if necessary.
 List getRadioButtons(Action action)
          Return the radio buttons list corresponding to the given action.
 JToggleButton getToggleButton(Action action)
          Return the first entry in the toggle buttons list corresponding to the given action.
private  Map getToggleButtons()
          Return the toggle buttons map, creating it if necessary.
 List getToggleButtons(Action action)
          Return the toggle buttons list corresponding to the given action.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_EVENT_CLASS_ARRAY

private static final Class[] ACTION_EVENT_CLASS_ARRAY

CALLBACK_PROPERTY_NAME

public static final String CALLBACK_PROPERTY_NAME
See Also:
Constant Field Values

_ownerClass

private Class _ownerClass
The class of the owner.


_actions

private Map _actions
Map which contains all actions, stored by name.


_buttons

private Map _buttons
Map which contains all buttons created by this, stored by action.


_checkBoxMenuItems

private Map _checkBoxMenuItems
Map which contains all check box menu items created by this, stored by action.


_checkBoxes

private Map _checkBoxes
Map which contains all check boxes created by this, stored by action.


_menuItems

private Map _menuItems
Map which contains all menu items created by this, stored by action.


_menus

private Map _menus
Map which contains all menus created by this, stored by action.


_radioButtonMenuItems

private Map _radioButtonMenuItems
Map which contains all radio button menu items created by this, stored by action.


_radioButtons

private Map _radioButtons
Map which contains all radio buttons created by this, stored by action.


_toggleButtons

private Map _toggleButtons
Map which contains all toggle buttons created by this, stored by action.


_owner

private Object _owner
The owner.


_isMacApp

private boolean _isMacApp
Flag which indicates if the items should be created in the Macintosh style or not.

Constructor Detail

ActionManager

public ActionManager(Object owner)
Construct the manager.

Parameters:
owner - The owner of this manager. The actions make method calls on this owner.
Since:
v0.01
Method Detail

getAction

public Action getAction(String name)
Return an action for the given name, creating it if necessary. The action uses these resources:
"MENU_" + name + "Action" The button label.
"MENU_" + name + "ToolTip" The tooltip text.
"ICON_" + name The icon filename.
name + "ActionPerformed" The callback method name on the owning object. This method is assumed to take one argument of type ActionEvent.

Parameters:
name - The name of the action, used for reference and to obtain resources.
Since:
v0.01

getAction

public Action getAction(String name,
                        boolean useIcon)
Return an action for the given name, creating it if necessary. The action uses these resources:
"MENU_" + name + "Action" The button label.
"MENU_" + name + "ToolTip" The tooltip text.
"ICON_" + name The icon filename.
name + "ActionPerformed" The callback method name on the owning object. This method is assumed to take one argument of type ActionEvent.

Parameters:
name - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
Since:
v0.01

getAction

public Action getAction(String name,
                        boolean useIcon,
                        boolean useText)
Return an action for the given name, creating it if necessary. The action uses these resources:
"MENU_" + name + "Action" The button label.
"MENU_" + name + "ToolTip" The tooltip text.
"ICON_" + name The icon filename.
name + "ActionPerformed" The callback method name on the owning object. This method is assumed to take one argument of type ActionEvent.

Parameters:
name - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
Since:
v0.01

getAction

public Action getAction(String name,
                        boolean useIcon,
                        boolean useText,
                        String defaultText)
Return an action for the given name, creating it if necessary. The action uses these resources:
"MENU_" + name + "Action" The button label.
"MENU_" + name + "ToolTip" The tooltip text.
"ICON_" + name The icon filename.
name + "ActionPerformed" The callback method name on the owning object. This method is assumed to take one argument of type ActionEvent.

Parameters:
name - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
Since:
v0.01

getAction

public Action getAction(String name,
                        boolean useIcon,
                        boolean useText,
                        String defaultText,
                        int mnemonic)
Return an action for the given name, creating it if necessary. The action uses these resources:
"MENU_" + name + "Action" The button label.
"MENU_" + name + "ToolTip" The tooltip text.
"ICON_" + name The icon filename.
name + "ActionPerformed" The callback method name on the owning object. This method is assumed to take one argument of type ActionEvent.

Parameters:
name - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
Since:
v0.01

getAction

public Action getAction(String name,
                        boolean useIcon,
                        boolean useText,
                        String defaultText,
                        int mnemonic,
                        KeyStroke accelerator)
Return an action for the given name, creating it if necessary. The action uses these resources:
"MENU_" + name + "Action" The button label.
"MENU_" + name + "ToolTip" The tooltip text.
"ICON_" + name The icon filename.
name + "ActionPerformed" The callback method name on the owning object. This method is assumed to take one argument of type ActionEvent.

Parameters:
name - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
accelerator - The accelerator key stroke.
Since:
v0.01

getButton

public JButton getButton(Action action)
Return the first entry in the buttons list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getButtons

public List getButtons(Action action)
Return the buttons list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getCheckBox

public JCheckBox getCheckBox(Action action)
Return the first entry in the check boxes list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getCheckBoxMenuItem

public JCheckBoxMenuItem getCheckBoxMenuItem(Action action)
Return the first entry in the check box menu items list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getCheckBoxMenuItems

public List getCheckBoxMenuItems(Action action)
Return the check box menu items list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getCheckBoxes

public List getCheckBoxes(Action action)
Return the check boxes list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getMenu

public JMenu getMenu(Action action)
Return the first entry in the menus list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getMenuItem

public JMenuItem getMenuItem(Action action)
Return the first entry in the menu items list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getMenuItems

public List getMenuItems(Action action)
Return the menu items list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getMenus

public List getMenus(Action action)
Return the menus list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getRadioButton

public JRadioButton getRadioButton(Action action)
Return the first entry in the radio buttons list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getRadioButtonMenuItem

public JRadioButtonMenuItem getRadioButtonMenuItem(Action action)
Return the first entry in the radio button menu items list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getRadioButtonMenuItems

public List getRadioButtonMenuItems(Action action)
Return the radio button menu items list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getRadioButtons

public List getRadioButtons(Action action)
Return the radio buttons list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getToggleButton

public JToggleButton getToggleButton(Action action)
Return the first entry in the toggle buttons list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getToggleButtons

public List getToggleButtons(Action action)
Return the toggle buttons list corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

clear

public void clear()
Clear all contents.

Since:
v0.01

configureAbstractButton

public AbstractButton configureAbstractButton(AbstractButton abstractButton,
                                              Action action)
Configure the given abstract button using the given action.

Parameters:
abstractButton - The abstract button to configure.
action - The action to use.
Since:
v0.01

configureMenuItem

public JMenuItem configureMenuItem(JMenuItem menuItem,
                                   Action action)
Configure the given menu item using the given action.

Parameters:
menuItem - The menu item to configure.
action - The action to use.
Since:
v0.01

createButton

public JButton createButton(Action action)
Create a button from the given action.

Parameters:
action - The action to use.
Since:
v0.01

createButton

public JButton createButton(String actionName,
                            boolean useIcon,
                            boolean useText,
                            String defaultText,
                            int mnemonic)
Create a button from the given action parameters.

Parameters:
actionName - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
Since:
v0.01
See Also:
getAction( String, boolean, boolean, String, int )

createCheckBox

public JCheckBox createCheckBox(Action action)
Create a check box from the given action.

Parameters:
action - The action to use.
Since:
v0.01

createCheckBox

public JCheckBox createCheckBox(String actionName,
                                boolean useIcon,
                                boolean useText,
                                String defaultText,
                                int mnemonic,
                                KeyStroke accelerator)
Create a check box from the given action parameters.

Parameters:
actionName - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
accelerator - The accelerator key stroke.
Since:
v0.01
See Also:
getAction( String, boolean, boolean, String, int, KeyStroke )

createCheckBoxMenuItem

public JCheckBoxMenuItem createCheckBoxMenuItem(Action action)
Create a check box menu item from the given action.

Parameters:
action - The action to use.
Since:
v0.01

createCheckBoxMenuItem

public JCheckBoxMenuItem createCheckBoxMenuItem(String actionName,
                                                boolean useIcon,
                                                boolean useText,
                                                String defaultText,
                                                int mnemonic,
                                                KeyStroke accelerator)
Create a check box menu item from the given action parameters.

Parameters:
actionName - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
accelerator - The accelerator key stroke.
Since:
v0.01
See Also:
getAction( String, boolean, boolean, String, int, KeyStroke )

createMenu

public JMenu createMenu(Action action)
Create a menu from the given action.

Parameters:
action - The action to use.
Since:
v0.01

createMenu

public JMenu createMenu(String actionName,
                        boolean useIcon,
                        boolean useText,
                        String defaultText,
                        int mnemonic)
Create a menu from the given action parameters.

Parameters:
actionName - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
Since:
v0.01
See Also:
getAction( String, boolean, boolean, String, int )

createMenuItem

public JMenuItem createMenuItem(Action action)
Create a menu item from the given action.

Parameters:
action - The action to use.
Since:
v0.01

createMenuItem

public JMenuItem createMenuItem(String actionName,
                                boolean useIcon,
                                boolean useText,
                                String defaultText,
                                int mnemonic,
                                KeyStroke accelerator)
Create a menu item from the given action parameters.

Parameters:
actionName - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
accelerator - The accelerator key stroke.
Since:
v0.01
See Also:
getAction( String, boolean, boolean, String, int, KeyStroke )

createRadioButton

public JRadioButton createRadioButton(Action action)
Create a radio button from the given action.

Parameters:
action - The action to use.
Since:
v0.01

createRadioButton

public JRadioButton createRadioButton(String actionName,
                                      boolean useIcon,
                                      boolean useText,
                                      String defaultText,
                                      int mnemonic,
                                      KeyStroke accelerator)
Create a radio button from the given action parameters.

Parameters:
actionName - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
accelerator - The accelerator key stroke.
Since:
v0.01
See Also:
getAction( String, boolean, boolean, String, int, KeyStroke )

createRadioButtonMenuItem

public JRadioButtonMenuItem createRadioButtonMenuItem(Action action)
Create a radio button menu item from the given action.

Parameters:
action - The action to use.
Since:
v0.01

createRadioButtonMenuItem

public JRadioButtonMenuItem createRadioButtonMenuItem(String actionName,
                                                      boolean useIcon,
                                                      boolean useText,
                                                      String defaultText,
                                                      int mnemonic,
                                                      KeyStroke accelerator)
Create a radio button menu item from the given action parameters.

Parameters:
actionName - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
accelerator - The accelerator key stroke.
Since:
v0.01
See Also:
getAction( String, boolean, boolean, String, int, KeyStroke )

createToggleButton

public JToggleButton createToggleButton(Action action)
Create a toggle button from the given action.

Parameters:
action - The action to use.
Since:
v0.01

createToggleButton

public JToggleButton createToggleButton(String actionName,
                                        boolean useIcon,
                                        boolean useText,
                                        String defaultText,
                                        int mnemonic)
Create a button from the given action parameters.

Parameters:
actionName - The name of the action, used for reference and to obtain resources.
useIcon - If true, use the default icon. If false, don't use an icon.
useText - If true, use the default text. If false, don't use text.
defaultText - The default text to use if the name resource key is not found.
mnemonic - The mnemonic KeyEvent.
Since:
v0.01
See Also:
getAction( String, boolean, boolean, String, int )

addToMap

private static void addToMap(Map map,
                             Action action,
                             AbstractButton button)
Add the given button to the given map under the given action.

Parameters:
map - The map to use.
action - The action to use.
button - The button to store.
Since:
v0.01

getButtons

private Map getButtons()
Return the buttons map, creating it if necessary.

Since:
v0.01

getCheckBoxMenuItems

private Map getCheckBoxMenuItems()
Return the check box menu items map, creating it if necessary.

Since:
v0.01

getCheckBoxes

private Map getCheckBoxes()
Return the check boxes map, creating it if necessary.

Since:
v0.01

getFirstInList

private Object getFirstInList(List list)
Return the first entry in the given list.

Parameters:
list - The list of interest.
Since:
v0.01

getList

private List getList(Map map,
                     Action action)
Return the list from the given map corresponding to the given action.

Parameters:
action - The action of interest.
Throws:
IllegalArgumentException - if action is null.
Since:
v0.01

getMenuItems

private Map getMenuItems()
Return the menu items map, creating it if necessary.

Since:
v0.01

getMenus

private Map getMenus()
Return the menu map, creating it if necessary.

Since:
v0.01

getRadioButtonMenuItems

private Map getRadioButtonMenuItems()
Return the radio button menu items map, creating it if necessary.

Since:
v0.01

getRadioButtons

private Map getRadioButtons()
Return the radio buttons map, creating it if necessary.

Since:
v0.01

getToggleButtons

private Map getToggleButtons()
Return the toggle buttons map, creating it if necessary.

Since:
v0.01