org.tigris.gef.base
Class Cmd

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.tigris.gef.base.Cmd
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action
Direct Known Subclasses:
CmdAdjustGrid, CmdAdjustGuide, CmdAdjustPageBreaks, CmdAlign, CmdCopy, CmdCreateNode, CmdCut, CmdDeleteFromModel, CmdDistribute, CmdExit, CmdGroup, CmdInsertPoint, CmdNudge, CmdNull, CmdOpen, CmdOpenPGML, CmdOpenSVG, CmdOpenWindow, CmdPaste, CmdPrint, CmdPrintPageSetup, CmdRemoveFromGraph, CmdRemovePoint, CmdReorder, CmdSave, CmdSaveGraphics, CmdSavePGML, CmdScroll, CmdSelectAll, CmdSelectInvert, CmdSelectNear, CmdSelectNext, CmdSequence, CmdSetMode, CmdShowProperties, CmdShowURL, CmdSpawn, CmdUngroup, CmdUseReshape, CmdUseResize, CmdUseRotate, CmdZoom

public abstract class Cmd
extends javax.swing.AbstractAction
implements java.io.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.

TODO Implement an undo queue externally from GEF

See Also:
Serialized Form

Field Summary
protected  java.util.Hashtable _args
          Arguments that configure the Cmd instance.
protected  java.lang.String _resource
           
 
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
protected Cmd(java.util.Hashtable args, java.lang.String name)
           
protected Cmd(java.util.Hashtable args, java.lang.String name, javax.swing.ImageIcon icon)
           
  Cmd(java.util.Hashtable args, java.lang.String resource, java.lang.String name)
          Construct a new Cmd with the given arguments
  Cmd(java.util.Hashtable args, java.lang.String resource, java.lang.String name, javax.swing.ImageIcon icon)
           
protected Cmd(java.lang.String name)
          Constructors with no resource name
  Cmd(java.lang.String resource, java.lang.String name)
           
 
Method Summary
 java.lang.String about()
          Return a URL that has user and programmer documentation.
 void actionPerformed(java.awt.event.ActionEvent ae)
           
static Cmd cmdAtIndex(int i)
          Return the "well-known" Cmd at a given index.
protected  boolean containsArg(java.lang.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  java.lang.Object getArg(java.lang.String key)
          Get the object stored as an argument under the given name.
protected  java.lang.Object getArg(java.lang.String key, java.lang.Object defaultValue)
          Get an argument by name.
 java.lang.String getName()
          Return a name for this Cmd suitable for display to the user
 java.lang.String getResource()
           
static void register(Cmd c)
          Add a "well-known" Cmd TODO Does this really belong in GEF?
static java.util.Enumeration registeredCmds()
          Return a list of "well-known" Cmd instances that should appear in lists for the user to pick from.
protected  void setArg(java.lang.String key, java.lang.Object value)
          Store the given argument under the given name.
 void setName(java.lang.String n)
           
 void setResource(java.lang.String resource)
          Set a new resource as basis for the localization of this command.
 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, 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

_args

protected java.util.Hashtable _args
Arguments that configure the Cmd instance.


_resource

protected java.lang.String _resource
Constructor Detail

Cmd

public Cmd(java.util.Hashtable args,
           java.lang.String resource,
           java.lang.String name)
Construct a new Cmd with the given arguments


Cmd

public Cmd(java.lang.String resource,
           java.lang.String name)

Cmd

public Cmd(java.util.Hashtable args,
           java.lang.String resource,
           java.lang.String name,
           javax.swing.ImageIcon icon)

Cmd

protected Cmd(java.lang.String name)
Constructors with no resource name


Cmd

protected Cmd(java.util.Hashtable args,
              java.lang.String name,
              javax.swing.ImageIcon icon)

Cmd

protected Cmd(java.util.Hashtable args,
              java.lang.String name)
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.


setResource

public void setResource(java.lang.String resource)
Set a new resource as basis for the localization of this command.


getResource

public java.lang.String getResource()

getName

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


setName

public void setName(java.lang.String n)

getArg

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


getArg

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


setArg

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


containsArg

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


about

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


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ae)
Specified by:
actionPerformed in interface java.awt.event.ActionListener

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.


undoIt

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

TODO Abandon this. We need the memento pattern for undo


registeredCmds

public static java.util.Enumeration registeredCmds()
Return a list of "well-known" Cmd instances that should appear in lists for the user to pick from. TODO Does this really belong in GEF?

See Also:
CmdOpenWindow

register

public static void register(Cmd c)
Add a "well-known" Cmd TODO Does this really belong in GEF?


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. TODO Does this really belong in GEF?