public class ReflectedAction extends AbstractAction
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");
changeSupport, enabled
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 |
---|
ReflectedAction(Object object,
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.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent event)
The action has been fired so now we use reflection to invoke the method that
was specified previously.
|
protected void |
assertNotNull(String fieldName,
Object object)
Throw an exception if the specified object is null
|
protected void |
exceptionThrown(Exception exception)
Callback that will be invoked if an exception is thrown during the
reflected method call.
|
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled
public ReflectedAction(Object object, String methodName) throws 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.IllegalArgumentException
- if there are no matching methods.public void actionPerformed(ActionEvent event)
event
- The ActionEventprotected void exceptionThrown(Exception exception)
Override this to provide custom error handling. Default behaviour is to print a stack trace.
exception
- The exceptionCopyright © 1998–2014 Gargoyle Software Inc.. All rights reserved.