Package com.nomagic.actions
Class SelectItemAction
java.lang.Object
javax.swing.AbstractAction
com.nomagic.actions.NMAction
com.nomagic.actions.ActionsCategory
com.nomagic.actions.SelectItemAction
- All Implemented Interfaces:
ActionListener
,PropertyChangeListener
,Serializable
,Cloneable
,Comparable
,EventListener
,Action
- Direct Known Subclasses:
SetFontFaceAction
,SetFontSizeAction
Action for selecting item from the list. List can contain any objects which
have correct
toString()
method. When this action is represented
as toolbar GUI component is a combo box. When this action is represented as
menu GUI component is a sub menu. By default combo box and sub menu items
displays only strings from list elements, but it can be changed by overriding
createAction(Object, String)
method which can create another
type of actions used to display list items.
Selected item can be got using getCurrent()
method. When
selection is changed action fires property change event with name
getValueName()
.- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
A name of additional action property for specifying max width of component.Fields inherited from class com.nomagic.actions.ActionsCategory
ACTIONS_PROPERTY, ADDED_ACTION_PROPERTY, CHANGE_ACTIONS_PROPERTY, DISABLE_IF_EMPTY, MAX_CATEGORY_ACTIONS, REMOVE_IF_EMPTY, REMOVED_ACTION_PROPERTY, USE_AS_SEPARATOR_IN_UI
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
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(ActionsVisitor visitor) If given visitor isMainActionsVisitor
, visit this action in different way.clone()
Clones the category.protected SelectionStateItem
createAction
(Object obj, String valueName) Method creates action which represents given object, and firesPropertyChangeEvent
with name valueName when it is executed.List<?>
getItems()
getValue()
Method returns current selection.Returns property name which will be used to fire property change and to put value.boolean
Returns true if new action item can be added.boolean
boolean
void
Listens for child action.void
setChangeable
(boolean val) Sets changeable property.void
setDisplayAsComboBox
(boolean displayAsComboBox) void
Sets List value.void
Deprecated.use #setItems(java.util.List)void
setShowActionName
(boolean showActionName) void
Sets new value of this list action.void
Updates state for actions from actions in list.Methods inherited from class com.nomagic.actions.ActionsCategory
actionPerformed, addAction, addAction, addActionNearTheGiven, addActions, breakActions, breakActions, breakActions, breakeActions, createSeparatorCategory, forEach, forEachIncludingSelf, getAction, getActions, getActionsRecursively, getCategories, isDisplayHeader, isEmpty, isNested, isUseActionForDisable, removeAction, removeIf, setActions, setDisplayHeader, setNested, setUseActionForDisable, shallowClone, size, sort
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
Methods inherited from class javax.swing.AbstractAction
getKeys, getValue, isEnabled, putValue, setEnabled
-
Field Details
-
ADDITIONAL_PROPERTY_MAX_WIDTH
A name of additional action property for specifying max width of component. Toolbar creator may use that setting if needed.- See Also:
-
-
Constructor Details
-
SelectItemAction
public SelectItemAction(String id, String name, @CheckForNull KeyStroke stroke, @CheckForNull String group, @CheckForNull List<?> items, String valueName) Creates action and fills it with action for each element from list.- Parameters:
id
- id of actionname
- action namestroke
- key stroke for action.group
- action group.items
- list of selections.valueName
- name of fired property when value is changed.- See Also:
-
SelectItemAction
public SelectItemAction(String id, String name, int stroke, @CheckForNull String group, @CheckForNull List<?> items, String valueName) Creates action and fills it with action for each element from list.- Parameters:
id
- id of actionname
- action namestroke
- key stroke for action.group
- action group.items
- list selections.valueName
- name of fired property when value is changed.- See Also:
-
-
Method Details
-
setItems
Sets List value. For each item from items new action will be created using createAction method.- Parameters:
items
- items of objects from which actions will be created.
-
getItems
-
setList
Deprecated.use #setItems(java.util.List) -
createAction
Method creates action which represents given object, and firesPropertyChangeEvent
with name valueName when it is executed.- Parameters:
obj
- object from which action will be created.valueName
- property name which should be fired when created action is executed.- See Also:
-
propertyChange
Listens for child action. Puts value got from the event withgetPropertyName()
usingsetCurrent( method )
method. If children actions is state actions updates theirs state.- Specified by:
propertyChange
in interfacePropertyChangeListener
-
updateState
public void updateState()Updates state for actions from actions in list.- Overrides:
updateState
in classNMAction
- See Also:
-
clone
Description copied from class:ActionsCategory
Clones the category. During clone does not fire any property change events. Does deep clone.- Overrides:
clone
in classActionsCategory
- Returns:
- deep clone of category.
-
getValue
Method returns current selection.- Returns:
- currently selected object.
-
isChangeable
public boolean isChangeable()Returns true if new action item can be added.- Returns:
- true if this action is changeable.
-
setChangeable
public void setChangeable(boolean val) Sets changeable property.- Parameters:
val
- new value.
-
setValue
Sets new value of this list action. -
getValueName
Returns property name which will be used to fire property change and to put value.- Returns:
- property name.
-
accept
If given visitor isMainActionsVisitor
, visit this action in different way.- Overrides:
accept
in classActionsCategory
- Parameters:
visitor
- the given visitor.
-
isShowActionName
public boolean isShowActionName() -
setShowActionName
public void setShowActionName(boolean showActionName) -
isDisplayAsComboBox
public boolean isDisplayAsComboBox() -
setDisplayAsComboBox
public void setDisplayAsComboBox(boolean displayAsComboBox)
-