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:
java.io.Serializable,java.lang.Iterable<E>,javax.swing.ComboBoxModel<E>,javax.swing.ListModel<E>,javax.swing.MutableComboBoxModel<E>
- Direct Known Subclasses:
AbstractListMergeModel.ComparePairListModel,AutoCompComboBoxModel,LanguagePreference.LanguageComboBoxModel
public class JosmComboBoxModel<E> extends javax.swing.AbstractListModel<E> implements javax.swing.MutableComboBoxModel<E>, java.lang.Iterable<E>
A data model for theJosmComboBox- Since:
- 18221
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classJosmComboBoxModel.PreferencesLoads and saves the model to the JOSM preferences.
-
Constructor Summary
Constructors Constructor Description JosmComboBoxModel()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAllElements(java.util.Collection<E> elems)Adds all elements from the collection.voidaddAllElements(java.util.Collection<java.lang.String> strings, java.util.function.Function<java.lang.String,E> buildE)Adds all elements from the collection of string representations.voidaddElement(E element)Adds an element to the end of the model.EaddTopElement(E newElement)Adds an element to the top of the list.java.util.Collection<E>asCollection()Returns a copy of the element list.protected voiddoAddElement(E element)Efind(java.lang.String s)Finds the item that matches string.EgetElementAt(int index)intgetIndexOf(E element)Returns the index of the specified elementjava.lang.ObjectgetSelectedItem()intgetSize()voidinsertElementAt(E element, int index)Adds an element at a specific index.java.util.Iterator<E>iterator()JosmComboBoxModel.Preferencesprefs(java.util.function.Function<java.lang.String,E> readE, java.util.function.Function<E,java.lang.String> writeE)Gets a preference loader and saver.voidremoveAllElements()Empties the list.voidremoveElement(java.lang.Object elem)voidremoveElementAt(int index)voidsetSelectedItem(java.lang.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, removeListDataListener
-
-
-
-
Constructor Detail
-
JosmComboBoxModel
public JosmComboBoxModel()
-
-
Method Detail
-
setSize
public void setSize(int size)
Sets the maximum number of elements.- Parameters:
size- The maximal number of elements in the model.
-
asCollection
public java.util.Collection<E> asCollection()
Returns a copy of the element list.- Returns:
- a copy of the data
-
getIndexOf
public int getIndexOf(E element)
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
protected void doAddElement(E element)
-
iterator
public java.util.Iterator<E> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<E>
-
addElement
public void addElement(E element)
Adds an element to the end of the model. Does nothing if max size is already reached.- Specified by:
addElementin interfacejavax.swing.MutableComboBoxModel<E>
-
removeElement
public void removeElement(java.lang.Object elem)
- Specified by:
removeElementin interfacejavax.swing.MutableComboBoxModel<E>
-
removeElementAt
public void removeElementAt(int index)
- Specified by:
removeElementAtin interfacejavax.swing.MutableComboBoxModel<E>
-
insertElementAt
public void insertElementAt(E element, int index)
Adds an element at a specific index.- Specified by:
insertElementAtin interfacejavax.swing.MutableComboBoxModel<E>- Parameters:
element- The element to addindex- Location to add the element
-
setSelectedItem
public void setSelectedItem(java.lang.Object elem)
Set the value of the selected item. The selected item may be null.- Specified by:
setSelectedItemin interfacejavax.swing.ComboBoxModel<E>- Parameters:
elem- The combo box value or null for no selection.
-
getSelectedItem
public java.lang.Object getSelectedItem()
- Specified by:
getSelectedItemin interfacejavax.swing.ComboBoxModel<E>
-
getElementAt
public E getElementAt(int index)
- Specified by:
getElementAtin interfacejavax.swing.ListModel<E>
-
addAllElements
public void addAllElements(java.util.Collection<E> elems)
Adds all elements from the collection.- Parameters:
elems- The elements to add.
-
addAllElements
public void addAllElements(java.util.Collection<java.lang.String> strings, java.util.function.Function<java.lang.String,E> buildE)
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
public E addTopElement(E newElement)
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
public void removeAllElements()
Empties the list.
-
find
public E find(java.lang.String s)
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
public JosmComboBoxModel.Preferences prefs(java.util.function.Function<java.lang.String,E> readE, java.util.function.Function<E,java.lang.String> writeE)
Gets a preference loader and saver.- Parameters:
readE- AFunctionthat builds an<E>from aString.writeE- AFunctionthat serializes an<E>to aString- Returns:
- The
JosmComboBoxModel.Preferencesinstance.
-
-