com.anthonyeden.lib.util
Class XArrayList

java.lang.Object
  extended byjava.util.AbstractCollection
      extended byjava.util.AbstractList
          extended byjava.util.ArrayList
              extended bycom.anthonyeden.lib.util.XArrayList
All Implemented Interfaces:
java.lang.Cloneable, java.util.Collection, javax.swing.ComboBoxModel, java.util.EventListener, java.util.List, javax.swing.ListModel, java.beans.PropertyChangeListener, java.util.RandomAccess, java.io.Serializable, java.awt.datatransfer.Transferable, XList

public class XArrayList
extends java.util.ArrayList
implements XList

This class extends the ArrayList class to support direct placement of the list in a JList or JComboBox. This class can also listen for PropertyChangeEvents on objects in the collection which have an addPropertyChangeListener(PropertyChangeListener l) method. This option is on by default, but can be turned off to invoid introspection overhead required to find and invoke this method.

Author:
Anthony Eden
See Also:
Serialized Form

Field Summary
static java.awt.datatransfer.DataFlavor dataFlavor
           
static XArrayList EMPTY_LIST
          Constant for an empty XArrayList.
 
Fields inherited from class java.util.AbstractList
modCount
 
Constructor Summary
XArrayList()
           
 
Method Summary
 void add(int index, java.lang.Object element)
          Add the given element to the list at the given index.
 boolean add(java.lang.Object element)
          Add the given object to the list.
 boolean addAll(java.util.Collection collection)
          Add all of the objects in the collection to this collection.
 boolean addAll(int index, java.util.Collection collection)
          Add all elements in the collection to this list inserting at the given index.
 void addListDataListener(javax.swing.event.ListDataListener l)
          Add a ListDataListener.
static XArrayList arrayToList(java.lang.Object[] array)
          Populate an XArrayList with the data from the given object array.
 void clear()
          Clear the list data.
protected  void fireContentsChanged(int index0, int index1)
          Fire a ListDataEvent for the changed interval.
protected  void fireIntervalAdded(int index0, int index1)
          Fire a ListDataEvent for the added interval.
protected  void fireIntervalRemoved(int index0, int index1)
          Fire a ListDataEvent for the removed interval.
 java.lang.Object getElementAt(int index)
          Get the element at the given index.
protected  java.util.ArrayList getListDataListeners()
          Get all registered ListDataListeners
 java.lang.Object getSelectedItem()
          Get the selected item or null if no item is selected.
 int getSize()
          Get the number of elements in the list.
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor dataFlavor)
          Get the transferable data for the given data flavor.
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
          Get an array of supported DataFlavors.
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor dataFlavor)
          Return true if the given DataFlavor is supported.
 void propertyChange(java.beans.PropertyChangeEvent evt)
           
 java.lang.Object remove(int index)
          Remove the object at the given index.
 boolean remove(java.lang.Object object)
          Remove the given object.
 boolean removeAll(java.util.Collection c)
          Remove the objects in the specified collection from this list.
 void removeListDataListener(javax.swing.event.ListDataListener l)
          Remove a ListDataListener.
protected  void removeRange(int startIndex, int endIndex)
          Remove the given range of objects.
 boolean retainAll(java.util.Collection c)
          See the ArrayList retainAll() method.
 void setPropertyChangeListenerEnabled(boolean propertyChangeListenerEnabled)
          Set to false to disable property change listener support.
 void setSelectedItem(java.lang.Object selectedItem)
          Set the selected item.
 
Methods inherited from class java.util.ArrayList
clone, contains, ensureCapacity, get, indexOf, isEmpty, lastIndexOf, set, 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
contains, containsAll, equals, get, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, set, size, subList, toArray, toArray
 

Field Detail

EMPTY_LIST

public static final XArrayList EMPTY_LIST
Constant for an empty XArrayList.


dataFlavor

public static java.awt.datatransfer.DataFlavor dataFlavor
Constructor Detail

XArrayList

public XArrayList()
Method Detail

arrayToList

public static XArrayList arrayToList(java.lang.Object[] array)
Populate an XArrayList with the data from the given object array.

Parameters:
array - The object array
Returns:
The XArrayList

add

public void add(int index,
                java.lang.Object element)
Add the given element to the list at the given index.

Specified by:
add in interface java.util.List
Parameters:
index - The index
element - The element

add

public boolean add(java.lang.Object element)
Add the given object to the list.

Specified by:
add in interface java.util.List
Parameters:
element - The element
Returns:
boolean If the element was added

addAll

public boolean addAll(java.util.Collection collection)
Add all of the objects in the collection to this collection.

Specified by:
addAll in interface java.util.List
Parameters:
collection - The collection to add
Returns:
Return true if this collection was modified

addAll

public boolean addAll(int index,
                      java.util.Collection collection)
Add all elements in the collection to this list inserting at the given index.

Specified by:
addAll in interface java.util.List
Parameters:
index - The offset index
collection - The collection to add

clear

public void clear()
Clear the list data.

Specified by:
clear in interface java.util.List

remove

public java.lang.Object remove(int index)
Remove the object at the given index.

Specified by:
remove in interface java.util.List
Parameters:
index - The index
Returns:
The Object removed or null

remove

public boolean remove(java.lang.Object object)
Remove the given object. Return true if the data was changed (the element was removed).

Specified by:
remove in interface java.util.List
Parameters:
object - The object
Returns:
True if the data was changed

retainAll

public boolean retainAll(java.util.Collection c)
See the ArrayList retainAll() method.

Specified by:
retainAll in interface java.util.List
Parameters:
c - The Collection of objects to retain
Returns:
True if this list was modified

removeAll

public boolean removeAll(java.util.Collection c)
Remove the objects in the specified collection from this list.

Specified by:
removeAll in interface java.util.List
Parameters:
c - The Collection to remove
Returns:
True if this collection was modified

getSize

public int getSize()
Get the number of elements in the list.

Specified by:
getSize in interface javax.swing.ListModel
Returns:
The list size

getElementAt

public java.lang.Object getElementAt(int index)
Get the element at the given index.

Specified by:
getElementAt in interface javax.swing.ListModel
Parameters:
index - The index
Returns:
The Object or null

addListDataListener

public void addListDataListener(javax.swing.event.ListDataListener l)
Add a ListDataListener.

Specified by:
addListDataListener in interface javax.swing.ListModel
Parameters:
l - The ListDataListener

removeListDataListener

public void removeListDataListener(javax.swing.event.ListDataListener l)
Remove a ListDataListener.

Specified by:
removeListDataListener in interface javax.swing.ListModel
Parameters:
l - The ListDataListener

getSelectedItem

public java.lang.Object getSelectedItem()
Get the selected item or null if no item is selected.

Specified by:
getSelectedItem in interface javax.swing.ComboBoxModel
Returns:
The selected item or null

setSelectedItem

public void setSelectedItem(java.lang.Object selectedItem)
Set the selected item. Set this value to null for no selected item.

Specified by:
setSelectedItem in interface javax.swing.ComboBoxModel
Parameters:
selectedItem - The new selected item

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor dataFlavor)
                                 throws java.awt.datatransfer.UnsupportedFlavorException
Get the transferable data for the given data flavor.

Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Parameters:
dataFlavor - The DataFlavor
Returns:
The data
Throws:
java.awt.datatransfer.UnsupportedFlavorException

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Get an array of supported DataFlavors.

Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable
Returns:
An array of DataFlavor objects

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor dataFlavor)
Return true if the given DataFlavor is supported.

Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable
Parameters:
dataFlavor - The DataFlavor
Returns:
True if the DataFlavor is supported

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent evt)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener

setPropertyChangeListenerEnabled

public void setPropertyChangeListenerEnabled(boolean propertyChangeListenerEnabled)
Set to false to disable property change listener support. The default value is true. Warning: do not change this flag while there are objects in the collection. Doing so may cause this collection to remain attached to objects which are removed from the collection.

Parameters:
propertyChangeListenerEnabled - Set to false to disable

getListDataListeners

protected java.util.ArrayList getListDataListeners()
Get all registered ListDataListeners

Returns:
An ArrayList of ListDataListeners

removeRange

protected void removeRange(int startIndex,
                           int endIndex)
Remove the given range of objects.

Parameters:
startIndex - The start index
endIndex - The end index

fireIntervalAdded

protected void fireIntervalAdded(int index0,
                                 int index1)
Fire a ListDataEvent for the added interval.

Parameters:
index0 - The start index
index1 - The end index

fireIntervalRemoved

protected void fireIntervalRemoved(int index0,
                                   int index1)
Fire a ListDataEvent for the removed interval.

Parameters:
index0 - The start index
index1 - The end index

fireContentsChanged

protected void fireContentsChanged(int index0,
                                   int index1)
Fire a ListDataEvent for the changed interval.

Parameters:
index0 - The start index
index1 - The end index


Copyright (c) 2000-2003 Anthony Eden. All Rights Reserved.