Class AutoCompComboBoxModel<E>
- java.lang.Object
-
- javax.swing.AbstractListModel<E>
-
- org.openstreetmap.josm.gui.widgets.JosmComboBoxModel<E>
-
- org.openstreetmap.josm.gui.tagging.ac.AutoCompComboBoxModel<E>
-
- Type Parameters:
E
- The element type.
- All Implemented Interfaces:
Serializable
,Iterable<E>
,ComboBoxModel<E>
,ListModel<E>
,MutableComboBoxModel<E>
- Direct Known Subclasses:
HistoryComboBoxModel
public class AutoCompComboBoxModel<E> extends JosmComboBoxModel<E>
A data model for theAutoCompComboBox
- Since:
- 18173
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.openstreetmap.josm.gui.widgets.JosmComboBoxModel
JosmComboBoxModel.Preferences
-
-
Field Summary
Fields Modifier and Type Field Description private Comparator<E>
comparator
The comparator used byfindBestCandidate(java.lang.String)
-
Fields inherited from class org.openstreetmap.josm.gui.widgets.JosmComboBoxModel
elements, selected
-
Fields inherited from class javax.swing.AbstractListModel
listenerList
-
-
Constructor Summary
Constructors Constructor Description AutoCompComboBoxModel()
Constructs a new empty model with a defaultcomparator
.AutoCompComboBoxModel(Comparator<E> comparator)
Constructs a new empty model with a customcomparator
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description E
findBestCandidate(String prefix)
Finds the best candidate for autocompletion.void
setComparator(Comparator<E> comparator)
Sets a customcomparator
.-
Methods inherited from class org.openstreetmap.josm.gui.widgets.JosmComboBoxModel
addAllElements, addAllElements, addElement, addTopElement, asCollection, doAddElement, find, getElementAt, getIndexOf, getSelectedItem, getSize, insertElementAt, iterator, prefs, removeAllElements, removeElement, removeElementAt, setSelectedItem, setSize
-
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface javax.swing.ListModel
addListDataListener, removeListDataListener
-
-
-
-
Field Detail
-
comparator
private Comparator<E> comparator
The comparator used byfindBestCandidate(java.lang.String)
The comparator is used exclusively for autocompleting, and not for sorting the combobox entries. The default comparator sorts elements in alphabetical order according to
E::toString
.
-
-
Constructor Detail
-
AutoCompComboBoxModel
public AutoCompComboBoxModel()
Constructs a new empty model with a defaultcomparator
.
-
AutoCompComboBoxModel
public AutoCompComboBoxModel(Comparator<E> comparator)
Constructs a new empty model with a customcomparator
.- Parameters:
comparator
- A customcomparator
.
-
-
Method Detail
-
setComparator
public void setComparator(Comparator<E> comparator)
Sets a customcomparator
.Example:
setComparator(Comparator.comparing(E::getPriority).thenComparing(E::toString));
If
<E>
implementsComparable
you can automagically create a comparator withsetComparator(Comparator.naturalOrder());
.- Parameters:
comparator
- A custom comparator.
-
findBestCandidate
public E findBestCandidate(String prefix)
Finds the best candidate for autocompletion.Looks in the model for an element whose prefix matches
prefix
. If more than one element matchesprefix
, returns the first of the matching elements (first according tocomparator
). An element that is equal toprefix
is always preferred.- Parameters:
prefix
- The prefix to match.- Returns:
- The best candidate (may be null)
-
-