com.jgoodies.common.collect
Class ArrayListModel<E>

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<E>
          extended by java.util.ArrayList<E>
              extended by com.jgoodies.common.collect.ArrayListModel<E>
Type Parameters:
E - the type of the list elements
All Implemented Interfaces:
ObservableList<E>, Serializable, Cloneable, Iterable<E>, Collection<E>, List<E>, RandomAccess, ListModel

public class ArrayListModel<E>
extends ArrayList<E>
implements ObservableList<E>

Adds ListModel capabilities to its superclass. It allows to observe changes in the content and structure. Useful for Lists that are bound to list views such as JList, JComboBox and JTable.

This class should be be final and it will be marked final in a future version, if its subclass in the JGoodies Binding has been removed.

Version:
$Revision: 1.2 $
Author:
Karsten Lentzsch
See Also:
ObservableList, LinkedListModel, Serialized Form

Field Summary
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ArrayListModel()
          Constructs an empty list with an initial capacity of ten.
ArrayListModel(Collection<? extends E> c)
          Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
ArrayListModel(int initialCapacity)
          Constructs an empty list with the specified initial capacity.
 
Method Summary
 boolean add(E e)
           
 void add(int index, E element)
           
 boolean addAll(Collection<? extends E> c)
           
 boolean addAll(int index, Collection<? extends E> c)
           
 void addListDataListener(ListDataListener l)
           
 void clear()
           
 void fireContentsChanged(int index)
          Notifies all registered ListDataListeners that the element at the specified index has changed.
 Object getElementAt(int index)
           
 ListDataListener[] getListDataListeners()
          Returns an array of all the list data listeners registered on this ArrayListModel.
 int getSize()
           
 E remove(int index)
           
 boolean remove(Object o)
           
 void removeListDataListener(ListDataListener l)
           
protected  void removeRange(int fromIndex, int toIndex)
           
 E set(int index, E element)
           
 
Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeAll, retainAll, size, subList, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
containsAll, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, removeAll, retainAll, size, subList, toArray, toArray
 

Constructor Detail

ArrayListModel

public ArrayListModel()
Constructs an empty list with an initial capacity of ten.


ArrayListModel

public ArrayListModel(int initialCapacity)
Constructs an empty list with the specified initial capacity.

Parameters:
initialCapacity - the initial capacity of the list.
Throws:
IllegalArgumentException - if the specified initial capacity is negative

ArrayListModel

public ArrayListModel(Collection<? extends E> c)
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator. The ArrayListModel instance has an initial capacity of 110% the size of the specified collection.

Parameters:
c - the collection whose elements are to be placed into this list.
Throws:
NullPointerException - if the specified collection is null
Method Detail

add

public final void add(int index,
                      E element)
Specified by:
add in interface List<E>
Overrides:
add in class ArrayList<E>

add

public final boolean add(E e)
Specified by:
add in interface Collection<E>
Specified by:
add in interface List<E>
Overrides:
add in class ArrayList<E>

addAll

public final boolean addAll(int index,
                            Collection<? extends E> c)
Specified by:
addAll in interface List<E>
Overrides:
addAll in class ArrayList<E>

addAll

public final boolean addAll(Collection<? extends E> c)
Specified by:
addAll in interface Collection<E>
Specified by:
addAll in interface List<E>
Overrides:
addAll in class ArrayList<E>

clear

public final void clear()
Specified by:
clear in interface Collection<E>
Specified by:
clear in interface List<E>
Overrides:
clear in class ArrayList<E>

remove

public final E remove(int index)
Specified by:
remove in interface List<E>
Overrides:
remove in class ArrayList<E>

remove

public final boolean remove(Object o)
Specified by:
remove in interface Collection<E>
Specified by:
remove in interface List<E>
Overrides:
remove in class ArrayList<E>

removeRange

protected final void removeRange(int fromIndex,
                                 int toIndex)
Overrides:
removeRange in class ArrayList<E>

set

public final E set(int index,
                   E element)
Specified by:
set in interface List<E>
Overrides:
set in class ArrayList<E>

addListDataListener

public final void addListDataListener(ListDataListener l)
Specified by:
addListDataListener in interface ListModel

removeListDataListener

public final void removeListDataListener(ListDataListener l)
Specified by:
removeListDataListener in interface ListModel

getElementAt

public final Object getElementAt(int index)
Specified by:
getElementAt in interface ListModel

getSize

public final int getSize()
Specified by:
getSize in interface ListModel

fireContentsChanged

public final void fireContentsChanged(int index)
Notifies all registered ListDataListeners that the element at the specified index has changed. Useful if there's a content change without any structural change.

This method must be called after the element of the list changes.

Parameters:
index - the index of the element that has changed
See Also:
EventListenerList

getListDataListeners

public final ListDataListener[] getListDataListeners()
Returns an array of all the list data listeners registered on this ArrayListModel.

Returns:
all of this model's ListDataListeners, or an empty array if no list data listeners are currently registered
See Also:
addListDataListener(ListDataListener), removeListDataListener(ListDataListener)


Copyright © 2009-2010 JGoodies Karsten Lentzsch. All Rights Reserved.