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 ArrayListModel<E>
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.List<E>, java.util.RandomAccess, javax.swing.ListModel

public class ArrayListModel<E>
extends java.util.ArrayList<E>
implements javax.swing.ListModel

ArrayList which can be used as a ListModel in UI code

See Also:
Serialized Form

Field Summary
static ArrayListModel EMPTY_LIST
          The empty list (immutable).
protected  java.util.List<javax.swing.event.ListDataListener> listDataListeners
          List of ListDataListeners
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
ArrayListModel()
           
 
Method Summary
 boolean add(E o)
          Augments superclass method to fire an appropriate event when an item is added to the collection
 void add(int index, E element)
          Augments superclass method to fire an appropriate event when an item is added to the collection.
 boolean addAll(java.util.Collection<? extends E> coll)
          Augments superclass method to fire an appropriate event when a collection is added to this collection
 void addListDataListener(javax.swing.event.ListDataListener listener)
          Implementation of the method in the ListModel interface
 void clear()
          Augments superclass method to fire an appropriate event when the collection is emptied
protected  void fireIntervalAdded(int firstIndex, int lastIndex)
          Helper method to fire an event to all listeners when an interval in the collection is added
protected  void fireIntervalRemoved(int firstIndex, int lastIndex)
          Helper method to fire an event to all listeners when an interval in the collection is removed
protected  void fireIntervalUpdated(int firstIndex, int lastIndex)
          Helper method to fire an event to all listeners when an interval in the collection is updated
 java.lang.Object getElementAt(int index)
          Implementation of the method in the ListModel interface
 int getSize()
          Implementation of the method in the ListModel interface
 E remove(int index)
          Augments superclass method to fire an appropriate event when the element at the given index is removed from the collection
 boolean remove(java.lang.Object obj)
          Overrides superclass method, forwarding it to the remove(index) method so the appropriate event can be fired.
 boolean removeAll(java.util.Collection coll)
          Augments superclass method to fire an appropriate event when the given collection is removed from this collection
 void removeListDataListener(javax.swing.event.ListDataListener listener)
          Implementation of the method in the ListModel interface
 void removeRange(int fromIndex, int toIndex)
          Augments superclass method to fire an appropriate event when a range of items is removed from the collection
 boolean retainAll(java.util.Collection<?> c)
          Augments superclass method to fire an appropriate event when the given collection is retained in this collection
 E set(int index, E element)
          Augments superclass method to fire an appropriate event when an item in the collection is modified
 
Methods inherited from class java.util.ArrayList
addAll, clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, size, toArray, toArray, trimToSize
 
Methods inherited from class java.util.AbstractList
equals, hashCode, iterator, listIterator, listIterator, subList
 
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
containsAll, equals, hashCode, iterator, listIterator, listIterator, subList
 

Field Detail

EMPTY_LIST

public static final ArrayListModel EMPTY_LIST
The empty list (immutable). This list is serializable.


listDataListeners

protected java.util.List<javax.swing.event.ListDataListener> listDataListeners
List of ListDataListeners

Constructor Detail

ArrayListModel

public ArrayListModel()
Method Detail

add

public void add(int index,
                E element)
Augments superclass method to fire an appropriate event when an item is added to the collection.

Specified by:
add in interface java.util.List<E>
Overrides:
add in class java.util.ArrayList<E>
Parameters:
index - int
obj - Object

add

public boolean add(E o)
Augments superclass method to fire an appropriate event when an item is added to the collection

Specified by:
add in interface java.util.Collection<E>
Specified by:
add in interface java.util.List<E>
Overrides:
add in class java.util.ArrayList<E>
Parameters:
o - E
Returns:
boolean true (as per the contract of Collection.add())

addAll

public boolean addAll(java.util.Collection<? extends E> coll)
Augments superclass method to fire an appropriate event when a collection is added to this collection

Specified by:
addAll in interface java.util.Collection<E>
Specified by:
addAll in interface java.util.List<E>
Overrides:
addAll in class java.util.ArrayList<E>
Parameters:
coll - Collection
Returns:
boolean true if obj was successfully added

clear

public void clear()
Augments superclass method to fire an appropriate event when the collection is emptied

Specified by:
clear in interface java.util.Collection<E>
Specified by:
clear in interface java.util.List<E>
Overrides:
clear in class java.util.ArrayList<E>

remove

public E remove(int index)
Augments superclass method to fire an appropriate event when the element at the given index is removed from the collection

Specified by:
remove in interface java.util.List<E>
Overrides:
remove in class java.util.ArrayList<E>
Parameters:
index - int
Returns:
the element removed from the list

remove

public boolean remove(java.lang.Object obj)
Overrides superclass method, forwarding it to the remove(index) method so the appropriate event can be fired.

Specified by:
remove in interface java.util.Collection<E>
Specified by:
remove in interface java.util.List<E>
Overrides:
remove in class java.util.ArrayList<E>
Parameters:
obj - Object
Returns:
true if the element was removed, false otherwise

removeRange

public void removeRange(int fromIndex,
                        int toIndex)
Augments superclass method to fire an appropriate event when a range of items is removed from the collection

Overrides:
removeRange in class java.util.ArrayList<E>
Parameters:
fromIndex - int
toIndex - int

removeAll

public boolean removeAll(java.util.Collection coll)
Augments superclass method to fire an appropriate event when the given collection is removed from this collection

Specified by:
removeAll in interface java.util.Collection<E>
Specified by:
removeAll in interface java.util.List<E>
Overrides:
removeAll in class java.util.AbstractCollection<E>
Parameters:
coll - Collection
Returns:
boolean true if the collection was successfully removed

retainAll

public boolean retainAll(java.util.Collection<?> c)
Augments superclass method to fire an appropriate event when the given collection is retained in this collection

Specified by:
retainAll in interface java.util.Collection<E>
Specified by:
retainAll in interface java.util.List<E>
Overrides:
retainAll in class java.util.AbstractCollection<E>
Parameters:
coll - Collection
boolean - true if successful

set

public E set(int index,
             E element)
Augments superclass method to fire an appropriate event when an item in the collection is modified

Specified by:
set in interface java.util.List<E>
Overrides:
set in class java.util.ArrayList<E>
Parameters:
index - int
element - Object

getSize

public int getSize()
Implementation of the method in the ListModel interface

Specified by:
getSize in interface javax.swing.ListModel
Returns:
int
See Also:
ListModel.getSize()

getElementAt

public java.lang.Object getElementAt(int index)
Implementation of the method in the ListModel interface

Specified by:
getElementAt in interface javax.swing.ListModel
Parameters:
index - int
Returns:
Object
See Also:
ListModel.getElementAt(int)

addListDataListener

public void addListDataListener(javax.swing.event.ListDataListener listener)
Implementation of the method in the ListModel interface

Specified by:
addListDataListener in interface javax.swing.ListModel
Parameters:
listener - ListDataListener
See Also:
ListModel.addListDataListener(javax.swing.event.ListDataListener)

removeListDataListener

public void removeListDataListener(javax.swing.event.ListDataListener listener)
Implementation of the method in the ListModel interface

Specified by:
removeListDataListener in interface javax.swing.ListModel
Parameters:
listener - ListDataListener
See Also:
ListModel.removeListDataListener(javax.swing.event.ListDataListener)

fireIntervalAdded

protected void fireIntervalAdded(int firstIndex,
                                 int lastIndex)
Helper method to fire an event to all listeners when an interval in the collection is added

Parameters:
firstIndex - int
lastIndex - int

fireIntervalRemoved

protected void fireIntervalRemoved(int firstIndex,
                                   int lastIndex)
Helper method to fire an event to all listeners when an interval in the collection is removed

Parameters:
firstIndex - int
lastIndex - int

fireIntervalUpdated

protected void fireIntervalUpdated(int firstIndex,
                                   int lastIndex)
Helper method to fire an event to all listeners when an interval in the collection is updated

Parameters:
firstIndex - int
lastIndex - int