Package com.nomagic.actions
Class ActionsMenuCreator
- java.lang.Object
-
- com.nomagic.actions.ActionsMenuCreator
-
@OpenApiAll public class ActionsMenuCreator extends java.lang.Object
Class for creating GUI menu items from actions.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ActionsMenuCreator.AMC_ActionsVisitor
static class
ActionsMenuCreator.CustomJMenuItem
private static class
ActionsMenuCreator.DisableLaterOnEnableListener
private static class
ActionsMenuCreator.DisableLaterOnEnableListenerCache
private static class
ActionsMenuCreator.DisablingListener
Class used to disable parent menu if all inner menu items of this parent are disabled.(package private) static class
ActionsMenuCreator.MenuItemActionListener
Class which listens for actions changes and updates menu item.class
ActionsMenuCreator.MutableActionListener
Class for handling ActionsCategory changes.private static class
ActionsMenuCreator.PopupMenuDelegateListener
Bug fix https://jira.nomagic.com/browse/MDUML-60388.(package private) static class
ActionsMenuCreator.StateActionListener
Class which listens state action state changes and updates CheckBox component according changes.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ACTION
private ActionsVisitor
actionsVisitor
private java.util.Stack<javax.swing.ButtonGroup>
buttonsGroups
Stack of button groups (if radio buttons will be created it should be added on top of of group.static java.lang.String
CATEGORY_HEADER
private java.util.Collection<java.lang.Runnable>
cleanupParticipants
private java.awt.Container
container
Current container where items will be added.private java.util.WeakHashMap<NMAction,java.lang.ref.WeakReference<?>>
currentItems
A list of current created items.private static ActionsMenuCreator.DisablingListener
DISABLING_LISTENER
Listens to menu showing and disable menu with disabled children(menu items).private com.nomagic.actions.MenuComponentFactory
factory
Factory for menu components creationstatic java.lang.String
HIDDEN_ALWAYS
private int
index
Index where items will be added, should be used only with JMenu.(package private) static java.lang.String
MUTABLE_ACTION_LISTENERS_LIST
private boolean
mutableAppending
Flag indicates that menu appending is done for mutable actions.static java.lang.String
POPUP_HEADER_ITEM_NAME
private static javax.swing.event.PopupMenuListener
POPUP_MENU_LISTENER_DELEGATOR
Listener to delegatePopupMenuListener
events to actionprivate boolean
useMenuListener
Do we need to useMenuListener
on category? This flag should be set to true only if software is running on mac and using -Dapple.laf.useScreenMenuBar=true system property.
-
Constructor Summary
Constructors Constructor Description ActionsMenuCreator()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addCleanupParticipant(java.lang.Runnable participant)
private void
addDisabledListenerRecursively(java.util.Collection<NMAction> actions, javax.swing.MenuElement menu, boolean recursively)
protected void
addJMenuItem(java.awt.Component item, NMAction action)
Adds menu item, according to index item will be added to end when index less than 0, or to specified by index position.void
appendMenuItems(java.awt.Container container, ActionsManager manager)
Appends menu items to given container.private void
appendMenuItems(java.awt.Container container, NMAction action, javax.swing.ButtonGroup group, java.util.WeakHashMap<NMAction,java.lang.ref.WeakReference<?>> created)
Appends menu items to given container.void
appendMenuItems(javax.swing.JPopupMenu popup, ActionsManager manager)
Appends menu items to the given pop up menu.void
appendMenuItems(javax.swing.JPopupMenu popup, ActionsManager manager, boolean addSeparator)
Appends menu items to given popup.protected ActionsVisitor
createActionsVisitor()
private void
createDisableLaterOnEnableListener(javax.swing.MenuElement menu, NMAction action)
javax.swing.JPopupMenu
createPopupMenu(ActionsManager manager)
Creates popup menu for given actions managerjavax.swing.JPopupMenu
createPopupMenu(ActionsManager manager, java.util.function.Supplier<javax.swing.JPopupMenu> factory)
Creates popup menu for given actions managerprivate static void
disable(javax.swing.MenuElement element)
Change the enable status of the given component depend on its action enable status.private static int
getComponentCount(java.awt.Container container)
com.nomagic.actions.MenuComponentFactory
getFactory()
Return menu component factoryprivate static NMAction
getSeparatorAction(java.awt.Component component)
private java.awt.Component
getSeparatorAt(int index)
protected void
internalAppendMenuItems(java.awt.Container container, ActionsManager manager)
protected void
internalAppendMenuItems(javax.swing.JPopupMenu popup, ActionsManager manager, boolean addSeparator)
private static boolean
isSeparator(javax.swing.Action category)
static boolean
isSeparatorComponent(java.awt.Component component)
private void
makeLastSeparatorVisible(java.awt.Component itemToAdd, int index)
void
setFactory(com.nomagic.actions.MenuComponentFactory factory)
Set menu component factoryprivate void
setMutableAppending(boolean flag)
Sets flag mMutableAppending to given value.static void
setPropertiesToMenuItem(javax.swing.JMenuItem item, NMAction action)
Sets properties to given JMenuItem from given action.void
setUseMenuListener(boolean useMenuListener)
Do we need to useMenuListener
on category? This flag should be set to true only if software is running on mac and using -Dapple.laf.useScreenMenuBar=true system property.private static void
updateShortcuts(javax.swing.JMenuItem component, NMAction action)
Updates shortcuts of component by action.
-
-
-
Field Detail
-
HIDDEN_ALWAYS
public static final java.lang.String HIDDEN_ALWAYS
- See Also:
- Constant Field Values
-
ACTION
public static final java.lang.String ACTION
- See Also:
- Constant Field Values
-
CATEGORY_HEADER
public static final java.lang.String CATEGORY_HEADER
- See Also:
- Constant Field Values
-
MUTABLE_ACTION_LISTENERS_LIST
static final java.lang.String MUTABLE_ACTION_LISTENERS_LIST
- See Also:
- Constant Field Values
-
POPUP_HEADER_ITEM_NAME
public static final java.lang.String POPUP_HEADER_ITEM_NAME
- See Also:
- Constant Field Values
-
factory
private com.nomagic.actions.MenuComponentFactory factory
Factory for menu components creation
-
DISABLING_LISTENER
private static final ActionsMenuCreator.DisablingListener DISABLING_LISTENER
Listens to menu showing and disable menu with disabled children(menu items).
-
POPUP_MENU_LISTENER_DELEGATOR
private static final javax.swing.event.PopupMenuListener POPUP_MENU_LISTENER_DELEGATOR
Listener to delegatePopupMenuListener
events to action
-
container
private java.awt.Container container
Current container where items will be added.
-
index
private int index
Index where items will be added, should be used only with JMenu.
-
buttonsGroups
private java.util.Stack<javax.swing.ButtonGroup> buttonsGroups
Stack of button groups (if radio buttons will be created it should be added on top of of group. Stack is used since groups can be nested.
-
mutableAppending
private boolean mutableAppending
Flag indicates that menu appending is done for mutable actions. When performing such code new listener should not be created.
-
currentItems
private java.util.WeakHashMap<NMAction,java.lang.ref.WeakReference<?>> currentItems
A list of current created items.
-
useMenuListener
private boolean useMenuListener
Do we need to useMenuListener
on category? This flag should be set to true only if software is running on mac and using -Dapple.laf.useScreenMenuBar=true system property.
-
cleanupParticipants
@CheckForNull private java.util.Collection<java.lang.Runnable> cleanupParticipants
-
actionsVisitor
private final ActionsVisitor actionsVisitor
-
-
Method Detail
-
createPopupMenu
public final javax.swing.JPopupMenu createPopupMenu(ActionsManager manager)
Creates popup menu for given actions manager- Parameters:
manager
- manager- Returns:
- popup menu
-
createPopupMenu
public final javax.swing.JPopupMenu createPopupMenu(ActionsManager manager, java.util.function.Supplier<javax.swing.JPopupMenu> factory)
Creates popup menu for given actions manager- Parameters:
manager
- managerfactory
- new popup menu factory- Returns:
- popup menu
-
appendMenuItems
public final void appendMenuItems(javax.swing.JPopupMenu popup, ActionsManager manager)
Appends menu items to the given pop up menu. Adds separator before new items if given pop up is not empty.- Parameters:
popup
- where items will be appendedmanager
- manager from which actions menu items will be created
-
appendMenuItems
public final void appendMenuItems(javax.swing.JPopupMenu popup, ActionsManager manager, boolean addSeparator)
Appends menu items to given popup.- Parameters:
popup
- where items will be appendedmanager
- manager from which actions menu items will be createdaddSeparator
- add separator after last item in the given popup or not
-
internalAppendMenuItems
protected void internalAppendMenuItems(javax.swing.JPopupMenu popup, ActionsManager manager, boolean addSeparator)
-
appendMenuItems
public final void appendMenuItems(java.awt.Container container, ActionsManager manager)
Appends menu items to given container.- Parameters:
container
- container where items will be appendedmanager
- manager from which actions items will be created
-
createActionsVisitor
protected ActionsVisitor createActionsVisitor()
-
internalAppendMenuItems
protected void internalAppendMenuItems(java.awt.Container container, ActionsManager manager)
-
appendMenuItems
private void appendMenuItems(java.awt.Container container, NMAction action, @CheckForNull javax.swing.ButtonGroup group, java.util.WeakHashMap<NMAction,java.lang.ref.WeakReference<?>> created)
Appends menu items to given container.- Parameters:
container
- container where items will be appended.action
- action from which items will be appended.group
- group of radio items, if any. If group is null, item will not be added to any group.created
- created items map
-
addJMenuItem
protected void addJMenuItem(java.awt.Component item, NMAction action)
Adds menu item, according to index item will be added to end when index less than 0, or to specified by index position.- Parameters:
item
- item to add.action
- action
-
getComponentCount
private static int getComponentCount(java.awt.Container container)
-
makeLastSeparatorVisible
private void makeLastSeparatorVisible(java.awt.Component itemToAdd, int index)
-
setPropertiesToMenuItem
public static void setPropertiesToMenuItem(javax.swing.JMenuItem item, NMAction action)
Sets properties to given JMenuItem from given action.- Parameters:
item
- item to set properties.action
- for getting properties.
-
isSeparator
private static boolean isSeparator(@CheckForNull javax.swing.Action category)
-
getSeparatorAction
@CheckForNull private static NMAction getSeparatorAction(java.awt.Component component)
-
getSeparatorAt
@CheckForNull private java.awt.Component getSeparatorAt(int index)
- Returns:
- true if last visible component is a visible separator or there is no last visible component at all
-
addDisabledListenerRecursively
private void addDisabledListenerRecursively(java.util.Collection<NMAction> actions, javax.swing.MenuElement menu, boolean recursively)
-
createDisableLaterOnEnableListener
private void createDisableLaterOnEnableListener(javax.swing.MenuElement menu, NMAction action)
-
setMutableAppending
private void setMutableAppending(boolean flag)
Sets flag mMutableAppending to given value. This flag indicates that menu is creating in event fired by ActionsCategory.- Parameters:
flag
- new value of mMutableAppending.
-
setUseMenuListener
public void setUseMenuListener(boolean useMenuListener)
Do we need to useMenuListener
on category? This flag should be set to true only if software is running on mac and using -Dapple.laf.useScreenMenuBar=true system property.- Parameters:
useMenuListener
- true if need to use.
-
updateShortcuts
private static void updateShortcuts(@CheckForNull javax.swing.JMenuItem component, NMAction action)
Updates shortcuts of component by action.- Parameters:
component
- JMenuItem to display shortcuts.action
- action which shortcuts will be displayed.
-
getFactory
public com.nomagic.actions.MenuComponentFactory getFactory()
Return menu component factory- Returns:
- factory
-
setFactory
public void setFactory(com.nomagic.actions.MenuComponentFactory factory)
Set menu component factory- Parameters:
factory
- factory
-
disable
private static void disable(javax.swing.MenuElement element)
Change the enable status of the given component depend on its action enable status.- Parameters:
element
- The given element.
-
isSeparatorComponent
public static boolean isSeparatorComponent(@CheckForNull java.awt.Component component)
-
addCleanupParticipant
protected void addCleanupParticipant(java.lang.Runnable participant)
-
-