edu.ucsb.nceas.morpho.util
Class GUIAction

java.lang.Object
  |
  +--javax.swing.AbstractAction
        |
        +--edu.ucsb.nceas.morpho.util.GUIAction
All Implemented Interfaces:
javax.swing.Action, java.awt.event.ActionListener, java.lang.Cloneable, java.util.EventListener, java.io.Serializable, StateChangeListener

public class GUIAction
extends javax.swing.AbstractAction
implements StateChangeListener

Class GUIAction This class extends javax.swing.AbstractAction in order to provide basic "Action" functionality for the GUI. Instances of this class are passed as arguments to Swing component constructors, in order to facilitate encapsulation and sharing of functionality (eg multiple ways of accessing the same command, such as from a drop-down menu and from a toolbar button). The Swing component generally adds this object to itself as an ActionListener automatically.

See Also:
Serialized Form

Field Summary
static int EVENT_GLOBAL
          Public constant to denote that a GUIAction should consume events originating from any frame, not just its own
static int EVENT_LOCAL
          Public constant to denote that a GUIAction should consume events originating only within the same frame as the GUIAction itself
 
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
GUIAction(java.lang.String name, javax.swing.Icon icon, Command cmd)
          Constructor
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent actionEvent)
          actionPerformed() method required by ActionListener interface
 GUIAction cloneAction()
          Make a clone of the GUIAction instance.
 javax.swing.KeyStroke getAcceleratorKey()
          Method to get accelerator key
 Command getCommand()
          Get the command in this action object
 javax.swing.Icon getDefaultIcon()
          gets the default Icon for this action object
 int getMenuItemPosition()
          Get the menu item position for this action
 java.lang.String getMenuName()
          Get the menu name for this action
 int getMenuPosition()
          Get the menu position for this action
static MorphoFrame getMorphoFrameAncestor(java.awt.Component c)
           
 java.lang.String getName()
          gets the text for the Name
 GUIAction getOriginalAction()
          Get the original action from which a clone was made.
 java.lang.String getSeparatorPosition()
          Get the separator position for this action
 javax.swing.Icon getSmallIcon()
          Get the small Icon to be displayed on menus
 int getToolbarPosition()
          Get the position of this action on the toolbar.
 java.lang.String getToolTipText()
          gets the text for the tooltip
 void handleStateChange(StateChangeEvent event)
          Handle a state change.
 void setAcceleratorKey(javax.swing.KeyStroke key)
          Method to set accelerator key
 void setAcceleratorKeyString(java.lang.String keyString)
          set a accelerator key for this action
 void setCommand(Command cmd)
          Set the command in this action object
 void setCommandOnStateChange(java.lang.String changedState, Command command, int respondTo)
          Set the state of this action to the enabled value if a state change matching changedState occurs.
 void setDefaultIcon(javax.swing.Icon icon)
          Set the default icon.
 void setEnabledOnStateChange(java.lang.String changedState, boolean enabled, int respondTo)
          Set the state of this action to the enabled value if a state change matching changedState occurs.
 void setMenu(java.lang.String menuName, int position)
          Sets the menu and its position for this action
 void setMenuItemPosition(int position)
          sets the menu item position for this action
 void setSeparatorPosition(java.lang.String position)
          sets the separator for this action
 void setSmallIcon(javax.swing.Icon smallIcon)
          sets the small Icon to be displayed on menus
 void setSubMenu(boolean flag)
          sets the action pull right submenu
 void setSubMenuPath(java.lang.String path)
          sets the action path for sub menu or sub menuitem.
 void setToolbarPosition(int position)
          Set the position of this action on the toolbar.
 void setToolTipText(java.lang.String toolTipText)
          sets the text to be displayed as a mouse-over tooltip
 
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EVENT_LOCAL

public static final int EVENT_LOCAL
Public constant to denote that a GUIAction should consume events originating only within the same frame as the GUIAction itself

EVENT_GLOBAL

public static final int EVENT_GLOBAL
Public constant to denote that a GUIAction should consume events originating from any frame, not just its own
Constructor Detail

GUIAction

public GUIAction(java.lang.String name,
                 javax.swing.Icon icon,
                 Command cmd)
Constructor
Parameters:
name - the display name of this action, as used in menus
icon - the default icon associated with this action
cmd - the Command object that will have its execute() method called by this object's actionPerformed() method
Method Detail

cloneAction

public GUIAction cloneAction()
Make a clone of the GUIAction instance.

getName

public java.lang.String getName()
gets the text for the Name
Returns:
String representing the name of the action

getDefaultIcon

public javax.swing.Icon getDefaultIcon()
gets the default Icon for this action object
Returns:
Icon the default icon for this action object

setDefaultIcon

public void setDefaultIcon(javax.swing.Icon icon)
Set the default icon.
Parameters:
icon - the icon to be used by default

getToolTipText

public java.lang.String getToolTipText()
gets the text for the tooltip
Returns:
String representing the tooltip text

setToolTipText

public void setToolTipText(java.lang.String toolTipText)
sets the text to be displayed as a mouse-over tooltip
Parameters:
toolTipText - the tooltip text to be displayed

getSmallIcon

public javax.swing.Icon getSmallIcon()
Get the small Icon to be displayed on menus
Returns:
the Icon to be displayed on menus etc

setSmallIcon

public void setSmallIcon(javax.swing.Icon smallIcon)
sets the small Icon to be displayed on menus
Parameters:
smallIcon - the Icon to be displayed on menus etc

setAcceleratorKeyString

public void setAcceleratorKeyString(java.lang.String keyString)
set a accelerator key for this action
Parameters:
keyString - the accelerator key string

getAcceleratorKey

public javax.swing.KeyStroke getAcceleratorKey()
Method to get accelerator key

setAcceleratorKey

public void setAcceleratorKey(javax.swing.KeyStroke key)
Method to set accelerator key

setSubMenu

public void setSubMenu(boolean flag)
sets the action pull right submenu
Parameters:
flag - true of false the action is sub menu

setSubMenuPath

public void setSubMenuPath(java.lang.String path)
sets the action path for sub menu or sub menuitem. Note: sub menu and sub menuitem for this sub menu has same path for example In file menu, it has a submenu delete and delete has 3 menuitems - delete local, delete network and delete both. The path for delete submenu is "file/delete", the path for the 3 menuitems is "file/delete" too.
Parameters:
path - the su

setMenu

public void setMenu(java.lang.String menuName,
                    int position)
Sets the menu and its position for this action
Parameters:
menuName - the name of the menu in which to embed this action
position - the position of the menu

getMenuName

public java.lang.String getMenuName()
Get the menu name for this action
Returns:
the name of the menu for this action

getMenuPosition

public int getMenuPosition()
Get the menu position for this action
Returns:
the position of the menu for this action

setMenuItemPosition

public void setMenuItemPosition(int position)
sets the menu item position for this action
Parameters:
position - the position of memu item

getMenuItemPosition

public int getMenuItemPosition()
Get the menu item position for this action

setSeparatorPosition

public void setSeparatorPosition(java.lang.String position)
sets the separator for this action
Parameters:
position - the position separator of memu item, follow or precding

getSeparatorPosition

public java.lang.String getSeparatorPosition()
Get the separator position for this action

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent actionEvent)
actionPerformed() method required by ActionListener interface
Overrides:
actionPerformed in class javax.swing.AbstractAction
Parameters:
actionEvent - the event generated by the component

getCommand

public Command getCommand()
Get the command in this action object

setCommand

public void setCommand(Command cmd)
Set the command in this action object

setEnabledOnStateChange

public void setEnabledOnStateChange(java.lang.String changedState,
                                    boolean enabled,
                                    int respondTo)
Set the state of this action to the enabled value if a state change matching changedState occurs.
Parameters:
changedState - the name of the state change
enabled - boolean value indicating whether the action should be enabled
localEventsOnly - boolean value indicating whether the change should occur in response only to events originating within the same frame as this GUIAction's container
respondTo - int value indicating whether the change should occur in response only to events originating within the same frame as this GUIAction's container (GUIAction.EVENT_LOCAL) or in response to all events, irrespective of their source (GUIAction.EVENT_GLOBAL).

setCommandOnStateChange

public void setCommandOnStateChange(java.lang.String changedState,
                                    Command command,
                                    int respondTo)
Set the state of this action to the enabled value if a state change matching changedState occurs.
Parameters:
changedState - the name of the state change
command - Command that should be set upon a state change
respondTo - int value indicating whether the change should occur in response only to events originating within the same frame as this GUIAction's container (GUIAction.EVENT_LOCAL) or in response to all events, irrespective of their source (GUIAction.EVENT_GLOBAL).

handleStateChange

public void handleStateChange(StateChangeEvent event)
Handle a state change. This results in a change to the enabled state of the action, or a change in the command, depending on which state changes have been registered for this action previously.
Specified by:
handleStateChange in interface StateChangeListener
Parameters:
event - the StateChangeEvent that has occurred

getToolbarPosition

public int getToolbarPosition()
Get the position of this action on the toolbar. If it is less than zero, the item is not shown on the toolbar.
Returns:
the position of the action on the toolbar

setToolbarPosition

public void setToolbarPosition(int position)
Set the position of this action on the toolbar. If it is less than zero, the item is not shown on the toolbar.
Parameters:
position - the position of the action on the toolbar

getOriginalAction

public GUIAction getOriginalAction()
Get the original action from which a clone was made.
Returns:
the original GUIAction that created the clone, or null if it is not actually a clone

getMorphoFrameAncestor

public static MorphoFrame getMorphoFrameAncestor(java.awt.Component c)


Copyright © 2000 National Center for Ecological Analysis and Synthesis. All Rights Reserved.