|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.pietschy.command.Command
com.pietschy.command.ActionCommand
public abstract class ActionCommand
ActionCommands provide the base for all executable commands. Subclasses must
implement handleExecute() to provide command specific behaviour.
To be used in groups commands must be bound to a
CommandContainer. Commands can be bound to a container directly or
to a Swing component. In the latter case the command will search for a
CommandContainer that has been bound
to an ancestor of the component.
// create a print command
ActionCommand command = new ActionCommand("print")
{
public void handleExecute()
{
// do the printing...
}
};
// and bind it to a CommandContainer
command.bind(commandContainer);
CommandContainer,
CommandGroup| Field Summary | |
|---|---|
static java.lang.String |
PARAMETER_ACTION_EVENT
The key for the action event hint. |
static java.lang.String |
PARAMETER_INVOKER
The key for the invoker hint. |
static java.lang.String |
PARAMETER_INVOKER_WINDOW
The key for the invoker window hint. |
static java.lang.String |
PARAMETER_MODIFIERS
The key for the modifiers hint. |
| Fields inherited from class com.pietschy.command.Command |
|---|
internalLog, PROPERTY_ENABLED, PROPERTY_VISIBLE |
| Constructor Summary | |
|---|---|
|
ActionCommand()
Creates a new anonymous instance. |
|
ActionCommand(java.lang.String id)
Creates a new instance with the specified id. |
protected |
ActionCommand(java.lang.String id,
boolean loadConfiguration)
Creates a new command with the specified id. |
| Method Summary | |
|---|---|
void |
addActionCommandListener(ActionCommandListener listener)
Adds the specified listener to the command. |
void |
addInterceptor(ActionCommandInterceptor interceptor)
Adds the specified interceptor to the command. |
protected void |
bindToContainer(CommandContainer container)
Invoked to bind this instance to the specified container. |
javax.swing.AbstractButton |
createButton(ButtonFactory factory,
java.util.Map<?,?> parameters)
Creates a parameterized button that will always invoke the commad with the specified parameters. |
javax.swing.AbstractButton |
createButton(ButtonFactory factory,
java.lang.String context,
java.util.Map<?,?> parameters)
Creates a parameterized button that will always invoke the commad with the specified parameters. |
javax.swing.AbstractButton |
createButton(java.util.Map<?,?> parameters)
Creates a parameterized button that will always invoke the commad with the specified parameters. |
javax.swing.AbstractButton |
createButton(java.lang.String context,
java.util.Map<?,?> parameters)
Creates a parameterized button that will always invoke the commad with the specified parameters. |
javax.swing.JMenuItem |
createMenuItem(java.util.Map<?,?> parameters)
Creates a parameterized menu item that will always invoke the commad with the specified parameters. |
javax.swing.JMenuItem |
createMenuItem(MenuFactory factory,
java.util.Map<?,?> parameters)
Creates a parameterized menu item that will always invoke the commad with the specified parameters. |
javax.swing.JMenuItem |
createMenuItem(MenuFactory factory,
java.lang.String context,
java.util.Map<?,?> parameters)
Creates a parameterized menu item that will always invoke the commad with the specified parameters. |
javax.swing.JMenuItem |
createMenuItem(java.lang.String context,
java.util.Map<?,?> parameters)
Creates a parameterized menu item that will always invoke the commad with the specified parameters. |
protected void |
doButtonAttachments(javax.swing.AbstractButton button,
java.lang.String faceName)
Overrides the default implementation to also add an ActionListener to the button. |
protected void |
doButtonDetachments(javax.swing.AbstractButton button)
Overrides the default implementation to remove the ActionListener installed by
doButtonAttachments(AbstractButton, String). |
void |
execute()
Causes the command to perform it's operation. |
void |
execute(java.util.Map<java.lang.Object,java.lang.Object> parameters)
Executes this command with the specified parameters. |
javax.swing.Action |
getActionAdapter()
Gets an action that mirrors the default face of this command. |
javax.swing.Action |
getActionAdapter(java.lang.String context)
Gets an action that mirrors this the specified face of this command. |
java.awt.event.ActionEvent |
getActionEvent()
Convenience method for getParameter(ActionCommand.PARAMETER_ACTION_EVENT). |
java.lang.Object |
getInvoker()
Convenience method to get the object that invoked the command. |
java.awt.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. |
java.lang.Object |
getParameter(java.lang.Object key)
Gets any paramters that may have been specified by a call to ActionCommandExecutor.execute(Map) or that have been
explicitly set by putParameter(java.lang.Object, java.lang.Object). |
java.lang.Object |
getParameter(java.lang.Object name,
java.lang.Object defaultValue)
Gets any parameters that may have been specified by a call to ActionCommandExecutor.execute(Map) or that have been
explicitly set by putParameter(java.lang.Object, java.lang.Object). |
java.util.Map<java.lang.Object,java.lang.Object> |
getParameters()
Gets all the parameters that have been specified by a call to ActionCommandExecutor.execute(Map) or that have
been explicitly set by putParameter(java.lang.Object, java.lang.Object). |
protected abstract void |
handleExecute()
Main entry point for command subclasses that must be implemented to provide command specific behaviour. |
void |
installShortCut(javax.swing.JComponent component,
int condition)
Installs a shortcut into the components input and action maps using the accelerator specified by the default face. |
void |
installShortCut(javax.swing.JComponent component,
java.lang.String faceContext,
int condition)
Installs a shortcut into the components input and action maps using the accelerator of the specified 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 |
putParameter(java.lang.Object key,
java.lang.Object value)
Adds the specified parameter to be available the next time ActionCommandExecutor.execute(java.util.Map is called. |
void |
putParameters(java.util.Map<?,?> parameters)
Adds the specified paramters to be available the next time ActionCommandExecutor.execute(java.util.Map is called. |
void |
removeActionCommandListener(ActionCommandListener listener)
Removes the specified listener from the command |
void |
removeInterceptor(ActionCommandInterceptor interceptor)
Removes the specified interceptor from the command. |
void |
requestDefaultIn(javax.swing.RootPaneContainer container)
This method will find the first button from this command that is a decendant of the specified RootPaneContainer and configure it as the default button
by calling JRootPane.setDefaultButton(javax.swing.JButton). |
protected void |
unbindFromContainer(CommandContainer container)
Invoked to unbind this instance to the specified container. |
void |
uninstallShortCut(javax.swing.JComponent component,
int condition)
Removes the short cut installed by a previous call to installShortCut(JComponent, int) |
void |
uninstallShortCut(javax.swing.JComponent component,
java.lang.String faceContext,
int condition)
Removes the short cut installed by a previous call to installShortCut(JComponent, String, int) |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.pietschy.command.ActionCommandExecutor |
|---|
addPropertyChangeListener, addPropertyChangeListener, isEnabled, removePropertyChangeListener, removePropertyChangeListener |
| Methods inherited from interface com.pietschy.command.Identifiable |
|---|
getId |
| Field Detail |
|---|
public static final java.lang.String PARAMETER_ACTION_EVENT
AbstractButton.
public static final java.lang.String PARAMETER_MODIFIERS
AbstractButton.
getModifiers(),
Constant Field Valuespublic static final java.lang.String PARAMETER_INVOKER
AbstractButton.
getInvoker(),
Constant Field Valuespublic static final java.lang.String PARAMETER_INVOKER_WINDOW
getInvokerWindow(),
Constant Field Values| Constructor Detail |
|---|
public ActionCommand()
GroupBuilders.
public ActionCommand(java.lang.String id)
protected ActionCommand(java.lang.String id,
boolean loadConfiguration)
loadConfiguration - true to load the configuration during
construction, false to let the subclass invoke it.| Method Detail |
|---|
protected void bindToContainer(CommandContainer container)
Command.isAnonymous() is false.
Subclasses may override this method to perform additional configuration such as
adding a listener to the container. In this case subclasses must also override
unbindFromContainer(CommandContainer).
bindToContainer in class Commandcontainer - the container to bind to.unbindFromContainer(CommandContainer)protected void unbindFromContainer(CommandContainer container)
Command.isAnonymous() is false.
unbindFromContainer in class Commandcontainer - the container to unbind from.bindToContainer(CommandContainer)public javax.swing.AbstractButton createButton(java.util.Map<?,?> parameters)
parameters - the parameters to use when invoking the command from this button.
public javax.swing.AbstractButton createButton(java.lang.String context,
java.util.Map<?,?> parameters)
context - the face context to use for the button.parameters - the parameters to use when invoking the command from this button.
public javax.swing.AbstractButton createButton(ButtonFactory factory,
java.util.Map<?,?> parameters)
factory - the factory to use when creating the button.parameters - the parameters to use when invoking the command from this button.
public javax.swing.AbstractButton createButton(ButtonFactory factory,
java.lang.String context,
java.util.Map<?,?> parameters)
factory - the factory to use when creating the button.context - the face context to use for the button.parameters - the parameters to use when invoking the command from this button.
public javax.swing.JMenuItem createMenuItem(java.util.Map<?,?> parameters)
parameters - the parameters to use when invoking the command from this button.
public javax.swing.JMenuItem createMenuItem(java.lang.String context,
java.util.Map<?,?> parameters)
context - the face context to use for the menu item.parameters - the parameters to use when invoking the command from this button.
public javax.swing.JMenuItem createMenuItem(MenuFactory factory,
java.util.Map<?,?> parameters)
factory - the factory to use when creating the menu item.parameters - the parameters to use when invoking the command from this button.
public javax.swing.JMenuItem createMenuItem(MenuFactory factory,
java.lang.String context,
java.util.Map<?,?> parameters)
factory - the factory to use when creating the menu item.context - the face context to use for the menu item.parameters - the parameters to use when invoking the command from this button.
protected abstract void handleExecute()
This method should never be called directly to invoke a command. All
command invocation must be performed using the execute() and
execute(Map) methods.
public final void execute(java.util.Map<java.lang.Object,java.lang.Object> parameters)
putParameter(java.lang.Object, java.lang.Object). The paramters are
only available for this execution of the command.
execute in interface ActionCommandExecutorparameters - the paramters this command is to use.putParameter(java.lang.Object, java.lang.Object),
getParameter(java.lang.Object)public final void execute()
handleExecute() to customize this commands behaviour.
public void requestDefaultIn(javax.swing.RootPaneContainer container)
RootPaneContainer and configure it as the default button
by calling JRootPane.setDefaultButton(javax.swing.JButton).
container - the root pane container to check.
public void putParameter(java.lang.Object key,
java.lang.Object value)
ActionCommandExecutor.execute(java.util.Map) is called.
key - the parameter name.value - the parameter value.public void putParameters(java.util.Map<?,?> parameters)
ActionCommandExecutor.execute(java.util.Map) is called.
parameters - the parameters to add.public java.lang.Object getParameter(java.lang.Object key)
ActionCommandExecutor.execute(Map) or that have been
explicitly set by putParameter(java.lang.Object, java.lang.Object).
key - the name of the paramter.
public java.lang.Object getParameter(java.lang.Object name,
java.lang.Object defaultValue)
ActionCommandExecutor.execute(Map) or that have been
explicitly set by putParameter(java.lang.Object, java.lang.Object).
name - the name of the paramter.defaultValue - the default value to return if the parameter was null.
null.putParameter(java.lang.Object, java.lang.Object)public java.util.Map<java.lang.Object,java.lang.Object> getParameters()
ActionCommandExecutor.execute(Map) or that have
been explicitly set by putParameter(java.lang.Object, java.lang.Object).
putParameter(java.lang.Object, java.lang.Object)public int getModifiers()
public java.lang.Object getInvoker()
AbstractButton that invoked to command. If the command was manually
invoked this will return null unless the parameter PARAMETER_INVOKER has been
explicitly set.public java.awt.Window getInvokerWindow()
null, or doesn't descend from Component then
null is returned. Otherwise, an attempt to find the Window ancestor is made
using the current WindowSearchStrategy.
null if the invoker is null, doesn't extend Component or
doesn't have a Window ancestor. Otherwise the invokers Window ancestor is
returned acording to the current WindowSearchStrategy.getInvoker()public java.awt.event.ActionEvent getActionEvent()
getParameter(ActionCommand.PARAMETER_ACTION_EVENT).
protected void doButtonAttachments(javax.swing.AbstractButton button,
java.lang.String faceName)
ActionListener to the button.
doButtonAttachments in class Commandbutton - the button to attach to.faceName - the face the button will be using.protected void doButtonDetachments(javax.swing.AbstractButton button)
ActionListener installed by
doButtonAttachments(AbstractButton, String).
doButtonDetachments in class Commandbutton - the button to detach from.public javax.swing.Action getActionAdapter()
public javax.swing.Action getActionAdapter(java.lang.String context)
context - the face context to base the action on. The Actions properties
will mirror those of the specified face.
protected boolean preExecute()
handleExecute() being called. It invokes
all the ActionCommandInterceptors and notifies all the
ActionCommandListeners
true if all the interceptors returned true, false
otherwise.protected void postExecute()
handleExecute() has been called. It invokes
all the ActionCommandInterceptors and notifies all the
ActionCommandListeners.
public void addActionCommandListener(ActionCommandListener listener)
listener - the listener to add.removeActionCommandListener(com.pietschy.command.ActionCommandListener)public void removeActionCommandListener(ActionCommandListener listener)
listener - the listener to removeaddActionCommandListener(com.pietschy.command.ActionCommandListener)public void addInterceptor(ActionCommandInterceptor interceptor)
interceptor - the interceptor to add.removeInterceptor(ActionCommandInterceptor)public void removeInterceptor(ActionCommandInterceptor interceptor)
interceptor - the interceptor to remove.addInterceptor(ActionCommandInterceptor)
public void installShortCut(javax.swing.JComponent component,
int condition)
component - The component to install the short cut in.condition - The condition as per JComponent.getInputMap(int).
public void installShortCut(javax.swing.JComponent component,
java.lang.String faceContext,
int condition)
component - The component to install the short cut in.faceContext - The face that defines the required accelerator.condition - The condition as per JComponent.getInputMap(int).
public void uninstallShortCut(javax.swing.JComponent component,
int condition)
installShortCut(JComponent, int)
component - The component the short cut was installed on.condition - The condition as per JComponent.getInputMap(int).
public void uninstallShortCut(javax.swing.JComponent component,
java.lang.String faceContext,
int condition)
installShortCut(JComponent, String, int)
component - The component the short cut was installed on.condition - The condition as per JComponent.getInputMap(int).
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||