|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.AbstractAction
org.jdesktop.application.ApplicationAction
public class ApplicationAction
The Action
class used to implement the
@Action annotation. This class is typically not
instantiated directly, it's created as a side effect of constructing
an ApplicationActionMap:
public class MyActions { @Action public void anAction() { } // an @Action named "anAction" } ApplicationContext ac = ApplicationContext.getInstance(); ActionMap actionMap = ac.getActionMap(new MyActions()); myButton.setAction(actionMap.get("anAction"));
When an ApplicationAction is constructed, it initializes all of its
properties from the specified ResourceMap. Resource names
must match the @Action's
name, which is the name of the
corresponding method, or the value of the optional @Action
name
parameter. To initialize the text and shortDescription properties
of the action named "anAction" in the previous example, one
would define two resources:
anAction.Action.text = Button/Menu/etc label text for anAction anAction.Action.shortDescription = Tooltip text for anAction
A complete description of the mapping between resources and Action
properties can be found in the ApplicationAction constructor
documentation.
An ApplicationAction's enabled and selected
properties can be delegated to boolean properties of the
Actions class, by specifying the corresponding property names.
This can be done with the @Action
annotation, e.g.:
public class MyActions { @Action(enabledProperty = "anActionEnabled") public void anAction() { } public boolean isAnActionEnabled() { // will fire PropertyChange when anActionEnabled changes return anActionEnabled; } }If the MyActions class supports PropertyChange events, then then ApplicationAction will track the state of the specified property ("anActionEnabled" in this case) with a PropertyChangeListener.
ApplicationActions can automatically block the GUI while the actionPerformed method is running, depending on the value of block annotation parameter. For example, if the value of block is Task.BlockingScope.ACTION, then the action will be disabled while the actionPerformed method runs.
An ApplicationAction can have a proxy Action, i.e. another Action that provides the actionPerformed method, the enabled/selected properties, and values for the Action's long and short descriptions. If the proxy property is set, this ApplicationAction tracks all of the aforementioned properties, and the actionPerformed method just calls the proxy's actionPerformed method. If a proxySource is specified, then it becomes the source of the ActionEvent that's passed to the proxy actionPerformed method. Proxy action dispatching is as simple as this:
public void actionPerformed(ActionEvent actionEvent) { javax.swing.Action proxy = getProxy(); if (proxy != null) { actionEvent.setSource(getProxySource()); proxy.actionPerformed(actionEvent); } // .... }
ApplicationContext.getActionMap(Object)
,
ResourceMap
,
Serialized FormField Summary |
---|
Fields inherited from class javax.swing.AbstractAction |
---|
changeSupport, enabled |
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 | |
---|---|
ApplicationAction(ApplicationActionMap appAM,
ResourceMap resourceMap,
java.lang.String baseName,
java.lang.reflect.Method actionMethod,
java.lang.String enabledProperty,
java.lang.String selectedProperty,
Task.BlockingScope block)
Construct an ApplicationAction that implements an @Action. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent actionEvent)
This method implements this Action's behavior. |
protected java.lang.Object |
getActionArgument(java.lang.Class pType,
java.lang.String pKey,
java.awt.event.ActionEvent actionEvent)
Provides parameter values to @Action methods. |
java.lang.String |
getName()
The name of this Action. |
javax.swing.Action |
getProxy()
Return the proxy for this action or null. |
java.lang.Object |
getProxySource()
Return the value that becomes the ActionEvent source before the ActionEvent is passed along to the proxy Action. |
ResourceMap |
getResourceMap()
The resourceMap for this Action. |
boolean |
isEnabled()
If the proxy action is null and enabledProperty was
specified, then return the value of the enabled property's
is/get method applied to our ApplicationActionMap's
actionsObject . |
boolean |
isSelected()
If the proxy action is null and selectedProperty was
specified, then return the value of the selected property's
is/get method applied to our ApplicationActionMap's actionsObject . |
void |
putValue(java.lang.String key,
java.lang.Object value)
Keeps the @Action selectedProperty in sync when
the value of key is Action.SELECTED_KEY . |
void |
setEnabled(boolean enabled)
If the proxy action is null and enabledProperty was
specified, then set the value of the enabled property by
invoking the corresponding set method on our
ApplicationActionMap's actionsObject . |
void |
setProxy(javax.swing.Action proxy)
Set the proxy for this action. |
void |
setProxySource(java.lang.Object source)
Set the value that becomes the ActionEvent source before the ActionEvent is passed along to the proxy Action. |
void |
setSelected(boolean selected)
If the proxy action is null and selectedProperty was
specified, then set the value of the selected property by
invoking the corresponding set method on our
ApplicationActionMap's actionsObject . |
java.lang.String |
toString()
Returns a string representation of this ApplicationAction that should be useful for debugging. |
Methods inherited from class javax.swing.AbstractAction |
---|
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, removePropertyChangeListener |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public ApplicationAction(ApplicationActionMap appAM, ResourceMap resourceMap, java.lang.String baseName, java.lang.reflect.Method actionMethod, java.lang.String enabledProperty, java.lang.String selectedProperty, Task.BlockingScope block)
If a ResourceMap
is provided, then all of the
Action
properties are initialized
with the values of resources whose key begins with baseName
.
ResourceMap keys are created by appending an @Action resource
name, like "Action.shortDescription" to the @Action's baseName
For example, Given an @Action defined like this:
@Action void actionBaseName() { }
Then the shortDescription resource key would be
actionBaseName.Action.shortDescription
, as in:
actionBaseName.Action.shortDescription = Do perform some action
The complete set of @Action resources is:
Action.icon Action.text Action.shortDescription Action.longDescription Action.smallIcon Action.largeIcon Action.command Action.accelerator Action.mnemonic Action.displayedMnemonicIndex
A few the resources are handled specially:
appAM
- the ApplicationActionMap this action is being constructed for.resourceMap
- initial Action properties are loaded from this ResourceMap.baseName
- the name of the @ActionactionMethod
- unless a proxy is specified, actionPerformed calls this method.enabledProperty
- name of the enabled property.selectedProperty
- name of the selected property.block
- how much of the GUI to block while this action executes.getName()
,
ApplicationActionMap.getActionsClass()
,
ApplicationActionMap.getActionsObject()
Method Detail |
---|
public javax.swing.Action getProxy()
setProxy(javax.swing.Action)
,
setProxySource(java.lang.Object)
,
actionPerformed(java.awt.event.ActionEvent)
public void setProxy(javax.swing.Action proxy)
SHORT_DESCRIPTION
is not null,
then set this action's shortDescription. Most Swing components use
the shortDescription to initialize their tooltip.
LONG_DESCRIPTION
is not null,
then set this action's longDescription.
proxy
- setProxy(javax.swing.Action)
,
setProxySource(java.lang.Object)
,
actionPerformed(java.awt.event.ActionEvent)
public java.lang.Object getProxySource()
getProxy()
,
setProxySource(java.lang.Object)
,
EventObject.getSource()
public void setProxySource(java.lang.Object source)
source
- the ActionEvent source/getProxy()
,
getProxySource()
,
AWTEvent.setSource(java.lang.Object)
public java.lang.String getName()
This name is used as a prefix to look up action resources, and the ApplicationContext Framework uses it as the key for this Action in ApplicationActionMaps.
Note: this property should not confused with the Action.NAME
key. That key is actually
used to initialize the text properties of Swing
components, which is why we call the corresponding
ApplicationAction resource "Action.text", as in:
myCloseButton.Action.text = Close
public ResourceMap getResourceMap()
protected java.lang.Object getActionArgument(java.lang.Class pType, java.lang.String pKey, java.awt.event.ActionEvent actionEvent)
Parameter Type | Parameter Value |
---|---|
ActionEvent | actionEvent |
javax.swing.Action | this ApplicationAction object |
ActionMap | the ActionMap that contains this Action |
ResourceMap | the ResourceMap of the the ActionMap that contains this Action |
ApplicationContext | the value of ApplicationContext.getInstance() |
ApplicationAction subclasses may also select values based on the value of the Action.Parameter annotation, which is passed along as the pKey argument to this method:
@Action public void doAction(@Action.Parameter("myKey") String myParameter) { // The value of myParameter is computed by: // getActionArgument(String.class, "myKey", actionEvent) }
If pType and pKey aren't recognized, this method
calls actionFailed(java.lang.Exception)
with an IllegalArgumentException.
pType
- parameter typepKey
- the value of the @Action.Parameter annotationactionEvent
- the ActionEvent that trigged this Actionpublic void actionPerformed(java.awt.event.ActionEvent actionEvent)
If there's a proxy Action then call its actionPerformed
method. Otherwise, call the @Action method with parameter
values provided by getActionArgument()
. If anything goes wrong
call actionFailed()
.
actionEvent
- @{inheritDoc}setProxy(javax.swing.Action)
,
getActionArgument(java.lang.Class, java.lang.String, java.awt.event.ActionEvent)
,
Task
public boolean isEnabled()
enabledProperty
was
specified, then return the value of the enabled property's
is/get method applied to our ApplicationActionMap's
actionsObject
.
Otherwise return the value of this Action's enabled property.
isEnabled
in interface javax.swing.Action
isEnabled
in class javax.swing.AbstractAction
setProxy(javax.swing.Action)
,
setEnabled(boolean)
,
ApplicationActionMap.getActionsObject()
public void setEnabled(boolean enabled)
enabledProperty
was
specified, then set the value of the enabled property by
invoking the corresponding set
method on our
ApplicationActionMap's actionsObject
.
Otherwise set the value of this Action's enabled property.
setEnabled
in interface javax.swing.Action
setEnabled
in class javax.swing.AbstractAction
enabled
- setProxy(javax.swing.Action)
,
isEnabled()
,
ApplicationActionMap.getActionsObject()
public boolean isSelected()
selectedProperty
was
specified, then return the value of the selected property's
is/get method applied to our ApplicationActionMap's actionsObject
.
Otherwise return the value of this Action's enabled property.
setProxy(javax.swing.Action)
,
setSelected(boolean)
,
ApplicationActionMap.getActionsObject()
public void setSelected(boolean selected)
selectedProperty
was
specified, then set the value of the selected property by
invoking the corresponding set
method on our
ApplicationActionMap's actionsObject
.
Otherwise set the value of this Action's selected property.
selected
- this Action's JToggleButton's valuesetProxy(javax.swing.Action)
,
isSelected()
,
ApplicationActionMap.getActionsObject()
public void putValue(java.lang.String key, java.lang.Object value)
@Action selectedProperty
in sync when
the value of key
is Action.SELECTED_KEY
.
putValue
in interface javax.swing.Action
putValue
in class javax.swing.AbstractAction
key
- value
- public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |