Class JosmComboBoxModel<E>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      class  JosmComboBoxModel.Preferences
      Loads and saves the model to the JOSM preferences.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.ArrayList<E> elements
      the elements shown in the dropdown
      private int maxSize
      The maximum number of elements to hold, -1 for no limit.
      protected java.lang.Object selected
      the selected element in the dropdown or null
      • Fields inherited from class javax.swing.AbstractListModel

        listenerList
    • 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 element
      java.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
      • 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

      • maxSize

        private int maxSize
        The maximum number of elements to hold, -1 for no limit. Used for histories.
      • elements

        protected java.util.ArrayList<E> elements
        the elements shown in the dropdown
      • selected

        protected java.lang.Object selected
        the selected element in the dropdown or null
    • 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<EasCollection()
        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 element

        Note: This is not part of the ComboBoxModel interface but is defined in DefaultComboBoxModel.

        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
      • iterator

        public java.util.Iterator<Eiterator()
        Specified by:
        iterator in interface java.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 interface javax.swing.MutableComboBoxModel<E>
      • removeElement

        public void removeElement​(java.lang.Object elem)
        Specified by:
        removeElement in interface javax.swing.MutableComboBoxModel<E>
      • removeElementAt

        public void removeElementAt​(int index)
        Specified by:
        removeElementAt in interface javax.swing.MutableComboBoxModel<E>
      • insertElementAt

        public void insertElementAt​(E element,
                                    int index)
        Adds an element at a specific index.
        Specified by:
        insertElementAt in interface javax.swing.MutableComboBoxModel<E>
        Parameters:
        element - The element to add
        index - 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 interface javax.swing.ComboBoxModel<E>
        Parameters:
        elem - The combo box value or null for no selection.
      • getSelectedItem

        public java.lang.Object getSelectedItem()
        Specified by:
        getSelectedItem in interface javax.swing.ComboBoxModel<E>
      • getSize

        public int getSize()
        Specified by:
        getSize in interface javax.swing.ListModel<E>
      • getElementAt

        public E getElementAt​(int index)
        Specified by:
        getElementAt in interface javax.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 - A Function that builds an <E> from a String.
      • 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.
      • find

        public E find​(java.lang.String s)
        Finds the item that matches string.

        Looks in the model for an element whose toString() matches s.

        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 - A Function that builds an <E> from a String.
        writeE - A Function that serializes an <E> to a String
        Returns:
        The JosmComboBoxModel.Preferences instance.