org.erights.e.ui.awt
Class EAction

java.lang.Object
  |
  +--javax.swing.AbstractAction
        |
        +--org.erights.e.ui.awt.EAction
All Implemented Interfaces:
Action, ActionListener, Cloneable, EventListener, Serializable

public class EAction
extends AbstractAction

Untamed: Enables an E-language programmer to effectively parameterize an javax.swing.AbstractAction, even though E cannot subclass Java.

AbstractAction was designed to be parameterized by subclassing. E-language code cannot subclass Java classes, so EAction provides a bridge between these issues. EAction is a subclass of AbstractAction whose behavior is determined by its properties, which is settable by E language code.

In addition, it provides various conveniences absent from Action and AbstractAction, such as the ability to use a description string like "Save &As" to set the Name ("Save As"), action Verb ("doSaveAs"), and mnemonic ('A').

The actual action represented by an EAction is the eventual sending of a message (verb and arguments) to a recipient.

Author:
Mark S. Miller
See Also:
Serialized Form

Field Summary
private static IntTable ModNames
           
private  Object[] myArgs
           
private  Object myRecip
          The recipient of the myVerb(myArgs...) message
private  Vat myVat
          Captures the current vat at the time of creation so it can be restored when this EAction is invoked.
private  String myVerb
           
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
EAction()
          Enabled: When created this way, it's useless until parameterized with the property setting methods.
EAction(Object recip, String desc)
          Enabled: Creates an action with a name, verb, and mnemonic derived from desc, which will 'recip <- verb()'.
EAction(Object recip, String desc, String acceleration)
          Enabled: As with the two argument constructor, but will also associate the described acceleration key with the action.
 
Method Summary
 void __printOn(TextWriter out)
          Enabled:
 void accelerate(String acceleration)
          Enabled: Parse an accelation description string into an acceleration keyStroke, and setAccelerator to that keyStroke.
 void actionPerformed(ActionEvent e)
          Enabled: Invoked by Swing when the EAction's action should be invoked.
static int descToMnemonic(String desc)
          Enabled: The mnemonic key is the character following the '&', or -1 if there isn't one.
static String descToName(String desc)
          Enabled: Extract the string to show in the menu.
static String descToVerb(String desc)
          Enabled: Derive a message name.
 KeyStroke getAccelerator()
          Enabled: Actually gets the AbstractAction's ACCELERATOR_KEY property.
 int getMnemonic()
          Enabled: Actually gets the AbstractAction's MNEMONIC_KEY property.
 String getName()
          Enabled: Actually gets the AbstractAction's NAME property.
 String getTip()
          Enabled: Actually gets the AbstractAction's SHORT_DESCRIPTION property.
 void setAccelerator(KeyStroke newKey)
          Enabled: Actually sets the AbstractAction's ACCELERATOR_KEY property.
 void setAction(Object recip)
          Enabled: Sets the action to 'recip <- run()', so action should be a Runnable or a Thunk.
 void setAction(Object recip, String verb)
          Enabled: Sets the action to 'recip <- verb()'
 void setAction(Object recip, String verb, Object[] args)
          Enabled: Sets the action to 'recip <- verb(args...)'
 void setDesc(Object recip, String desc)
          Enabled: Sets the name, verb, and mnemonic according to desc, and the action to 'recip <- verb()'.
 void setMnemonic(int newMnemonic)
          Enabled: Actually sets the AbstractAction's MNEMONIC_KEY property.
 void setName(String newName)
          Enabled: Actually sets the AbstractAction's NAME property.
 void setTip(String newTip)
          Enabled: Actually sets the AbstractAction's SHORT_DESCRIPTION property.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ModNames

private static final IntTable ModNames

myVat

private final Vat myVat
Captures the current vat at the time of creation so it can be restored when this EAction is invoked.

This is necessary since this EAction can be (and generally is) invoked during an AWT event that's not a vat turn.


myRecip

private Object myRecip
The recipient of the myVerb(myArgs...) message


myVerb

private String myVerb

myArgs

private Object[] myArgs
Constructor Detail

EAction

public EAction()
Enabled: When created this way, it's useless until parameterized with the property setting methods.


EAction

public EAction(Object recip,
               String desc)
Enabled: Creates an action with a name, verb, and mnemonic derived from desc, which will 'recip <- verb()'.

For example, 'EAction new(foo, "Save &As")' will have the name "Save As", the mnemonic 'A', and when invoked will 'foo <- doSaveAs()'.


EAction

public EAction(Object recip,
               String desc,
               String acceleration)
Enabled: As with the two argument constructor, but will also associate the described acceleration key with the action.

The acceleration parameter is in approximately the format in which acceleration are displayed on Windows menus. For example, the acceleration parameter "Ctrl+A" sets the acceleration keystroke to be Control-A.

Method Detail

descToName

public static String descToName(String desc)
Enabled: Extract the string to show in the menu.
     "Save &As.." => "Save As.."
 


descToVerb

public static String descToVerb(String desc)
Enabled: Derive a message name.
     "Save &As.." => "doSaveAs"
 


descToMnemonic

public static int descToMnemonic(String desc)
Enabled: The mnemonic key is the character following the '&', or -1 if there isn't one.

     "Save &As" => 'A'
 


setDesc

public void setDesc(Object recip,
                    String desc)
Enabled: Sets the name, verb, and mnemonic according to desc, and the action to 'recip <- verb()'.

For example, 'ea.setDesc(foo, "Save &As")' will set the name to "Save As", the mnemonic 'A', and the action to be invoked to 'foo <- doSaveAs()'.


actionPerformed

public void actionPerformed(ActionEvent e)
Enabled: Invoked by Swing when the EAction's action should be invoked.

Does a sendOnly of 'recip <- verb(args...)'


setAction

public void setAction(Object recip)
Enabled: Sets the action to 'recip <- run()', so action should be a Runnable or a Thunk.


setAction

public void setAction(Object recip,
                      String verb)
Enabled: Sets the action to 'recip <- verb()'


setAction

public void setAction(Object recip,
                      String verb,
                      Object[] args)
Enabled: Sets the action to 'recip <- verb(args...)'


getAccelerator

public KeyStroke getAccelerator()
Enabled: Actually gets the AbstractAction's ACCELERATOR_KEY property.


setAccelerator

public void setAccelerator(KeyStroke newKey)
Enabled: Actually sets the AbstractAction's ACCELERATOR_KEY property.


accelerate

public void accelerate(String acceleration)
Enabled: Parse an accelation description string into an acceleration keyStroke, and setAccelerator to that keyStroke.


getName

public String getName()
Enabled: Actually gets the AbstractAction's NAME property.


setName

public void setName(String newName)
Enabled: Actually sets the AbstractAction's NAME property.


getMnemonic

public int getMnemonic()
Enabled: Actually gets the AbstractAction's MNEMONIC_KEY property.


setMnemonic

public void setMnemonic(int newMnemonic)
Enabled: Actually sets the AbstractAction's MNEMONIC_KEY property.


getTip

public String getTip()
Enabled: Actually gets the AbstractAction's SHORT_DESCRIPTION property.


setTip

public void setTip(String newTip)
Enabled: Actually sets the AbstractAction's SHORT_DESCRIPTION property.


__printOn

public void __printOn(TextWriter out)
               throws IOException
Enabled:

IOException


comments?