Package com.jidesoft.swing
Class DelegateAction
- java.lang.Object
-
- javax.swing.AbstractAction
-
- com.jidesoft.swing.DelegateAction
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.io.Serializable
,java.lang.Cloneable
,java.util.EventListener
,javax.swing.Action
- Direct Known Subclasses:
DelegateAction.PassthroughDelegateAction
public abstract class DelegateAction extends javax.swing.AbstractAction
DelegateAction is a special AbstractAction which can do something then delegate to another action depending on the return value ofdelegateActionPerformed(java.awt.event.ActionEvent)
. There are two usages of it. First, you can usereplaceAction(javax.swing.JComponent, int, javax.swing.KeyStroke, DelegateAction)
to replace the action associated with the specified keystroke with the DelegateAction. The DelegateAction will be triggered when the keystroke is pressed. After DelegateAction is done, it can return true or false. If false, the original action associated with the keystroke will be triggered as well. This solves the problem thatJComponent.registerKeyboardAction(java.awt.event.ActionListener, String, javax.swing.KeyStroke, int)
will replace the original action so that the original action will never be triggered. The second way to use DelegateAction is to delegate the action from one component to another component usingreplaceAction(javax.swing.JComponent, int, javax.swing.JComponent, int, javax.swing.KeyStroke, DelegateAction)
. In this case, the keystroke on the first component parameter will be triggered the DelegateAction. If DelegateAction returns false, the registered action on the second component parameter will be triggered. If you pass inDelegateAction.PassthroughDelegateAction
, the registered action on the second component will always be triggered. Please notes, if you call replaceAction several times on the same component with the same keystroke, it will form a chain of DelegateActions. In this case, the first call will be the first DelegateAction. In the other words, the first one will have the highest priority and will be triggered first. Ideally, we should assign a priority to each DelegateAction. But for the sake of simplicity, we decided not doing it for now. So because of this, this class is not ready to be used as public API. We have to make it public because different packages in JIDE need to use it. If you want to use, please use it with caution. We don't guarantee that we will not change the public methods on this classes.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DelegateAction.PassthroughDelegateAction
-
Constructor Summary
Constructors Constructor Description DelegateAction()
DelegateAction(javax.swing.Action action)
DelegateAction(javax.swing.Action action, javax.swing.JComponent target)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent e)
abstract boolean
delegateActionPerformed(java.awt.event.ActionEvent e)
Performs an action.protected javax.swing.Action
getAction()
protected javax.swing.JComponent
getTarget()
boolean
isDelegateEnabled()
Checks if an action can be performed.boolean
isEnabled()
Returns true if either delegateIsEnabled or the action is enabled.static void
replaceAction(javax.swing.JComponent component, int condition, javax.swing.JComponent target, int targetCondition, javax.swing.KeyStroke keyStroke)
static void
replaceAction(javax.swing.JComponent component, int condition, javax.swing.JComponent target, int targetCondition, javax.swing.KeyStroke keyStroke, DelegateAction delegateAction)
static void
replaceAction(javax.swing.JComponent component, int condition, javax.swing.JComponent target, int targetCondition, javax.swing.KeyStroke keyStroke, DelegateAction delegateAction, boolean first)
static void
replaceAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke, DelegateAction delegateAction)
static void
replaceAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke, DelegateAction delegateAction, boolean first)
static void
restoreAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke)
static void
restoreAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke, java.lang.Class<?> actionClass)
static void
restoreAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke, javax.swing.Action actionToBeRemoved)
protected void
setAction(javax.swing.Action action)
protected void
setTarget(javax.swing.JComponent target)
-
Methods inherited from class javax.swing.AbstractAction
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, putValue, removePropertyChangeListener, setEnabled
-
-
-
-
Method Detail
-
isEnabled
public boolean isEnabled()
Returns true if either delegateIsEnabled or the action is enabled.- Specified by:
isEnabled
in interfacejavax.swing.Action
- Overrides:
isEnabled
in classjavax.swing.AbstractAction
-
actionPerformed
public final void actionPerformed(java.awt.event.ActionEvent e)
-
getAction
protected javax.swing.Action getAction()
-
setAction
protected void setAction(javax.swing.Action action)
-
getTarget
protected javax.swing.JComponent getTarget()
-
setTarget
protected void setTarget(javax.swing.JComponent target)
-
isDelegateEnabled
public boolean isDelegateEnabled()
Checks if an action can be performed. Returns true if delegateActionPerformed would perform an action. Otherwise returns false.- Returns:
true
if the action can be performed.
-
delegateActionPerformed
public abstract boolean delegateActionPerformed(java.awt.event.ActionEvent e)
Performs an action. Returns true if no further action should be taken for this keystroke. Otherwise, returns false.- Parameters:
e
- the action event.- Returns:
- true if no further action should be taken for this keystroke. Otherwise, returns false.
-
replaceAction
public static void replaceAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke, DelegateAction delegateAction)
-
replaceAction
public static void replaceAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke, DelegateAction delegateAction, boolean first)
-
replaceAction
public static void replaceAction(javax.swing.JComponent component, int condition, javax.swing.JComponent target, int targetCondition, javax.swing.KeyStroke keyStroke)
-
replaceAction
public static void replaceAction(javax.swing.JComponent component, int condition, javax.swing.JComponent target, int targetCondition, javax.swing.KeyStroke keyStroke, DelegateAction delegateAction)
-
replaceAction
public static void replaceAction(javax.swing.JComponent component, int condition, javax.swing.JComponent target, int targetCondition, javax.swing.KeyStroke keyStroke, DelegateAction delegateAction, boolean first)
-
restoreAction
public static void restoreAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke)
-
restoreAction
public static void restoreAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke, java.lang.Class<?> actionClass)
-
restoreAction
public static void restoreAction(javax.swing.JComponent component, int condition, javax.swing.KeyStroke keyStroke, javax.swing.Action actionToBeRemoved)
-
-