Package com.nomagic.actions
Class ActionsManager
- java.lang.Object
-
- com.nomagic.actions.ActionsManager
-
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
MDActionsManager
@OpenApiAll public class ActionsManager extends java.lang.Object implements java.lang.Cloneable
The class responsible for managing the actions and categories. It has a list of categories and the helper maps where actions are registered by shortcuts and by id.- See Also:
ActionsCategory
,NMAction
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ActionsManager.ActionPropertyChangeListener
The action property change listener class.
-
Field Summary
Fields Modifier and Type Field Description private com.nomagic.actions.ActionsCache
cache
private java.util.List<ActionsCategory>
categories
private ActionsManager
parent
static java.lang.String
SHORTCUTS_MODIFIED
A key for Boolean which marks action with modified shortcuts in UI
-
Constructor Summary
Constructors Constructor Description ActionsManager()
Creates the actions manager.ActionsManager(ActionsManager parent)
Creates the actions manager.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addActionNearTheGiven(java.lang.String givenID, boolean addAfter, NMAction action)
Adds given action near the action with the given id.void
addActionNearTheGiven(java.lang.String givenID, boolean addAfter, NMAction action, ActionsCategory defaultCategory)
Adds given action near the action with the given id.void
addCategory(int index, ActionsCategory category)
Adds the given category to the manager.void
addCategory(ActionsCategory category)
Adds the given category to the manager.void
addCategory(ActionsCategory relatedCategory, ActionsCategory category, boolean addAfter)
Adds the given category to the manager.void
addCategory(java.lang.String relatedCategoryID, ActionsCategory category, boolean addAfter)
Adds the given category to the manager.ActionsManager
clone()
Clones the manager.static MDAction
constructNoneAction()
Constructs a none action.protected com.nomagic.actions.ActionsCache
createCache()
void
dropCache()
void
forEach(java.util.function.Consumer<NMAction> consumer)
Performs the given consumer for each owned action.void
forEachIncludingSelf(java.util.function.Consumer<NMAction> consumer)
Performs the given consumer for each owned action including self.NMAction
getActionFor(java.lang.String id)
Returns the action for given id.NMAction
getActionFor(javax.swing.KeyStroke stroke)
Returns the action for given stroke.private NMAction
getActionFromCategory(java.lang.String id)
NMAction
getActionParent(NMAction action)
Returns parent action for given action.ActionsCategory
getActionsCategoryRecursively(java.util.List<ActionsCategory> categories, java.lang.String id)
Recursively finds an action category with a given id.java.util.List<NMAction>
getAllActions()
Returns the list of all actions registered in this manager.java.util.List<NMAction>
getAllOrderedActions(boolean includeCategories)
Returns the list if all ordered actions registered in this manager.java.util.List<ActionsCategory>
getCategories()
Returns the list of the categories.ActionsCategory
getCategory(java.lang.String id)
Returns the category with given id.java.util.Map<java.lang.String,NMAction>
getIdToActionMap()
ActionsCategory
getLastActionsCategory()
Returns last category by order.protected com.nomagic.actions.ActionsCache
getOrCreateCache()
ActionsManager
getParent()
Returns the actions manager parent.boolean
isEmpty()
ActionsManager
makeCopy()
Copies this manager and adds property change listeners to all actions in order to have the same action state in source and copy.static void
markShortcutsModified(javax.swing.Action action)
Add a mark that shortcuts are modified externally in UIvoid
removeAction(NMAction action)
Removes action from this manager.void
removeAction(NMAction action, NMAction parent)
Removes action with given ID from this manager.void
removeAction(java.lang.String actionID)
Removes action with given ID from this manager.void
removeAllActions()
Removes all actions.void
removeCategory(ActionsCategory category)
Removes the given category from the manager.private static void
removeIf(NMAction action, java.util.function.Predicate<NMAction> filter)
void
removeIf(java.util.function.Predicate<NMAction> filter)
Removes all of the actions of this manager that satisfy the given predicatevoid
setCategories(java.util.List<? extends ActionsCategory> list)
Sets the list of the categories.void
setParent(ActionsManager parent)
Sets the actions manager parent.void
updateCommandKeysFrom(ActionsManager manager)
Deprecated.void
updateShortcutsFrom(ActionsManager manager)
Takes all action from the given manager with modified shortcuts and overwrites the shortcuts for actions in this manager.void
updateStateForAllActions()
Calls updateState() method for all inner actions.
-
-
-
Field Detail
-
SHORTCUTS_MODIFIED
public static final java.lang.String SHORTCUTS_MODIFIED
A key for Boolean which marks action with modified shortcuts in UI- See Also:
- Constant Field Values
-
parent
@CheckForNull private ActionsManager parent
-
categories
private java.util.List<ActionsCategory> categories
-
cache
@CheckForNull private com.nomagic.actions.ActionsCache cache
-
-
Constructor Detail
-
ActionsManager
public ActionsManager(@CheckForNull ActionsManager parent)
Creates the actions manager.- Parameters:
parent
- the parent of the actions manager. May be null.
-
ActionsManager
public ActionsManager()
Creates the actions manager.
-
-
Method Detail
-
markShortcutsModified
public static void markShortcutsModified(javax.swing.Action action)
Add a mark that shortcuts are modified externally in UI- Parameters:
action
- action
-
getCategories
public java.util.List<ActionsCategory> getCategories()
Returns the list of the categories.- Returns:
- the cloned list of the categories.
-
getActionsCategoryRecursively
@CheckForNull public ActionsCategory getActionsCategoryRecursively(java.util.List<ActionsCategory> categories, java.lang.String id)
Recursively finds an action category with a given id.- Parameters:
categories
- categories to search.id
- id of a category to find.- Returns:
- found action category or null if it is not found.
-
setCategories
public void setCategories(java.util.List<? extends ActionsCategory> list)
Sets the list of the categories. All old actions will be unregistered and new registered.- Parameters:
list
- the list of the categories.
-
addCategory
public void addCategory(ActionsCategory category)
Adds the given category to the manager. The actions from the given category will be registered.- Parameters:
category
- the given category.
-
addCategory
public void addCategory(int index, ActionsCategory category)
Adds the given category to the manager. The actions from the given category will be registered.- Parameters:
category
- the given category.index
- index where category will be added.
-
removeCategory
public void removeCategory(ActionsCategory category)
Removes the given category from the manager. The actions from the given category will be unregistered.- Parameters:
category
- the given category.
-
addCategory
public void addCategory(java.lang.String relatedCategoryID, ActionsCategory category, boolean addAfter)
Adds the given category to the manager. The actions from the given category will be registered.- Parameters:
relatedCategoryID
- related category idcategory
- the given categoryaddAfter
- add after related category or before related category
-
addCategory
public void addCategory(@CheckForNull ActionsCategory relatedCategory, ActionsCategory category, boolean addAfter)
Adds the given category to the manager. The actions from the given category will be registered.- Parameters:
relatedCategory
- related categorycategory
- the given categoryaddAfter
- add after related category or before related category
-
getCategory
@CheckForNull public ActionsCategory getCategory(java.lang.String id)
Returns the category with given id.- Parameters:
id
- the id of the category.- Returns:
- the category with given id or null if this manager does not have such category.
-
updateCommandKeysFrom
@Deprecated public void updateCommandKeysFrom(ActionsManager manager)
Deprecated.
-
updateShortcutsFrom
public void updateShortcutsFrom(ActionsManager manager)
Takes all action from the given manager with modified shortcuts and overwrites the shortcuts for actions in this manager.- Parameters:
manager
- the given manager.- See Also:
SHORTCUTS_MODIFIED
-
getAllActions
public java.util.List<NMAction> getAllActions()
Returns the list of all actions registered in this manager.- Returns:
- the list of all registered actions.
-
removeIf
public void removeIf(java.util.function.Predicate<NMAction> filter)
Removes all of the actions of this manager that satisfy the given predicate- Parameters:
filter
- given predicate
-
removeIf
private static void removeIf(NMAction action, java.util.function.Predicate<NMAction> filter)
-
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- See Also:
NMAction.forEachIncludingSelf(Consumer)
-
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- See Also:
NMAction.forEach(Consumer)
-
isEmpty
public boolean isEmpty()
- Returns:
- true if this manager currently contains no actions, false if there are actions. Parent actions are not considered
-
getAllOrderedActions
public java.util.List<NMAction> getAllOrderedActions(boolean includeCategories)
Returns the list if all ordered actions registered in this manager.- Parameters:
includeCategories
- If true, then ActionsCategories will be included in the list- Returns:
- the list of all registered actions.
-
removeAllActions
public void removeAllActions()
Removes all actions.
-
getActionFor
@CheckForNull public NMAction getActionFor(@CheckForNull javax.swing.KeyStroke stroke)
Returns the action for given stroke. If this manager does not have such action, it looks in the parent.- Parameters:
stroke
- stroke- Returns:
- the action for given stroke or null if there are no action with such stroke.
-
getActionFor
@CheckForNull public NMAction getActionFor(java.lang.String id)
Returns the action for given id. If this manager does not have such action, it looks in the parent.- Parameters:
id
- action id- Returns:
- the action for given id or null if there are no action with such id.
-
getIdToActionMap
public java.util.Map<java.lang.String,NMAction> getIdToActionMap()
-
clone
public ActionsManager clone()
Clones the manager. Does deep clone.- Overrides:
clone
in classjava.lang.Object
- Returns:
- cloned instance
-
dropCache
public void dropCache()
-
setParent
public void setParent(@CheckForNull ActionsManager parent)
Sets the actions manager parent.- Parameters:
parent
- the new parent.
-
getParent
@CheckForNull public ActionsManager getParent()
Returns the actions manager parent.- Returns:
- parent.
-
getActionParent
@CheckForNull public NMAction getActionParent(NMAction action)
Returns parent action for given action. Searches for the action object itself, if a provided object is not found actions are compared using equals(by action ID).- Parameters:
action
- the given action.- Returns:
- parent of given action.
-
makeCopy
public ActionsManager makeCopy()
Copies this manager and adds property change listeners to all actions in order to have the same action state in source and copy.- Returns:
- copied manager.
-
updateStateForAllActions
public void updateStateForAllActions()
Calls updateState() method for all inner actions.- See Also:
NMAction.updateState()
-
getLastActionsCategory
@CheckForNull public ActionsCategory getLastActionsCategory()
Returns last category by order.- Returns:
- last category
-
removeAction
public void removeAction(java.lang.String actionID)
Removes action with given ID from this manager. Searches for action parent, removes action from it's parent and removes parent if it does not have any more actions. If given ID is id of root category(added into manager), removes this category.- Parameters:
actionID
- actionID id of action to remove.
-
removeAction
public void removeAction(NMAction action)
Removes action from this manager.- Parameters:
action
- action to remove.
-
removeAction
public void removeAction(NMAction action, @CheckForNull NMAction parent)
Removes action with given ID from this manager. Takes given parent, removes action from it's parent and removes parent if it does not have any more actions. If given ID is id of root category(added into manager), removes this category.- Parameters:
action
- action to remove.parent
- parent of action to remove from.
-
addActionNearTheGiven
public void addActionNearTheGiven(@CheckForNull java.lang.String givenID, boolean addAfter, @CheckForNull NMAction action)
Adds given action near the action with the given id. The given action will be added into the same parent as action with givenID. The position of the given action will be above or below the "givenID".- Parameters:
givenID
- the id of action to add nearaddAfter
- add after or before "givenID"action
- the action to add.
-
addActionNearTheGiven
public void addActionNearTheGiven(@CheckForNull java.lang.String givenID, boolean addAfter, @CheckForNull NMAction action, @CheckForNull ActionsCategory defaultCategory)
Adds given action near the action with the given id. The given action will be added into the same parent as action with givenID. The position of the given action will be above or below the "givenID".- Parameters:
givenID
- the id of action to add nearaddAfter
- add after or before "givenID"action
- the action to adddefaultCategory
- category to add action into if action with givenID does not exist. Last category from manager is used if defaultCategory is null
-
getActionFromCategory
@CheckForNull private NMAction getActionFromCategory(java.lang.String id)
-
getOrCreateCache
@InternalApi protected com.nomagic.actions.ActionsCache getOrCreateCache()
-
createCache
@InternalApi protected com.nomagic.actions.ActionsCache createCache()
-
constructNoneAction
public static MDAction constructNoneAction()
Constructs a none action.- Returns:
- created none action.
-
-