uci.gef
Class Cmd

java.lang.Object
  |
  +--javax.swing.AbstractAction
        |
        +--uci.gef.Cmd
Direct Known Subclasses:
CmdAdjustGrid, CmdAdjustGuide, CmdAdjustPageBreaks, CmdAlign, CmdCopy, CmdCreateNode, CmdDelete, CmdDispose, CmdDistribute, CmdExit, CmdGroup, CmdInsertPoint, CmdNudge, CmdNull, CmdOpen, CmdOpenPGML, CmdOpenWindow, CmdPaste, CmdPrint, CmdRemovePoint, CmdReorder, CmdSave, CmdSavePGML, CmdScroll, CmdSelectAll, CmdSelectInvert, CmdSelectNear, CmdSelectNext, CmdSequence, CmdSetMode, CmdShowProperties, CmdShowURL, CmdSpawn, CmdUMLProperties, CmdUngroup, CmdUseReshape, CmdUseResize, CmdUseRotate

public abstract class Cmd
extends AbstractAction
implements Serializable

Abstract class for all editor commands. The editor serves as a command shell for executing actions in much the same way that a DOS or UNIX commmand command shell executes programs. Each command can have a Hashtable of "command-line" arguments and also look at global variables (its environment). Once an instance of a Cmd is made, it can be sent the doIt() and undoIt() messages to perform that action.

Since this is subclassed from class AbstractAction in the Swing user interface library, Cmd objects can be easily added to menus and toolbars.

needs-more-work: canDoIt, canUndoIt predicates control graying.

needs-more-work: Editor will keep a history of recent actions for undo.

See Also:
Editor, ExecuteActionWindow, Serialized Form

Field Summary
protected  Hashtable _args
          Arguments that configure the Cmd instance.
static boolean HAS_ICON
           
static boolean NO_ICON
           
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Constructor Summary
Cmd(Hashtable args, String name)
          Construct a new Cmd with the given arguments
Cmd(Hashtable args, String name, boolean hasIcon)
           
Cmd(Hashtable args, String name, ImageIcon icon)
           
Cmd(String name)
          Construct a new Cmd with no arguments
Cmd(String name, boolean hasIcon)
           
 
Method Summary
 String about()
          Return a URL that has user and programmer documentation.
 void actionPerformed(ActionEvent ae)
           
static Cmd cmdAtIndex(int i)
          Return the "well-known" Cmd at a given index.
protected  boolean containsArg(String key)
          Reply true if this Cmd instance has the named argument defined.
abstract  void doIt()
          Perform whatever Cmd this Cmd is meant to do.
protected  Object getArg(String key)
          Get the object stored as an argument under the given name.
protected  Object getArg(String key, Object defaultValue)
          Get an argument by name.
 String getName()
          Return a name for this Cmd suitable for display to the user
static void register(Cmd c)
          Add a "well-known" Cmd
static Enumeration registeredCmds()
          Return a list of "well-known" Cmd instances that should appear in lists for the user to pick from.
protected  void setArg(String key, Object value)
          Store the given argument under the given name.
 void setName(String n)
           
 boolean shouldBeEnabled()
          Return true if this action should be available to the user.
abstract  void undoIt()
          Undo the Cmd using information stored during its execution.
 void updateEnabled()
          Determine if this Cmd should be shown as grayed out in menus and toolbars.
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HAS_ICON

public static final boolean HAS_ICON

NO_ICON

public static final boolean NO_ICON

_args

protected Hashtable _args
Arguments that configure the Cmd instance.
Constructor Detail

Cmd

public Cmd(Hashtable args,
           String name)
Construct a new Cmd with the given arguments

Cmd

public Cmd(Hashtable args,
           String name,
           boolean hasIcon)

Cmd

public Cmd(String name,
           boolean hasIcon)

Cmd

public Cmd(Hashtable args,
           String name,
           ImageIcon icon)

Cmd

public Cmd(String name)
Construct a new Cmd with no arguments
Method Detail

updateEnabled

public void updateEnabled()
Determine if this Cmd should be shown as grayed out in menus and toolbars.

shouldBeEnabled

public boolean shouldBeEnabled()
Return true if this action should be available to the user. This method should examine the ProjectBrowser that owns it. Sublass implementations of this method should always call super.shouldBeEnabled first.

getName

public String getName()
Return a name for this Cmd suitable for display to the user

setName

public void setName(String n)

getArg

protected Object getArg(String key)
Get the object stored as an argument under the given name.

getArg

protected Object getArg(String key,
                        Object defaultValue)
Get an argument by name. If it's not defined then use the given default.

setArg

protected void setArg(String key,
                      Object value)
Store the given argument under the given name.

containsArg

protected boolean containsArg(String key)
Reply true if this Cmd instance has the named argument defined.

about

public String about()
Return a URL that has user and programmer documentation. FEATURE: view_Cmd_documentation

actionPerformed

public void actionPerformed(ActionEvent ae)
Overrides:
actionPerformed in class AbstractAction

doIt

public abstract void doIt()
Perform whatever Cmd this Cmd is meant to do. Subclasses should override this to do whatever is intended. When the Cmd executes, it should store enough information to undo itself later if needed.
Parameters:
e - The event that caused this Cmd to be performed. Generally it is a bad idea to depend on the contents of this event too much.

undoIt

public abstract void undoIt()
Undo the Cmd using information stored during its execution.

needs-more-work: This is not currently implemented.


registeredCmds

public static Enumeration registeredCmds()
Return a list of "well-known" Cmd instances that should appear in lists for the user to pick from.
See Also:
ExecuteCmdWindow

register

public static void register(Cmd c)
Add a "well-known" Cmd

cmdAtIndex

public static Cmd cmdAtIndex(int i)
Return the "well-known" Cmd at a given index. Useful for displaying a list of "well-known" cmds.