dsto.dfc.swing.commands
Class AbstractEnumeratedCommand

java.lang.Object
  extended by dsto.dfc.swing.commands.AbstractCommand
      extended by dsto.dfc.swing.commands.AbstractMutableCommand
          extended by dsto.dfc.swing.commands.AbstractEnumeratedCommand
All Implemented Interfaces:
Command, CustomMenuProvider, EnumeratedCommand, Iconic, Copyable, EnumerationValue, PropertyEventSource, ActionListener, Cloneable, EventListener

public abstract class AbstractEnumeratedCommand
extends AbstractMutableCommand
implements CustomMenuProvider, EnumeratedCommand

Abstract base class for commands that act to select one or more values from an enumerated set (eg zoom levels, open windows, etc). Provides an implementation of CustomMenuProvider (via delegation to EnumeratedCmdMenuSynchronizer) that generates an appropriate set of menu items for selecting the available enumerated values.

Version:
$Revision$

Field Summary
 
Fields inherited from class dsto.dfc.swing.commands.AbstractMutableCommand
listeners
 
Fields inherited from class dsto.dfc.swing.commands.AbstractCommand
displayName, icon
 
Fields inherited from interface dsto.dfc.swing.icons.Iconic
NULL_ICON
 
Constructor Summary
AbstractEnumeratedCommand()
           
 
Method Summary
 void addChangeListener(ChangeListener l)
          Custom menu providers should fire change events when the menu UI needs to be updated.
 List createMenuItems()
          Create the menu items that represent the UI for the command.
 void destroyMenuItems(List items)
          Destroy menu items created by createMenuItems ().
abstract  void execute()
          Execute the command.
abstract  String getDescription()
          A short description of the command, suitable for a tooltip or use in a status panel.
abstract  EnumerationValue[] getEnumValues()
          Get the list of values within the enumeration.
abstract  String getGroupInView(String viewName)
          Get the preferred group that this command should appear in for a given view.
abstract  int getMaxSelectedValues()
          Get the maximum number of values that may be selected at any one time.
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).
abstract  Object[] getNextSelectedValues()
          Get the values that will be set by executing the command.
abstract  Object[] getSelectedValues()
          The currently selected values.
abstract  boolean isInteractive()
          True if this command will interact with the user when execute() is called.
 boolean isSelected(Object value)
           
 void removeChangeListener(ChangeListener l)
           
abstract  void setNextSelectedValues(Object[] values)
          Set the values that will be 'selected' when execute() is next called (this is usually called immediately before execute() by an action listener attached to the appropriate menu item).
 
Methods inherited from class dsto.dfc.swing.commands.AbstractMutableCommand
addPropertyChangeListener, clone, isEnabled, removePropertyChangeListener, setEnabled, setIcon
 
Methods inherited from class dsto.dfc.swing.commands.AbstractCommand
actionPerformed, canReplace, getAccelerator, getDefaultDisplayName, getDisplayName, getIcon, getLargeIcon, getLogString, setDisplayName
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface dsto.dfc.swing.commands.Command
canReplace, getAccelerator, getDisplayName, getLogString, isEnabled
 
Methods inherited from interface dsto.dfc.swing.icons.Iconic
getIcon, getLargeIcon
 
Methods inherited from interface dsto.dfc.util.PropertyEventSource
addPropertyChangeListener, removePropertyChangeListener
 

Constructor Detail

AbstractEnumeratedCommand

public AbstractEnumeratedCommand()
Method Detail

isSelected

public boolean isSelected(Object value)

getEnumValues

public abstract EnumerationValue[] getEnumValues()
Description copied from interface: EnumerationValue
Get the list of values within the enumeration.

Specified by:
getEnumValues in interface EnumerationValue

setNextSelectedValues

public abstract void setNextSelectedValues(Object[] values)
Description copied from interface: EnumeratedCommand
Set the values that will be 'selected' when execute() is next called (this is usually called immediately before execute() by an action listener attached to the appropriate menu item). The number of values in the array must not be more than specified by getMaxSelectedValues().

Specified by:
setNextSelectedValues in interface EnumeratedCommand
See Also:
EnumeratedCommand.getMaxSelectedValues()

getNextSelectedValues

public abstract Object[] getNextSelectedValues()
Description copied from interface: EnumeratedCommand
Get the values that will be set by executing the command.

Specified by:
getNextSelectedValues in interface EnumeratedCommand
See Also:
EnumeratedCommand.setNextSelectedValues(java.lang.Object[])

getSelectedValues

public abstract Object[] getSelectedValues()
Description copied from interface: EnumeratedCommand
The currently selected values. If these values change, the command should fire a property change event. If maxSelectedValues is 0, this should return null or an empty array.

Specified by:
getSelectedValues in interface EnumeratedCommand

getMaxSelectedValues

public abstract int getMaxSelectedValues()
Description copied from interface: EnumeratedCommand
Get the maximum number of values that may be selected at any one time. eg this may affect the way the menu items are rendered for the command: if max selected values is 0, then vanilla JMenuItem's are used for each value, if 1 JRadioButtonMenuItem's are used and if >1 then JCheckBoxMenuItem's are used.

Specified by:
getMaxSelectedValues in interface EnumeratedCommand
See Also:
EnumeratedCommand.setNextSelectedValues(java.lang.Object[])

execute

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

Specified by:
execute in interface Command
Specified by:
execute in class AbstractCommand

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
Specified by:
getName in class AbstractCommand

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
Specified by:
getDescription in class AbstractCommand

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
Specified by:
isInteractive in class AbstractCommand

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
Specified by:
getGroupInView in class AbstractCommand
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
Specified by:
getMnemonic in class AbstractCommand

createMenuItems

public List createMenuItems()
Description copied from interface: CustomMenuProvider
Create the menu items that represent the UI for the command.

Specified by:
createMenuItems in interface CustomMenuProvider
Returns:
A new list of JComponent's to be added to the menu for the command.

destroyMenuItems

public void destroyMenuItems(List items)
Description copied from interface: CustomMenuProvider
Destroy menu items created by createMenuItems ().

Specified by:
destroyMenuItems in interface CustomMenuProvider

removeChangeListener

public void removeChangeListener(ChangeListener l)
Specified by:
removeChangeListener in interface CustomMenuProvider

addChangeListener

public void addChangeListener(ChangeListener l)
Description copied from interface: CustomMenuProvider
Custom menu providers should fire change events when the menu UI needs to be updated. This event will trigger any interested listeners to destroy old menu items (destroyMenuItems ()) and create new ones (createMenuItems ()).

Specified by:
addChangeListener in interface CustomMenuProvider


Copyright © 2008 Commonwealth of Australia