Class CommandAction
- java.lang.Object
-
- org.jadice.util.swing.action.commands.CommandAction
-
- All Implemented Interfaces:
ActionListener
,EventListener
,Action
,ContextualAction
,ContextListener
public class CommandAction extends Object implements Action, ContextListener, ContextualAction
Super class for all actions.A
CommandAction
contains information about its presentation and behavior. It implementsAction
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
Fields Modifier and Type Field Description protected SwingPropertyChangeSupport
changeSupport
If anyPropertyChangeListeners
have been registered, thechangeSupport
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
Constructors Constructor Description 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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(ActionEvent e)
Run the commandAction.void
addPropertyChangeListener(PropertyChangeListener listener)
Adds aPropertyChangeListener
to the listener list.void
contextChanged(Context source)
Check the commandAction by the change of the context.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 thePropertyChangeListener
s added to this AbstractAction with addPropertyChangeListener().Object
getValue(String key)
Gets theObject
associated with the specified key.boolean
isEnabled()
Returns true if the action is enabled.void
putValue(String key, Object newValue)
Sets theValue
associated with the specified key.void
removePropertyChangeListener(PropertyChangeListener listener)
Removes aPropertyChangeListener
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 theAction.SELECTED_KEY
.String
toString()
-
-
-
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 anyPropertyChangeListeners
have been registered, thechangeSupport
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)
ConstructorIt sets a context and registers the commandAction as one of the
ContextListener
in the context.It sets the commandList for this commandAction and sets all parameters in from the
Action
.- Parameters:
context
- which the action belongs incommands
- all commands for this actionkey
- the action key, same asAction.DEFAULT
useful constants that can be used as the storage-retrieval key when setting or getting one of this object's propertiesname
- same asAction.NAME
used for storing theString
name for the action, used for a menu or button.shortDescription
- same asAction.SHORT_DESCRIPTION
used for storing a shortString
description for the action, used for tooltip text.longDescription
- same asAction.LONG_DESCRIPTION
used for storing a longerString
description for the action, could be used for context-sensitive help.smallIcon
- same asAction.SMALL_ICON
used for storing a smallIcon
largeIcon
- same asAction.LARGE_ICON_KEY
used for storing a largeIcon
actionCommandKey
- same asAction.ACTION_COMMAND_KEY
used to determine the commandString
for theActionEvent
that will be created when anAction
is going to be notifiedacceleratorKey
- same asAction.ACCELERATOR_KEY
used for storing aKeyStroke
to be used as the accelerator for the actionmnemonicKey
- same asAction.MNEMONIC_KEY
used for storing anInteger
that corresponds to one of theKeyEvent
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 interfaceContextListener
- Parameters:
source
- the source of the event- See Also:
ContextListener.contextChanged(org.jadice.util.swing.action.context.Context)
-
actionPerformed
public void actionPerformed(ActionEvent e)
Run the commandAction. (Run all commands in the action)- Specified by:
actionPerformed
in interfaceActionListener
- See Also:
ActionListener.actionPerformed(ActionEvent)
-
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 theAction.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 theObject
associated with the specified key.- Specified by:
getValue
in interfaceAction
- Parameters:
key
- a string containing the specifiedkey
- Returns:
- the binding
Object
stored with this key; if there are no keys, it will returnnull
- See Also:
Action.getValue(java.lang.String)
-
putValue
public void putValue(String key, Object newValue)
Sets theValue
associated with the specified key.- Specified by:
putValue
in interfaceAction
- Parameters:
key
- theString
that identifies the stored objectnewValue
- theObject
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 interfaceContextualAction
-
getContext
public Context getContext()
-
isEnabled
public boolean isEnabled()
Returns true if the action is enabled.- Specified by:
isEnabled
in interfaceAction
- 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 interfaceAction
- 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 appropriatePropertyChangeEvent
to any registeredPropertyChangeListeners
.- Parameters:
propertyName
- the programmatic name of the property that was changedoldValue
- the old value of the propertynewValue
- the new value of the property
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Adds aPropertyChangeListener
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
, orsetForeground
. 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 interfaceAction
- Parameters:
listener
- ThePropertyChangeListener
to be added- See Also:
Action.addPropertyChangeListener(java.beans.PropertyChangeListener)
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Removes aPropertyChangeListener
from the listener list. This removes aPropertyChangeListener
that was registered for all properties.- Specified by:
removePropertyChangeListener
in interfaceAction
- Parameters:
listener
- thePropertyChangeListener
to be removed- See Also:
Action.removePropertyChangeListener(java.beans.PropertyChangeListener)
-
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all thePropertyChangeListener
s added to this AbstractAction with addPropertyChangeListener().- Returns:
- all of the
PropertyChangeListener
s 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
- the 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
-
-