com.pietschy.command.delegate
Class SwingActionDelegate

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

public class SwingActionDelegate
extends ActionCommandDelegate

An instance of ActionCommandDelegate that invokes an existing swing action. This is useful for creating delegates from standard actions built into existing components.

The following example will invoke the "copy-to-clipboard" action when the "copy" command is executed.

    SwingActionDelegate delegate = new SwingActionDelegate("copy", myTextPane, "copy-to-clipboard");
    delegate.bind(myTextPane);
 

This class also provides convenience methods for creating and binding a number of delegates at once.

    SwingActionDelegate.bindAll(myTextPane, "copy-to-clipboard", "cut-to-clipboard", "paste-from-clipboard");
 
In this case the delegate ids will match the action ids.

Version:
$Revision: 1.2 $
Author:
andrewp

Field Summary
 
Fields inherited from class com.pietschy.command.delegate.ActionCommandDelegate
PROPERTY_ENABLED
 
Constructor Summary
SwingActionDelegate(java.lang.String id, javax.swing.Action action)
          Creates a new delegate with the specified id that invokes the specfied Action.
SwingActionDelegate(java.lang.String id, javax.swing.JComponent component)
          Creates a new delegate with the specified id that invokes the corresponding Action in the specified component.
SwingActionDelegate(java.lang.String id, javax.swing.JComponent component, java.lang.Object actionKey)
          Creates a new delegate with the specified id that invokes the Action in the specifeid componetn with the specified action id.
 
Method Summary
static void bindAll(CommandContainer container, javax.swing.JComponent component, java.lang.Object... actionIds)
          Creates SwingActionDelegate instances for all the specified action ids defined for the specified component.
static void bindAll(javax.swing.JComponent component, java.lang.Object... actionIds)
          Creates SwingActionDelegate instances for all the specified action ids defined for the specified component.
protected  void handleExecute()
          Invokes this delegates Action.
 
Methods inherited from class com.pietschy.command.delegate.ActionCommandDelegate
addPropertyChangeListener, addPropertyChangeListener, bind, bind, bind, bindToContainer, execute, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getActionEvent, getId, getInvoker, getInvokerWindow, getModifiers, getParameter, getParameter, getParameters, getPropertyChangeListeners, getPropertyChangeListeners, isEnabled, notifyCommandContainersChanged, putParameter, putParameters, rebind, removePropertyChangeListener, removePropertyChangeListener, setEnabled, unbind, unbindFromContainer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingActionDelegate

public SwingActionDelegate(java.lang.String id,
                           javax.swing.Action action)
Creates a new delegate with the specified id that invokes the specfied Action.

Parameters:
id - the id of the delegate.
action - the Action to invoke.

SwingActionDelegate

public SwingActionDelegate(java.lang.String id,
                           javax.swing.JComponent component)
Creates a new delegate with the specified id that invokes the corresponding Action in the specified component.

The follwing example will invoke the "copy-to-clipboard" action on the specified component when executed.

    CommandDelegate delgate = new SwingActionDelegate("copy-to-clipboard", component)
 

Parameters:
id - the id of the delegate and action.
component - the component whose action map contains the Action.

SwingActionDelegate

public SwingActionDelegate(java.lang.String id,
                           javax.swing.JComponent component,
                           java.lang.Object actionKey)
Creates a new delegate with the specified id that invokes the Action in the specifeid componetn with the specified action id.

The following example will invoke the "copy-to-clipboard" action when the "copy" command is executed.

    CommandDelegate delgate = new SwingActionDelegate("copy-command", myTextPane, "copy-to-clipboard")
 

Parameters:
id - the id of the delegate.
component - the component whose action map contains the Action.
actionKey - the actions key within the map.
Method Detail

bindAll

public static void bindAll(javax.swing.JComponent component,
                           java.lang.Object... actionIds)
Creates SwingActionDelegate instances for all the specified action ids defined for the specified component. All the SwingActionDelegates are then bound to the component.

Parameters:
component - the component containing the actions.
actionIds - the action ids to create delegates for.

bindAll

public static void bindAll(CommandContainer container,
                           javax.swing.JComponent component,
                           java.lang.Object... actionIds)
Creates SwingActionDelegate instances for all the specified action ids defined for the specified component. All the SwingActionDelegates are then bound to the specified CommandContainer.

Parameters:
container - the container to which the delegates will be bound.
component - the component containing the actions.
actionIds - the action ids to create delegates for.

handleExecute

protected void handleExecute()
Invokes this delegates Action.

Specified by:
handleExecute in class ActionCommandDelegate


Copyright © 2006 - 2007 Andrew Pietsch