Package com.nomagic.actions
Class ActionsCategory
- java.lang.Object
-
- javax.swing.AbstractAction
-
- com.nomagic.actions.NMAction
-
- com.nomagic.actions.ActionsCategory
-
- 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:
MDActionsCategory,MenuAction,SelectItemAction,SetFontAction
@OpenApiAll public class ActionsCategory extends NMAction
Actions category owns a list of actions. Actions category can represent structure of menu or toolbar, and it can be nested (represents sub menu).- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringACTIONS_PROPERTYProperty Change event name fired when actions of this category were changed.static java.lang.StringADDED_ACTION_PROPERTYProperty Change event name fired when new action is added.static java.lang.StringCHANGE_ACTIONS_PROPERTYDeprecated.static java.lang.StringDISABLE_IF_EMPTYA name of property to disable the category if it has no actions.static intMAX_CATEGORY_ACTIONSDefault value limiting maximum action count in one categorystatic java.lang.StringREMOVE_IF_EMPTYA name of property to drop the category if it has no actions.static java.lang.StringREMOVED_ACTION_PROPERTYProperty Change event name fired when new action is removed.static java.lang.StringUSE_AS_SEPARATOR_IN_UIA name of property to use this category as separator in UI even if it does not have inner actions-
Fields inherited from class com.nomagic.actions.NMAction
ACTION_SHORTCUTS, BELONGS_TO_SEPARATE_GROUP_IN_UI, DO_NO_SHOW_ACTION_NAME_IN_UI, DO_NOT_REGISTER_ACTION_TO_COMPONENTS, GENERATED_ID_PREFIX, GROUP, ID, LARGE_ICON, MENU_SHORTCUT_MASK, TINY_ICON
-
-
Constructor Summary
Constructors Constructor Description ActionsCategory()Creates actions category with no nameActionsCategory(java.lang.String id, java.lang.String name)Creates actions category with given name and id.ActionsCategory(java.lang.String id, java.lang.String name, int keyCode)Creates actions category with given id, name, and key code.ActionsCategory(java.lang.String id, java.lang.String name, int keyCode, java.lang.String group)Creates actions category with given id, name, and key code.ActionsCategory(java.lang.String id, java.lang.String name, javax.swing.KeyStroke stroke)Creates actions category with given id, name, and keystroke.ActionsCategory(java.lang.String id, java.lang.String name, javax.swing.KeyStroke stroke, java.lang.String group)Creates actions category with given id, name, keystroke and assigned group.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaccept(ActionsVisitor visitor)Accepts visitor and calls visit method of visitor.voidactionPerformed(java.awt.event.ActionEvent e)Empty implementation.voidaddAction(NMAction action)Adds the given action to the category.voidaddAction(NMAction action, int position)Adds the given action at the specified position to the category.voidaddActionNearTheGiven(java.lang.String givenID, boolean addAfter, NMAction action)Adds given action near the action with the given id.voidaddActions(java.util.List<? extends NMAction> actions)Adds given actions to the category.static voidbreakActions(ActionsCategory category, java.util.List<? extends NMAction> actions, int maxCategorySize, java.lang.String categoryName, boolean nested)Breaks given actions into subcategories of given category if the actions number exceeds maxCategorySize.static voidbreakActions(ActionsCategory category, java.util.List<? extends NMAction> actions, int maxCategorySize, java.lang.String categoryName, boolean nested, int innerCategorySize)Breaks category into sub categories, but it has ability to specify inner category size separatelystatic voidbreakActions(ActionsCategory category, java.util.List<NMAction> actions)Breaks given actions into subcategories of given category if the actions number exceeds predefined number.static voidbreakeActions(ActionsCategory category, java.util.List<? extends NMAction> actions, int maxCategorySize, java.lang.String categoryName, boolean nested)ActionsCategoryclone()Clones the category.static ActionsCategorycreateSeparatorCategory()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.NMActiongetAction(java.lang.String actionID)Find direct action with given IDjava.util.List<NMAction>getActions()Returns the list of the owned actions.java.util.List<NMAction>getActionsRecursively(boolean includeCategories)Returns all simple actions (not ActionsCategory) recursively.java.util.List<ActionsCategory>getCategories()Gets inner action categories.booleanisDisplayHeader()booleanisEmpty()booleanisNested()Returns value of nested flag.booleanisUseActionForDisable()Returns value of nested flag.voidremoveAction(NMAction action)Removes the given action from the category.voidremoveIf(java.util.function.Predicate<NMAction> filter)Removes all of the owned actions that satisfy the given predicatevoidsetActions(java.util.List<? extends NMAction> actions)Sets the list of the new actions overriding old actions.voidsetDisplayHeader(boolean displayHeader)Display category name as header of category.voidsetNested(boolean nested)Sets new value of nested flag.voidsetUseActionForDisable(boolean use)ActionsCategoryshallowClone()Clones the category.intsize()Size of category - number of inner actions.voidsort()-
Methods inherited from class com.nomagic.actions.NMAction
addPropertyChangeListener, addShortcut, addShotcut, addWeakPropertyChangeListener, compareTo, createMenuItem, equals, firePropertyChange, getCommandKey, getDescription, getGroup, getIcon, getID, getLargeIcon, getLargeOrSmallIcon, getMenuShortcutMaskAsString, getMnemonicKey, getName, getPropertyChangeListeners, getShortcuts, getSmallIcon, getSmallOrLargeIcon, getTinyIcon, hashCode, hasMenuShortcutMask, isIDGenerated, removePropertyChangeListener, removeShortcut, removeWeakPropertyChangeListener, setDescription, setGroup, setIcon, setLargeIcon, setMnemonicKey, setName, setShortcuts, setSmallIcon, setTinyIcon, toString, updateState
-
Methods inherited from class javax.swing.AbstractAction
getKeys, getValue, isEnabled, putValue, setEnabled
-
-
-
-
Field Detail
-
USE_AS_SEPARATOR_IN_UI
public static final java.lang.String USE_AS_SEPARATOR_IN_UI
A name of property to use this category as separator in UI even if it does not have inner actions- See Also:
- Constant Field Values
-
DISABLE_IF_EMPTY
public static final java.lang.String DISABLE_IF_EMPTY
A name of property to disable the category if it has no actions.- See Also:
- Constant Field Values
-
REMOVE_IF_EMPTY
public static final java.lang.String REMOVE_IF_EMPTY
A name of property to drop the category if it has no actions.- See Also:
- Constant Field Values
-
MAX_CATEGORY_ACTIONS
public static final int MAX_CATEGORY_ACTIONS
Default value limiting maximum action count in one category- See Also:
- Constant Field Values
-
ADDED_ACTION_PROPERTY
public static final java.lang.String ADDED_ACTION_PROPERTY
Property Change event name fired when new action is added.
-
REMOVED_ACTION_PROPERTY
public static final java.lang.String REMOVED_ACTION_PROPERTY
Property Change event name fired when new action is removed.- See Also:
removeAction(NMAction), Constant Field Values
-
ACTIONS_PROPERTY
public static final java.lang.String ACTIONS_PROPERTY
Property Change event name fired when actions of this category were changed.- See Also:
setActions(List), Constant Field Values
-
CHANGE_ACTIONS_PROPERTY
@Deprecated public static final java.lang.String CHANGE_ACTIONS_PROPERTY
Deprecated.Property Change event name fired when actions of this category were changed.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ActionsCategory
public ActionsCategory()
Creates actions category with no name
-
ActionsCategory
public ActionsCategory(@CheckForNull java.lang.String id, @CheckForNull java.lang.String name)Creates actions category with given name and id.- Parameters:
id- the id of the category.name- the name of the category.
-
ActionsCategory
public ActionsCategory(@CheckForNull java.lang.String id, @CheckForNull java.lang.String name, @CheckForNull javax.swing.KeyStroke stroke)Creates actions category with given id, name, and keystroke.- Parameters:
id- the id of the category.name- the name of the category.stroke- keystroke used for invoking action category.
-
ActionsCategory
public ActionsCategory(@CheckForNull java.lang.String id, @CheckForNull java.lang.String name, @CheckForNull javax.swing.KeyStroke stroke, @CheckForNull java.lang.String group)Creates actions category with given id, name, keystroke and assigned group.- Parameters:
id- the id of the category.name- the name of the category.stroke- keystroke used for invoking action category.group- the name of the related commands group.
-
ActionsCategory
public ActionsCategory(@CheckForNull java.lang.String id, @CheckForNull java.lang.String name, int keyCode)Creates actions category with given id, name, and key code.- Parameters:
id- the id of the category.name- the name of the category.keyCode- keystroke used for invoking action category.
-
ActionsCategory
public ActionsCategory(@CheckForNull java.lang.String id, @CheckForNull java.lang.String name, int keyCode, @CheckForNull java.lang.String group)Creates actions category with given id, name, and key code.- Parameters:
id- the id of the category.name- the name of the category.keyCode- keystroke used for invoking action category.group- the name of the related commands group.
-
-
Method Detail
-
createSeparatorCategory
public static ActionsCategory createSeparatorCategory()
-
addAction
public void addAction(@CheckForNull NMAction action)Adds the given action to the category. FiresADDED_ACTION_PROPERTYproperty change event, where new value is added action. FiresCHANGE_ACTIONS_PROPERTY(for backward compatibility) property change event, where old value is old actions list, new value is new actions list.
-
addActions
public void addActions(java.util.List<? extends NMAction> actions)
Adds given actions to the category. FiresACTIONS_PROPERTY(andCHANGE_ACTIONS_PROPERTYfor backward compatibility) property change event, where old value is old actions list, new value is new actions list.- Parameters:
actions- the given actions to add, parameter can be null.
-
addAction
public void addAction(@CheckForNull NMAction action, int position)Adds the given action at the specified position to the category. FiresADDED_ACTION_PROPERTYproperty change event, where new value is added action. FiresCHANGE_ACTIONS_PROPERTY(for backward compatibility) property change event, where old value is old actions list, new value is new actions list.- Parameters:
action- the given action to add, parameter can be null.position- the given position to be added.
-
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.
-
removeAction
public void removeAction(@CheckForNull NMAction action)Removes the given action from the category. FiresREMOVED_ACTION_PROPERTYproperty change event, where old value is removed action. FiresCHANGE_ACTIONS_PROPERTY(for backward compatibility) property change event, where old value is old actions list, new value is new actions list.- Overrides:
removeActionin classNMAction- Parameters:
action- the given action to remove, parameter can be null.
-
getActions
public java.util.List<NMAction> getActions()
Returns the list of the owned actions.- Overrides:
getActionsin classNMAction- Returns:
- the cloned list of the actions.
-
getCategories
public java.util.List<ActionsCategory> getCategories()
Gets inner action categories.- Returns:
- a list of action categories.
-
getActionsRecursively
public java.util.List<NMAction> getActionsRecursively(boolean includeCategories)
Returns all simple actions (not ActionsCategory) recursively.- Parameters:
includeCategories- If true, then ActionsCategories will be included in the list- Returns:
- all actions recursively
-
setActions
public void setActions(java.util.List<? extends NMAction> actions)
Sets the list of the new actions overriding old actions. FiresACTIONS_PROPERTY(andCHANGE_ACTIONS_PROPERTYfor backward compatibility) property change event, where old value is old actions list, new value is new actions list.- Overrides:
setActionsin classNMAction- Parameters:
actions- the new list of the actions.
-
removeIf
public void removeIf(java.util.function.Predicate<NMAction> filter)
Description copied from class:NMActionRemoves all of the owned actions that satisfy the given predicate
-
forEach
public void forEach(java.util.function.Consumer<NMAction> consumer)
Description copied from class:NMActionPerforms the given consumer for each owned action. Owned actions should not be added/removed inside consumer.
-
forEachIncludingSelf
public void forEachIncludingSelf(java.util.function.Consumer<NMAction> consumer)
Description copied from class:NMActionPerforms the given consumer for each owned action including self. Owned actions should not be added/removed inside consumer.- Overrides:
forEachIncludingSelfin classNMAction- Parameters:
consumer- the action to be performed for each NMAction
-
clone
public ActionsCategory clone()
Clones the category. During clone does not fire any property change events. Does deep clone.
-
shallowClone
public ActionsCategory shallowClone()
Clones the category. During clone does not fire any property change events. Does deep clone.- Overrides:
shallowClonein classNMAction- Returns:
- deep clone of category.
-
setNested
public void setNested(boolean nested)
Sets new value of nested flag. Flag indicates that children of this action is nested elements. When representing this action as menu, nested action means new sub menu. Not nested means group(usually separated by some menu separator).- Parameters:
nested- new value of nested flag.
-
isNested
public boolean isNested()
Returns value of nested flag.- Returns:
- true if this category is nested.
- See Also:
setNested(boolean)
-
accept
public void accept(ActionsVisitor visitor)
Accepts visitor and calls visit method of visitor.
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent e)
Empty implementation.- Specified by:
actionPerformedin interfacejava.awt.event.ActionListener- Specified by:
actionPerformedin classNMAction- Parameters:
e- event caused this action execution.
-
setUseActionForDisable
public void setUseActionForDisable(boolean use)
- Parameters:
use- if true, menus created from this category will be disabled if all children are disabled.- See Also:
useActionForDisable
-
isUseActionForDisable
public boolean isUseActionForDisable()
Returns value of nested flag.- Returns:
- value of mUseActionForDisable field
- See Also:
(boolean)
-
breakActions
public static void breakActions(ActionsCategory category, java.util.List<NMAction> actions)
Breaks given actions into subcategories of given category if the actions number exceeds predefined number.- Parameters:
category- category to add created inner categoriesactions- actions to break into categories
-
breakeActions
@Deprecated public static void breakeActions(ActionsCategory category, java.util.List<? extends NMAction> actions, int maxCategorySize, java.lang.String categoryName, boolean nested)
-
breakActions
public static void breakActions(ActionsCategory category, java.util.List<? extends NMAction> actions, int maxCategorySize, java.lang.String categoryName, boolean nested)
Breaks given actions into subcategories of given category if the actions number exceeds maxCategorySize.- Parameters:
category- category to add created inner categoriesactions- actions to break into categoriesmaxCategorySize- max size of inner categorycategoryName- subcategory namenested- make nested subcategories
-
breakActions
public static void breakActions(ActionsCategory category, java.util.List<? extends NMAction> actions, int maxCategorySize, java.lang.String categoryName, boolean nested, int innerCategorySize)
Breaks category into sub categories, but it has ability to specify inner category size separately- Parameters:
category- category to add created inner categoriesactions- actions to break into categoriesmaxCategorySize- max size of inner categorycategoryName- subcategory namenested- make nested subcategoriesinnerCategorySize- maximum size of inner category
-
sort
public void sort()
-
getAction
@CheckForNull public NMAction getAction(java.lang.String actionID)
Find direct action with given ID- Parameters:
actionID- action ID- Returns:
- a list of action categories.
-
isEmpty
public boolean isEmpty()
- Returns:
- true if this category contains no actions at all
-
isDisplayHeader
public boolean isDisplayHeader()
- Returns:
- display header flag
-
setDisplayHeader
public void setDisplayHeader(boolean displayHeader)
Display category name as header of category. This has affect only if category is not nested- Parameters:
displayHeader- display header of not nested menu
-
size
public int size()
Size of category - number of inner actions.- Returns:
- size of category
-
-