Package ca.corbett.extras.properties
Class ListProperty<T>
java.lang.Object
ca.corbett.extras.properties.AbstractProperty
ca.corbett.extras.properties.ListProperty<T>
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.
You can add action buttons to the generated ListField via a FormFieldGenerationListener. See ListField for more information on how to do this.
- Since:
- swing-extras 2.3
- Author:
- scorbo2
-
Field Summary
Fields inherited from class ca.corbett.extras.properties.AbstractProperty
categoryName, DEFAULT_CATEGORY, DEFAULT_PROPERTY_NAME, extraAttributes, fullyQualifiedName, helpText, isEnabled, isExposed, isInitiallyEditable, isInitiallyVisible, marginPadding, propertyLabel, propertyName, subCategoryName -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected FormFieldDescendant classes must implement this method to generate a FormField associated with this property.intintIf the ListField generated from this property is to include buttons, this gets the preferred dimensions of those buttons (requires a FormFieldGenerationListener to add buttons).intintReturns the pixel width of each list cell.getItems()Returns a copy of the list of all items in this list, regardless of whether they are selected or not.Returns a list of all the items in this list that are currently selected.voidloadFromFormField(FormField field) Populates this Property's value(s) from the given form field, assuming the field is of the correct type.voidloadFromProps(Properties props) Loads the value(s) for this property from the given Properties instance, overwriting any current value.voidsaveToProps(Properties props) Saves the current value(s) of this property to the given Properties instance.setButtonAlignment(int buttonAlignment) If the ListField generated from this property is to include buttons, this sets the alignment of those buttons (requires a FormFieldGenerationListener to add buttons).setButtonHgap(int buttonHgap) If the ListField generated from this property is to include buttons, this sets the horizontal gap between those buttons (requires a FormFieldGenerationListener to add buttons).setButtonLayout(int buttonAlignment, int buttonHgap, int buttonVgap) A convenience method to set button alignment, horizontal gap, and vertical gap all at once.setButtonPosition(ListField.ButtonPosition buttonPosition) If the ListField generated from this property is to include buttons, this sets the position of those buttons (requires a FormFieldGenerationListener to add buttons).setButtonPreferredDimensions(int buttonPreferredWidth, int buttonPreferredHeight) If the ListField generated from this property is to include buttons, this sets the preferred dimensions of those buttons (requires a FormFieldGenerationListener to add buttons).setButtonVgap(int buttonVgap) If the ListField generated from this property is to include buttons, this sets the vertical gap between those buttons (requires a FormFieldGenerationListener to add buttons).setFixedCellWidth(int width) Sets the pixel width of each list cell.Sets the items to include in the list.setLayoutOrientation(int orientation) Sets the layout orientation (allowable values are JList.VERTICAL, JList.VERTICAL_WRAP, and JList.HORIZONTAL_WRAP).setSelectedItems(List<T> items) Clears any current selection and marks each of the given items as selected, if the item exists.setSelectionMode(int selectionMode) Sets the list selection model (allowable values are ListSelectionModel.SINGLE_SELECTION, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, and ListSelectionModel.SINGLE_INTERVAL_SELECTION).setVisibleRowCount(int count) Sets the desired visible row count.Methods inherited from class ca.corbett.extras.properties.AbstractProperty
addAllExtraAttributes, addBottomPadding, addFormFieldChangeListener, addFormFieldGenerationListener, addInnerPadding, addLeftPadding, addPadding, addRightPadding, addTopPadding, clearExtraAttribute, clearExtraAttributes, equals, fireFormFieldChangedEvent, fireFormFieldGeneratedEvent, generateFormField, generateFormField, getCategoryName, getExtraAttribute, getFullyQualifiedName, getHelpText, getMarginPadding, getPropertyLabel, getPropertyName, getSubCategoryName, hashCode, isAllowsUserInput, isEnabled, isExposed, isInitiallyEditable, isInitiallyVisible, removeAllFormFieldChangeListeners, removeAllFormFieldGenerationListeners, removeFormFieldChangeListener, removeFormFieldGenerationListener, setAllExtraAttributes, setEnabled, setExposed, setExtraAttribute, setHelpText, setInitiallyEditable, setInitiallyVisible, setPropertyLabel
-
Constructor Details
-
ListProperty
-
-
Method Details
-
getItems
Returns a copy of the list of all items in this list, regardless of whether they are selected or not. -
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
Sets the items to include in the list. This will reset any current selection. -
setSelectedItems
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
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
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
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
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. -
getButtonPosition
-
setButtonPosition
If the ListField generated from this property is to include buttons, this sets the position of those buttons (requires a FormFieldGenerationListener to add buttons).- Parameters:
buttonPosition- One of the ListField.ButtonPosition enum values.- Returns:
- This ListProperty, for method chaining.
-
getButtonAlignment
public int getButtonAlignment() -
setButtonAlignment
If the ListField generated from this property is to include buttons, this sets the alignment of those buttons (requires a FormFieldGenerationListener to add buttons).- Parameters:
buttonAlignment- One of FlowLayout's alignment options: LEFT, CENTER, RIGHT, LEADING, or TRAILING from the FlowLayout class.- Returns:
- This ListProperty, for method chaining.
-
getButtonHgap
public int getButtonHgap() -
setButtonHgap
If the ListField generated from this property is to include buttons, this sets the horizontal gap between those buttons (requires a FormFieldGenerationListener to add buttons). -
getButtonVgap
public int getButtonVgap() -
setButtonVgap
If the ListField generated from this property is to include buttons, this sets the vertical gap between those buttons (requires a FormFieldGenerationListener to add buttons).- Parameters:
buttonVgap- The vertical gap in pixels.
-
setButtonLayout
A convenience method to set button alignment, horizontal gap, and vertical gap all at once.- Parameters:
buttonAlignment- One of the FlowLayout alignment options: LEFT, CENTER, RIGHT, LEADING, or TRAILING.buttonHgap- The horizontal gap between buttons, in pixels.buttonVgap- The vertical gap between the buttons and the list, in pixels.- Returns:
- This ListProperty, for method chaining.
-
getButtonPreferredDimensions
If the ListField generated from this property is to include buttons, this gets the preferred dimensions of those buttons (requires a FormFieldGenerationListener to add buttons).- Returns:
- The preferred dimensions, or null to use the button's default preferred size.
-
setButtonPreferredDimensions
public ListProperty<T> setButtonPreferredDimensions(int buttonPreferredWidth, int buttonPreferredHeight) If the ListField generated from this property is to include buttons, this sets the preferred dimensions of those buttons (requires a FormFieldGenerationListener to add buttons).- Parameters:
buttonPreferredWidth- The preferred width in pixels, or 0 to use the button's default preferred width.buttonPreferredHeight- The preferred height in pixels, or 0 to use the button's default preferred height.
-
saveToProps
Description copied from class:AbstractPropertySaves the current value(s) of this property to the given Properties instance.- Specified by:
saveToPropsin classAbstractProperty- Parameters:
props- Any Properties instance which will receive the value(s) of this property.
-
loadFromProps
Description copied from class:AbstractPropertyLoads 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:
loadFromPropsin classAbstractProperty- Parameters:
props- Any Properties instance which contains value(s) for this property.
-
generateFormFieldImpl
Description copied from class:AbstractPropertyDescendant 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:
generateFormFieldImplin classAbstractProperty- Returns:
- A FormField associated with this property.
-
loadFromFormField
Description copied from class:AbstractPropertyPopulates this Property's value(s) from the given form field, assuming the field is of the correct type.- Specified by:
loadFromFormFieldin classAbstractProperty- Parameters:
field- The FormField containing a value for this property.
-