org.pietschy.command

Class ActionCommand

Implemented Interfaces:
ActionCommandExecutor
Known Direct Subclasses:
AboutCommand, AbstractFileCommand, BeepCommand, CompoundCommand, DelegatingCommand, LazyCommand, OpenUrlCommand, ReflectionCommand, ToggleCommand, UndoableActionCommand

public abstract class ActionCommand
extends Command
implements ActionCommandExecutor

ActionCommands provide the base for all executable commands. Subclasses must implement handleExecute() to provide command specific behaviour.

Field Summary

static String
HINT_ACTION_EVENT
The key for the action event hint.
static String
HINT_INVOKER
The key for the invoker hint.
static String
HINT_INVOKER_WINDOW
The key for the invoker window hint.
static String
HINT_MODIFIERS
The key for the modifiers hint.

Fields inherited from class org.pietschy.command.Command

internalLog, listenerList, pcs

Constructor Summary

ActionCommand()
Creates a new anonymous ActionCommand.
ActionCommand(String id)
Creates a new command with the speicifed Id that is bound to the CommandManager.defaultInstance().
ActionCommand(CommandManager commandManager)
Creates a new anonymous command bound to the specified CommandManager.defaultInstance().
ActionCommand(CommandManager commandManager, String commandId)
Creates a new ActionCommand with the specified id that is bound to the specified CommandManager.

Method Summary

void
addCommandListener(CommandListener l)
Deprecated. Use addInterceptor(ActionCommandInterceptor) instead.
void
addInterceptor(ActionCommandInterceptor interceptor)
Adds an ActionCommandInterceptor the the command.
protected boolean
areEqual(Object oldValue, Object newValue)
Checks if the the two values are equal.
void
attach(AbstractButton button, String faceName)
Overrides the default implementation to also installFace an ActionListener to the button.
protected void
configureButtonStates(AbstractButton button)
This method is called to configure newly created buttons.
void
detach(AbstractButton button)
Overrides the default implementation to remove the ActionListener installed by attach(javax.swing.AbstractButton, String).
void
execute()
Causes the command to perform it's operation.
void
execute(Map hints)
Executes this command with the specified hints.
Action
getActionAdapter()
Gets an action that mirrors the default face of this command.
Action
getActionAdapter(String faceName)
Gets an action that mirrors this the specified face of this command.
String
getActionCommand()
Gets the value of this commands actionCommand string.
ActionEvent
getActionEvent()
Convenience method for getHint(ActionCommand.HINT_ACTION_EVENT).
Object
getHint(Object key)
Gets any hints that may have been specified by a call to execute(java.util.Map) or that have been explicitly set by putHint(Object,Object).
Object
getHint(Object key, Object defaultValue)
Gets any hints that may have been specified by a call to execute(java.util.Map) or that have been explicitly set by putHint(Object,Object).
Map
getHints()
Gets any hints that may have been specified by a call to execute(java.util.Map) or that have been explicitly set by putHint(Object,Object).
Object
getInvoker()
Convenience method to get the object that invoked the command.
Window
getInvokerWindow()
Convenience method to get the Window ancestor of the object that invoked the command.
int
getModifiers()
Convenience method to get any modifiers that were specified.
protected abstract void
handleExecute()
Main entry point for command subclasses that must be implemented to provide command specific behaviour.
void
installShortCut(JComponent component, String faceName, int condition)
Installs a shortcut into the components input and action maps using the accelerator of the specified face.
void
installShortCut(JComponent component, int condition)
Installs a shortcut into the components input and action maps using the accelerator specified by the default face.
protected void
postExecute()
This method is called after handleExecute() has been called.
protected boolean
preExecute()
This method is called prior to handleExecute() being called.
void
putHint(Object key, Object value)
Adds the specified hint to be available the next time execute is called.
void
putHints(Map hints)
Adds the specified hints to be available the next time execute is called.
void
removeCommandListener(CommandListener l)
Deprecated. use removeInterceptor(ActionCommandInterceptor) instead.
void
removeInterceptor(ActionCommandInterceptor interceptor)
Removes an ActionCommandInterceptor from the command.
void
requestDefautIn(RootPaneContainer container)
This method will find the first button from this command in the javax.swing.RootPaneContainer and set it to be the default button by calling javax.swing.JRootPane.setDefaultButton.
void
setActionCommand(String actionCommand)
Sets the value of this commands actionCommand string.
void
uninstallShortCut(JComponent component, String faceName, int condition)
Removes the short cut installed by a previous call to installShortCut(javax.swing.JComponent, String, int)
void
uninstallShortCut(JComponent component, int condition)
Removes the short cut installed by a previous call to installShortCut(javax.swing.JComponent, int)

Methods inherited from class org.pietschy.command.Command

addFace, addHoverListener, addNewFace, addNotify, addPropertyChangeListener, addPropertyChangeListener, attach, buttonIterator, configureButtonAppearance, configureButtonAppearances, configureButtonAppearances, configureButtonStates, createButton, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, createMenuItem, detach, export, faceExists, fireHoverEnded, fireHoverStarted, getAccelerator, getAlternativeFaceNames, getButtonFactory, getButtonIn, getCommandManager, getDefaultFace, getDefaultFace, getDescription, getFace, getFace, getIcon, getId, getLongDescription, getMenuFactory, getMnemonic, getMnemonicIndex, getProperty, getProperty, getPropertyNames, getSelectedIcon, getText, getTextPosition, getToolbarFactory, initCommandManager, installFace, isAnonymous, isAttachedTo, isEnabled, isVisible, putProperty, removeHoverListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, requestFocusIn, setAccelerator, setButtonFactory, setDescription, setEnabled, setIcon, setLongDescription, setMenuFactory, setMnemonic, setMnemonicIndex, setSelectedIcon, setText, setTextPosition, setToolbarFactory, setVisible, toString

Field Details

HINT_ACTION_EVENT

public static final String HINT_ACTION_EVENT
The key for the action event hint. This hint will be present when ever the command is invoked from an attached AbstractButton.

HINT_INVOKER

public static final String HINT_INVOKER
The key for the invoker hint. This hint will be present when ever the command is invoked from an attached AbstractButton.

HINT_INVOKER_WINDOW

public static final String HINT_INVOKER_WINDOW
The key for the invoker window hint. This hint will be present whenever the a Window parent can be found from the invoker.

HINT_MODIFIERS

public static final String HINT_MODIFIERS
The key for the modifiers hint. This hint will be present when ever the command is invoked from an attached AbstractButton.

Constructor Details

ActionCommand

public ActionCommand()
Creates a new anonymous ActionCommand. Anonymous commands must be fully programatically generated and can only be added to groups manually by calling groupCommand.installFace(myAnonymousCommand).

ActionCommand

public ActionCommand(String id)

ActionCommand

public ActionCommand(CommandManager commandManager)
Creates a new anonymous command bound to the specified CommandManager.defaultInstance().

ActionCommand

public ActionCommand(CommandManager commandManager,
                     String commandId)
Creates a new ActionCommand with the specified id that is bound to the specified CommandManager.

Method Details

addCommandListener

public void addCommandListener(CommandListener l)

Deprecated. Use addInterceptor(ActionCommandInterceptor) instead.

Adds a CommandListener the the command. The listener will be notified when the command is executed.
Parameters:
l - the CommandListener to register

addInterceptor

public void addInterceptor(ActionCommandInterceptor interceptor)
Adds an ActionCommandInterceptor the the command. The interceptor will be invoked before and after the command is executed.
Parameters:
interceptor - the ActionCommandInterceptor to register

areEqual

protected boolean areEqual(Object oldValue,
                           Object newValue)
Checks if the the two values are equal. This method is null safe, that is either value may be null.
Returns:
true if oldValue equals newValue or if both values are null, false otherwise.

attach

public void attach(AbstractButton button,
                   String faceName)
Overrides the default implementation to also installFace an ActionListener to the button.
Overrides:
attach in interface Command
Parameters:
button - the button to attach to.
faceName - the face the button will be using.

configureButtonStates

protected void configureButtonStates(AbstractButton button)
This method is called to configure newly created buttons. Subclasses may override this method to perform special configuration if required.
Overrides:
configureButtonStates in interface Command
Parameters:
button - the button to configure.

detach

public void detach(AbstractButton button)
Overrides the default implementation to remove the ActionListener installed by attach(javax.swing.AbstractButton, String).
Overrides:
detach in interface Command
Parameters:
button - the button to attach to.

execute

public final void execute()

execute

public final void execute(Map hints)
Specified by:
execute in interface ActionCommandExecutor
Parameters:
hints - the hints this command is to use.
See Also:
putHint(Object,Object), getHint

getActionAdapter

public Action getActionAdapter()
Gets an action that mirrors the default face of this command. This is useful for use with the native cut and paste clipboard methods that require an action.

getActionAdapter

public Action getActionAdapter(String faceName)
Gets an action that mirrors this the specified face of this command. This is useful for use with the native cut and paste clipboard methods that require an action.

getActionCommand

public String getActionCommand()
Returns:
the 'actionCommand' value of this command.

getActionEvent

public ActionEvent getActionEvent()
Convenience method for getHint(ActionCommand.HINT_ACTION_EVENT).

getHint

public Object getHint(Object key)
Parameters:
key - the name of the hint.
Returns:
the hint or null if the hint doesn't exist.

getHint

public Object getHint(Object key,
                      Object defaultValue)
Parameters:
key - the name of the hint.
defaultValue - a default to return if the hint wasn't provided.
Returns:
the hint or defaultValue if the hint wasn't specified exist.

getHints

public Map getHints()
Returns:
the hint or defaultValue if the hint wasn't specified exist.

getInvoker

public Object getInvoker()
Convenience method to get the object that invoked the command. If the command was invoked from from a button (or menu) then the invoker will be that button.

getInvokerWindow

public Window getInvokerWindow()
Convenience method to get the Window ancestor of the object that invoked the command. If the invoker is null, or doesn't decend from Component then null is returned. Otherwise, an attempt to find the Window ancestor is made using SwingUtilities.getWindowAncestor or by traversing the ancestors and invokers of popup menus.
Returns:
null if the invoker is null, doesn't extend Component or doesn't have a Window ancestor. Otherwise the invokers Window ancestor is returned.

getModifiers

public int getModifiers()
Convenience method to get any modifiers that were specified. Modifiers are always copied from any action event that triggers this command.

handleExecute

protected abstract void handleExecute()

installShortCut

public void installShortCut(JComponent component,
                            String faceName,
                            int condition)
Installs a shortcut into the components input and action maps using the accelerator of the specified face.
Parameters:
component - The component to install the short cut in.
faceName - The face that defines the required accelerator.
condition - The condition as per javax.swing.JComponent.getInputMap(int).

installShortCut

public void installShortCut(JComponent component,
                            int condition)
Installs a shortcut into the components input and action maps using the accelerator specified by the default face.
Parameters:
component - The component to install the short cut in.
condition - The condition as per javax.swing.JComponent.getInputMap(int).

postExecute

protected void postExecute()
This method is called after handleExecute() has been called. It simply calls firePostExecute to notify all the register CommandListener that the command has just completed.

preExecute

protected boolean preExecute()
This method is called prior to handleExecute() being called. It simply calls firePreExecute to notify all the register CommandListener that the command is about to execute.

putHint

public void putHint(Object key,
                    Object value)
Adds the specified hint to be available the next time execute is called.
Parameters:
key - the name of the hint.
value - the hint value.

putHints

public void putHints(Map hints)
Adds the specified hints to be available the next time execute is called.
Parameters:
hints - a list of hints to insert.

removeCommandListener

public void removeCommandListener(CommandListener l)

Deprecated. use removeInterceptor(ActionCommandInterceptor) instead.

Removes a CommandListener the the command.
Parameters:
l - the CommandListener to removed

removeInterceptor

public void removeInterceptor(ActionCommandInterceptor interceptor)
Removes an ActionCommandInterceptor from the command.
Parameters:
interceptor - the ActionCommandInterceptor to remove

requestDefautIn

public void requestDefautIn(RootPaneContainer container)
This method will find the first button from this command in the javax.swing.RootPaneContainer and set it to be the default button by calling javax.swing.JRootPane.setDefaultButton.
Parameters:
container - the root pane container to check.

setActionCommand

public void setActionCommand(String actionCommand)
Sets the value of this commands actionCommand string. The actionCommand is provided for compatability with Swing actions. If it isn't explicity configured it will be equal to the id of the command.
Parameters:
actionCommand - the new value of the 'actionCommand'.

uninstallShortCut

public void uninstallShortCut(JComponent component,
                              String faceName,
                              int condition)
Removes the short cut installed by a previous call to installShortCut(javax.swing.JComponent, String, int)
Parameters:
component - The component the short cut was installed on.
condition - The condition as per javax.swing.JComponent.getInputMap(int).

uninstallShortCut

public void uninstallShortCut(JComponent component,
                              int condition)
Removes the short cut installed by a previous call to installShortCut(javax.swing.JComponent, int)
Parameters:
component - The component the short cut was installed on.
condition - The condition as per javax.swing.JComponent.getInputMap(int).