Class NMAction
- All Implemented Interfaces:
ActionListener
,Serializable
,Cloneable
,Comparable
,EventListener
,Action
- Direct Known Subclasses:
ActionsCategory
,BaseNMStateAction
,ColorChooseAction
,MDAction
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Key for storing command keys.static final String
A name of property to put this action into a dedicate special group.static final String
A name of property to hide action name text in create UI.static final String
A name of property to skip registering this action to components.static final String
static final String
Key for storing group.static final String
Key for storing id.static final String
Key for storing large icon.static final int
Menu shortcut mask used to create shortcuts.static final String
Key for storing tiny icon (smaller than small icon).Fields inherited from class javax.swing.AbstractAction
changeSupport, enabled
Fields inherited from interface javax.swing.Action
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 Summary
ConstructorDescriptionNMAction()
Constructs the action with nulls.Constructs the action with given id, name, mnemonic key.Constructs the action with given id, name, mnemonic key and group.Constructs the action with given id, name, keystroke.Constructs the action with given id, name, keystroke and group. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(ActionsVisitor visitor) Accepts ActionsVisitor using Visitor pattern.abstract void
Executes given action.void
Adds action.void
Adds aPropertyChangeListener
to the listener list.void
addShortcut
(KeyStroke key) Adds the shortcut to the action.void
addShotcut
(KeyStroke key) Deprecated.type error.void
Adds aPropertyChangeListener
to the weak listener list.clone()
Clones the object.int
Compares the name of the action.createMenuItem
(com.nomagic.actions.MenuComponentFactory factory) Action can return preferred representation of itself as menu item.boolean
Checks if given object is equal to the current action.protected void
firePropertyChange
(String propertyName, Object oldValue, Object newValue) Supports reporting bound property changes.void
Performs the given consumer for each owned action.void
forEachIncludingSelf
(Consumer<NMAction> consumer) Performs the given consumer for each owned action including self.Returns the list of the actions.Returns the shortcut of the action.Returns description of this action.getGroup()
Returns the name of the related actions group.getIcon()
Deprecated.use {link #getSmallOrLargeIcon}getID()
Returns the id of the action.Returns the large icon of the action.static String
int
Returns the mnemonic of the action.getName()
Returns the name of the action.Returns an array of all thePropertyChangeListener
s added to this action with addPropertyChangeListener().Returns all shortcuts of the the action.Returns the small icon of the action.Returns the tiny icon of the action.int
hashCode()
Creates hashcode from id.static boolean
hasMenuShortcutMask
(AWTEvent event) Check if event has menu shortcut mask modifierboolean
Returns true if id was generated.void
removeAction
(NMAction action) Remove action.void
Removes all of the owned actions that satisfy the given predicatevoid
Removes aPropertyChangeListener
from the listener list.void
removeShortcut
(KeyStroke key) Removes the shortcut from the action.void
Removes aPropertyChangeListener
from the weak listener list.void
setActions
(List<? extends NMAction> actions) Sets the list of the actions(do nothing here).void
setDescription
(String description) Sets new action description.protected void
Sets new group for this action.void
Sets small and large icon.void
setLargeIcon
(Icon icon) Sets the large icon of the action.void
setMnemonicKey
(int key) Sets the mnemonic key of the action.void
Sets new name of action, method implemented by putting value with key Action.NAMEvoid
setShortcuts
(List<KeyStroke> shortcuts) Sets the shortcuts list.void
setSmallIcon
(Icon icon) Sets the small icon of the action.void
setTinyIcon
(Icon icon) Sets the tiny icon of the action.Returns itselftoString()
toString returns the action's name.void
Method should update action state (enabled or disabled, checked or unchecked).Methods inherited from class javax.swing.AbstractAction
getKeys, getValue, isEnabled, putValue, setEnabled
-
Field Details
-
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:
-
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:
-
DO_NOT_REGISTER_ACTION_TO_COMPONENTS
A name of property to skip registering this action to components.- See Also:
-
ACTION_SHORTCUTS
Key for storing command keys.- See Also:
-
ID
Key for storing id.- See Also:
-
LARGE_ICON
Key for storing large icon.- See Also:
-
TINY_ICON
Key for storing tiny icon (smaller than small icon).- See Also:
-
GROUP
Key for storing group.- See Also:
-
MENU_SHORTCUT_MASK
public static final int MENU_SHORTCUT_MASKMenu shortcut mask used to create shortcuts. -
GENERATED_ID_PREFIX
- See Also:
-
-
Constructor Details
-
NMAction
public NMAction(@CheckForNull String id, @CheckForNull String name, @CheckForNull KeyStroke stroke, @CheckForNull 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
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 String id, @CheckForNull String name, int mnemonic, @CheckForNull 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
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 Details
-
setName
Sets new name of action, method implemented by putting value with key Action.NAME- Parameters:
name
- name
-
getID
Returns the id of the action.- Returns:
- the id of the action.
-
getCommandKey
Returns the shortcut of the action.- Returns:
- the first shortcut from all available shortcuts, null if no shortcuts are defined.
-
addShotcut
Deprecated.type error. UseaddShortcut(KeyStroke)
Adds the shortcut to the action.- Parameters:
key
- the given shortcut.
-
addShortcut
Adds the shortcut to the action.- Parameters:
key
- the given shortcut.
-
removeShortcut
Removes the shortcut from the action.- Parameters:
key
- the given shortcut.
-
setShortcuts
Sets the shortcuts list.- Parameters:
shortcuts
- the list of all shortcuts.
-
getShortcuts
Returns all shortcuts of the the action.- Returns:
- the list of all shortcuts. List is unmodifiable.
-
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
Sets small and large icon.- Parameters:
icon
- Icon of the action.
-
setSmallIcon
Sets the small icon of the action.- Parameters:
icon
- the small icon of the action.
-
getSmallIcon
Returns the small icon of the action.- Returns:
- the small icon of the action.
-
setTinyIcon
Sets the tiny icon of the action.- Parameters:
icon
- the tiny icon of the action
-
getTinyIcon
Returns the tiny icon of the action.- Returns:
- the tiny icon of the action.
-
getIcon
Deprecated.use {link #getSmallOrLargeIcon} -
setLargeIcon
Sets the large icon of the action.- Parameters:
icon
- the large icon of the action.
-
getLargeIcon
Returns the large icon of the action.- Returns:
- the large icon of the action.
-
getLargeOrSmallIcon
- Returns:
- large icon if present. If not, small one
-
getSmallOrLargeIcon
- Returns:
- small icon if present. If not, large one
-
equals
Checks if given object is equal to the current action. -
hashCode
public int hashCode()Creates hashcode from id. -
toString
toString returns the action's name. -
actionPerformed
Executes given action.- Specified by:
actionPerformed
in interfaceActionListener
- Parameters:
e
- event caused execution.
-
compareTo
Compares the name of the action. Uses String.compareTo method.- Specified by:
compareTo
in interfaceComparable
- Parameters:
o
- the given object to compare to.- Returns:
- name comparison result
-
clone
Clones the object. Does the deep clone.- Overrides:
clone
in classAbstractAction
- Returns:
- cloned object
-
shallowClone
Returns itself- Returns:
- itself here
-
accept
Accepts ActionsVisitor using Visitor pattern.- Parameters:
visitor
- visitor to accept.
-
setDescription
Sets new action description.- Parameters:
description
- action description.
-
getDescription
Returns description of this action.- Returns:
- action description.
-
setGroup
Sets new group for this action. Empty string will be converted to null.- Parameters:
group
- group name.
-
getGroup
Returns the name of the related actions group.- Returns:
- the name of the related actions group.
-
getActions
Returns the list of the actions.- Returns:
- empty list here. Some derived classes may override this method.
-
forEach
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
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
Sets the list of the actions(do nothing here).- Parameters:
actions
- the list of the actions.
-
addAction
Adds action. Not supported here.- Parameters:
action
- the action to add.
-
removeAction
Remove action. Not supported here.- Parameters:
action
- the action to remove.
-
removeIf
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
Adds aPropertyChangeListener
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
, 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:
addPropertyChangeListener
in interfaceAction
- Overrides:
addPropertyChangeListener
in classAbstractAction
- Parameters:
listener
- ThePropertyChangeListener
to be added- See Also:
-
addWeakPropertyChangeListener
Adds aPropertyChangeListener
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
, 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
- ThePropertyChangeListener
to be added- See Also:
-
firePropertyChange
protected void firePropertyChange(String propertyName, @CheckForNull Object oldValue, @CheckForNull Object newValue) Supports reporting bound property changes. This method can be called when a bound property has changed and it will send the appropriatePropertyChangeEvent
to any registeredPropertyChangeListeners
.- Overrides:
firePropertyChange
in classAbstractAction
-
removePropertyChangeListener
Removes aPropertyChangeListener
from the listener list. This removes aPropertyChangeListener
that was registered for all properties.- Specified by:
removePropertyChangeListener
in interfaceAction
- Overrides:
removePropertyChangeListener
in classAbstractAction
- Parameters:
listener
- thePropertyChangeListener
to be removed- See Also:
-
removeWeakPropertyChangeListener
Removes aPropertyChangeListener
from the weak listener list. This removes aPropertyChangeListener
that was registered for all properties.- Parameters:
listener
- thePropertyChangeListener
to be removed- See Also:
-
createMenuItem
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
Returns an array of all thePropertyChangeListener
s added to this action with addPropertyChangeListener().- Overrides:
getPropertyChangeListeners
in classAbstractAction
- Returns:
- all of the
PropertyChangeListener
s added or an empty array if no listeners have been added
-
hasMenuShortcutMask
Check if event has menu shortcut mask modifier- Parameters:
event
- event- Returns:
- true if event has CONTROL (or COMMAND on Mac) modifiers
-
getMenuShortcutMaskAsString
- Returns:
- representation of menu shortcut modifier. Representation can be used in various UI messages.
-