project35.util
Class SortableListModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by javax.swing.DefaultListModel
          extended by project35.util.SortableListModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.ListModel

public class SortableListModel
extends javax.swing.DefaultListModel

One shortfall of DefaultListModel is there is no easy way to sort the items. With a Vector you can employ the Collections.sort() convenience method but then you lose update notifications. This is simply a DefaultListModel with a sort function.


Copyright (c) Kevin Garwood and University of Manchester 2007. All rights reserved. Licensed under the Academic Free License version 3.0. For more information on the terms and conditions, please see the file "LICENSE" that is included in this distribution.

Version:
1.0
Author:
Kevin Garwood (kgarwood@users.sourceforge.net), Tim Booth code contributions from 2002 - September 30, 2007.
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
SortableListModel()
          DefaultListModel has but one constructor.
 
Method Summary
 void add(java.lang.Object obj)
          Make add(Object) call addElement(obj)
 void remove(java.lang.Object obj)
          Make remove(Object) call
 void sort()
          Sort the items in the list - logic is: Check if already sorted and if so return Export a Vector, sort, reimport
The screen redraw is the slow part here, assuming the list is not vast.
 void sort(java.util.Comparator comparator)
          As per sort() but you may specify a comparator.
 
Methods inherited from class javax.swing.DefaultListModel
add, addElement, capacity, clear, contains, copyInto, elementAt, elements, ensureCapacity, firstElement, get, getElementAt, getSize, indexOf, indexOf, insertElementAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, remove, removeAllElements, removeElement, removeElementAt, removeRange, set, setElementAt, 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

SortableListModel

public SortableListModel()
DefaultListModel has but one constructor.

Method Detail

sort

public void sort()
Sort the items in the list - logic is:
  1. Check if already sorted and if so return
  2. Export a Vector, sort, reimport

The screen redraw is the slow part here, assuming the list is not vast.
As with Collections.dort all objects must be comparable


sort

public void sort(java.util.Comparator comparator)
As per sort() but you may specify a comparator.

Parameters:
comparator - The comparator to use.

add

public void add(java.lang.Object obj)
Make add(Object) call addElement(obj)

Parameters:
obj - The object to add

remove

public void remove(java.lang.Object obj)
Make remove(Object) call

Parameters:
obj - The object to remove