|
JAPI 0.9.0 Yet another Java API API Documentation |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.swing.AbstractAction net.sf.japi.swing.ReflectionAction
public final class ReflectionAction
Action implementation which invokes the desired method using Reflection. Usage example:
class SomeClass { SomeClass() { ReflectionAction action = new ReflectionAction(); action.putValue(REFLECTION_TARGET, this); action.putValue(REFLECTION_METHOD_NAME, "myAction"); new JMenuItem(action); } void myAction() { // do something } }Note that because of Reflection this Action is slightly slower than implementing your own Action instance, but in most cases this really does not matter at all. Usually you won't use ReflectionAction yourself. Instead you'll let
ActionFactory
create an instance for you.
Field Summary | |
---|---|
static String |
REFLECTION_MESSAGE_PROVIDER
The key used for storing the action factory that provides access to error handlers strings. |
static String |
REFLECTION_METHOD
The key used for storing the method object to use when invoking the method. |
static String |
REFLECTION_METHOD_NAME
The key used for storing the method name to use when searching for a method using reflection. |
static String |
REFLECTION_TARGET
The key used for storing the target object to invoke the method on. |
Fields inherited from class javax.swing.AbstractAction |
---|
changeSupport, enabled |
Fields inherited from interface javax.swing.Action |
---|
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SHORT_DESCRIPTION, SMALL_ICON |
Constructor Summary | |
---|---|
ReflectionAction()
Create an uninitialized ReflectionAction. |
|
ReflectionAction(String name,
Icon icon,
String methodName,
Object target)
Defines an Action object with the specified description string and a the specified icon. |
|
ReflectionAction(String methodName,
Object target)
Create a ReflectionAction with method and target. |
Method Summary | |
---|---|
void |
actionPerformed(ActionEvent e)
Invoked when an action occurs. The implementation of this method first looks whether the Action is enabled. |
protected Object |
clone()
Clones the abstract action. |
void |
putValue(String key,
Object newValue)
Sets the Value associated with the specified key.
This implementation checks the type of newValue if the key is REFLECTION_METHOD_NAME or REFLECTION_METHOD , so you'll know of errors quite soon. |
Methods inherited from class javax.swing.AbstractAction |
---|
addPropertyChangeListener, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, removePropertyChangeListener, setEnabled |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String REFLECTION_TARGET
Object
.
public static final String REFLECTION_METHOD_NAME
String
(checked).
public static final String REFLECTION_METHOD
Method
(checked).
public static final String REFLECTION_MESSAGE_PROVIDER
Constructor Detail |
---|
public ReflectionAction()
public ReflectionAction(String methodName, Object target)
methodName
- Name of method to invoketarget
- Target object to invoke method atpublic ReflectionAction(String name, Icon icon, String methodName, Object target)
Action
object with the specified description string and a the specified icon.
name
- description stringicon
- iconmethodName
- Name of method to invoketarget
- Target object to invoke method atMethod Detail |
---|
public void putValue(String key, Object newValue) throws IllegalArgumentException
Value
associated with the specified key.
This implementation checks the type of newValue if the key is REFLECTION_METHOD_NAME
or REFLECTION_METHOD
, so you'll know of errors quite soon.
putValue
in interface Action
putValue
in class AbstractAction
key
- the String
that identifies the stored objectnewValue
- the Object
to store using this key
IllegalArgumentException
- if newValue is of the wrong typeAction.putValue(java.lang.String, java.lang.Object)
public void actionPerformed(ActionEvent e)
RuntimeException
- with cause in case the invocation of the method threw an exception and there was no handler for that exception.protected Object clone() throws CloneNotSupportedException
Object.clone()
.
clone
in class AbstractAction
CloneNotSupportedException
- if the object's class does not
support the Cloneable
interface. Subclasses
that override the clone
method can also
throw this exception to indicate that an instance cannot
be cloned.Cloneable
|
JAPI Yet another Java API API Documentation |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |