public class DispatcherAction extends AbstractAction
Action
benefits and also acts as a dispatcher.
It is most useful in the context of SwingXMLBuilder, and if there are e.g. both toolbar and
menu entries for one action.Modifier and Type | Field and Description |
---|---|
protected EventListenerList |
mListenerList
A list of event listeners for this component.
|
protected Object |
mRealSource
Null or the "real" source of an ActionEvent, only set during the event delivery.
|
static String |
TOGGLE_MODEL
Key we store the ButtonModel into.
|
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 |
---|
DispatcherAction()
Default constuctor, this will create a non menubar/toolbar action,
useful for pure dispatching.
|
DispatcherAction(String pEntryText,
String pEntryAccelerator,
String pEntryMnemonic,
String pEntryTooltip,
Icon pIcon,
boolean pIsToggle)
Create a dispatcher action with the handed information.
|
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent pEvent)
Callback method of our visual representations, dispatch the action
to our listeners.
|
void |
addActionListener(ActionListener pListener)
Adds an
ActionListener to the dispatcher. |
String |
getEntryAccelerator()
Returns the entry accelerator.
|
Icon |
getEntryIcon()
Returns the (relativ) entry icon name.
|
String |
getEntryMnemonic()
Returns the entry mnemonic.
|
String |
getEntryText()
Returns the name of the entry for this action.
|
Object |
getRealSource()
Due to the way SwingConnectionManager works, we must change the source
of the action event during callback.
|
ButtonModel |
getToggleModel()
Returns null if isToggle() is false, otherwise a ButtonModel for the
toggle state.
|
String |
getTooltip()
Returns the tool tip for the entry.
|
boolean |
isSelected()
Returns the toggle state of our toggle model, always false if
we are not toggable.
|
boolean |
isToggle()
Returns whether or not this action acts as a toggle entry.
|
void |
removeActionListener(ActionListener pListener)
Removes an
ActionListener from the button. |
void |
setEnabled(boolean pNewValue)
Enables or disables the action.
|
void |
setSelected(boolean pSelected)
Sets the toggle state of our button model, does nothing if we
are not toggable.
|
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener
public static final String TOGGLE_MODEL
protected EventListenerList mListenerList
protected Object mRealSource
public DispatcherAction()
public DispatcherAction(String pEntryText, String pEntryAccelerator, String pEntryMnemonic, String pEntryTooltip, Icon pIcon, boolean pIsToggle)
pEntryText
- null or the text of the actionpEntryAccelerator
- null or the action acceleratorpEntryMnemonic
- null or the action mnemonic, the first character is used after
converting it to upper casepEntryTooltip
- null or the action tooltippIcon
- null or the action iconpIsToggle
- true if this is a toggle actionIllegalArgumentException
- if pEntryText is nullpublic String getEntryText()
public String getEntryAccelerator()
public String getEntryMnemonic()
public String getTooltip()
public Icon getEntryIcon()
public boolean isToggle()
public ButtonModel getToggleModel()
public void setEnabled(boolean pNewValue)
setEnabled
in interface Action
setEnabled
in class AbstractAction
pNewValue
- true to enable the action, false to
disable itAbstractAction.setEnabled(boolean)
public boolean isSelected()
public void setSelected(boolean pSelected)
pSelected
- new statepublic void actionPerformed(ActionEvent pEvent)
pEvent
- the event describing the actionpublic void addActionListener(ActionListener pListener)
ActionListener
to the dispatcher.pListener
- the ActionListener
to be addedpublic void removeActionListener(ActionListener pListener)
ActionListener
from the button.
If the listener is the currently set Action
for the button, then the Action
is set to null
.pListener
- the ActionListener
to be removedpublic Object getRealSource()
Copyright © 2017 Jürgen Zeller (privat). All rights reserved.