org.eodisp.ui.common.actions
Class EodispAction

java.lang.Object
  extended by javax.swing.AbstractAction
      extended by org.eodisp.ui.common.actions.EodispAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, javax.swing.Action

public class EodispAction
extends javax.swing.AbstractAction

An EodispAction extends the AbstractAction to be used by the EODiSP framework. It adds some functionality needed by the framework. More specifically, it specifies if an EodispAction should be used in the menu bar, in the tool bar, or in the context menu (or any combination of those).

It also has the functionality to add a target handler to the action. The target handler is responsible to handle the actionPerformed(ActionEvent) event. Usually, this will be a controller which takes the responsibility to react to an action.

Registering a controller as a target handler can be done through the use of the delegation mechanism provided by the EodispDelegate class.

Version:
$Id:EodispAction.java 2134 2006-05-16 08:43:27Z eglimi $
Author:
eglimi
See Also:
Serialized Form

Field Summary
static java.lang.String CTX_GROUP
          This is the name of a context group.
static java.lang.String CTX_GROUP_SUBMENU
          This is the name of a dedicated sub-menu for a list of menu item.
protected  java.awt.event.ActionListener targetHandler
          Holds the target handler which is responsible for handling the events (i.e.
static java.lang.String USER_OBJECT
          An additional user object.
 
Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
 
Fields inherited from interface javax.swing.Action
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON
 
Constructor Summary
EodispAction()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          This distributes the event.
 java.lang.Class<? extends ActionSourceProvider> getActionSource()
          Returns the action source for this action.
 int getMenuIndex()
          Return the value of the index of this action.
 javax.swing.ImageIcon getToolBarIcon()
           
 int getToolBarIndex()
           
 java.lang.String getTopMenuItemName()
          Returns the name of the parent menu as a string.
 boolean isAlwaysSelected()
           
 boolean isCheckBox()
           
 boolean isCheckBoxEnabled()
           
 boolean isProcessed()
          Return whether the action has already been processed.
 boolean isShowInContextMenu()
          Returns whether or not this action should be showed as an entry in the context menu.
 boolean isShowInMenuBar()
          Returns whether or not this action should be showed as an entry in the menu bar.
 boolean isShowInToolBar()
          Returns whether or not this action should be showed as an entry in the tool bar.
 void registerTargetHandler(java.awt.event.ActionListener l)
          Registers a target handler.
<T extends ActionSourceProvider>
void
setActionSource(java.lang.Class<T> actionSource)
          Sets the action source for this action.
 void setAlwaysSelected(boolean isAlwaysSelected)
          This can be set to indicate that an action cannot be disabled.
 void setCheckBox(boolean isCheckBox)
          Sets the isCheckBox flag.
 void setCheckBoxEnabled(boolean checkBoxEnabled)
          Toggles the initial state of a checkbox enabled action.
 void setMenuIndex(int menuIndex)
          Changes the value of the index in the menu bar for this action.
 void setProcessed(boolean isProcessed)
          Sets whether the action has been processed by the action manager.
 void setShowInContextMenu(boolean showInContextMenu)
          Specifies whether this action should be showed as an entry in the menu bar.
 void setShowInMenuBar(boolean showInMenuBar)
          Specifies whether this action should be showed as an entry in the menu bar.
 void setShowInToolBar(boolean showInToolBar)
          Specifies whether this action should be showed as an entry in the tool bar.
 void setToolBarIcon(javax.swing.ImageIcon toolBarIcon)
           
 void setToolBarIndex(int toolBarIndex)
           
 void setTopMenuItemName(java.lang.String topMenuItemName)
          Sets the name of the parent menu.
 
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

USER_OBJECT

public static final java.lang.String USER_OBJECT
An additional user object.

See Also:
Constant Field Values

CTX_GROUP_SUBMENU

public static final java.lang.String CTX_GROUP_SUBMENU
This is the name of a dedicated sub-menu for a list of menu item.

See Also:
Constant Field Values

CTX_GROUP

public static final java.lang.String CTX_GROUP
This is the name of a context group. A context group is a section within a JMenu that is separated by a JSeparator. The menu item will not be placed in a dedicated sub-menu when using this value.

See Also:
Constant Field Values

targetHandler

protected java.awt.event.ActionListener targetHandler
Holds the target handler which is responsible for handling the events (i.e. if an action is performed). See actionPerformed(ActionEvent). Such a target handler should be an instance of the class EodispDelegate.

Constructor Detail

EodispAction

public EodispAction()
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
This distributes the event. There is either a targetHandler attached to this action, or the event will be distributed to all listeners by the EodispActionRegistry. The first is the preferred way, the second the more natural way for dynamic actions. Also, the second approach (distributing the event), is only available for dynamic actions.


registerTargetHandler

public void registerTargetHandler(java.awt.event.ActionListener l)
Registers a target handler. This should be an instance of EodispDelegate. The target class in this defined in this instance will be responsible to execute appropriate code when an action is performed.

Parameters:
l - The target handler which is responsible to handle the event.

isShowInContextMenu

public boolean isShowInContextMenu()
Returns whether or not this action should be showed as an entry in the context menu. The default is 'false'.

Returns:
True, if the action is shown in the context menu or false, if it should be omitted.

setShowInContextMenu

public void setShowInContextMenu(boolean showInContextMenu)
Specifies whether this action should be showed as an entry in the menu bar.

Parameters:
showInContextMenu - Used to set the visibility in the context menu.

isShowInMenuBar

public boolean isShowInMenuBar()
Returns whether or not this action should be showed as an entry in the menu bar. The default is 'true'.

Returns:
True, if the action is shown in the menu bar or false, if it should be omitted.

setShowInMenuBar

public void setShowInMenuBar(boolean showInMenuBar)
Specifies whether this action should be showed as an entry in the menu bar.

The default value is true.

Parameters:
showInMenuBar - Used to set the visibility in the menu bar.

isShowInToolBar

public boolean isShowInToolBar()
Returns whether or not this action should be showed as an entry in the tool bar. The default is 'false'.

The default value is false.

Returns:
True, if the action is shown in the tool bar or false, if it should be omitted.

setShowInToolBar

public void setShowInToolBar(boolean showInToolBar)
Specifies whether this action should be showed as an entry in the tool bar.

Remember to specify an icon for the action if you set this to true.

The default value is false.

Parameters:
showInToolBar - Used to set the visibility in the tool bar.

getMenuIndex

public int getMenuIndex()
Return the value of the index of this action. This is only useful for displaying the action as an item in the menu bar. You should not be using this method, since the ordering of the menu items in the menu bar is done automatically.

Returns:
The value of the index.

setMenuIndex

public void setMenuIndex(int menuIndex)
Changes the value of the index in the menu bar for this action. This possibly resorts the items in the menu bar.

Parameters:
menuIndex -

getTopMenuItemName

public java.lang.String getTopMenuItemName()
Returns the name of the parent menu as a string.

Returns:
The name of the parent menu as String.

setTopMenuItemName

public void setTopMenuItemName(java.lang.String topMenuItemName)
Sets the name of the parent menu. See topMenuItemName for further explanation how the name can be constructed (especially for sub-menus).

This is only useful if this action should be displayed in the menu bar.

Parameters:
topMenuItemName - The name of the parent menu. If this action should be shown in the menu bar, it will be a child item of the top menu bar.

isCheckBox

public boolean isCheckBox()
Returns:
Returns the enableCheckBox.

setCheckBox

public void setCheckBox(boolean isCheckBox)
Sets the isCheckBox flag. If this flag is set, the item will be shown as check box.

Parameters:
isCheckBox - The enableCheckBox to set.

isCheckBoxEnabled

public boolean isCheckBoxEnabled()
Returns:
Returns the checkBoxEnabled.

setCheckBoxEnabled

public void setCheckBoxEnabled(boolean checkBoxEnabled)
Toggles the initial state of a checkbox enabled action.

Parameters:
checkBoxEnabled - The checkBoxEnabled to set. If true, the initial state of the checkbox will be enabled, if false, the initial state of will be disabled.

getActionSource

public java.lang.Class<? extends ActionSourceProvider> getActionSource()
Returns the action source for this action.

This information can be use to clear all actions defined for such a component. This can happen if the component is disposed or if the if it uses dynamic action entries.

Parameters:
actionSource - The action source for this action.

setActionSource

public <T extends ActionSourceProvider> void setActionSource(java.lang.Class<T> actionSource)
Sets the action source for this action. This should be either a EodispView or a EodispFrame. It is the component which is responsible for registering this action.


isProcessed

public boolean isProcessed()
Return whether the action has already been processed. This can be used to dynamically update actions in the menu bar, tool bar and context menu. If an action is dynamically added, we just process it if it was not processed before.

Returns:
Returns the isProcessed.

setProcessed

public void setProcessed(boolean isProcessed)
Sets whether the action has been processed by the action manager. If set to true, future requests to process it will be ignored.

Parameters:
isProcessed - True, if the action has been processed.

isAlwaysSelected

public boolean isAlwaysSelected()
Returns:
Returns the isAlwaysSelected.

setAlwaysSelected

public void setAlwaysSelected(boolean isAlwaysSelected)
This can be set to indicate that an action cannot be disabled.

Parameters:
isAlwaysSelected - The isAlwaysSelected to set.

getToolBarIcon

public javax.swing.ImageIcon getToolBarIcon()
Returns:
Returns the toolBarIcon.

setToolBarIcon

public void setToolBarIcon(javax.swing.ImageIcon toolBarIcon)
Parameters:
toolBarIcon - The toolBarIcon to set.

getToolBarIndex

public int getToolBarIndex()
Returns:
Returns the toolBarIndex.

setToolBarIndex

public void setToolBarIndex(int toolBarIndex)
Parameters:
toolBarIndex - The toolBarIndex to set.