Class RmaListModel<E>

java.lang.Object
javax.swing.AbstractListModel<E>
rma.swing.list.RmaListModel<E>
All Implemented Interfaces:
Serializable, ComboBoxModel<E>, ListModel<E>, MutableComboBoxModel<E>

public class RmaListModel<E> extends AbstractListModel<E> implements MutableComboBoxModel<E>, Serializable
a sorted list model for JLists and JComboBoxes
See Also:
  • Field Details

    • _ascendingSort

      protected boolean _ascendingSort
    • _enableSort

      protected boolean _enableSort
    • _caseInsensitiveSort

      protected boolean _caseInsensitiveSort
    • _selectedObject

      protected Object _selectedObject
    • delegate

      protected List<E> delegate
  • Constructor Details

    • RmaListModel

      public RmaListModel()
    • RmaListModel

      public RmaListModel(boolean enableSort)
    • RmaListModel

      public RmaListModel(boolean enableSort, Collection<E> items)
    • RmaListModel

      public RmaListModel(boolean enableSort, E... items)
  • Method Details

    • setAscendingSort

      public void setAscendingSort(boolean tf)
    • isAscendingSort

      public boolean isAscendingSort()
    • getSize

      public int getSize()
      Returns the number of components in this list.

      This method is identical to size(), which implements the List interface defined in the 1.2 Collections framework. This method exists in conjunction with setSize() so that "size" is identifiable as a JavaBean property.

      Specified by:
      getSize in interface ListModel<E>
      Returns:
      the number of components in this list.

      See Also:
    • getElementAt

      public E getElementAt(int index)
      Returns the component at the specified index.
      Note: Although this method is not deprecated, the preferred method to use is get(int), which implements the List interface defined in the 1.2 Collections framework.

      Specified by:
      getElementAt in interface ListModel<E>
      Parameters:
      index - an index into this list.

      Returns:
      the component at the specified index.

      Throws:
      ArrayIndexOutOfBoundsException - if the index is negative or not less than the current size of this list. given.
      See Also:
    • copyInto

      public void copyInto(Object[] anArray)
      Copies the components of this list into the specified array. The array must be big enough to hold all the objects in this list, else an IndexOutOfBoundsException is thrown.
      Parameters:
      anArray - the array into which the components get copied.

      See Also:
    • trimToSize

      @Deprecated public void trimToSize()
      Deprecated.
      Trims the capacity of this list to be the list's current size. No-op unless the delegate is a Vector.
      See Also:
    • ensureCapacity

      @Deprecated public void ensureCapacity(int minCapacity)
      Deprecated.
      Increases the capacity of this list, if necessary, to ensure that it can hold at least the number of components specified by the minimum capacity argument. No-op unless the delegate is a Vector.
      Parameters:
      minCapacity - the desired minimum capacity.

      See Also:
    • setSize

      @Deprecated public void setSize(int newSize)
      Deprecated.
      Sets the size of this list. No-op unless the delegate is a Vector.
      Parameters:
      newSize - the new size of this list.

      See Also:
    • capacity

      @Deprecated public int capacity()
      Deprecated.
      For a vector, Returns the current capacity of this vector For any other list type, returns the size
      Returns:
      the current capacity

      See Also:
    • size

      public int size()
      Returns the number of components in this list.
      Returns:
      the number of components in this list.

      See Also:
    • isEmpty

      public boolean isEmpty()
      Tests if this list has no components.
      Returns:
      true if and only if this list has no components, that is, its size is zero; false otherwise.

      See Also:
    • elements

      @Deprecated public Enumeration<E> elements()
      Deprecated.
      Returns an enumeration of the components of this list.
      Returns:
      an enumeration of the components of this list.

      See Also:
    • iterator

      public Iterator<E> iterator()
    • contains

      public boolean contains(Object elem)
      Tests if the specified object is a component in this list.
      Parameters:
      elem - an object.

      Returns:
      true if the specified object is the same as a component in this list

      See Also:
    • firstIndexOf

      public int firstIndexOf(String match, int index, boolean wrap, boolean wholeWord, boolean caseSensitive)
      Returns the index of an object in this list using a string match.

      Parameters:
      match - The string to match.
      index - The index to start the search at.
      wrap - When the end of the model is reached do we wrap to the front?
      wholeWord - Whether to match only whole words or not.
      caseSensitive - Is the match case sensitive?

      Returns:
      the index of the first object that matches the search criteria; returns -1 if no object matches the search criteria.
    • lastIndexOf

      public int lastIndexOf(String match, int index, boolean wholeWord, boolean caseSensitive)
      Iterating from rear to front, returns the first occurance of an object in this list using a string match.

      Parameters:
      match - The string to match.
      index - The index to start the search at.
      wholeWord - Whether to match only whole words or not.
      caseSensitive - Is the match case sensitive?

      Returns:
      the index of the last object that matches the search criteria; returns -1 if no object matches the search criteria.
    • indexOf

      public int indexOf(Object elem)
      Searches for the first occurence of the given argument.
      Parameters:
      elem - an object.

      Returns:
      the index of the first occurrence of the argument in this list; returns -1 if the object is not found.

      See Also:
    • indexOf

      @Deprecated public int indexOf(Object elem, int index)
      Deprecated.
      Searches for the first occurence of the given argument, beginning the search at index. No-op and returns -1 if delegate is not a vector
      Parameters:
      elem - an object.
      index - the index to start searching from.
      Returns:
      the index of the first occurrence of the object argument in this list at position index or later in the list; returns -1 if the object is not found.

      See Also:
    • lastIndexOf

      public int lastIndexOf(Object elem)
      Returns the index of the last occurrence of the specified object in this list.
      Parameters:
      elem - the desired component.

      Returns:
      the index of the last occurrence of the specified object in this list; returns -1 if the object is not found.

      See Also:
    • lastIndexOf

      @Deprecated public int lastIndexOf(Object elem, int index)
      Deprecated.
      Searches backwards for the specified object, starting from the specified index, and returns an index to it. No-op and returns -1 if delegate is not a vector
      Parameters:
      elem - the desired component.
      index - the index to start searching from.

      Returns:
      the index of the last occurrence of the specified object in this list at position less than index in the list; -1 if the object is not found.

      See Also:
    • get

      public Object get(int index)
      Returns the component at the specified index. Throws an ArrayIndexOutOfBoundsException if the index is negative or not less than the size of the list.
      Note: Although this method is not deprecated, the preferred method to use is get(int), which implements the List interface defined in the 1.2 Collections framework.
      Parameters:
      index - an index into this list.

      Returns:
      the component at the specified index.

      See Also:
    • getIndexOf

      public int getIndexOf(Object anObject)
      Returns the index-position of the specified object in the list.
      Parameters:
      anObject -
      Returns:
      an int representing the index position, where 0 is the first position
    • firstElement

      @Deprecated public Object firstElement()
      Deprecated.
      Returns the first component of this list. Throws a NoSuchElementException if this vector has no components

      Returns:
      the first component of this list

      See Also:
    • lastElement

      @Deprecated public Object lastElement()
      Deprecated.
      Returns the last component of the list. Throws a NoSuchElementException if this vector has no components *
      Returns:
      the last component of the list

      See Also:
    • setElementAt

      public void setElementAt(E obj, int index)
      Sets the component at the specified index of this list to be the specified object. The previous component at that position is discarded.

      Throws an ArrayIndexOutOfBoundsException if the index is invalid.

      Note: Although this method is not deprecated, the preferred method to use is set(int,Object), which implements the List interface defined in the 1.2 Collections framework.
      Parameters:
      obj - what the component is to be set to.
      index - the specified index.

      See Also:
    • removeElementAt

      public void removeElementAt(int index)
      Deletes the component at the specified index.

      Throws an ArrayIndexOutOfBoundsException if the index is invalid.

      Note: Although this method is not deprecated, the preferred method to use is remove(int), which implements the List interface defined in the 1.2 Collections framework.
      Specified by:
      removeElementAt in interface MutableComboBoxModel<E>
      Parameters:
      index - the index of the object to remove.

      See Also:
    • insertElementAt

      public void insertElementAt(E obj, int index)
      Inserts the specified object as a component in this list at the specified index.

      Throws an ArrayIndexOutOfBoundsException if the index is invalid.

      Note: Although this method is not deprecated, the preferred method to use is add(int,Object), which implements the List interface defined in the 1.2 Collections framework.
      Specified by:
      insertElementAt in interface MutableComboBoxModel<E>
      Parameters:
      obj - the component to insert.
      index - where to insert the new component.

      Throws:
      ArrayIndexOutOfBoundsException - if the index was invalid.
      See Also:
    • checkComparable

      public boolean checkComparable(List list)
    • getCaseInsensitiveSort

      public boolean getCaseInsensitiveSort()
    • setCaseInsensitiveSort

      public void setCaseInsensitiveSort(boolean caseInsensitiveSort)
    • sort

      public boolean sort()
    • addElements

      public void addElements(E[] objs)
      Adds the specified components to the list.
      Parameters:
      objs - the components to be added.
    • addElement

      public void addElement(E obj)
      Adds the specified component to the list.
      Specified by:
      addElement in interface MutableComboBoxModel<E>
      Parameters:
      obj - the component to be added.

      See Also:
    • compare

      protected int compare(Object newObj, Object existingObj)
      the method called during inserting an item in the list that is sorted

      See Also:
    • removeElement

      public void removeElement(Object obj)
      Removes the first (lowest-indexed) occurrence of the argument from this list.
      Specified by:
      removeElement in interface MutableComboBoxModel<E>
      Parameters:
      obj - the component to be removed.

      See Also:
    • removeElements

      public void removeElements(Object[] objs)
      Removes the first (lowest-indexed) occurrence of the arguments from this list.
      Parameters:
      objs - the components to be removed.
    • removeAllElements

      public void removeAllElements()
      Removes all components from this list and sets its size to zero.
      Note: Although this method is not deprecated, the preferred method to use is clear(), which implements the List interface defined in the 1.2 Collections framework.
      See Also:
    • toArray

      public Object[] toArray()
      Returns an array containing all of the elements in this list in the correct order.

      Throws an ArrayStoreException if the runtime type of the array a is not a supertype of the runtime type of every element in this list.

      Returns:
      an array containing the elements of the list.
      See Also:
    • elementAt

      public Object elementAt(int index)
      Returns the element at the specified position in this list.

      Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).

      Parameters:
      index - index of element to return.
    • set

      public Object set(int index, E element)
      Replaces the element at the specified position in this list with the specified element.

      Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).

      Parameters:
      index - index of element to replace.
      element - element to be stored at the specified position.

      Returns:
      the element previously at the specified position.
    • add

      public void add(int index, E element)
      Inserts the specified element at the specified position in this list.

      Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).

      Parameters:
      index - index at which the specified element is to be inserted.
      element - element to be inserted.
    • remove

      public Object remove(int index)
      Removes the element at the specified position in this list. Returns the element that was removed from the list.

      Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).

      Parameters:
      index - the index of the element to removed.
    • clear

      public void clear()
      Removes all of the elements from this list. The list will be empty after this call returns (unless it throws an exception).
    • removeRange

      public void removeRange(int fromIndex, int toIndex)
      Deletes the components at the specified range of indexes. The removal is inclusive, so specifying a range of (1,5) removes the component at index 1 and the component at index 5, as well as all components in between.

      Throws an ArrayIndexOutOfBoundsException if the index was invalid. Throws an IllegalArgumentException if fromIndex > toIndex.

      Parameters:
      fromIndex - the index of the lower end of the range
      toIndex - the index of the upper end of the range

      See Also:
    • setEnableSort

      public void setEnableSort(boolean enableSort)
    • isEnableSort

      public boolean isEnableSort()
      Returns true if the list model is sorting its elements.
    • setSelectedItem

      public void setSelectedItem(Object anObject)
      Specified by:
      setSelectedItem in interface ComboBoxModel<E>
    • getSelectedItem

      public Object getSelectedItem()
      Specified by:
      getSelectedItem in interface ComboBoxModel<E>
    • getSelectedIndex

      public int getSelectedIndex()
    • setAll

      public void setAll(E[] o)
      Replaces the current contents with the contents of the Object Array
    • setAll

      public void setAll(Collection<? extends E> c)
    • addAll

      public void addAll(Collection<? extends E> c)
    • addAll

      public void addAll(Object[] o)
    • getVector

      public Vector<E> getVector()
    • getList

      public List<E> getList()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • main

      public static void main(String[] args)
    • fireContentsChanged

      public void fireContentsChanged(int startRowIndex, int endRowIndex)