edu.northwestern.at.utils.swing
Class SortedListModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by javax.swing.DefaultListModel
          extended by edu.northwestern.at.utils.swing.SortedListModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.ListModel

public class SortedListModel
extends javax.swing.DefaultListModel

Sorted list model.

This class extends DefaultListModel to support sorted lists.

All elements must implement the Comparable interface.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
SortedListModel()
          Constructs a new empty sorted list model.
 
Method Summary
 void add(int index, java.lang.Object element)
          Prohibits attempts to add elements at specific locations.
 int add(java.lang.Object obj)
          Adds an element to the list.
 void addElement(java.lang.Object element)
          Prohibits attempts to add elements at the end of the list.
 void insertElementAt(java.lang.Object obj, int index)
          Prohibits attempts to add elements at specific locations.
 void redraw(int index)
          Redraws an element after a change.
 boolean remove(java.lang.Object obj)
          Removes an element from the list.
 boolean removeElement(java.lang.Object obj)
          Removes an element from the list.
 java.lang.Object set(int index, java.lang.Object element)
          Prohibits attempts to set an element.
 void setData(java.util.List list)
          Sets new list data.
 void setElementAt(java.lang.Object obj, int index)
          Prohibits attempts to set an element.
 
Methods inherited from class javax.swing.DefaultListModel
capacity, clear, contains, copyInto, elementAt, elements, ensureCapacity, firstElement, get, getElementAt, getSize, indexOf, indexOf, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElementAt, removeRange, setSize, size, toArray, toString, trimToSize
 
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, wait, wait, wait
 

Constructor Detail

SortedListModel

public SortedListModel()
Constructs a new empty sorted list model.

Method Detail

add

public int add(java.lang.Object obj)
Adds an element to the list.

The element must be comparable. It is added in the correct sorted position in the list. If the element or one equal to it is already in the list it is ignored.

Parameters:
obj - The element to be added to the list.
Returns:
The index in the list of the added element, or -1 if it was not added.

removeElement

public boolean removeElement(java.lang.Object obj)
Removes an element from the list.

Overrides:
removeElement in class javax.swing.DefaultListModel
Parameters:
obj - The element to be removed from the list.
Returns:
True if the element was found and removed, false if it was not found.

remove

public boolean remove(java.lang.Object obj)
Removes an element from the list.

This method is the same as removeElement.

Parameters:
obj - The element to be removed from the list.
Returns:
True if the element was found and removed, false if it was not found.

setData

public void setData(java.util.List list)
Sets new list data.

The list is sorted. The sorted list replaces the previous list data.

Parameters:
list - The new list data.

redraw

public void redraw(int index)
Redraws an element after a change.

Parameters:
index - Element index.

addElement

public void addElement(java.lang.Object element)
Prohibits attempts to add elements at the end of the list.

Overrides:
addElement in class javax.swing.DefaultListModel
Throws:
java.lang.UnsupportedOperationException

add

public void add(int index,
                java.lang.Object element)
Prohibits attempts to add elements at specific locations.

Overrides:
add in class javax.swing.DefaultListModel
Throws:
java.lang.UnsupportedOperationException

insertElementAt

public void insertElementAt(java.lang.Object obj,
                            int index)
Prohibits attempts to add elements at specific locations.

Overrides:
insertElementAt in class javax.swing.DefaultListModel
Throws:
java.lang.UnsupportedOperationException

set

public java.lang.Object set(int index,
                            java.lang.Object element)
Prohibits attempts to set an element.

Overrides:
set in class javax.swing.DefaultListModel
Throws:
java.lang.UnsupportedOperationException

setElementAt

public void setElementAt(java.lang.Object obj,
                         int index)
Prohibits attempts to set an element.

Overrides:
setElementAt in class javax.swing.DefaultListModel
Throws:
java.lang.UnsupportedOperationException