|
JAPI 0_6-alpha-2 Yet another Java API API Documentation |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.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.
| Field Summary | |
|---|---|
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)
The implementation of this method first looks whether the Action is enabled. |
protected Object |
clone()
|
void |
putValue(String key,
Object newValue)
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).
| Constructor Detail |
|---|
public ReflectionAction()
public ReflectionAction(String methodName,
Object target)
methodName - Name of method to invoketarget - Target object to invoke method at
public 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 at| Method Detail |
|---|
public void putValue(String key,
Object newValue)
throws IllegalArgumentException
REFLECTION_METHOD_NAME or REFLECTION_METHOD, so you'll know of errors quite soon.
putValue in interface ActionputValue in class AbstractActionIllegalArgumentException - if newValue is of the wrong typepublic void actionPerformed(ActionEvent e)
RuntimeException - with cause in case the invocation of the method threw an exception
protected Object clone()
throws CloneNotSupportedException
clone in class AbstractActionCloneNotSupportedException
|
JAPI Yet another Java API API Documentation |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||