org.openbp.jaspira.action
Class JaspiraAction

java.lang.Object
  extended by org.openbp.common.generic.description.DescriptionObjectImpl
      extended by org.openbp.common.generic.description.DisplayObjectImpl
          extended by org.openbp.jaspira.action.JaspiraAction
All Implemented Interfaces:
java.awt.event.ActionListener, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable, java.util.EventListener, javax.swing.Action, Copyable, DescriptionObject, Displayable, DisplayObject, Validatable
Direct Known Subclasses:
GeneratorPlugin.GeneratorAction, JaspiraProxyAction

public class JaspiraAction
extends DisplayObjectImpl
implements javax.swing.Action

Base class for actions within the Jaspria framework. Each action has an optional name, display name and a description. The display will be show as menu item text, the description will be used as tool tip of a component that activates the action. if the actionPerformed(java.awt.event.ActionEvent) method is not overriden, it will fire an JaspiraActionEvent using the name of the action as event name. The source plugin of the event will be the currently focused plugin or (if none) the owner plugin of the action. Actions can contain several icons and descriptions. The small icon is used in Menus. The large icon is used in toolbars. Jaspira actions are also used to build menu and toolbar structures. The type of the action determines what the action represents:
TYPE_ACTION or null: Regular action
TYPE_MENU: Menu (used to hold sub menu items; it doesn't have a real action functionality)
TYPE_GROUP: Menu or toolbar group An action can have a menu parent and/or a toolbar parent, which determines where to place the action in the main menu or the main toolbar.
Group or menu actions may also have menu or toolbar children.

Author:
Stephan Moritz
See Also:
Serialized Form

Field Summary
static int DFLT_PRIORITY
          Default priority of an action
static java.lang.String KEY_SEQUENCE_DELIM
          Delimiter for multiple key sequences
static java.lang.String MENU_ROOT
          Id for the menu root - top level of a menu
static java.lang.String MNEMONIC_DELIMITER
          Delimiter to show the mnemonic key - key after delimiter gets mnemonic
static java.lang.String PROPERTY_CONDITION
          Property id for the conditional expression
static java.lang.String PROPERTY_DESCRIPTION
          Property id for description
static java.lang.String PROPERTY_DISABLED_ICON
          Property id for disabled icon
static java.lang.String PROPERTY_DISPLAY_NAME
          Property id for display name
static java.lang.String PROPERTY_ENABLED
          Property id for enabled option
static java.lang.String PROPERTY_ICON
          Property id for normal icon
static java.lang.String PROPERTY_MENU_PARENT
          Property id for menu parent if action has to be displayed in the menu
static java.lang.String PROPERTY_NAME
          Property id for name
static java.lang.String PROPERTY_PAGE_NAMES
          Property id for the names of the Jaspira pages that should display this action in the page menu or toolbar
static java.lang.String PROPERTY_PRIO
          Property id for priority of the action
static java.lang.String PROPERTY_SCOPE
          Property id for action scope
static java.lang.String PROPERTY_SELECTED
          Propertyid for selected option
static java.lang.String PROPERTY_SEQUENCE
          Property id for key sequences
static java.lang.String PROPERTY_TOOLBAR_PARENT
          Property id for toolbar parent if action has to be displayed in teh toolbar
static java.lang.String PROPERTY_TYPE
          Property id for the type of action
static java.lang.String TOOLBAR_ROOT
          Id for the toolbar root - top level of a toolbar
static java.lang.String TYPE_ACTION
          Regular action
static java.lang.String TYPE_COMBO
          Combo box action
static java.lang.String TYPE_GROUP
          Menu or toolbar group
static java.lang.String TYPE_MENU
          Menu (used to hold sub menu items; it doesn't have a real action functionality)
 
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
 
Fields inherited from interface org.openbp.common.generic.Copyable
COPY_DEEP, COPY_FIRST_LEVEL, COPY_SHALLOW
 
Constructor Summary
JaspiraAction(DisplayObject obj)
          Constructor using the given display object.
JaspiraAction(Plugin owner, java.lang.String name)
          Constructor.
JaspiraAction(ResourceCollection res, java.lang.String name)
          Constructor.
JaspiraAction(java.lang.String name, java.lang.String displayName, java.lang.String description, MultiIcon icon, KeySequence[] keySequences, int priority, java.lang.String type)
          Explicit constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ae)
          Called if the action has been activated.
 void addMenuChild(JaspiraAction action)
          Registers an action at this parent.
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Adds a property change listener to the listener list.
 void addToolbarChild(JaspiraAction action)
          Registers an action at this parent.
 void checkForMnemonic()
          Checks the Title of the Menu for Mnemonic.
 void clearValues()
          Clears all action values.
 boolean decreaseCounter()
          Decrease the reference counter of the action.
protected  void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)
          Supports reporting bound property changes.
 java.lang.Object getActionProperty(java.lang.String key)
          Gets an action property, either from the action's property map or from the resource file.
 boolean getActionPropertyBoolean(java.lang.String key, boolean dflt)
          Gets an action property of type boolean.
 int getActionPropertyInt(java.lang.String key, int dflt)
          Gets an action property of type int.
 java.lang.String getActionPropertyString(java.lang.String key)
          Gets an action property of type String.
 java.lang.String getActionPropertyString(java.lang.String key, java.lang.String dflt)
          Gets an action property of type String.
 ResourceCollection getActionResource()
          Gets the resource containing the action properties.
 java.lang.String getCondition()
          Gets the conditional expression that determines if the plugin should be active.
 int getCounter()
          Returns the current value of the reference counter.
 MultiIcon getDisabledIcon()
          Gets the disabled version of the icon.
 MultiIcon getIcon()
          Gets the toolbar/menu icon.
 KeySequence[] getKeySequences()
          Gets the key sequences for action activation.
 java.util.SortedSet getMenuchildren()
          Returns the menu children.
 char getMnemonicChar()
          Returns the mnemonic char of this action.
 int getMnemonicPos()
          Returns the position of the mnemonic underscore in the display name of the action.
 java.lang.String[] getPageNames()
          Gets the names of the Jaspira pages that should display this action in the page menu or toolbar.
 int getPriority()
          Gets the priority.
 java.util.SortedSet getToolbarchildren()
          Returns the toolbarchildren.
 java.lang.String getType()
          Returns the type.
 java.lang.Object getValue(java.lang.String key)
           
 void increaseCounter()
          Increases the reference counter of the action.
 boolean isEnabled()
          Gets the enabled status.
 boolean isMnemonic()
          Returns true if the Action has mnemonic.
 boolean isSelected()
          Returns the selected status.
 boolean matchesPageName(java.lang.String currentPageName)
          Checks if an action should be added to the menu or toolbar of this page.
 void putValue(java.lang.String key, java.lang.Object value)
           
protected  void removeMenuChild(JaspiraAction action)
          Unregisters an action from this parent.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Removes a property change listener from the listener list.
protected  void removeToolbarChild(JaspiraAction action)
          Unregisters an action from this parent.
 void setDescription(java.lang.String description)
          Sets a new description for the action.
 void setDisabledIcon(MultiIcon disabledIcon)
          Sets the disabled version of the icon.
 void setDisplayName(java.lang.String displayName)
          Sets a new displayname for the action.
 void setEnabled(boolean enabled)
          Sets the enabled status.
 void setIcon(MultiIcon icon)
          Sets the toolbar/menu icon.
 void setPageNames(java.lang.String[] pageNames)
          Sets the names of the Jaspira pages that should display this action in the page menu or toolbar.
 void setPriority(int priority)
          Sets the priority.
 void setSelected(boolean selected)
          Sets the selected status.
 javax.swing.JComponent toComponent()
          Constructs a component from this action.
 javax.swing.JMenuItem toMenuItem()
          Constructs a menu item from this action.
 javax.swing.JMenuItem toMenuItem(java.lang.String currentPageName)
          Constructs a menu item from this action, considering the given page name.
 javax.swing.JComponent toToolBarComponent()
          Constructs a tool bar component from this action.
 javax.swing.JComponent toToolBarComponent(java.lang.String currentPageName)
          Constructs a tool bar component from this action, considering the given page name.
 
Methods inherited from class org.openbp.common.generic.description.DisplayObjectImpl
copyFrom, getDisplayName, getDisplayText
 
Methods inherited from class org.openbp.common.generic.description.DescriptionObjectImpl
clone, compareTo, getDescription, getDescriptionEscape, getDescriptionText, getName, setDescriptionEscape, setName, toString, validate
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.openbp.common.generic.description.DescriptionObject
clone, getDescription, getDescriptionText, getName, setName
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

PROPERTY_NAME

public static final java.lang.String PROPERTY_NAME
Property id for name

See Also:
Constant Field Values

PROPERTY_DISPLAY_NAME

public static final java.lang.String PROPERTY_DISPLAY_NAME
Property id for display name

See Also:
Constant Field Values

PROPERTY_DESCRIPTION

public static final java.lang.String PROPERTY_DESCRIPTION
Property id for description

See Also:
Constant Field Values

PROPERTY_ICON

public static final java.lang.String PROPERTY_ICON
Property id for normal icon

See Also:
Constant Field Values

PROPERTY_DISABLED_ICON

public static final java.lang.String PROPERTY_DISABLED_ICON
Property id for disabled icon

See Also:
Constant Field Values

PROPERTY_SEQUENCE

public static final java.lang.String PROPERTY_SEQUENCE
Property id for key sequences

See Also:
Constant Field Values

PROPERTY_ENABLED

public static final java.lang.String PROPERTY_ENABLED
Property id for enabled option

See Also:
Constant Field Values

PROPERTY_SELECTED

public static final java.lang.String PROPERTY_SELECTED
Propertyid for selected option

See Also:
Constant Field Values

PROPERTY_PRIO

public static final java.lang.String PROPERTY_PRIO
Property id for priority of the action

See Also:
Constant Field Values

PROPERTY_SCOPE

public static final java.lang.String PROPERTY_SCOPE
Property id for action scope

See Also:
Constant Field Values

PROPERTY_TYPE

public static final java.lang.String PROPERTY_TYPE
Property id for the type of action

See Also:
Constant Field Values

PROPERTY_MENU_PARENT

public static final java.lang.String PROPERTY_MENU_PARENT
Property id for menu parent if action has to be displayed in the menu

See Also:
Constant Field Values

PROPERTY_TOOLBAR_PARENT

public static final java.lang.String PROPERTY_TOOLBAR_PARENT
Property id for toolbar parent if action has to be displayed in teh toolbar

See Also:
Constant Field Values

PROPERTY_PAGE_NAMES

public static final java.lang.String PROPERTY_PAGE_NAMES
Property id for the names of the Jaspira pages that should display this action in the page menu or toolbar

See Also:
Constant Field Values

PROPERTY_CONDITION

public static final java.lang.String PROPERTY_CONDITION
Property id for the conditional expression

See Also:
Constant Field Values

MENU_ROOT

public static final java.lang.String MENU_ROOT
Id for the menu root - top level of a menu

See Also:
Constant Field Values

TOOLBAR_ROOT

public static final java.lang.String TOOLBAR_ROOT
Id for the toolbar root - top level of a toolbar

See Also:
Constant Field Values

TYPE_ACTION

public static final java.lang.String TYPE_ACTION
Regular action

See Also:
Constant Field Values

TYPE_COMBO

public static final java.lang.String TYPE_COMBO
Combo box action

See Also:
Constant Field Values

TYPE_MENU

public static final java.lang.String TYPE_MENU
Menu (used to hold sub menu items; it doesn't have a real action functionality)

See Also:
Constant Field Values

TYPE_GROUP

public static final java.lang.String TYPE_GROUP
Menu or toolbar group

See Also:
Constant Field Values

KEY_SEQUENCE_DELIM

public static final java.lang.String KEY_SEQUENCE_DELIM
Delimiter for multiple key sequences

See Also:
Constant Field Values

DFLT_PRIORITY

public static final int DFLT_PRIORITY
Default priority of an action

See Also:
Constant Field Values

MNEMONIC_DELIMITER

public static final java.lang.String MNEMONIC_DELIMITER
Delimiter to show the mnemonic key - key after delimiter gets mnemonic

See Also:
Constant Field Values
Constructor Detail

JaspiraAction

public JaspiraAction(Plugin owner,
                     java.lang.String name)
Constructor. The new action retrieves its properties from the resource of its owner plugin using the given action name.

Parameters:
owner - Owner plugin of the action
name - Action name

JaspiraAction

public JaspiraAction(ResourceCollection res,
                     java.lang.String name)
Constructor. The new action retrieves its properties from the given resource using the given action name.

Parameters:
res - Action resource
name - Action name

JaspiraAction

public JaspiraAction(java.lang.String name,
                     java.lang.String displayName,
                     java.lang.String description,
                     MultiIcon icon,
                     KeySequence[] keySequences,
                     int priority,
                     java.lang.String type)
Explicit constructor. Usually it is preferable to use the resource based constructor.

Parameters:
name - The internal name of the object
displayName - Display name of this object
description - Description of this object
icon - Toolbar/menu icon
keySequences - Key sequences for action activation
priority - Priority
type - Type of the action (TYPE_ACTION/TYPE_COMBO/TYPE_MENU/TYPE_GROUP/null)

JaspiraAction

public JaspiraAction(DisplayObject obj)
Constructor using the given display object.

Parameters:
obj - Display object to copy name, display name and description from
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ae)
Called if the action has been activated. For actions of the TYPE_ACTION or TYPE_COMBO, the method fires a JaspiraActionEvent that has the same name as the action either to the currently focused plugin (if there is one) or to the global application plugin.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
ae - Action event

toComponent

public javax.swing.JComponent toComponent()
Constructs a component from this action.

Returns:
Null

toToolBarComponent

public javax.swing.JComponent toToolBarComponent()
Constructs a tool bar component from this action.

Returns:
A JaspiraToolbarButton if the action is a regular action, a JaspiraToolbar if the action has toolbar children, null otherwise

toToolBarComponent

public javax.swing.JComponent toToolBarComponent(java.lang.String currentPageName)
Constructs a tool bar component from this action, considering the given page name. The toolbar will contain only those children that match the given page name (see matchesPageName(java.lang.String)).

Parameters:
currentPageName - Name of the Jaspira page to check against or null
Returns:
A JaspiraToolbarButton if the action is a regular action, a JaspiraToolbar if the action has toolbar children, null otherwise

toMenuItem

public javax.swing.JMenuItem toMenuItem()
Constructs a menu item from this action.

Returns:
A JaspiraMenuItem if the action is a regular action, a JaspiraMenu if the action is a menu action and has menu children, null otherwise

toMenuItem

public javax.swing.JMenuItem toMenuItem(java.lang.String currentPageName)
Constructs a menu item from this action, considering the given page name. If the result is a menu, it will contain only those children that match the given page name (see matchesPageName(java.lang.String)).

Parameters:
currentPageName - Name of the Jaspira page to check against or null
Returns:
A JaspiraMenuItem if the action is a regular action, a JaspiraMenu if the action is a menu action and has menu children, null otherwise

matchesPageName

public boolean matchesPageName(java.lang.String currentPageName)
Checks if an action should be added to the menu or toolbar of this page. This is the case if the page name (Plugin.getName()) matches the page names defined for the action (getPageNames()), in detail if:
- The action page name list is empty
- The page name equals an entry in the action page name list

Parameters:
currentPageName - Name of the Jaspira page to check against
Returns:
true The action should be added to this page. false The action should not appear on this page.

checkForMnemonic

public void checkForMnemonic()
Checks the Title of the Menu for Mnemonic.


getMnemonicPos

public int getMnemonicPos()
Returns the position of the mnemonic underscore in the display name of the action. The method returns -1 if no mnemonic is available.

Returns:
int the position in the display name string or -1

isMnemonic

public boolean isMnemonic()
Returns true if the Action has mnemonic.

Returns:
boolean true if mnemonic is available, false otherwise

getMnemonicChar

public char getMnemonicChar()
Returns the mnemonic char of this action.

Returns:
char mnemonic char

getActionResource

public ResourceCollection getActionResource()
Gets the resource containing the action properties.


getMenuchildren

public java.util.SortedSet getMenuchildren()
Returns the menu children.

Returns:
The set of child actions or null

addMenuChild

public void addMenuChild(JaspiraAction action)
Registers an action at this parent.

Parameters:
action - the childaction that wants to register

removeMenuChild

protected void removeMenuChild(JaspiraAction action)
Unregisters an action from this parent.

Parameters:
action - the child action that wants to unregister

getToolbarchildren

public java.util.SortedSet getToolbarchildren()
Returns the toolbarchildren.

Returns:
Set of toolbar children or null

addToolbarChild

public void addToolbarChild(JaspiraAction action)
Registers an action at this parent.

Parameters:
action - the childaction that wants to register

removeToolbarChild

protected void removeToolbarChild(JaspiraAction action)
Unregisters an action from this parent.

Parameters:
action - the child action that wants to unregister

getPageNames

public java.lang.String[] getPageNames()
Gets the names of the Jaspira pages that should display this action in the page menu or toolbar.

Returns:
The list of page names (see JaspiraPage.getName) or null if the action should appear for all pages

setPageNames

public void setPageNames(java.lang.String[] pageNames)
Sets the names of the Jaspira pages that should display this action in the page menu or toolbar.

Parameters:
pageNames - The list of page names (see JaspiraPage.getName) or null if the action should appear for all pages

getType

public java.lang.String getType()
Returns the type.

Returns:
The type of the action (TYPE_ACTION/TYPE_COMBO/TYPE_MENU/TYPE_GROUP/null)

getIcon

public MultiIcon getIcon()
Gets the toolbar/menu icon.


setIcon

public void setIcon(MultiIcon icon)
Sets the toolbar/menu icon.


getDisabledIcon

public MultiIcon getDisabledIcon()
Gets the disabled version of the icon.


setDisabledIcon

public void setDisabledIcon(MultiIcon disabledIcon)
Sets the disabled version of the icon.


getKeySequences

public KeySequence[] getKeySequences()
Gets the key sequences for action activation.


isEnabled

public boolean isEnabled()
Gets the enabled status.

Specified by:
isEnabled in interface javax.swing.Action

setEnabled

public void setEnabled(boolean enabled)
Sets the enabled status.

Specified by:
setEnabled in interface javax.swing.Action

isSelected

public boolean isSelected()
Returns the selected status.


setDisplayName

public void setDisplayName(java.lang.String displayName)
Sets a new displayname for the action.

Specified by:
setDisplayName in interface DisplayObject
Overrides:
setDisplayName in class DisplayObjectImpl
See Also:
DisplayObjectImpl.setDisplayName(String)

setDescription

public void setDescription(java.lang.String description)
Sets a new description for the action.

Specified by:
setDescription in interface DescriptionObject
Overrides:
setDescription in class DescriptionObjectImpl
See Also:
DescriptionObjectImpl.setDescription(String)

setSelected

public void setSelected(boolean selected)
Sets the selected status.


getPriority

public int getPriority()
Gets the priority.


setPriority

public void setPriority(int priority)
Sets the priority.


getCondition

public java.lang.String getCondition()
Gets the conditional expression that determines if the plugin should be active.


getCounter

public int getCounter()
Returns the current value of the reference counter.

Returns:
The reference counter determines how many actions of this type have been created using the ActionMgr

increaseCounter

public void increaseCounter()
Increases the reference counter of the action.


decreaseCounter

public boolean decreaseCounter()
Decrease the reference counter of the action.

Returns:
true There are still references left to this action.
false The reference counter decreased to 0.

getValue

public java.lang.Object getValue(java.lang.String key)
Specified by:
getValue in interface javax.swing.Action
See Also:
Action.getValue(String)

putValue

public void putValue(java.lang.String key,
                     java.lang.Object value)
Specified by:
putValue in interface javax.swing.Action
See Also:
Action.putValue(String, Object)

clearValues

public void clearValues()
Clears all action values.


getActionProperty

public java.lang.Object getActionProperty(java.lang.String key)
Gets an action property, either from the action's property map or from the resource file. For resource file access, the name of the action and "." will be prepended to the resource key.

Parameters:
key - Key of the property
Returns:
The property value or null if not found

getActionPropertyString

public java.lang.String getActionPropertyString(java.lang.String key)
Gets an action property of type String.

Parameters:
key - Key of the property
Returns:
The property value or null if not found

getActionPropertyString

public java.lang.String getActionPropertyString(java.lang.String key,
                                                java.lang.String dflt)
Gets an action property of type String.

Parameters:
key - Key of the property
dflt - Default value
Returns:
The property value or null if not found

getActionPropertyBoolean

public boolean getActionPropertyBoolean(java.lang.String key,
                                        boolean dflt)
Gets an action property of type boolean.

Parameters:
key - Key of the property
dflt - Default value
Returns:
The property value or null if not found

getActionPropertyInt

public int getActionPropertyInt(java.lang.String key,
                                int dflt)
Gets an action property of type int.

Parameters:
key - Key of the property
dflt - Default value
Returns:
The property value or null if not found

firePropertyChange

protected void firePropertyChange(java.lang.String propertyName,
                                  java.lang.Object oldValue,
                                  java.lang.Object newValue)
Supports reporting bound property changes. This method can be called when a bound property has changed and will send the appropriate PropertyChangeEvent to any registered property change listeners.

Parameters:
propertyName - Name of the bound property
oldValue - Old value of the property
newValue - New value of the property

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a property change listener to the listener list. A PropertyChangeEvent will get fired in response to setting a bound property. The listener is registered for all properties as a WEAK listener, i. e. it may be garbage-collected if not referenced otherwise.
ATTENTION: Never add an automatic class (i. e new PropertyChangeListener () { ... }) or an inner class that is not referenced otherwise as a weak listener to the list. These objects will be cleared by the garbage collector during the next gc run!

Specified by:
addPropertyChangeListener in interface javax.swing.Action
Parameters:
listener - The listener to be added

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a property change listener from the listener list.

Specified by:
removePropertyChangeListener in interface javax.swing.Action
Parameters:
listener - The listener to be removed


Copyright © 2011. All Rights Reserved.