@OpenApiAll
public abstract class NMAction
extends javax.swing.AbstractAction
implements java.lang.Comparable
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ACTION_SHORTCUTS
Key for storing command keys.
|
static java.lang.String |
BELONGS_TO_SEPARATE_GROUP_IN_UI
A name of property to put this action into a dedicate special group.
|
static java.lang.String |
DO_NO_SHOW_ACTION_NAME_IN_UI
A name of property to hide action name text in create UI.
|
static java.lang.String |
GENERATED_ID_PREFIX |
static java.lang.String |
GROUP
Key for storing group.
|
static java.lang.String |
ID
Key for storing id.
|
static java.lang.String |
LARGE_ICON
Key for storing large icon.
|
static int |
MENU_SHORTCUT_MASK
Menu shortcut mask used to create shortcuts.
|
static java.lang.String |
TINY_ICON
Key for storing tiny icon (smaller than small icon).
|
| Constructor and Description |
|---|
NMAction()
Constructs the action with nulls.
|
NMAction(java.lang.String id,
java.lang.String name,
int mnemonic)
Constructs the action with given id, name, mnemonic key.
|
NMAction(java.lang.String id,
java.lang.String name,
int mnemonic,
java.lang.String group)
Constructs the action with given id, name, mnemonic key and group.
|
NMAction(java.lang.String id,
java.lang.String name,
javax.swing.KeyStroke stroke)
Constructs the action with given id, name, keystroke.
|
NMAction(java.lang.String id,
java.lang.String name,
javax.swing.KeyStroke stroke,
java.lang.String group)
Constructs the action with given id, name, keystroke and group.
|
| Modifier and Type | Method and Description |
|---|---|
void |
accept(ActionsVisitor visitor)
Accepts ActionsVisitor using Visitor pattern.
|
abstract void |
actionPerformed(java.awt.event.ActionEvent e)
Executes given action.
|
void |
addAction(NMAction action)
Adds action.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a
PropertyChangeListener to the listener list. |
void |
addShortcut(javax.swing.KeyStroke key)
Adds the shortcut to the action.
|
void |
addShotcut(javax.swing.KeyStroke key)
Deprecated.
type error. Use
addShortcut(KeyStroke) |
void |
addWeakPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a
PropertyChangeListener to the weak listener list. |
NMAction |
clone()
Clones the object.
|
int |
compareTo(java.lang.Object o)
Compares the name of the action.
|
javax.swing.JMenuItem |
createMenuItem(com.nomagic.actions.MenuComponentFactory factory)
Action can return preferred representation of itself as menu item.
|
boolean |
equals(java.lang.Object o)
Checks if given object is equal to the current action.
|
protected void |
firePropertyChange(java.lang.String propertyName,
java.lang.Object oldValue,
java.lang.Object newValue)
Supports reporting bound property changes.
|
void |
forEach(java.util.function.Consumer<NMAction> consumer)
Performs the given consumer for each owned action.
|
java.util.List<NMAction> |
getActions()
Returns the list of the actions.
|
javax.swing.KeyStroke |
getCommandKey()
Returns the shortcut of the action.
|
java.lang.String |
getDescription()
Returns description of this action.
|
java.lang.String |
getGroup()
Returns the name of the related actions group.
|
javax.swing.Icon |
getIcon()
Deprecated.
use {link #getSmallOrLargeIcon}
|
java.lang.String |
getID()
Returns the id of the action.
|
javax.swing.Icon |
getLargeIcon()
Returns the large icon of the action.
|
javax.swing.Icon |
getLargeOrSmallIcon() |
static java.lang.String |
getMenuShortcutMaskAsString() |
int |
getMnemonicKey()
Returns the mnemonic of the action.
|
java.lang.String |
getName()
Returns the name of the action.
|
java.beans.PropertyChangeListener[] |
getPropertyChangeListeners()
Returns an array of all the
PropertyChangeListeners added
to this action with addPropertyChangeListener(). |
java.util.List<javax.swing.KeyStroke> |
getShortcuts()
Returns all shortcuts of the the action.
|
javax.swing.Icon |
getSmallIcon()
Returns the small icon of the action.
|
javax.swing.Icon |
getSmallOrLargeIcon() |
javax.swing.Icon |
getTinyIcon()
Returns the tiny icon of the action.
|
int |
hashCode()
Creates hashcode from id.
|
static boolean |
hasMenuShortcutMask(java.awt.AWTEvent event)
Check if event has menu shortcut mask modifier
|
boolean |
isIDGenerated()
Returns true if id was generated.
|
void |
removeAction(NMAction action)
Remove action.
|
void |
removeIf(java.util.function.Predicate<NMAction> filter)
Removes all of the owned actions that satisfy the given predicate
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a
PropertyChangeListener from the listener list. |
void |
removeShortcut(javax.swing.KeyStroke key)
Removes the shortcut from the action.
|
void |
removeWeakPropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a
PropertyChangeListener from the weak listener list. |
void |
setActions(java.util.List<? extends NMAction> actions)
Sets the list of the actions(do nothing here).
|
void |
setDescription(java.lang.String description)
Sets new action description.
|
protected void |
setGroup(java.lang.String group)
Sets new group for this action.
|
void |
setIcon(javax.swing.Icon icon)
Sets small and large icon.
|
void |
setLargeIcon(javax.swing.Icon icon)
Sets the large icon of the action.
|
void |
setMnemonicKey(int key)
Sets the mnemonic key of the action.
|
void |
setName(java.lang.String name)
Sets new name of action, method implemented by putting value with key Action.NAME
|
void |
setShortcuts(java.util.List<javax.swing.KeyStroke> shortcuts)
Sets the shortcuts list.
|
void |
setSmallIcon(javax.swing.Icon icon)
Sets the small icon of the action.
|
void |
setTinyIcon(javax.swing.Icon icon)
Sets the tiny icon of the action.
|
NMAction |
shallowClone()
Returns itself
|
java.lang.String |
toString()
toString returns the action's name.
|
void |
updateState()
Method should update action state (enabled or disabled, checked or unchecked).
|
public static final java.lang.String DO_NO_SHOW_ACTION_NAME_IN_UI
public static final java.lang.String BELONGS_TO_SEPARATE_GROUP_IN_UI
public static final java.lang.String ACTION_SHORTCUTS
public static final java.lang.String ID
public static final java.lang.String LARGE_ICON
public static final java.lang.String TINY_ICON
public static final java.lang.String GROUP
public static final int MENU_SHORTCUT_MASK
public static final java.lang.String GENERATED_ID_PREFIX
public NMAction(@CheckForNull
java.lang.String id,
@CheckForNull
java.lang.String name,
@CheckForNull
javax.swing.KeyStroke stroke,
@CheckForNull
java.lang.String group)
id - the id of the action.name - the name of the action.stroke - the KeyStroke of the action.group - the name of the related commands group.public NMAction(@CheckForNull
java.lang.String id,
@CheckForNull
java.lang.String name,
@CheckForNull
javax.swing.KeyStroke stroke)
id - the id of the action.name - the name of the action.stroke - the KeyStroke of the action.public NMAction()
public NMAction(@CheckForNull
java.lang.String id,
@CheckForNull
java.lang.String name,
int mnemonic,
@CheckForNull
java.lang.String group)
id - the id of the action.name - the name of the action.mnemonic - the mnemonic key of the actiongroup - the name of the related commands group.public NMAction(@CheckForNull
java.lang.String id,
@CheckForNull
java.lang.String name,
int mnemonic)
id - the id of the action.name - the name of the action.mnemonic - the mnemonic key of the actionpublic void setName(java.lang.String name)
name - namepublic java.lang.String getID()
@CheckForNull public javax.swing.KeyStroke getCommandKey()
@Deprecated
public void addShotcut(@CheckForNull
javax.swing.KeyStroke key)
addShortcut(KeyStroke)key - the given shortcut.public void addShortcut(@CheckForNull
javax.swing.KeyStroke key)
key - the given shortcut.public void removeShortcut(@CheckForNull
javax.swing.KeyStroke key)
key - the given shortcut.public void setShortcuts(@CheckForNull
java.util.List<javax.swing.KeyStroke> shortcuts)
shortcuts - the list of all shortcuts.public java.util.List<javax.swing.KeyStroke> getShortcuts()
public java.lang.String getName()
public void setMnemonicKey(int key)
key - the mnemonic key of the action.public int getMnemonicKey()
public void setIcon(@CheckForNull
javax.swing.Icon icon)
icon - Icon of the action.public void setSmallIcon(@CheckForNull
javax.swing.Icon icon)
icon - the small icon of the action.@CheckForNull public javax.swing.Icon getSmallIcon()
public void setTinyIcon(@CheckForNull
javax.swing.Icon icon)
icon - the tiny icon of the action@CheckForNull public javax.swing.Icon getTinyIcon()
@Deprecated @CheckForNull public javax.swing.Icon getIcon()
public void setLargeIcon(@CheckForNull
javax.swing.Icon icon)
icon - the large icon of the action.@CheckForNull public javax.swing.Icon getLargeIcon()
@CheckForNull public javax.swing.Icon getLargeOrSmallIcon()
@CheckForNull public javax.swing.Icon getSmallOrLargeIcon()
public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic abstract void actionPerformed(@CheckForNull
java.awt.event.ActionEvent e)
actionPerformed in interface java.awt.event.ActionListenere - event caused execution.public int compareTo(java.lang.Object o)
compareTo in interface java.lang.Comparableo - the given object to compare to.public NMAction clone()
clone in class javax.swing.AbstractActionpublic NMAction shallowClone()
public void accept(ActionsVisitor visitor)
visitor - visitor to accept.public void setDescription(@CheckForNull
java.lang.String description)
description - action description.public java.lang.String getDescription()
protected void setGroup(@CheckForNull
java.lang.String group)
group - group name.public java.lang.String getGroup()
public java.util.List<NMAction> getActions()
public void forEach(java.util.function.Consumer<NMAction> consumer)
consumer - the action to be performed for each NMActionpublic void setActions(java.util.List<? extends NMAction> actions)
actions - the list of the actions.public void addAction(NMAction action)
action - the action to add.public void removeAction(NMAction action)
action - the action to remove.public void removeIf(java.util.function.Predicate<NMAction> filter)
filter - given predicatepublic void updateState()
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
PropertyChangeListener to the listener list.
The listener is registered for all properties.
A PropertyChangeEvent will get fired in response to setting
a bound property, e.g. setFont, setBackground,
or setForeground.
Note that if the current component is inheriting its foreground,
background, or font from its container, then no event will be
fired in response to a change in the inherited property.
This method creates advanced SwingPropertyChangeSupport which is safe to use when
removing/adding listeners during firing property change event.
addPropertyChangeListener in interface javax.swing.ActionaddPropertyChangeListener in class javax.swing.AbstractActionlistener - The PropertyChangeListener to be addedAction.addPropertyChangeListener(java.beans.PropertyChangeListener)public void addWeakPropertyChangeListener(java.beans.PropertyChangeListener listener)
PropertyChangeListener to the weak listener list.
The listener is registered for all properties.
A PropertyChangeEvent will get fired in response to setting
a bound property, e.g. setFont, setBackground,
or setForeground.
Note that if the current component is inheriting its foreground,
background, or font from its container, then no event will be
fired in response to a change in the inherited property.
This method creates advanced SwingPropertyChangeSupport which is safe to use when
removing/adding listeners during firing property change event.
listener - The PropertyChangeListener to be addedAction.addPropertyChangeListener(java.beans.PropertyChangeListener)protected void firePropertyChange(java.lang.String propertyName,
@CheckForNull
java.lang.Object oldValue,
@CheckForNull
java.lang.Object newValue)
PropertyChangeEvent to any registered
PropertyChangeListeners.firePropertyChange in class javax.swing.AbstractActionpublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
PropertyChangeListener from the listener list.
This removes a PropertyChangeListener that was registered
for all properties.removePropertyChangeListener in interface javax.swing.ActionremovePropertyChangeListener in class javax.swing.AbstractActionlistener - the PropertyChangeListener to be removedAction.removePropertyChangeListener(java.beans.PropertyChangeListener)public void removeWeakPropertyChangeListener(java.beans.PropertyChangeListener listener)
PropertyChangeListener from the weak listener list.
This removes a PropertyChangeListener that was registered
for all properties.listener - the PropertyChangeListener to be removedAction.removePropertyChangeListener(java.beans.PropertyChangeListener)@CheckForNull public javax.swing.JMenuItem createMenuItem(com.nomagic.actions.MenuComponentFactory factory)
factory - factory.public boolean isIDGenerated()
public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
PropertyChangeListeners added
to this action with addPropertyChangeListener().getPropertyChangeListeners in class javax.swing.AbstractActionPropertyChangeListeners added or an empty
array if no listeners have been addedpublic static boolean hasMenuShortcutMask(java.awt.AWTEvent event)
event - eventpublic static java.lang.String getMenuShortcutMaskAsString()