Class NMAction
- java.lang.Object
 - 
- javax.swing.AbstractAction
 - 
- com.nomagic.actions.NMAction
 
 
 
- 
- All Implemented Interfaces:
 java.awt.event.ActionListener,java.io.Serializable,java.lang.Cloneable,java.lang.Comparable,java.util.EventListener,javax.swing.Action
- Direct Known Subclasses:
 ActionsCategory,ColorChooseAction,MDAction,NMStateAction
@OpenApiAll public abstract class NMAction extends javax.swing.AbstractAction implements java.lang.ComparableThe class describes some abstract action. Any specific action must implement actionPerformed() method. The action has such properties: name, id,small icon,large icon,some shortcuts,mnemonic, description, group- See Also:
 - Serialized Form
 
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static java.lang.StringACTION_SHORTCUTSKey for storing command keys.static java.lang.StringBELONGS_TO_SEPARATE_GROUP_IN_UIA name of property to put this action into a dedicate special group.static java.lang.StringDO_NO_SHOW_ACTION_NAME_IN_UIA name of property to hide action name text in create UI.static java.lang.StringGENERATED_ID_PREFIXstatic java.lang.StringGROUPKey for storing group.static java.lang.StringIDKey for storing id.private static com.nomagic.utils.CounterID_GENERATORThe id generator for actions without id.static java.lang.StringLARGE_ICONKey for storing large icon.static intMENU_SHORTCUT_MASKMenu shortcut mask used to create shortcuts.private com.nomagic.utils.ExtendedPropertyChangeSupportsupportProperty change support.static java.lang.StringTINY_ICONKey for storing tiny icon (smaller than small icon).private com.nomagic.utils.WeakExtendedPropertyChangeSupportweakSupportProperty change support for weak property change listeners This support allows adding/removing property change listeners of this action. 
- 
Constructor Summary
Constructors Constructor 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. 
- 
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccept(ActionsVisitor visitor)Accepts ActionsVisitor using Visitor pattern.abstract voidactionPerformed(java.awt.event.ActionEvent e)Executes given action.voidaddAction(NMAction action)Adds action.voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Adds aPropertyChangeListenerto the listener list.voidaddShortcut(javax.swing.KeyStroke key)Adds the shortcut to the action.voidaddShotcut(javax.swing.KeyStroke key)Deprecated.type error.voidaddWeakPropertyChangeListener(java.beans.PropertyChangeListener listener)Adds aPropertyChangeListenerto the weak listener list.private static java.lang.StringcheckID(java.lang.String id)Method generates id if it is null or empty.NMActionclone()Clones the object.intcompareTo(java.lang.Object o)Compares the name of the action.javax.swing.JMenuItemcreateMenuItem(com.nomagic.actions.MenuComponentFactory factory)Action can return preferred representation of itself as menu item.booleanequals(java.lang.Object o)Checks if given object is equal to the current action.protected voidfirePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)Supports reporting bound property changes.voidforEach(java.util.function.Consumer<NMAction> consumer)Performs the given consumer for each owned action.voidforEachIncludingSelf(java.util.function.Consumer<NMAction> consumer)Performs the given consumer for each owned action including self.java.util.List<NMAction>getActions()Returns the list of the actions.javax.swing.KeyStrokegetCommandKey()Returns the shortcut of the action.java.lang.StringgetDescription()Returns description of this action.java.lang.StringgetGroup()Returns the name of the related actions group.javax.swing.IcongetIcon()Deprecated.use {link #getSmallOrLargeIcon}java.lang.StringgetID()Returns the id of the action.javax.swing.IcongetLargeIcon()Returns the large icon of the action.javax.swing.IcongetLargeOrSmallIcon()static java.lang.StringgetMenuShortcutMaskAsString()intgetMnemonicKey()Returns the mnemonic of the action.java.lang.StringgetName()Returns the name of the action.java.beans.PropertyChangeListener[]getPropertyChangeListeners()Returns an array of all thePropertyChangeListeners added to this action with addPropertyChangeListener().java.util.List<javax.swing.KeyStroke>getShortcuts()Returns all shortcuts of the the action.javax.swing.IcongetSmallIcon()Returns the small icon of the action.javax.swing.IcongetSmallOrLargeIcon()javax.swing.IcongetTinyIcon()Returns the tiny icon of the action.inthashCode()Creates hashcode from id.static booleanhasMenuShortcutMask(java.awt.AWTEvent event)Check if event has menu shortcut mask modifierbooleanisIDGenerated()Returns true if id was generated.voidremoveAction(NMAction action)Remove action.voidremoveIf(java.util.function.Predicate<NMAction> filter)Removes all of the owned actions that satisfy the given predicatevoidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)Removes aPropertyChangeListenerfrom the listener list.voidremoveShortcut(javax.swing.KeyStroke key)Removes the shortcut from the action.voidremoveWeakPropertyChangeListener(java.beans.PropertyChangeListener listener)Removes aPropertyChangeListenerfrom the weak listener list.voidsetActions(java.util.List<? extends NMAction> actions)Sets the list of the actions(do nothing here).voidsetDescription(java.lang.String description)Sets new action description.protected voidsetGroup(java.lang.String group)Sets new group for this action.voidsetIcon(javax.swing.Icon icon)Sets small and large icon.voidsetLargeIcon(javax.swing.Icon icon)Sets the large icon of the action.voidsetMnemonicKey(int key)Sets the mnemonic key of the action.voidsetName(java.lang.String name)Sets new name of action, method implemented by putting value with key Action.NAMEvoidsetShortcuts(java.util.List<javax.swing.KeyStroke> shortcuts)Sets the shortcuts list.voidsetSmallIcon(javax.swing.Icon icon)Sets the small icon of the action.voidsetTinyIcon(javax.swing.Icon icon)Sets the tiny icon of the action.NMActionshallowClone()Returns itselfjava.lang.StringtoString()toString returns the action's name.voidupdateState()Method should update action state (enabled or disabled, checked or unchecked).- 
Methods inherited from class javax.swing.AbstractAction
getKeys, getValue, isEnabled, putValue, setEnabled 
 - 
 
 - 
 
- 
- 
Field Detail
- 
DO_NO_SHOW_ACTION_NAME_IN_UI
public static final java.lang.String DO_NO_SHOW_ACTION_NAME_IN_UI
A name of property to hide action name text in create UI. For example buttons will not show name of this action as text- See Also:
 - Constant Field Values
 
 
- 
BELONGS_TO_SEPARATE_GROUP_IN_UI
public static final java.lang.String BELONGS_TO_SEPARATE_GROUP_IN_UI
A name of property to put this action into a dedicate special group. For example Options action can be in the right side of horizontal toolbar.- See Also:
 - Constant Field Values
 
 
- 
ID_GENERATOR
private static final com.nomagic.utils.Counter ID_GENERATOR
The id generator for actions without id. 
- 
ACTION_SHORTCUTS
public static final java.lang.String ACTION_SHORTCUTS
Key for storing command keys.- See Also:
 - Constant Field Values
 
 
- 
ID
public static final java.lang.String ID
Key for storing id.- See Also:
 - Constant Field Values
 
 
- 
LARGE_ICON
public static final java.lang.String LARGE_ICON
Key for storing large icon.- See Also:
 - Constant Field Values
 
 
- 
TINY_ICON
public static final java.lang.String TINY_ICON
Key for storing tiny icon (smaller than small icon).- See Also:
 - Constant Field Values
 
 
- 
GROUP
public static final java.lang.String GROUP
Key for storing group.- See Also:
 - Constant Field Values
 
 
- 
MENU_SHORTCUT_MASK
public static final int MENU_SHORTCUT_MASK
Menu shortcut mask used to create shortcuts. 
- 
GENERATED_ID_PREFIX
public static final java.lang.String GENERATED_ID_PREFIX
- See Also:
 - Constant Field Values
 
 
- 
support
@CheckForNull private com.nomagic.utils.ExtendedPropertyChangeSupport support
Property change support. This support allows adding/removing property change listeners of this action. 
- 
weakSupport
@CheckForNull private com.nomagic.utils.WeakExtendedPropertyChangeSupport weakSupport
Property change support for weak property change listeners This support allows adding/removing property change listeners of this action. 
 - 
 
- 
Constructor Detail
- 
NMAction
public NMAction(@CheckForNull java.lang.String id, @CheckForNull java.lang.String name, @CheckForNull javax.swing.KeyStroke stroke, @CheckForNull java.lang.String group)Constructs the action with given id, name, keystroke and group.- Parameters:
 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.
 
- 
NMAction
public NMAction(@CheckForNull java.lang.String id, @CheckForNull java.lang.String name, @CheckForNull javax.swing.KeyStroke stroke)Constructs the action with given id, name, keystroke.- Parameters:
 id- the id of the action.name- the name of the action.stroke- the KeyStroke of the action.
 
- 
NMAction
public NMAction()
Constructs the action with nulls. 
- 
NMAction
public NMAction(@CheckForNull java.lang.String id, @CheckForNull java.lang.String name, int mnemonic, @CheckForNull java.lang.String group)Constructs the action with given id, name, mnemonic key and group.- Parameters:
 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.
 
- 
NMAction
public NMAction(@CheckForNull java.lang.String id, @CheckForNull java.lang.String name, int mnemonic)Constructs the action with given id, name, mnemonic key.- Parameters:
 id- the id of the action.name- the name of the action.mnemonic- the mnemonic key of the action
 
 - 
 
- 
Method Detail
- 
checkID
private static java.lang.String checkID(@CheckForNull java.lang.String id)Method generates id if it is null or empty.- Parameters:
 id- id to check.- Returns:
 - String generated or original id.
 
 
- 
setName
public void setName(java.lang.String name)
Sets new name of action, method implemented by putting value with key Action.NAME- Parameters:
 name- name
 
- 
getID
public java.lang.String getID()
Returns the id of the action.- Returns:
 - the id of the action.
 
 
- 
getCommandKey
@CheckForNull public javax.swing.KeyStroke getCommandKey()
Returns the shortcut of the action.- Returns:
 - the first shortcut from all available shortcuts, null if no shortcuts are defined.
 
 
- 
addShotcut
@Deprecated public void addShotcut(@CheckForNull javax.swing.KeyStroke key)Deprecated.type error. UseaddShortcut(KeyStroke)Adds the shortcut to the action.- Parameters:
 key- the given shortcut.
 
- 
addShortcut
public void addShortcut(@CheckForNull javax.swing.KeyStroke key)Adds the shortcut to the action.- Parameters:
 key- the given shortcut.
 
- 
removeShortcut
public void removeShortcut(@CheckForNull javax.swing.KeyStroke key)Removes the shortcut from the action.- Parameters:
 key- the given shortcut.
 
- 
setShortcuts
public void setShortcuts(@CheckForNull java.util.List<javax.swing.KeyStroke> shortcuts)Sets the shortcuts list.- Parameters:
 shortcuts- the list of all shortcuts.
 
- 
getShortcuts
public java.util.List<javax.swing.KeyStroke> getShortcuts()
Returns all shortcuts of the the action.- Returns:
 - the list of all shortcuts. List is unmodifiable.
 
 
- 
getName
public java.lang.String getName()
Returns the name of the action.- Returns:
 - the name of the action.
 
 
- 
setMnemonicKey
public void setMnemonicKey(int key)
Sets the mnemonic key of the action.- Parameters:
 key- the mnemonic key of the action.
 
- 
getMnemonicKey
public int getMnemonicKey()
Returns the mnemonic of the action.- Returns:
 - the mnemonic of the action or -1 if command does not have mnemonic.
 
 
- 
setIcon
public void setIcon(@CheckForNull javax.swing.Icon icon)Sets small and large icon.- Parameters:
 icon- Icon of the action.
 
- 
setSmallIcon
public void setSmallIcon(@CheckForNull javax.swing.Icon icon)Sets the small icon of the action.- Parameters:
 icon- the small icon of the action.
 
- 
getSmallIcon
@CheckForNull public javax.swing.Icon getSmallIcon()
Returns the small icon of the action.- Returns:
 - the small icon of the action.
 
 
- 
setTinyIcon
public void setTinyIcon(@CheckForNull javax.swing.Icon icon)Sets the tiny icon of the action.- Parameters:
 icon- the tiny icon of the action
 
- 
getTinyIcon
@CheckForNull public javax.swing.Icon getTinyIcon()
Returns the tiny icon of the action.- Returns:
 - the tiny icon of the action.
 
 
- 
getIcon
@Deprecated @CheckForNull public javax.swing.Icon getIcon()
Deprecated.use {link #getSmallOrLargeIcon} 
- 
setLargeIcon
public void setLargeIcon(@CheckForNull javax.swing.Icon icon)Sets the large icon of the action.- Parameters:
 icon- the large icon of the action.
 
- 
getLargeIcon
@CheckForNull public javax.swing.Icon getLargeIcon()
Returns the large icon of the action.- Returns:
 - the large icon of the action.
 
 
- 
getLargeOrSmallIcon
@CheckForNull public javax.swing.Icon getLargeOrSmallIcon()
- Returns:
 - large icon if present. If not, small one
 
 
- 
getSmallOrLargeIcon
@CheckForNull public javax.swing.Icon getSmallOrLargeIcon()
- Returns:
 - small icon if present. If not, large one
 
 
- 
equals
public boolean equals(java.lang.Object o)
Checks if given object is equal to the current action.- Overrides:
 equalsin classjava.lang.Object- Returns:
 - true if given object is NMAction and id of the given action is the same as id of current action.
 
 
- 
hashCode
public int hashCode()
Creates hashcode from id.- Overrides:
 hashCodein classjava.lang.Object- Returns:
 - hash code of action.
 
 
- 
toString
public java.lang.String toString()
toString returns the action's name.- Overrides:
 toStringin classjava.lang.Object- Returns:
 - the name.
 
 
- 
actionPerformed
public abstract void actionPerformed(@CheckForNull java.awt.event.ActionEvent e)Executes given action.- Specified by:
 actionPerformedin interfacejava.awt.event.ActionListener- Parameters:
 e- event caused execution.
 
- 
compareTo
public int compareTo(java.lang.Object o)
Compares the name of the action. Uses String.compareTo method.- Specified by:
 compareToin interfacejava.lang.Comparable- Parameters:
 o- the given object to compare to.- Returns:
 - name comparison result
 
 
- 
clone
public NMAction clone()
Clones the object. Does the deep clone.- Overrides:
 clonein classjavax.swing.AbstractAction- Returns:
 - cloned object
 
 
- 
shallowClone
public NMAction shallowClone()
Returns itself- Returns:
 - itself here
 
 
- 
accept
public void accept(ActionsVisitor visitor)
Accepts ActionsVisitor using Visitor pattern.- Parameters:
 visitor- visitor to accept.
 
- 
setDescription
public void setDescription(@CheckForNull java.lang.String description)Sets new action description.- Parameters:
 description- action description.
 
- 
getDescription
public java.lang.String getDescription()
Returns description of this action.- Returns:
 - action description.
 
 
- 
setGroup
protected void setGroup(@CheckForNull java.lang.String group)Sets new group for this action. Empty string will be converted to null.- Parameters:
 group- group name.
 
- 
getGroup
public java.lang.String getGroup()
Returns the name of the related actions group.- Returns:
 - the name of the related actions group.
 
 
- 
getActions
public java.util.List<NMAction> getActions()
Returns the list of the actions.- Returns:
 - empty list here. Some derived classes may override this method.
 
 
- 
forEach
public void forEach(java.util.function.Consumer<NMAction> consumer)
Performs the given consumer for each owned action. Owned actions should not be added/removed inside consumer.- Parameters:
 consumer- the action to be performed for each NMAction
 
- 
forEachIncludingSelf
public void forEachIncludingSelf(java.util.function.Consumer<NMAction> consumer)
Performs the given consumer for each owned action including self. Owned actions should not be added/removed inside consumer.- Parameters:
 consumer- the action to be performed for each NMAction
 
- 
setActions
public void setActions(java.util.List<? extends NMAction> actions)
Sets the list of the actions(do nothing here).- Parameters:
 actions- the list of the actions.
 
- 
addAction
public void addAction(NMAction action)
Adds action. Not supported here.- Parameters:
 action- the action to add.
 
- 
removeAction
public void removeAction(NMAction action)
Remove action. Not supported here.- Parameters:
 action- the action to remove.
 
- 
removeIf
public void removeIf(java.util.function.Predicate<NMAction> filter)
Removes all of the owned actions that satisfy the given predicate- Parameters:
 filter- given predicate
 
- 
updateState
public void updateState()
Method should update action state (enabled or disabled, checked or unchecked). Method is called after other actions was executed. Always enable here. 
- 
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds aPropertyChangeListenerto the listener list. The listener is registered for all properties.A
PropertyChangeEventwill get fired in response to setting a bound property, e.g.setFont,setBackground, orsetForeground. 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.- Specified by:
 addPropertyChangeListenerin interfacejavax.swing.Action- Overrides:
 addPropertyChangeListenerin classjavax.swing.AbstractAction- Parameters:
 listener- ThePropertyChangeListenerto be added- See Also:
 Action.addPropertyChangeListener(java.beans.PropertyChangeListener)
 
- 
addWeakPropertyChangeListener
public void addWeakPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds aPropertyChangeListenerto the weak listener list. The listener is registered for all properties.A
PropertyChangeEventwill get fired in response to setting a bound property, e.g.setFont,setBackground, orsetForeground. 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.- Parameters:
 listener- ThePropertyChangeListenerto be added- See Also:
 Action.addPropertyChangeListener(java.beans.PropertyChangeListener)
 
- 
firePropertyChange
protected void firePropertyChange(java.lang.String propertyName, @CheckForNull java.lang.Object oldValue, @CheckForNull java.lang.Object newValue)Supports reporting bound property changes. This method can be called when a bound property has changed and it will send the appropriatePropertyChangeEventto any registeredPropertyChangeListeners.- Overrides:
 firePropertyChangein classjavax.swing.AbstractAction
 
- 
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes aPropertyChangeListenerfrom the listener list. This removes aPropertyChangeListenerthat was registered for all properties.- Specified by:
 removePropertyChangeListenerin interfacejavax.swing.Action- Overrides:
 removePropertyChangeListenerin classjavax.swing.AbstractAction- Parameters:
 listener- thePropertyChangeListenerto be removed- See Also:
 Action.removePropertyChangeListener(java.beans.PropertyChangeListener)
 
- 
removeWeakPropertyChangeListener
public void removeWeakPropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes aPropertyChangeListenerfrom the weak listener list. This removes aPropertyChangeListenerthat was registered for all properties.- Parameters:
 listener- thePropertyChangeListenerto be removed- See Also:
 Action.removePropertyChangeListener(java.beans.PropertyChangeListener)
 
- 
createMenuItem
@CheckForNull public javax.swing.JMenuItem createMenuItem(com.nomagic.actions.MenuComponentFactory factory)
Action can return preferred representation of itself as menu item. If action returns null, some external menu item creation mechanism will be used.- Parameters:
 factory- factory.- Returns:
 - the menu item or null.
 
 
- 
isIDGenerated
public boolean isIDGenerated()
Returns true if id was generated.- Returns:
 - true if id was generated.
 
 
- 
getPropertyChangeListeners
public java.beans.PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all thePropertyChangeListeners added to this action with addPropertyChangeListener().- Overrides:
 getPropertyChangeListenersin classjavax.swing.AbstractAction- Returns:
 - all of the 
PropertyChangeListeners added or an empty array if no listeners have been added 
 
- 
hasMenuShortcutMask
public static boolean hasMenuShortcutMask(java.awt.AWTEvent event)
Check if event has menu shortcut mask modifier- Parameters:
 event- event- Returns:
 - true if event has CONTROL (or COMMAND on Mac) modifiers
 
 
- 
getMenuShortcutMaskAsString
public static java.lang.String getMenuShortcutMaskAsString()
- Returns:
 - representation of menu shortcut modifier. Representation can be used in various UI messages.
 
 
 - 
 
 -