public class CommandAction extends Object implements Action, ContextListener, ContextualAction
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)
Modifier and Type | Field and Description |
---|---|
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.
|
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 and 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
|
Modifier and Type | Method and Description |
---|---|
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 |
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
PropertyChangeListener s 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() |
public static final String LARGE_ICON
public static final String MULTISCREEN_ABILITY
protected boolean enabled
protected SwingPropertyChangeSupport changeSupport
PropertyChangeListeners
have been registered,
the changeSupport
field describes them.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)
It 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
.
context
- which the action belongs incommands
- all commands for this actionkey
- 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 propertiesname
- 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 notifiedacceleratorKey
- same as Action.ACCELERATOR_KEY
used for storing a
KeyStroke
to be used as the accelerator for the actionmnemonicKey
- 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)public void contextChanged(Context source)
contextChanged
in interface ContextListener
source
- the source of the eventContextListener.contextChanged(org.jadice.util.swing.action.context.Context)
public void actionPerformed(ActionEvent e)
actionPerformed
in interface ActionListener
ActionListener.actionPerformed(ActionEvent)
public Collection<Command> getCommands()
public void setSelected(boolean newValue)
Action.SELECTED_KEY
.
This is typically used only if this action has a meaningful selection state.
newValue
- true selects the action, false the action is not selectedAction.SELECTED_KEY
public Object getValue(String key)
Object
associated with the specified key.getValue
in interface Action
key
- a string containing the specified key
Object
stored with this key; if there are no keys, it will
return null
Action.getValue(java.lang.String)
public void putValue(String key, Object newValue)
Value
associated with the specified key.putValue
in interface Action
key
- the String
that identifies the stored objectnewValue
- the Object
to store using this keyAction.putValue(java.lang.String, java.lang.Object)
public void setContext(Context context)
setContext
in interface ContextualAction
public Context getContext()
public boolean isEnabled()
isEnabled
in interface Action
Action.isEnabled()
public void setEnabled(boolean newValue)
setEnabled
in interface Action
newValue
- true to enable the action, false to disable itAction.setEnabled(boolean)
protected void firePropertyChange(String propertyName, Object oldValue, Object newValue)
PropertyChangeEvent
to any registered
PropertyChangeListeners
.propertyName
- the programmatic name of the property that was changedoldValue
- the old value of the propertynewValue
- the new value of the propertypublic void addPropertyChangeListener(PropertyChangeListener listener)
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.
addPropertyChangeListener
in interface Action
listener
- The PropertyChangeListener
to be addedAction.addPropertyChangeListener(java.beans.PropertyChangeListener)
public void removePropertyChangeListener(PropertyChangeListener listener)
PropertyChangeListener
from the listener list. This removes a
PropertyChangeListener
that was registered for all properties.removePropertyChangeListener
in interface Action
listener
- the PropertyChangeListener
to be removedAction.removePropertyChangeListener(java.beans.PropertyChangeListener)
public PropertyChangeListener[] getPropertyChangeListeners()
PropertyChangeListener
s added to this AbstractAction
with addPropertyChangeListener().PropertyChangeListener
s added or an empty array if no listeners
have been addedpublic static void setLastTriggerEvent(AWTEvent lastTriggerEvent)
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.
lastTriggerEvent
- the lastTriggerEventpublic static AWTEvent getLastTriggerEvent()
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.
Copyright © 2024 levigo holding gmbh. All rights reserved.