org.fopps.ui.actions
Class BaseAction

java.lang.Object
  |
  +--javax.swing.AbstractAction
        |
        +--org.fopps.ui.actions.BaseAction
All Implemented Interfaces:
javax.swing.Action, java.awt.event.ActionListener, java.lang.Cloneable, java.lang.Comparable, java.util.EventListener, java.awt.event.ItemListener, java.io.Serializable
Direct Known Subclasses:
FeatureAction, FileAction, FixAllTimingsAction, ItemAction, ItemPropertiesAction, NewCoreAssetAction, NewProductAction, OptionsAction, ProjectAction, QuitAction, UndoAction, ViewAction

public abstract class BaseAction
extends javax.swing.AbstractAction
implements java.awt.event.ItemListener, java.lang.Comparable

BaseAction is the base class of all actions. In comparison to AbstractAction it provides the following extensions

One significant method is acceptSelection(). Most actions will override this method to ensure that the action can operate on the existing selection. This implementation accepts every selection.

In collaboration with ActionHandler every instance of BaseAction will be considered in a context menu, if the action can operate on the current selection. Therefore BaseAction provides a group attribute, which enables the action handler to group similar actions together.

See Also:
PopupMenuFactory, ActionHandler, Serialized Form

Field Summary
static java.lang.String GROUP
          Group key
protected static java.lang.Object[] selectedItems
           
 
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
BaseAction(ActionHandler pListener)
          Constructor for BaseAction
BaseAction(java.lang.String pName, ActionHandler pListener)
          Constructor for BaseAction.
BaseAction(java.lang.String name, javax.swing.Icon icon, ActionHandler pListener)
          Constructor for BaseAction.
 
Method Summary
 boolean acceptSelection()
          Indicates, if an action is able to work with the selected items.
abstract  void actionPerformed(java.awt.event.ActionEvent e)
           
 boolean addToMenu()
          Return true, if action should be added to menu.
abstract  boolean addToPopup()
          Determines, if action should appear in popup menu
 boolean addToToolBar()
          Return true, if action should be added to toolbar.
static void clearSelection()
          Clear selection.
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 javax.swing.KeyStroke getAccelerator()
          Returns the accelerator
 ActionHandler getActionHandler()
          Returns the underlying action handler
 Application getApplication()
          Returns the application object
 ProjectContainer getContainer()
          Returns the current project container
 java.lang.String getGroup()
          Returns the name of the group.
 javax.swing.Icon getIcon()
          Returns the icon of the action
 java.lang.String getLocaleName()
           
 java.lang.String getLongDescription()
           
 java.lang.Integer getMnemonic()
           
 java.lang.String getName()
          Convenience method to access the name of the action
 java.lang.Object[] getSelectedItems()
          Returns the selectedItems.
 int getSelectionSize()
          Returns the number of selected items
 java.lang.String getShortDescription()
           
 boolean isStringPropertySet(java.lang.String pKey)
          Return true, if string property is set (property not null and length > 0)
 boolean isTogglable()
          Returns true, if action is a toggle action (behaves similar to a checkbox).
 boolean itemInSelection(java.lang.Object pItem)
          Checks if selection contains an item
 void itemStateChanged(java.awt.event.ItemEvent e)
          Handler of itemListener
 void setAccelerator(int keyChar)
          Convenience method to simplify the less intuitive setting in Swing :-)
 void setAccelerator(int keyChar, int pModifier)
          Convenience method to simplify the less intuitive setting in Swing :-)
 void setAcceleratorWithAlt(int keyChar)
          Sets an accelerator with alt modifier
 void setAcceleratorWithCtrl(int keyChar)
          Sets an accelerator with ctrl modifier
 void setAcceleratorWithShift(int keyChar)
          Sets an accelerator with shift modifier
protected  void setGroup(java.lang.String group)
          Setter for group.
 void setLocaleName(java.lang.String localeName)
           
 void setLongDescription(java.lang.String longDescription)
          Covenience method to simplify the less intuitive setting in Swing :-)
 void setMnemonic(int keyChar)
          Covenience method to simplify the less intuitive setting in Swing :-)
 void setMnemonic(int keyChar, int pModifier)
          Covenience method to simplify the less intuitive setting in Swing :-)
 void setShortDescription(java.lang.String shortDescription)
          Covenience method to simplify the less intuitive setting in Swing :-)
 java.lang.String toString()
          Returns a string representation of the object.
 void updateState()
          Force refresh of action
 
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, wait, wait, wait
 

Field Detail

GROUP

public static final java.lang.String GROUP
Group key

See Also:
Constant Field Values

selectedItems

protected static java.lang.Object[] selectedItems
Constructor Detail

BaseAction

public BaseAction(ActionHandler pListener)
Constructor for BaseAction

Parameters:
pListener - Action handler to connect to

BaseAction

public BaseAction(java.lang.String pName,
                  ActionHandler pListener)
Constructor for BaseAction.

Parameters:
pName - Name of the action
pListener - Action handler to connect to

BaseAction

public BaseAction(java.lang.String name,
                  javax.swing.Icon icon,
                  ActionHandler pListener)
Constructor for BaseAction.

Parameters:
pListener - Action handler to connect to
name - Name of the action
icon - Icon to show in toolbar
Method Detail

acceptSelection

public boolean acceptSelection()
Indicates, if an action is able to work with the selected items. If acceptSelection returns false, the action will be disabled. This method is called after every selection change

Returns:
true, if action is able to operate on current selection

clearSelection

public static void clearSelection()
Clear selection. Action is not refreshed


getContainer

public ProjectContainer getContainer()
Returns the current project container


getGroup

public final java.lang.String getGroup()
Returns the name of the group. If no special group is assigned, "default" is returned


setGroup

protected final void setGroup(java.lang.String group)
Setter for group.


getLocaleName

public java.lang.String getLocaleName()

setLocaleName

public void setLocaleName(java.lang.String localeName)

getApplication

public final Application getApplication()
Returns the application object


getActionHandler

public ActionHandler getActionHandler()
Returns the underlying action handler


getLongDescription

public java.lang.String getLongDescription()

setLongDescription

public void setLongDescription(java.lang.String longDescription)
Covenience method to simplify the less intuitive setting in Swing :-)


getShortDescription

public java.lang.String getShortDescription()

setShortDescription

public void setShortDescription(java.lang.String shortDescription)
Covenience method to simplify the less intuitive setting in Swing :-)


setMnemonic

public void setMnemonic(int keyChar)
Covenience method to simplify the less intuitive setting in Swing :-)


setMnemonic

public void setMnemonic(int keyChar,
                        int pModifier)
Covenience method to simplify the less intuitive setting in Swing :-)


getMnemonic

public java.lang.Integer getMnemonic()

setAccelerator

public void setAccelerator(int keyChar)
Convenience method to simplify the less intuitive setting in Swing :-)


setAccelerator

public void setAccelerator(int keyChar,
                           int pModifier)
Convenience method to simplify the less intuitive setting in Swing :-)


setAcceleratorWithCtrl

public void setAcceleratorWithCtrl(int keyChar)
Sets an accelerator with ctrl modifier


setAcceleratorWithAlt

public void setAcceleratorWithAlt(int keyChar)
Sets an accelerator with alt modifier


setAcceleratorWithShift

public void setAcceleratorWithShift(int keyChar)
Sets an accelerator with shift modifier


getAccelerator

public javax.swing.KeyStroke getAccelerator()
Returns the accelerator


getIcon

public javax.swing.Icon getIcon()
Returns the icon of the action


addToToolBar

public boolean addToToolBar()
Return true, if action should be added to toolbar. Default is true


addToMenu

public boolean addToMenu()
Return true, if action should be added to menu. Default is true


isTogglable

public boolean isTogglable()
Returns true, if action is a toggle action (behaves similar to a checkbox). Default is false


isStringPropertySet

public final boolean isStringPropertySet(java.lang.String pKey)
Return true, if string property is set (property not null and length > 0)


itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent e)
Handler of itemListener

Specified by:
itemStateChanged in interface java.awt.event.ItemListener

getSelectionSize

public int getSelectionSize()
Returns the number of selected items

Returns:
int

getSelectedItems

public java.lang.Object[] getSelectedItems()
Returns the selectedItems.

Returns:
Object[] Array containing the current selection. If nothing is selected, an empty array is returned.

itemInSelection

public boolean itemInSelection(java.lang.Object pItem)
Checks if selection contains an item

Parameters:
pItem - Item to search for

getName

public java.lang.String getName()
Convenience method to access the name of the action


compareTo

public int compareTo(java.lang.Object o)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure sgn(x.compareTo(y)) == -sgn(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception iff y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y)>0 && y.compareTo(z)>0) implies x.compareTo(z)>0.

Finally, the implementer must ensure that x.compareTo(y)==0 implies that sgn(x.compareTo(z)) == sgn(y.compareTo(z)), for all z.

It is strongly recommended, but not strictly required that (x.compareTo(y)==0) == (x.equals(y)). Generally speaking, any class that implements the Comparable interface and violates this condition should clearly indicate this fact. The recommended language is "Note: this class has a natural ordering that is inconsistent with equals."

Specified by:
compareTo in interface java.lang.Comparable
Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.ClassCastException - if the specified object's type prevents it from being compared to this Object.

updateState

public void updateState()
Force refresh of action


toString

public java.lang.String toString()
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString in class java.lang.Object
Returns:
a string representation of the object.

addToPopup

public abstract boolean addToPopup()
Determines, if action should appear in popup menu

Returns:
true, if action should added to context menu, otherwise false

actionPerformed

public abstract void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener
See Also:
ActionListener.actionPerformed(ActionEvent)


Fopps 0.19 - Copyright © 2002 Oliver Wieland. All Rights Reserved.