com.pietschy.command.delegate
Class ActionCommandDelegate

java.lang.Object
  extended by com.pietschy.command.delegate.ActionCommandDelegate
All Implemented Interfaces:
ActionCommandExecutor, Bindable, Identifiable
Direct Known Subclasses:
SwingActionDelegate

public abstract class ActionCommandDelegate
extends java.lang.Object
implements ActionCommandExecutor, Identifiable, Bindable

Base class for creating delegates for use with DelegatingCommands. Its implementation is similar to ActionCommands and supports the same binding options.

Version:
$Revision: 1.6 $
Author:
andrewp
See Also:
DelegatingCommand, SwingActionDelegate

Field Summary
static java.lang.String PROPERTY_ENABLED
           
 
Constructor Summary
protected ActionCommandDelegate(java.lang.String id)
          Creaets a new delegate with the specified id.
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds the specified property change listener.
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Adds a property change listener for the specified property.
 void bind()
          Binds to the global command container.
 void bind(CommandContainer container)
          Binds to the specified CommandContainer.
 void bind(java.awt.Component component)
          Binds to the specified component.
protected  void bindToContainer(CommandContainer container)
          Invoked to add this delegate to the specified container as a result of a binding operation.
 void execute(java.util.Map<java.lang.Object,java.lang.Object> parameters)
          Standard execute method for ActionCommandExecutor instances.
protected  void firePropertyChange(java.beans.PropertyChangeEvent evt)
           
protected  void firePropertyChange(java.lang.String propertyName, boolean oldValue, boolean newValue)
           
protected  void firePropertyChange(java.lang.String propertyName, int oldValue, int newValue)
           
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
           
 java.awt.event.ActionEvent getActionEvent()
          Convenience method for getParameter(ActionCommand.PARAMETER_ACTION_EVENT).
 java.lang.String getId()
          Gets the Id of this delegate.
 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 hints 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 key, java.lang.Object defaultValue)
          Gets any hints 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 any hints 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.beans.PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all the listeners that were added to the delegate with addPropertyChangeListener().
 java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
          Returns an array of all the listeners which have been associated with the named property.
protected abstract  void handleExecute()
          Subclasses implement this method to define the delegates behaviour.
 boolean isEnabled()
          Checks if this delegate is enabled.
protected  void notifyCommandContainersChanged()
          Convience method for subclasses to be notified when their CommandContainer hierarhcy has changed.
 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<?,?> hints)
          Adds the specified hints to be available the next time ActionCommandExecutor.execute(java.util.Map) is called.
 void rebind()
          Re-evaluates the current binding.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes the specified property change listener.
 void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Removes the property change listener from the specified property.
 void setEnabled(boolean enabled)
          Sets the enabled state of the delegate.
 void unbind()
          Unbinds from the current container or component.
protected  void unbindFromContainer(CommandContainer container)
          Invoked to remove this delegate from the specified container as a result of a binding operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_ENABLED

public static final java.lang.String PROPERTY_ENABLED
See Also:
Constant Field Values
Constructor Detail

ActionCommandDelegate

protected ActionCommandDelegate(java.lang.String id)
Creaets a new delegate with the specified id. This delegate will be automatically used by any DelegatingCommand with the same id.

Parameters:
id - the id of the DelegatingCommand to which this delegate should bind.
Method Detail

getId

public java.lang.String getId()
Gets the Id of this delegate.

Specified by:
getId in interface Identifiable
Returns:
the delegates id.

bind

public void bind()
Description copied from interface: Bindable
Binds to the global command container.

Specified by:
bind in interface Bindable
See Also:
CommandContainer.globalInstance()

bind

public void bind(java.awt.Component component)
Description copied from interface: Bindable
Binds to the specified component. The component heirarhy will be traversed to locate the nearest bound CommandContainer.

Specified by:
bind in interface Bindable
Parameters:
component - the component to bind to.
See Also:
CommandContainer.bind(Component)

bind

public void bind(CommandContainer container)
Description copied from interface: Bindable
Binds to the specified CommandContainer.

Specified by:
bind in interface Bindable
Parameters:
container - the container to bind to.

rebind

public void rebind()
Description copied from interface: Bindable
Re-evaluates the current binding. This is only relevant for component bindings.

Specified by:
rebind in interface Bindable

unbind

public void unbind()
Description copied from interface: Bindable
Unbinds from the current container or component.

Specified by:
unbind in interface Bindable

bindToContainer

protected void bindToContainer(CommandContainer container)
Invoked to add this delegate to the specified container as a result of a binding operation.

Parameters:
container - the container to bind to.

unbindFromContainer

protected void unbindFromContainer(CommandContainer container)
Invoked to remove this delegate from the specified container as a result of a binding operation.

Parameters:
container - the container to which the delegate was previously bound.

notifyCommandContainersChanged

protected void notifyCommandContainersChanged()
Convience method for subclasses to be notified when their CommandContainer hierarhcy has changed.


execute

public final void execute(java.util.Map<java.lang.Object,java.lang.Object> parameters)
Standard execute method for ActionCommandExecutor instances. This method attempts to updates the parameters with the invoker and then invokes handleExecute().

Specified by:
execute in interface ActionCommandExecutor
Parameters:
parameters - any additional execution parameters.

handleExecute

protected abstract void handleExecute()
Subclasses implement this method to define the delegates behaviour.


putParameter

public 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.

Parameters:
key - the name of the parameter.
value - the parameter value.

putParameters

public void putParameters(java.util.Map<?,?> hints)
Adds the specified hints to be available the next time ActionCommandExecutor.execute(java.util.Map) is called.

Parameters:
hints - a list of hints to insert.

getParameter

public java.lang.Object getParameter(java.lang.Object key)
Gets any hints 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).

Parameters:
key - the name of the parameter.
Returns:
the parameter or null if the parameter doesn't exist.

getParameter

public java.lang.Object getParameter(java.lang.Object key,
                                     java.lang.Object defaultValue)
Gets any hints 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).

Parameters:
key - the name of the parameter.
defaultValue - a default to return if the parameter wasn't provided.
Returns:
the parameter or defaultValue if the parameter wasn't specified exist.
See Also:
putParameter(java.lang.Object, java.lang.Object)

getParameters

public java.util.Map<java.lang.Object,java.lang.Object> getParameters()
Gets any hints 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).

Returns:
the parameter or defaultValue if the parameter wasn't specified exist.
See Also:
putParameter(java.lang.Object, java.lang.Object)

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.


getInvoker

public java.lang.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.

Returns:
the AbstractButton that invoked to command. If the command was manually invoked this will return null unless the parameter ActionCommand.PARAMETER_INVOKER has been explicitly set.

getInvokerWindow

public java.awt.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(java.awt.Component) 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.
See Also:
getInvoker()

getActionEvent

public java.awt.event.ActionEvent getActionEvent()
Convenience method for getParameter(ActionCommand.PARAMETER_ACTION_EVENT).


isEnabled

public boolean isEnabled()
Checks if this delegate is enabled.

This is a bound property, changes to its value will fire property change events.

Specified by:
isEnabled in interface ActionCommandExecutor
Returns:
true if the delegate is enabled, false otherwise.

setEnabled

public void setEnabled(boolean enabled)
Sets the enabled state of the delegate.

This is a bound property, changes to its value will fire property change events.

Parameters:
enabled - true if the delegate is enabled, false otherwise.

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Description copied from interface: ActionCommandExecutor
Adds the specified property change listener.

Specified by:
addPropertyChangeListener in interface ActionCommandExecutor
Parameters:
listener - the listener to add.

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Description copied from interface: ActionCommandExecutor
Removes the specified property change listener.

Specified by:
removePropertyChangeListener in interface ActionCommandExecutor
Parameters:
listener - the listener to remove.

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all the listeners that were added to the delegate with addPropertyChangeListener().

Returns:
an array of all the listeners that were added to the delegate with addPropertyChangeListener().

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Description copied from interface: ActionCommandExecutor
Adds a property change listener for the specified property.

Specified by:
addPropertyChangeListener in interface ActionCommandExecutor
Parameters:
propertyName - the property to listen to.
listener - the listener to add.

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String propertyName,
                                         java.beans.PropertyChangeListener listener)
Description copied from interface: ActionCommandExecutor
Removes the property change listener from the specified property.

Specified by:
removePropertyChangeListener in interface ActionCommandExecutor
Parameters:
propertyName - the property being monitored.
listener - the listener to remove.

getPropertyChangeListeners

public java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
Returns an array of all the listeners which have been associated with the named property.

Parameters:
propertyName - the property name.
Returns:
an array of all the listeners which have been associated with the named property.

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  int oldValue,
                                  int newValue)

firePropertyChange

protected void firePropertyChange(java.beans.PropertyChangeEvent evt)

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  boolean oldValue,
                                  boolean newValue)

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)


Copyright © 2006 - 2007 Andrew Pietsch