com.levigo.util.swing.action
Class CommandAction

java.lang.Object
  extended by com.levigo.util.swing.action.CommandAction
All Implemented Interfaces:
ContextListener, ContextualAction, ActionListener, EventListener, Action

public class CommandAction
extends Object
implements Action, ContextListener, ContextualAction

Super class for all actions.

A CommandAction contains information about its presentation and behavior. It implements Action interface. In addition to this, it provides more action parameters:

For example with parameter setSelected(boolean) for the actions which have two states.

Permission checking for an action works as follows:

0. Check action.properties if the action is visible.
1. Check user privileges if action is visible. (no -> break)
2. Check user privileges if action is enabled. (no -> break)
3. Check user privileges if commands for the action are executable. (no -> break)
4. Ask the command object if the command is executable with the given context objects. (no -> break)

Author:
l.boureanu@levigo.de, Carolin Koehler

Field Summary
protected  SwingPropertyChangeSupport changeSupport
          If any PropertyChangeListeners have been registered, the changeSupport field describes them.
protected  boolean enabled
          Specifies whether action is enabled; the default is true.
static String LARGE_ICON
           
static String MULTISCREEN_ABILITY
          In multi screen environments positioning of tooltips, popups and other graphics configuration dependent component functionalities do not work correctly caused by a VM bug.
 
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
CommandAction(Context context, Collection<Command> commands, String key, String name, String shortDescription, String longDescription, Icon smallIcon, Icon largeIcon, String actionCommandKey, KeyStroke acceleratorKey, int mnemonicKey, Map<String,Object> otherParameters)
          Constructor
 
Method Summary
 void actionPerformed(ActionEvent e)
          Run the commandAction.
 void addPropertyChangeListener(PropertyChangeListener listener)
          Adds a PropertyChangeListener to the listener list.
 void contextChanged(Context source)
          Check the commandAction by the change of the context.
protected  void finalize()
          Removes listeners.
protected  void firePropertyChange(String propertyName, Object oldValue, Object newValue)
          Supports reporting bound property changes.
 Collection<Command> getCommands()
          Method returns collection of the commands which are related to the action.
 Context getContext()
           
static AWTEvent getLastTriggerEvent()
          Due to technical reasons this method is temporary part of this class.
 PropertyChangeListener[] getPropertyChangeListeners()
          Returns an array of all the PropertyChangeListeners added to this AbstractAction with addPropertyChangeListener().
 Object getValue(String key)
          Gets the Object associated with the specified key.
 boolean isEnabled()
          Returns true if the action is enabled.
 void putValue(String key, Object newValue)
          Sets the Value associated with the specified key.
 void removePropertyChangeListener(PropertyChangeListener listener)
          Removes a PropertyChangeListener from the listener list.
 void setContext(Context context)
           
 void setEnabled(boolean newValue)
          Enables or disables the action.
static void setLastTriggerEvent(AWTEvent lastTriggerEvent)
          Due to technical reasons this method is temporary part of this class.
 void setSelected(boolean newValue)
          Sets the selected state of this action by setting given value with the Action.SELECTED_KEY.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LARGE_ICON

public static final String LARGE_ICON
See Also:
Constant Field Values

MULTISCREEN_ABILITY

public static final String MULTISCREEN_ABILITY
In multi screen environments positioning of tooltips, popups and other graphics configuration dependent component functionalities do not work correctly caused by a VM bug. Some action framework components are able to apply a workaround for the erroneous VM behavior but with the cost of some performance penalty. Therefore the workaround is not the default behavior and have to be forced by the action configuration with this key identifier.

See Also:
Constant Field Values

enabled

protected boolean enabled
Specifies whether action is enabled; the default is true.


changeSupport

protected SwingPropertyChangeSupport changeSupport
If any PropertyChangeListeners have been registered, the changeSupport field describes them.

Constructor Detail

CommandAction

public CommandAction(Context context,
                     Collection<Command> commands,
                     String key,
                     String name,
                     String shortDescription,
                     String longDescription,
                     Icon smallIcon,
                     Icon largeIcon,
                     String actionCommandKey,
                     KeyStroke acceleratorKey,
                     int mnemonicKey,
                     Map<String,Object> otherParameters)
Constructor

It sets a context and registers the commandAction as one of the ContextListenerin the context.

It sets the commandList for this commandAction and sets all parameters in from the Action.

Parameters:
context - which the action belongs in
commands - all commands for this action
key - the action key, same as Action.DEFAULT useful constants that can be used as the storage-retrieval key when setting or getting one of this object's properties
name - same as Action.NAME used for storing the String name for the action, used for a menu or button.
shortDescription - same as Action.SHORT_DESCRIPTION used for storing a short String description for the action, used for tooltip text.
longDescription - same as Action.LONG_DESCRIPTION used for storing a longer String description for the action, could be used for context-sensitive help.
smallIcon - same as Action.SMALL_ICON used for storing a small Icon
largeIcon - same as Action.LARGE_ICON_KEY used for storing a large Icon
actionCommandKey - same as Action.ACTION_COMMAND_KEY used to determine the command String for the ActionEvent that will be created when an Action is going to be notified
acceleratorKey - same as Action.ACCELERATOR_KEY used for storing a KeyStroke to be used as the accelerator for the action
mnemonicKey - same as Action.MNEMONIC_KEY used for storing an Integer that corresponds to one of the KeyEvent key codes.
otherParameters - parameters which will be added to the action (can be null)
Method Detail

contextChanged

public void contextChanged(Context source)
Check the commandAction by the change of the context. The action is asked if it is enabled.

Specified by:
contextChanged in interface ContextListener
Parameters:
source - the source of the event
See Also:
ContextListener.contextChanged(com.levigo.util.swing.action.Context)

actionPerformed

public void actionPerformed(ActionEvent e)
Run the commandAction. (Run all commands in the action)

Specified by:
actionPerformed in interface ActionListener
See Also:
ActionListener.actionPerformed(ActionEvent)

finalize

protected void finalize()
                 throws Throwable
Removes listeners.

Overrides:
finalize in class Object
Throws:
Throwable
See Also:
Object.finalize()

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()

getCommands

public Collection<Command> getCommands()
Method returns collection of the commands which are related to the action.

Returns:
Collection of the related commands

setSelected

public void setSelected(boolean newValue)
Sets the selected state of this action by setting given value with the Action.SELECTED_KEY.

This is typically used only if this action has a meaningful selection state.

Parameters:
newValue - true selects the action, false the action is not selected
See Also:
Action.SELECTED_KEY

getValue

public Object getValue(String key)
Gets the Object associated with the specified key.

Specified by:
getValue in interface Action
Parameters:
key - a string containing the specified key
Returns:
the binding Object stored with this key; if there are no keys, it will return null
See Also:
Action.getValue(java.lang.String)

putValue

public void putValue(String key,
                     Object newValue)
Sets the Value associated with the specified key.

Specified by:
putValue in interface Action
Parameters:
key - the String that identifies the stored object
newValue - the Object to store using this key
See Also:
Action.putValue(java.lang.String, java.lang.Object)

setContext

public void setContext(Context context)
Specified by:
setContext in interface ContextualAction
Parameters:
context - the context to set

getContext

public Context getContext()
Returns:
the context

isEnabled

public boolean isEnabled()
Returns true if the action is enabled.

Specified by:
isEnabled in interface Action
Returns:
true if the action is enabled, false otherwise
See Also:
Action.isEnabled()

setEnabled

public void setEnabled(boolean newValue)
Enables or disables the action.

Specified by:
setEnabled in interface Action
Parameters:
newValue - true to enable the action, false to disable it
See Also:
Action.setEnabled(boolean)

firePropertyChange

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


addPropertyChangeListener

public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. The listener is registered for all properties.

A PropertyChangeEvent will get fired in response to setting a bound property, e.g. setFont, setBackground, or setForeground. Note that if the current component is inheriting its foreground, background, or font from its container, then no event will be fired in response to a change in the inherited property.

Specified by:
addPropertyChangeListener in interface Action
Parameters:
listener - The PropertyChangeListener to be added
See Also:
Action.addPropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This removes a PropertyChangeListener that was registered for all properties.

Specified by:
removePropertyChangeListener in interface Action
Parameters:
listener - the PropertyChangeListener to be removed
See Also:
Action.removePropertyChangeListener(java.beans.PropertyChangeListener)

getPropertyChangeListeners

public PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all the PropertyChangeListeners added to this AbstractAction with addPropertyChangeListener().

Returns:
all of the PropertyChangeListeners added or an empty array if no listeners have been added

setLastTriggerEvent

public static void setLastTriggerEvent(AWTEvent lastTriggerEvent)
Due to technical reasons this method is temporary part of this class.

It is strongly recommended that developers should not use this method. levigo reserves the right to remove or to change this method with future releases.

Parameters:
lastTriggerEvent -

getLastTriggerEvent

public static AWTEvent getLastTriggerEvent()
Due to technical reasons this method is temporary part of this class.

It is strongly recommended that developers should not use this method. levigo reserves the right to remove or to change this method with future releases.

Returns:
the lastTriggerEvent


Copyright © 1995-2020 levigo holding gmbh. All Rights Reserved.