Class 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 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:
    createAction(Object, String), Serialized Form
    • 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 action
        name - action name
        stroke - 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 action
        name - action name
        stroke - 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 fires PropertyChangeEvent 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 with getPropertyName() using setCurrent( method ) method. If children actions is state actions updates theirs state.
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
      • clone

        public SelectItemAction clone()
        Description copied from class: ActionsCategory
        Clones the category. During clone does not fires any property change events. Does deep clone.
        Overrides:
        clone in class ActionsCategory
        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 is MainActionsVisitor, visit this action in different way.
        Overrides:
        accept in class ActionsCategory
        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)