uk.ac.man.bioinf.gui.misc
Class ChunkyListModel

java.lang.Object
  |
  +--javax.swing.AbstractListModel
        |
        +--uk.ac.man.bioinf.gui.misc.ChunkyListModel
All Implemented Interfaces:
ListModel, Serializable

public class ChunkyListModel
extends AbstractListModel

ChunkyListModel.java This is a small extension to the list model class. It allows the addition of several elements at once, with only one fireIntervalAdded event occuring. The reason for this is essentially performance. The DefaultListModel appears to cause a huge amount of repainting whilst it is being loaded with data, which means that it gets a lot slower to add elements when they already are. Whilst there are probably better ways to solve this problem, the simplest would appear to be add the elements in chunks. Since I have written this code I have found various other ways around the repaint problem. However this code is still pretty useful because its got some nice convenience methods for adding and removing many elements at once. The class name is still pretty terrible though.

Created: Tue Nov 17 13:43:56 1998

Compliant: 1.0

Version:
$Id: ChunkyListModel.java,v 1.4 2001/04/11 17:04:42 lord Exp $
Author:
Phillip Lord
See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
ChunkyListModel()
           
 
Method Summary
 void add(int index, Object element)
           
 void addAll(Collection collection)
          This method takes a collection, adds all the elements, then fires an event.
 void addAll(Object[] object)
          Add all the elements of this array to the list model
 void addAll(Vector vector)
          Add all the elements of this vector to the list model
 void addElement(Object obj)
           
 int capacity()
           
 void clear()
           
 boolean contains(Object elem)
           
 void copyInto(Object[] anArray)
           
 Object elementAt(int index)
           
 Enumeration elements()
           
 void ensureCapacity(int minCapacity)
           
 Object firstElement()
           
 Object get(int index)
           
 Object getElementAt(int index)
           
 int getSize()
          Everything that follows this is just a straight copy from the default list model
 int indexOf(Object elem)
           
 int indexOf(Object elem, int index)
           
 void insertElementAt(Object obj, int index)
           
 boolean isEmpty()
           
 Object lastElement()
           
 int lastIndexOf(Object elem)
           
 int lastIndexOf(Object elem, int index)
           
 Object remove(int index)
           
 void removeAll(Collection collection)
           
 void removeAll(Object[] object)
          Removes all the elements of this array from the list modely
 void removeAll(Vector vector)
           
 void removeAllElements()
           
 boolean removeElement(Object obj)
           
 void removeElementAt(int index)
           
 void removeRange(int fromIndex, int toIndex)
           
 Object set(int index, Object element)
           
 void setElementAt(Object obj, int index)
           
 void setSize(int newSize)
           
 int size()
           
 Object[] toArray()
           
 List toList()
           
 String toString()
           
 void 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

ChunkyListModel

public ChunkyListModel()
Method Detail

addAll

public void addAll(Collection collection)
This method takes a collection, adds all the elements, then fires an event. This method isnt thread safe, call from the event thread only


addAll

public void addAll(Object[] object)
Add all the elements of this array to the list model

Parameters:
object - the array

addAll

public void addAll(Vector vector)
Add all the elements of this vector to the list model

Parameters:
vector - the vector

toList

public List toList()

removeAll

public void removeAll(Object[] object)
Removes all the elements of this array from the list modely

Parameters:
object - the array

removeAll

public void removeAll(Vector vector)

removeAll

public void removeAll(Collection collection)

getSize

public int getSize()
Everything that follows this is just a straight copy from the default list model

Returns:
the size

getElementAt

public Object getElementAt(int index)

copyInto

public void copyInto(Object[] anArray)

trimToSize

public void trimToSize()

ensureCapacity

public void ensureCapacity(int minCapacity)

setSize

public void setSize(int newSize)

capacity

public int capacity()

size

public int size()

isEmpty

public boolean isEmpty()

elements

public Enumeration elements()

contains

public boolean contains(Object elem)

indexOf

public int indexOf(Object elem)

indexOf

public int indexOf(Object elem,
                   int index)

lastIndexOf

public int lastIndexOf(Object elem)

lastIndexOf

public int lastIndexOf(Object elem,
                       int index)

elementAt

public Object elementAt(int index)

firstElement

public Object firstElement()

lastElement

public Object lastElement()

setElementAt

public void setElementAt(Object obj,
                         int index)

removeElementAt

public void removeElementAt(int index)

insertElementAt

public void insertElementAt(Object obj,
                            int index)

addElement

public void addElement(Object obj)

removeElement

public boolean removeElement(Object obj)

removeAllElements

public void removeAllElements()

toString

public String toString()
Overrides:
toString in class Object

toArray

public Object[] toArray()

get

public Object get(int index)

set

public Object set(int index,
                  Object element)

add

public void add(int index,
                Object element)

remove

public Object remove(int index)

clear

public void clear()

removeRange

public void removeRange(int fromIndex,
                        int toIndex)