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 class
JosmComboBoxModel.Preferences
Loads 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 void
addAllElements(java.util.Collection<E> elems)
Adds all elements from the collection.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.void
addElement(E element)
Adds an element to the end of the model.E
addTopElement(E newElement)
Adds an element to the top of the list.java.util.Collection<E>
asCollection()
Returns a copy of the element list.protected void
doAddElement(E element)
E
find(java.lang.String s)
Finds the item that matches string.E
getElementAt(int index)
int
getIndexOf(E element)
Returns the index of the specified elementjava.lang.Object
getSelectedItem()
int
getSize()
void
insertElementAt(E element, int index)
Adds an element at a specific index.java.util.Iterator<E>
iterator()
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.void
removeAllElements()
Empties the list.void
removeElement(java.lang.Object elem)
void
removeElementAt(int index)
void
setSelectedItem(java.lang.Object elem)
Set the value of the selected item.void
setSize(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
ComboBoxModel
interface 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:
iterator
in 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:
addElement
in interfacejavax.swing.MutableComboBoxModel<E>
-
removeElement
public void removeElement(java.lang.Object elem)
- Specified by:
removeElement
in interfacejavax.swing.MutableComboBoxModel<E>
-
removeElementAt
public void removeElementAt(int index)
- Specified by:
removeElementAt
in interfacejavax.swing.MutableComboBoxModel<E>
-
insertElementAt
public void insertElementAt(E element, int index)
Adds an element at a specific index.- Specified by:
insertElementAt
in 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:
setSelectedItem
in interfacejavax.swing.ComboBoxModel<E>
- Parameters:
elem
- The combo box value or null for no selection.
-
getSelectedItem
public java.lang.Object getSelectedItem()
- Specified by:
getSelectedItem
in interfacejavax.swing.ComboBoxModel<E>
-
getElementAt
public E getElementAt(int index)
- Specified by:
getElementAt
in 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
- AFunction
that 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
- AFunction
that builds an<E>
from aString
.writeE
- AFunction
that serializes an<E>
to aString
- Returns:
- The
JosmComboBoxModel.Preferences
instance.
-
-