public abstract class AbstractEditorAction extends TextAction implements Presenter.Menu, Presenter.Popup, Presenter.Toolbar
EditorActionRegistration
annotation.
kit.getActions()
gets used).
public static final class MyAction extends AbstractEditorAction {
@EditorActionRegistration(name = "my-action")
public static MyAction create(Map<String,?> attrs) {
return new MyAction(attrs);
}
private MyAction(Map<String,?> attrs) {
super(attrs);
...
}
protected void actionPerformed(ActionEvent evt, JTextComponent component) {
...
}
}
WrapperEditorAction
is constructed
upon editor kit's construction and the target action only gets
created when the action needs to be executed
(upon ActionListener.actionPerformed(java.awt.event.ActionEvent)
call).
Existing properties of the wrapper action (including Action.NAME
property)
get transferred into delegate action.
EditorActionRegistration
).
@EditorActionRegistration(name = "my-action")
public static final class MyAction extends AbstractEditorAction {
public MyAction() {
// Here the properties are not yet set.
}
@Override
protected void valuesUpdated() {
// Here the wrapper action has transferred all its properties into this action
// so properties like Action.NAME etc. are now populated.
}
protected void actionPerformed(ActionEvent evt, JTextComponent component) {
...
}
}
Presenter.Menu, Presenter.Popup, Presenter.Toolbar
Modifier and Type | Field and Description |
---|---|
static String |
ASYNCHRONOUS_KEY
Key of
Boolean property containing a boolean whether the action should be performed asynchronously or synchronously. |
static String |
DISPLAY_NAME_KEY
Key of
String property containing a localized display name of the action. |
static String |
ICON_RESOURCE_KEY
Key of
String property containing a string path to icon. |
static String |
MENU_TEXT_KEY
Key of
String property containing a localized text to be displayed in a main menu for this action. |
static String |
MIME_TYPE_KEY
Key of
String property containing a mime type for which this action
is registered. |
static String |
MULTI_ACCELERATOR_LIST_KEY
Key of property containing a
List < List <
listing all multi-key bindings by which the action may be invoked. |
static String |
NO_ICON_IN_MENU
Key of
Boolean property which determines whether icon of this action should be
displayed in menu (false or unset) or not (true). |
static String |
NO_KEY_BINDING
Key of
Boolean property which determines if this action should be
displayed in key binding customizer (false or unset) or not (true). |
static String |
POPUP_TEXT_KEY
Key of
String property containing a localized text to be displayed in a popup menu for this action. |
static String |
PREFERENCES_DEFAULT_KEY
Key of
String property containing preferences key's default value. |
static String |
PREFERENCES_KEY_KEY
Key of
String property containing a name of a boolean key in preferences in which this action changes settings
(according to PREFERENCES_NODE_KEY property). |
static String |
PREFERENCES_NODE_KEY
Key of
Preferences property containing a node in preferences in which this action changes settings. |
static String |
WRAPPER_ACTION_KEY
Key of
Boolean property determining whether this is just a wrapper action
that is being used until the action needs to be executed. |
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
Modifier | Constructor and Description |
---|---|
protected |
AbstractEditorAction()
Constructor typically used when action is constructed lazily
upon its performing (the action is always enabled and its properties
are declared in xml layer by annotation processor for
@EditorActionRegistration ). |
protected |
AbstractEditorAction(Map<String,?> attrs)
Constructor that takes a map of attributes that are typically obtained
from an xml layer when an action's creation method is annotated with
@EditorActionRegistration . |
Modifier and Type | Method and Description |
---|---|
protected String |
actionName() |
void |
actionPerformed(ActionEvent evt) |
protected abstract void |
actionPerformed(ActionEvent evt,
JTextComponent component)
Implementation of the action must be defined by descendants.
|
protected boolean |
asynchronous()
Possibly allow asynchronous execution of this action by returning true.
|
protected Object |
createValue(String key)
This method is called when a value for the given property
was not yet populated.
|
Object[] |
getKeys() |
JMenuItem |
getMenuPresenter()
Get presenter of this action in main menu.
|
JMenuItem |
getPopupPresenter()
Get presenter of this action in popup menu.
|
Component |
getToolbarPresenter()
Get presenter of this action in toolbar.
|
Object |
getValue(String key) |
boolean |
isEnabled() |
void |
putValue(String key,
Object value) |
protected void |
resetCaretMagicPosition(JTextComponent component)
Reset caret's magic position.
|
void |
setEnabled(boolean enabled) |
String |
toString() |
protected void |
valuesUpdated()
Called when property values from wrapper action were transferred into delegate action (this action)
so properties like Action.NAME will start to return correct values.
|
augmentList, getFocusedComponent, getTextComponent
addPropertyChangeListener, clone, firePropertyChange, getPropertyChangeListeners, removePropertyChangeListener
public static final String DISPLAY_NAME_KEY
String
property containing a localized display name of the action.
getValue(java.lang.String)
to obtain the property value.public static final String MENU_TEXT_KEY
String
property containing a localized text to be displayed in a main menu for this action.
getValue(java.lang.String)
to obtain the property value.public static final String POPUP_TEXT_KEY
String
property containing a localized text to be displayed in a popup menu for this action.
MENU_TEXT_KEY
is attempted.
getValue(java.lang.String)
to obtain the property value.public static final String ICON_RESOURCE_KEY
String
property containing a string path to icon.public static final String NO_ICON_IN_MENU
Boolean
property which determines whether icon of this action should be
displayed in menu (false or unset) or not (true).
getValue(java.lang.String)
to obtain the property value.public static final String NO_KEY_BINDING
Boolean
property which determines if this action should be
displayed in key binding customizer (false or unset) or not (true).
getValue(java.lang.String)
to obtain the property value.public static final String MULTI_ACCELERATOR_LIST_KEY
List < List < KeyStroke
> >
listing all multi-key bindings by which the action may be invoked.
public static final String ASYNCHRONOUS_KEY
Boolean
property containing a boolean whether the action should be performed asynchronously or synchronously.public static final String MIME_TYPE_KEY
String
property containing a mime type for which this action
is registered.
EditorKit.getContentType()
for which the action was created because the kit may inherit some actions
from a global mime-type "".
public static final String PREFERENCES_NODE_KEY
Preferences
property containing a node in preferences in which this action changes settings.public static final String PREFERENCES_KEY_KEY
String
property containing a name of a boolean key in preferences in which this action changes settings
(according to PREFERENCES_NODE_KEY
property).
PREFERENCES_NODE_KEY
is also set
to a valid value and checkbox menu presenter will be used automatically.public static final String PREFERENCES_DEFAULT_KEY
String
property containing preferences key's default value.public static final String WRAPPER_ACTION_KEY
Boolean
property determining whether this is just a wrapper action
that is being used until the action needs to be executed. Then the target action
gets created and run.
protected AbstractEditorAction(Map<String,?> attrs)
@EditorActionRegistration
.
public static final class MyAction extends AbstractEditorAction {
@EditorActionRegistration(name = "my-action")
public static MyAction create(Map<String,?> attrs) {
return new MyAction(attrs);
}
private MyAction(Map<String,?> attrs) {
super(attrs);
...
}
protected void actionPerformed(ActionEvent evt, JTextComponent component) {
...
}
}
attrs
- non-null attributes that hold action's properties.
The map is expected to be constant (no key-value changes).protected AbstractEditorAction()
@EditorActionRegistration
).
@EditorActionRegistration(name = "my-action")
public static final class MyAction extends AbstractEditorAction {
public MyAction() {
// Here the properties are not yet set.
}
@Override
protected void valuesUpdated() {
// Here the wrapper action has transferred all its properties into this action
// so properties like Action.NAME etc. are now populated.
}
protected void actionPerformed(ActionEvent evt, JTextComponent component) {
...
}
}
protected abstract void actionPerformed(ActionEvent evt, JTextComponent component)
evt
- action event (may be null).component
- "active" text component obtained by TextAction.getFocusedComponent()
.
It may be null.protected void valuesUpdated()
AbstractEditorAction()
protected boolean asynchronous()
ASYNCHRONOUS_KEY
property is returned
but subclasses may possibly implement some more elaborate algorithm.protected final void resetCaretMagicPosition(JTextComponent component)
component
- target text component.public JMenuItem getMenuPresenter()
MENU_TEXT_KEY
for menu item's text
and the presenter is placed in the menu according to rules
given in the corresponding EditorActionRegistration
.
getMenuPresenter
in interface Presenter.Menu
public JMenuItem getPopupPresenter()
POPUP_TEXT_KEY
for popup menu item's text
and the presenter is placed in the popup menu according to rules
given in the corresponding EditorActionRegistration
.getPopupPresenter
in interface Presenter.Popup
public Component getToolbarPresenter()
getToolbarPresenter
in interface Presenter.Toolbar
protected final String actionName()
Action.NAME
property.public final void actionPerformed(ActionEvent evt)
actionPerformed
in interface ActionListener
public final Object getValue(String key)
getValue
in interface Action
getValue
in class AbstractAction
protected Object createValue(String key)
putValue(java.lang.String, java.lang.Object)
.)
AbstractAction.firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)
.key
- key of the property.public final void putValue(String key, Object value)
putValue
in interface Action
putValue
in class AbstractAction
public boolean isEnabled()
isEnabled
in interface Action
isEnabled
in class AbstractAction
public void setEnabled(boolean enabled)
setEnabled
in interface Action
setEnabled
in class AbstractAction
public Object[] getKeys()
getKeys
in class AbstractAction