Class JosmComboBoxModel<E>
java.lang.Object
javax.swing.AbstractListModel<E>
org.openstreetmap.josm.gui.widgets.JosmComboBoxModel<E>
- Type Parameters:
E- The element type.
- All Implemented Interfaces:
Serializable,Iterable<E>,ComboBoxModel<E>,ListModel<E>,MutableComboBoxModel<E>
- Direct Known Subclasses:
AbstractListMergeModel.ComparePairListModel,AutoCompComboBoxModel,LanguagePreference.LanguageComboBoxModel
public class JosmComboBoxModel<E>
extends AbstractListModel<E>
implements MutableComboBoxModel<E>, Iterable<E>
A data model for the
JosmComboBox- Since:
- 18221
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classLoads and saves the model to the JOSM preferences. -
Field Summary
FieldsModifier and TypeFieldDescriptionthe elements shown in the dropdownprivate intThe maximum number of elements to hold, -1 for no limit.protected Objectthe selected element in the dropdown or nullFields inherited from class javax.swing.AbstractListModel
listenerList -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAllElements(Collection<E> elems) Adds all elements from the collection.voidaddAllElements(Collection<String> strings, Function<String, E> buildE) Adds all elements from the collection of string representations.voidaddElement(E element) Adds an element to the end of the model.addTopElement(E newElement) Adds an element to the top of the list.Returns a copy of the element list.protected voiddoAddElement(E element) Finds the item that matches string.getElementAt(int index) intgetIndexOf(E element) Returns the index of the specified elementintgetSize()voidinsertElementAt(E element, int index) Adds an element at a specific index.iterator()Gets a preference loader and saver.voidEmpties the list.voidremoveElement(Object elem) voidremoveElementAt(int index) voidsetSelectedItem(Object elem) Set the value of the selected item.voidsetSize(int size) Sets the maximum number of elements.Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliteratorMethods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
-
Field Details
-
maxSize
The maximum number of elements to hold, -1 for no limit. Used for histories. -
elements
the elements shown in the dropdown -
selected
the selected element in the dropdown or null
-
-
Constructor Details
-
JosmComboBoxModel
public JosmComboBoxModel()
-
-
Method Details
-
setSize
Sets the maximum number of elements.- Parameters:
size- The maximal number of elements in the model.
-
asCollection
Returns a copy of the element list.- Returns:
- a copy of the data
-
getIndexOf
Returns the index of the specified elementNote: This is not part of the
ComboBoxModelinterface but is defined inDefaultComboBoxModel.- Parameters:
element- the element to get the index of- Returns:
- the index of the first occurrence of the specified element in this model, or -1 if this model does not contain the element
-
doAddElement
-
iterator
-
addElement
Adds an element to the end of the model. Does nothing if max size is already reached.- Specified by:
addElementin interfaceMutableComboBoxModel<E>
-
removeElement
- Specified by:
removeElementin interfaceMutableComboBoxModel<E>
-
removeElementAt
- Specified by:
removeElementAtin interfaceMutableComboBoxModel<E>
-
insertElementAt
Adds an element at a specific index.- Specified by:
insertElementAtin interfaceMutableComboBoxModel<E>- Parameters:
element- The element to addindex- Location to add the element
-
setSelectedItem
Set the value of the selected item. The selected item may be null.- Specified by:
setSelectedItemin interfaceComboBoxModel<E>- Parameters:
elem- The combo box value or null for no selection.
-
getSelectedItem
- Specified by:
getSelectedItemin interfaceComboBoxModel<E>
-
getSize
-
getElementAt
- Specified by:
getElementAtin interfaceListModel<E>
-
addAllElements
Adds all elements from the collection.- Parameters:
elems- The elements to add.
-
addAllElements
Adds all elements from the collection of string representations.- Parameters:
strings- The string representation of the elements to add.buildE- AFunctionthat builds an<E>from aString.
-
addTopElement
Adds an element to the top of the list.If the element is already in the model, moves it to the top. If the model gets too big, deletes the last element.
- Parameters:
newElement- the element to add- Returns:
- The element that is at the top now.
-
removeAllElements
Empties the list. -
find
Finds the item that matches string.Looks in the model for an element whose
toString()matchess.- Parameters:
s- The string to match.- Returns:
- The item or null
-
prefs
Gets a preference loader and saver.- Parameters:
readE- AFunctionthat builds an<E>from aString.writeE- AFunctionthat serializes an<E>to aString- Returns:
- The
JosmComboBoxModel<E>.Preferencesinstance.
-