|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.AbstractAction
com.gargoylesoftware.base.gui.ReflectedAction
public class ReflectedAction
A swing "action" that uses reflection to find and invoke a given target method.
ReflectedAction is a Swing "action" that uses reflection to call a specific target method when the action is fired. Actions are often implemented using inner classes which can be very inefficient in terms of performance and deployment size. This action is a tiny bit slower when it is actually fired but is smaller and generally faster otherwise due to the fact that those inner classes are no longer needed.
Action searchAction = new ReflectedAction(this, "performSearch");
Field Summary | |
---|---|
private java.lang.String |
methodName_
|
private java.lang.Object |
object_
|
private static long |
serialVersionUID
|
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 | |
---|---|
ReflectedAction(java.lang.Object object,
java.lang.String methodName)
Create a reflected action with an object and the name of the method that will be invoked on that object when the action is fired. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent event)
The action has been fired so now we use reflection to invoke the method that was specified previously. |
protected void |
assertNotNull(java.lang.String fieldName,
java.lang.Object object)
Throw an exception if the specified object is null |
protected void |
exceptionThrown(java.lang.Exception exception)
Callback that will be invoked if an exception is thrown during the reflected method call. |
private java.lang.reflect.Method |
findMethodOnObject(java.lang.Object object,
java.lang.String methodName)
Return the Method object that corresponds to the specified method name. |
Methods inherited from class javax.swing.AbstractAction |
---|
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final long serialVersionUID
private final java.lang.Object object_
private final java.lang.String methodName_
Constructor Detail |
---|
public ReflectedAction(java.lang.Object object, java.lang.String methodName) throws java.lang.IllegalArgumentException
object
- The object upon which we will invoke a method when
the action is firedmethodName
- The name of the method that we will invoke. This method
must take either no parameters or one parameter which is an ActionEvent.
java.lang.IllegalArgumentException
- if there are no matching methods.Method Detail |
---|
public void actionPerformed(java.awt.event.ActionEvent event)
event
- The ActionEventprivate java.lang.reflect.Method findMethodOnObject(java.lang.Object object, java.lang.String methodName)
object
- The object that contains the methodmethodName
- The name of the method that we're looking for
java.lang.IllegalArgumentException
- If there aren't any methods that match.
java.lang.SecurityException
- If we do not have access to this method.protected void exceptionThrown(java.lang.Exception exception)
Override this to provide custom error handling. Default behaviour is to print a stack trace.
exception
- The exceptionprotected final void assertNotNull(java.lang.String fieldName, java.lang.Object object)
fieldName
- The name of the paremeter we are checkingobject
- The value of the parameter we are checking
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |