Class ListProperty<T>

java.lang.Object
ca.corbett.extras.properties.AbstractProperty
ca.corbett.extras.properties.ListProperty<T>

public class ListProperty<T> extends AbstractProperty
Wraps a ListField to allow for a multi-select property. You can use any type for the list items, but they must have a meaningful toString() implementation for displaying in the list.
Since:
swing-extras 2.3
Author:
scorbo2
  • Constructor Details

    • ListProperty

      public ListProperty(String name, String label)
  • Method Details

    • getItems

      public List<T> getItems()
      Returns a copy of the list of all items in this list, regardless of whether they are selected or not.
    • getSelectedItems

      public List<T> getSelectedItems()
      Returns a list of all the items in this list that are currently selected. This list may be empty if nothing is selected.
    • setItems

      public ListProperty<T> setItems(List<T> items)
      Sets the items to include in the list. This will reset any current selection.
    • setSelectedItems

      public ListProperty<T> setSelectedItems(List<T> items)
      Clears any current selection and marks each of the given items as selected, if the item exists. Note: this may not do what you expect it to do depending on the current selection mode (default selection mode is MULTIPLE_INTERVAL_SELECTION, which allows multiple non-contiguous items to be selected).
    • setSelectionMode

      public ListProperty<T> setSelectionMode(int selectionMode)
      Sets the list selection model (allowable values are ListSelectionModel.SINGLE_SELECTION, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, and ListSelectionModel.SINGLE_INTERVAL_SELECTION). Any other value is ignored. The default value is MULTIPLE_INTERVAL_SELECTION.
    • setLayoutOrientation

      public ListProperty<T> setLayoutOrientation(int orientation)
      Sets the layout orientation (allowable values are JList.VERTICAL, JList.VERTICAL_WRAP, and JList.HORIZONTAL_WRAP). Any other value is ignored. The default value is VERTICAL.
    • setVisibleRowCount

      public ListProperty<T> setVisibleRowCount(int count)
      Sets the desired visible row count. The default count is 4.
    • getFixedCellWidth

      public int getFixedCellWidth()
      Returns the pixel width of each list cell. A value of -1 here means the list cells will auto-size their widths based on the width of the longest item in the list.
    • setFixedCellWidth

      public ListProperty<T> setFixedCellWidth(int width)
      Sets the pixel width of each list cell. The default value is -1, which will set each cell's width to the width of the largest item.
    • saveToProps

      public void saveToProps(Properties props)
      Description copied from class: AbstractProperty
      Saves the current value(s) of this property to the given Properties instance.
      Specified by:
      saveToProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which will receive the value(s) of this property.
    • loadFromProps

      public void loadFromProps(Properties props)
      Description copied from class: AbstractProperty
      Loads the value(s) for this property from the given Properties instance, overwriting any current value. The current value of this property will be used as a default value in the event that this property does not exist in the given Properties instance.
      Specified by:
      loadFromProps in class AbstractProperty
      Parameters:
      props - Any Properties instance which contains value(s) for this property.
    • generateFormFieldImpl

      protected FormField generateFormFieldImpl()
      Description copied from class: AbstractProperty
      Descendant classes must implement this method to generate a FormField associated with this property. The generateFormField() method in this class will call this abstract method to create the FormField, which will then be augmented with our fully qualified name, read-only state, help text, and extra attributes.
      Specified by:
      generateFormFieldImpl in class AbstractProperty
      Returns:
      A FormField associated with this property.
    • loadFromFormField

      public void loadFromFormField(FormField field)
      Description copied from class: AbstractProperty
      Populates this Property's value(s) from the given form field, assuming the field is of the correct type.
      Specified by:
      loadFromFormField in class AbstractProperty
      Parameters:
      field - The FormField containing a value for this property.