dsto.dfc.swing.commands
Class AbstractCommand

java.lang.Object
  extended by dsto.dfc.swing.commands.AbstractCommand
All Implemented Interfaces:
Command, Iconic, Copyable, ActionListener, Cloneable, EventListener
Direct Known Subclasses:
AbstractMutableCommand, BasicAboutCommand, BasicAddEntryCommand, BasicCopyCommand, BasicCutCommand, BasicExitCommand, BasicFileOpenCommand, BasicPasteCommand, CmdCollapse, CmdExpandAll, CmdInsertRow, CmdSelectAll, CmdShowLogWindow, DfcDialog.CmdCancel

public abstract class AbstractCommand
extends Object
implements Command, Copyable, ActionListener

Base class for commands. Provides default implementations for some methods.

Version:
$Revision$

Field Summary
protected  String displayName
           
protected  Icon icon
           
 
Fields inherited from interface dsto.dfc.swing.icons.Iconic
NULL_ICON
 
Constructor Summary
AbstractCommand()
           
AbstractCommand(String iconName)
           
 
Method Summary
 void actionPerformed(ActionEvent e)
           
 boolean canReplace(Command command)
          Returns false;
 Object clone()
          Create a completely separate copy of this object and any mutable objects owned by the object.
abstract  void execute()
          Execute the command.
 KeyStroke getAccelerator()
          Get a keyboard accelerator for the command.
protected  String getDefaultDisplayName()
          Generates a display name based on the last component of the command name.
abstract  String getDescription()
          A short description of the command, suitable for a tooltip or use in a status panel.
 String getDisplayName()
          The name of the command as it should be displayed (eg on a menu).
abstract  String getGroupInView(String viewName)
          Get the preferred group that this command should appear in for a given view.
 Icon getIcon()
          The small (16x16) icon for the object.
 Icon getLargeIcon()
          The large (32x32) icon.
 String getLogString()
          Returns the command name followed by empty brackets.
abstract  char getMnemonic()
          Get a character shortcut for the command (eg for use on a menu).
abstract  String getName()
          The formal identifying name for this command (eg edit.Copy, file.Open).
 boolean isEnabled()
          Returns true.
abstract  boolean isInteractive()
          True if this command will interact with the user when execute() is called.
 void setDisplayName(String newDisplayName)
           
 void setIcon(Icon newIcon)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

icon

protected Icon icon

displayName

protected String displayName
Constructor Detail

AbstractCommand

public AbstractCommand()

AbstractCommand

public AbstractCommand(String iconName)
Method Detail

execute

public abstract void execute()
Description copied from interface: Command
Execute the command.

Specified by:
execute in interface Command

getName

public abstract String getName()
Description copied from interface: Command
The formal identifying name for this command (eg edit.Copy, file.Open). This must not change during the lifetime of a command instance.

Specified by:
getName in interface Command
Specified by:
getName in interface Iconic

getDescription

public abstract String getDescription()
Description copied from interface: Command
A short description of the command, suitable for a tooltip or use in a status panel.

Specified by:
getDescription in interface Command

isInteractive

public abstract boolean isInteractive()
Description copied from interface: Command
True if this command will interact with the user when execute() is called.

Specified by:
isInteractive in interface Command

getGroupInView

public abstract String getGroupInView(String viewName)
Description copied from interface: Command
Get the preferred group that this command should appear in for a given view. This may be overridden by a setting in the CommandRegistry.

If the command changes its group in any view it should generate a groupInView property change event with the old value set to the old group and the new value set to the new group.

Specified by:
getGroupInView in interface Command
Parameters:
viewName - The name of the view.
Returns:
The group in the view, or null if this command does not appear in the given view.

getMnemonic

public abstract char getMnemonic()
Description copied from interface: Command
Get a character shortcut for the command (eg for use on a menu). May return 0 for no mnemonic.

Specified by:
getMnemonic in interface Command

getAccelerator

public KeyStroke getAccelerator()
Description copied from interface: Command
Get a keyboard accelerator for the command. May return null for no accelerator.

Specified by:
getAccelerator in interface Command

getDisplayName

public String getDisplayName()
Description copied from interface: Command
The name of the command as it should be displayed (eg on a menu). May be null in which case the command name (or some derivative) will be used.

Specified by:
getDisplayName in interface Command

setDisplayName

public void setDisplayName(String newDisplayName)

getDefaultDisplayName

protected String getDefaultDisplayName()
Generates a display name based on the last component of the command name. eg "file.oc.Edit" becomes "Edit".


getLogString

public String getLogString()
Returns the command name followed by empty brackets.

Specified by:
getLogString in interface Command

isEnabled

public boolean isEnabled()
Returns true.

Specified by:
isEnabled in interface Command

canReplace

public boolean canReplace(Command command)
Returns false;

Specified by:
canReplace in interface Command

getIcon

public Icon getIcon()
Description copied from interface: Iconic
The small (16x16) icon for the object. May be null if no small icon is available.

Specified by:
getIcon in interface Iconic

setIcon

public void setIcon(Icon newIcon)

getLargeIcon

public Icon getLargeIcon()
Description copied from interface: Iconic
The large (32x32) icon.

Specified by:
getLargeIcon in interface Iconic
Returns:
The large icon, or null if no large icon is available.

actionPerformed

public void actionPerformed(ActionEvent e)
Specified by:
actionPerformed in interface ActionListener

clone

public Object clone()
Description copied from interface: Copyable
Create a completely separate copy of this object and any mutable objects owned by the object.

NOTE: subclasses should not remove the CloneNotSupportedException throws clause if they themselves support subclassing: removing the CloneNotSupportedException declaration stops subclasses from indicating that a clone was not possible.

Specified by:
clone in interface Copyable
Overrides:
clone in class Object


Copyright © 2008 Commonwealth of Australia