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:
java.awt.event.ActionListener
,java.beans.PropertyChangeListener
,java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable
,java.util.EventListener
,javax.swing.Action
- Direct Known Subclasses:
SetFontFaceAction
,SetFontSizeAction
@OpenApiAll public class SelectItemAction extends ActionsCategory implements java.beans.PropertyChangeListener
Action for selecting item from the list. List can contain any objects which have correcttoString()
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 overridingcreateAction(Object, String)
method which can create another type of actions used to display list items. Selected item can be got usinggetCurrent()
method. When selection is changed action fires property change event with namegetValueName()
.- See Also:
createAction(Object, String)
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ADDITIONAL_PROPERTY_MAX_WIDTH
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
-
-
Constructor Summary
Constructors Constructor Description SelectItemAction(java.lang.String id, java.lang.String name, int stroke, java.lang.String group, java.util.List<?> items, java.lang.String valueName)
Creates action and fills it with action for each element from list.SelectItemAction(java.lang.String id, java.lang.String name, javax.swing.KeyStroke stroke, java.lang.String group, java.util.List<?> items, java.lang.String valueName)
Creates action and fills it with action for each element from list.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
accept(ActionsVisitor visitor)
If given visitor isMainActionsVisitor
, visit this action in different way.SelectItemAction
clone()
Clones the category.protected SelectionStateItem
createAction(java.lang.Object obj, java.lang.String valueName)
Method creates action which represents given object, and firesPropertyChangeEvent
with name valueName when it is executed.java.util.List<?>
getItems()
java.lang.Object
getValue()
Method returns current selection.java.lang.String
getValueName()
Returns property name which will be used to fire property change and to put value.boolean
isChangeable()
Returns true if new action item can be added.boolean
isDisplayAsComboBox()
boolean
isShowActionName()
void
propertyChange(java.beans.PropertyChangeEvent e)
Listens for child action.void
setChangeable(boolean val)
Sets changeable property.void
setDisplayAsComboBox(boolean displayAsComboBox)
void
setItems(java.util.List<?> items)
Sets List value.void
setList(java.util.List newList)
Deprecated.use #setItems(java.util.List)void
setShowActionName(boolean showActionName)
void
setValue(java.lang.Object value)
Sets new value of this list action.void
updateState()
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 Detail
-
ADDITIONAL_PROPERTY_MAX_WIDTH
public static final java.lang.String 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:
- Constant Field Values
-
-
Constructor Detail
-
SelectItemAction
public SelectItemAction(java.lang.String id, java.lang.String name, @CheckForNull javax.swing.KeyStroke stroke, @CheckForNull java.lang.String group, @CheckForNull java.util.List<?> items, java.lang.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:
setItems(List)
-
SelectItemAction
public SelectItemAction(java.lang.String id, java.lang.String name, int stroke, @CheckForNull java.lang.String group, @CheckForNull java.util.List<?> items, java.lang.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:
setItems(List)
-
-
Method Detail
-
setItems
public void setItems(@CheckForNull java.util.List<?> items)
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
public java.util.List<?> getItems()
-
setList
@Deprecated public void setList(java.util.List newList)
Deprecated.use #setItems(java.util.List)
-
createAction
protected SelectionStateItem createAction(java.lang.Object obj, java.lang.String valueName)
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:
SelectionStateItem
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent e)
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 interfacejava.beans.PropertyChangeListener
-
updateState
public void updateState()
Updates state for actions from actions in list.- Overrides:
updateState
in classNMAction
- See Also:
NMStateAction.setState(boolean)
-
clone
public SelectItemAction 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
public java.lang.Object 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
public void setValue(java.lang.Object value)
Sets new value of this list action.
-
getValueName
public java.lang.String getValueName()
Returns property name which will be used to fire property change and to put value.- Returns:
- property name.
-
accept
public void accept(ActionsVisitor visitor)
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)
-
-