org.softsmithy.lib.swing.action
Class ReflectiveXAction
java.lang.Object
javax.swing.AbstractAction
org.softsmithy.lib.swing.action.AbstractXAction
org.softsmithy.lib.swing.action.ReflectiveXAction
- All Implemented Interfaces:
- ActionListener, Serializable, Cloneable, EventListener, Action, XAction
- Direct Known Subclasses:
- ReflectiveCustomizerAction
public class ReflectiveXAction
- extends AbstractXAction
A trampoline class that reflectivly calls an action method. The method must
take an ActionEvent object as its single parameter.
Normally there are two standard ways to implement the ActionListener interface:
The first is to let a class implement the ActionListener interface and then add an
object of this class to the addActionListener methods of the components
firing ActionEvents. You then have to check the source in the
actionPerformed method. You end up with a big ugly, unmaintainable and
unstable if-then-else- statement. The second approach is to define a class for
every such component. You end up with tons of small classes all
increasing the memory footprint (typically 3K per class).
Now this approach using reflection lets you define a method for each such component avoiding the
mentioned drawbacks. The new drawbacks are however:
- Reflectivly calling method does not identify typos during
compile-time.
- Calling a method refectivly is slower (but it's unlikely the user
notices it).
More to read about reflective actions:
Chapter 6.2.3, p. 73 of the Java Series Book Java Platform Performance
Strategies and Tactics by Steve Wilson and Jeff Kesselman.
Note: This class might change package in a future version!
Note: This class might throw different Exceptions in a future version!
- Author:
- Florian Brunner
- See Also:
- Serialized Form
Fields inherited from interface org.softsmithy.lib.swing.action.XAction |
LARGE_DISABLED_ICON, LARGE_DISABLED_SELECTED_ICON, LARGE_ICON, LARGE_PRESSED_ICON, LARGE_ROLLOVER_ICON, LARGE_ROLLOVER_SELECTED_ICON, LARGE_SELECTED_ICON, SMALL_DISABLED_ICON, SMALL_DISABLED_SELECTED_ICON, SMALL_PRESSED_ICON, SMALL_ROLLOVER_ICON, SMALL_ROLLOVER_SELECTED_ICON, SMALL_SELECTED_ICON |
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 |
Methods inherited from class org.softsmithy.lib.swing.action.AbstractXAction |
getAccelerator, getActionCommand, getLargeDisabledIcon, getLargeDisabledSelectedIcon, getLargeIcon, getLargePressedIcon, getLargeRolloverIcon, getLargeRolloverSelectedIcon, getLargeSelectedIcon, getLongDescription, getMnemonicKey, getName, getShortDescription, getSmallDisabledIcon, getSmallDisabledSelectedIcon, getSmallIcon, getSmallPressedIcon, getSmallRolloverIcon, getSmallRolloverSelectedIcon, getSmallSelectedIcon, setAccelerator, setActionCommand, setLargeDisabledIcon, setLargeDisabledSelectedIcon, setLargeIcon, setLargePressedIcon, setLargeRolloverIcon, setLargeRolloverSelectedIcon, setLargeSelectedIcon, setLongDescription, setMnemonicKey, setName, setShortDescription, setSmallDisabledIcon, setSmallDisabledSelectedIcon, setSmallIcon, setSmallPressedIcon, setSmallRolloverIcon, setSmallRolloverSelectedIcon, setSmallSelectedIcon |
ReflectiveXAction
public ReflectiveXAction(Object target,
String methodName)
throws NoSuchMethodException
- Creates a new ReflectiveAction
- Parameters:
target
- the object with the specified methodmethodName
- the method name (must be public and take an ActionEvent
obect as its single parameter)
- Throws:
NoSuchMethodException
- if no such method found
actionPerformed
public void actionPerformed(ActionEvent e)
- Invoked when an action occurs. Springs to the method specified in the
constructor.
- Parameters:
e
- an ActionEvent object
Copyright © 2002-2011 SoftSmithy. All Rights Reserved.