org.vizzini.ui
Class ActionManager

java.lang.Object
  extended by org.vizzini.ui.ActionManager

public final class ActionManager
extends Object

Provides a factory for creating Swing actions and Swing button-type components. Actions are cached by name so subsequent accesses return the same object. Components created with this are cached by action, so subsequent accesses return the same object.

Since:
v0.1
Version:
v0.3
Author:
Jeffrey M. Thompson

Nested Class Summary
(package private) static class ActionManager.CallbackAction
          Provides an action which looks up the method to call.
 
Field Summary
static String CALLBACK_PROPERTY
          Callback property.
static String NAME_PROPERTY
          Name property.
static String TARGET_PROPERTY
          Target property.
static String USES_CALLBACK_PROPERTY
          Uses callback property.
 
Method Summary
 void clear()
          Clear all actions and controls.
static void clearInstances()
          Clear all instances.
static Action configureAction(Action action, Object target, String name, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator)
          Configure the given action.
static KeyStroke getAcceleratorFor(String string)
          Return the accelerator for the given string.
static Action getAction(Object target, String name)
          Return an action for the given name, creating it if necessary.
static Action getAction(Object target, String name, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator)
          Return an action for the given name, creating it if necessary.
static Action getAction(Object target, String name, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator, boolean useCallback)
          Return an action for the given name, creating it if necessary.
static JButton getButton(Object target, Action action)
          Return a button for the given action, creating it if necessary.
static JButton getButton(Object target, String actionName, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator, boolean useCallback)
          Return a button for the given action parameters, creating it if necessary.
static JCheckBox getCheckBox(Object target, Action action)
          Return a check box for the given action, creating it if necessary.
static JCheckBox getCheckBox(Object target, String actionName, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator, boolean useCallback)
          Return a check box for the given action parameters, creating it if necessary.
static JCheckBoxMenuItem getCheckBoxMenuItem(Object target, Action action)
          Return a check box menu item for the given action, creating it if necessary.
static JCheckBoxMenuItem getCheckBoxMenuItem(Object target, String actionName, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator, boolean useCallback)
          Return a check box menu item for the given action parameters, creating it if necessary.
static int getKeyCodeFor(String string)
          Return the key code for the given string.
static JMenu getMenu(Object target, Action action)
          Return a menu for the given action, creating it if necessary.
static JMenu getMenu(Object target, String actionName, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator)
          Return a menu for the given action parameters, creating it if necessary.
static MenuButton getMenuButton(Object target, Action action)
          Return a menu button for the given action, creating it if necessary.
static MenuButton getMenuButton(Object target, String actionName, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator)
          Return a menu button for the given action parameters, creating it if necessary.
static JMenuItem getMenuItem(Object target, Action action)
          Return a menu item for the given action, creating it if necessary.
static JMenuItem getMenuItem(Object target, String actionName, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator, boolean useCallback)
          Return a menu item for the given action parameters, creating it if necessary.
static JRadioButton getRadioButton(Object target, Action action)
          Return a radio button for the given action, creating it if necessary.
static JRadioButton getRadioButton(Object target, String actionName, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator, boolean useCallback)
          Return a radio button for the given action parameters, creating it if necessary.
static JRadioButtonMenuItem getRadioButtonMenuItem(Object target, Action action)
          Return a radio button menu item for the given action, creating it if necessary.
static JRadioButtonMenuItem getRadioButtonMenuItem(Object target, String actionName, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator, boolean useCallback)
          Return a radio button menu item for the given action parameters, creating it if necessary.
static JToggleButton getToggleButton(Object target, Action action)
          Return a toggle button for the given action, creating it if necessary.
static JToggleButton getToggleButton(Object target, String actionName, boolean useIcon, boolean useText, boolean useMnemonic, boolean useAccelerator, boolean useCallback)
          Return a toggle button for the given action parameters, creating it if necessary.
static boolean isMacApp()
          Return true if this is a Macintosh app in the sense used by this class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USES_CALLBACK_PROPERTY

public static final String USES_CALLBACK_PROPERTY
Uses callback property.

See Also:
Constant Field Values

CALLBACK_PROPERTY

public static final String CALLBACK_PROPERTY
Callback property.

See Also:
Constant Field Values

NAME_PROPERTY

public static final String NAME_PROPERTY
Name property.

See Also:
Constant Field Values

TARGET_PROPERTY

public static final String TARGET_PROPERTY
Target property.

See Also:
Constant Field Values
Method Detail

clearInstances

public static void clearInstances()
Clear all instances.

Since:
v0.1

configureAction

public static Action configureAction(Action action,
                                     Object target,
                                     String name,
                                     boolean useIcon,
                                     boolean useText,
                                     boolean useMnemonic,
                                     boolean useAccelerator)
Configure the given action. This method sets the icon, text, tool tip text, mnemonic, and accelerator as indicated by the input parameters and resources. Applets don't use mnemonics or accelerators.

Since:
v0.1

getAcceleratorFor

public static KeyStroke getAcceleratorFor(String string)
Return the accelerator for the given string.

Since:
v0.1

getAction

public static Action getAction(Object target,
                               String name)
Return an action for the given name, creating it if necessary.

Throws:
IllegalArgumentException - if target is null.
IllegalArgumentException - if name is null.
Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

getAction

public static Action getAction(Object target,
                               String name,
                               boolean useIcon,
                               boolean useText,
                               boolean useMnemonic,
                               boolean useAccelerator)
Return an action for the given name, creating it if necessary. The action uses these resources:
"STRING_" + name + "Action" The button label.
"STRING_" + name + "ToolTip" The tooltip text.
"STRING_" + name + "Mnemonic" The mnemonic text (only the first character is used).
"STRING_" + name + "Accelerator" The accelerator is in the form [[CMD,ALT,CTRL,META,SHIFT]|]{character}.
"ICON_" + name The icon filename.
name + "ActionPerformed" The callback method name on the target object. This method is assumed to take one argument of type ActionEvent.

Parameters:
target - The target object.
name - The name of the action, used for reference and to obtain resources.
useIcon - If true, use either the resource icon or the default icon. If false, don't use an icon.
useText - If true, use either the resource text or the default text. If false, don't use text.
useMnemonic - If true, use the resource mnemonic. If false, don't use a mnemonic.
useAccelerator - If true, use the resource accelerator. If false, don't use an accelerator.
Throws:
IllegalArgumentException - if target is null.
IllegalArgumentException - if name is null.
Since:
v0.1

getAction

public static Action getAction(Object target,
                               String name,
                               boolean useIcon,
                               boolean useText,
                               boolean useMnemonic,
                               boolean useAccelerator,
                               boolean useCallback)
Return an action for the given name, creating it if necessary. The action uses these resources:
"STRING_" + name + "Action" The button label.
"STRING_" + name + "ToolTip" The tooltip text.
"STRING_" + name + "Mnemonic" The mnemonic text (only the first character is used).
"STRING_" + name + "Accelerator" The accelerator is in the form [[CMD,ALT,CTRL,META,SHIFT]|]{character}.
"ICON_" + name The icon filename.
name + "ActionPerformed" The callback method name on the target object. This method is assumed to take one argument of type ActionEvent.

Parameters:
target - The target object.
name - The name of the action, used for reference and to obtain resources.
useIcon - If true, use either the resource icon or the default icon. If false, don't use an icon.
useText - If true, use either the resource text or the default text. If false, don't use text.
useMnemonic - If true, use the resource mnemonic. If false, don't use a mnemonic.
useAccelerator - If true, use the resource accelerator. If false, don't use an accelerator.
useCallback - Flag indicating whether to associate a callback method.
Throws:
IllegalArgumentException - if target is null.
IllegalArgumentException - if name is null.
Since:
v0.1

getButton

public static JButton getButton(Object target,
                                Action action)
Return a button for the given action, creating it if necessary.

Parameters:
target - The target object.
action - The action of interest.
Throws:
IllegalArgumentException - if target or action is null.
Since:
v0.1

getButton

public static JButton getButton(Object target,
                                String actionName,
                                boolean useIcon,
                                boolean useText,
                                boolean useMnemonic,
                                boolean useAccelerator,
                                boolean useCallback)
Return a button for the given action parameters, creating it if necessary.

Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

getCheckBox

public static JCheckBox getCheckBox(Object target,
                                    Action action)
Return a check box for the given action, creating it if necessary.

Parameters:
target - The target object.
action - The action of interest.
Throws:
IllegalArgumentException - if target or action is null.
Since:
v0.1

getCheckBox

public static JCheckBox getCheckBox(Object target,
                                    String actionName,
                                    boolean useIcon,
                                    boolean useText,
                                    boolean useMnemonic,
                                    boolean useAccelerator,
                                    boolean useCallback)
Return a check box for the given action parameters, creating it if necessary.

Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

getCheckBoxMenuItem

public static JCheckBoxMenuItem getCheckBoxMenuItem(Object target,
                                                    Action action)
Return a check box menu item for the given action, creating it if necessary.

Parameters:
target - The target object.
action - The action of interest.
Throws:
IllegalArgumentException - if target or action is null.
Since:
v0.1

getCheckBoxMenuItem

public static JCheckBoxMenuItem getCheckBoxMenuItem(Object target,
                                                    String actionName,
                                                    boolean useIcon,
                                                    boolean useText,
                                                    boolean useMnemonic,
                                                    boolean useAccelerator,
                                                    boolean useCallback)
Return a check box menu item for the given action parameters, creating it if necessary.

Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

getKeyCodeFor

public static int getKeyCodeFor(String string)
Return the key code for the given string.

Since:
v0.1

getMenu

public static JMenu getMenu(Object target,
                            Action action)
Return a menu for the given action, creating it if necessary.

Parameters:
target - The target object.
action - The action of interest.
Throws:
IllegalArgumentException - if target or action is null.
Since:
v0.1

getMenu

public static JMenu getMenu(Object target,
                            String actionName,
                            boolean useIcon,
                            boolean useText,
                            boolean useMnemonic,
                            boolean useAccelerator)
Return a menu for the given action parameters, creating it if necessary.

Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

getMenuButton

public static MenuButton getMenuButton(Object target,
                                       Action action)
Return a menu button for the given action, creating it if necessary.

Parameters:
target - The target object.
action - The action of interest.
Throws:
IllegalArgumentException - if target or action is null.
Since:
v0.1

getMenuButton

public static MenuButton getMenuButton(Object target,
                                       String actionName,
                                       boolean useIcon,
                                       boolean useText,
                                       boolean useMnemonic,
                                       boolean useAccelerator)
Return a menu button for the given action parameters, creating it if necessary.

Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

getMenuItem

public static JMenuItem getMenuItem(Object target,
                                    Action action)
Return a menu item for the given action, creating it if necessary.

Parameters:
target - The target object.
action - The action of interest.
Throws:
IllegalArgumentException - if target or action is null.
Since:
v0.1

getMenuItem

public static JMenuItem getMenuItem(Object target,
                                    String actionName,
                                    boolean useIcon,
                                    boolean useText,
                                    boolean useMnemonic,
                                    boolean useAccelerator,
                                    boolean useCallback)
Return a menu item for the given action parameters, creating it if necessary.

Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

getRadioButton

public static JRadioButton getRadioButton(Object target,
                                          Action action)
Return a radio button for the given action, creating it if necessary.

Parameters:
target - The target object.
action - The action of interest.
Throws:
IllegalArgumentException - if target or action is null.
Since:
v0.1

getRadioButton

public static JRadioButton getRadioButton(Object target,
                                          String actionName,
                                          boolean useIcon,
                                          boolean useText,
                                          boolean useMnemonic,
                                          boolean useAccelerator,
                                          boolean useCallback)
Return a radio button for the given action parameters, creating it if necessary.

Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

getRadioButtonMenuItem

public static JRadioButtonMenuItem getRadioButtonMenuItem(Object target,
                                                          Action action)
Return a radio button menu item for the given action, creating it if necessary.

Parameters:
target - The target object.
action - The action of interest.
Throws:
IllegalArgumentException - if target or action is null.
Since:
v0.1

getRadioButtonMenuItem

public static JRadioButtonMenuItem getRadioButtonMenuItem(Object target,
                                                          String actionName,
                                                          boolean useIcon,
                                                          boolean useText,
                                                          boolean useMnemonic,
                                                          boolean useAccelerator,
                                                          boolean useCallback)
Return a radio button menu item for the given action parameters, creating it if necessary.

Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

getToggleButton

public static JToggleButton getToggleButton(Object target,
                                            Action action)
Return a toggle button for the given action, creating it if necessary.

Parameters:
target - The target object.
action - The action of interest.
Throws:
IllegalArgumentException - if target or action is null.
Since:
v0.1

getToggleButton

public static JToggleButton getToggleButton(Object target,
                                            String actionName,
                                            boolean useIcon,
                                            boolean useText,
                                            boolean useMnemonic,
                                            boolean useAccelerator,
                                            boolean useCallback)
Return a toggle button for the given action parameters, creating it if necessary.

Since:
v0.1
See Also:
getAction( Object, String, boolean, boolean, boolean, boolean, boolean )

isMacApp

public static boolean isMacApp()
Return true if this is a Macintosh app in the sense used by this class.

Since:
v0.2

clear

public void clear()
Clear all actions and controls.

Since:
v0.1


Copyright © 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02