ca.odell.glazedlists.swing
Class DefaultEventListModel<E>

java.lang.Object
  extended by ca.odell.glazedlists.swing.DefaultEventListModel<E>
All Implemented Interfaces:
ListEventListener<E>, EventListener, ListModel
Direct Known Subclasses:
DefaultEventComboBoxModel, EventListModel

public class DefaultEventListModel<E>
extends Object
implements ListEventListener<E>, ListModel

A DefaultEventListModel adapts an EventList to the ListModel interface making it appropriate for use with a JList. Each element of the list corresponds to an element in the ListModel.

The DefaultEventListModel class is not thread-safe. Unless otherwise noted, all methods are only safe to be called from the event dispatch thread. To do this programmatically, use SwingUtilities.invokeAndWait(Runnable) and wrap the source list (or some part of the source list's pipeline) using GlazedListsSwing.swingThreadProxyList(EventList).

Author:
Jesse Wilson, Holger Brands
See Also:
Bug 14, Bug 146, Bug 177, Bug 228, SwingUtilities.invokeAndWait(Runnable)

Field Summary
protected  ca.odell.glazedlists.swing.MutableListDataEvent listDataEvent
          recycle the list data event to prevent unnecessary object creation
protected  EventList<E> source
          the source EventList
 
Constructor Summary
  DefaultEventListModel(EventList<E> source)
          Creates a new model that contains all objects located in the given source and reacts to any changes in the given source.
protected DefaultEventListModel(EventList<E> source, boolean disposeSource)
          Creates a new model that contains all objects located in the given source and reacts to any changes in the given source.
 
Method Summary
 void addListDataListener(ListDataListener listDataListener)
          Registers the specified ListDataListener to receive updates whenever this list changes.
 void dispose()
          Releases the resources consumed by this DefaultEventListModel so that it may eventually be garbage collected.
protected  void fireListDataEvent(ListDataEvent listDataEvent)
          Notifies all ListDataListeners about one block of changes in the list.
 Object getElementAt(int index)
          Returns the value at the specified index.
 int getSize()
          Gets the size of the list.
 void listChanged(ListEvent<E> listChanges)
          For implementing the ListEventListener interface.
 void removeListDataListener(ListDataListener listDataListener)
          Deregisters the specified ListDataListener from receiving updates whenever this list changes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

source

protected EventList<E> source
the source EventList


listDataEvent

protected final ca.odell.glazedlists.swing.MutableListDataEvent listDataEvent
recycle the list data event to prevent unnecessary object creation

Constructor Detail

DefaultEventListModel

public DefaultEventListModel(EventList<E> source)
Creates a new model that contains all objects located in the given source and reacts to any changes in the given source.

Parameters:
source - the EventList that provides the elements

DefaultEventListModel

protected DefaultEventListModel(EventList<E> source,
                                boolean disposeSource)
Creates a new model that contains all objects located in the given source and reacts to any changes in the given source.

Parameters:
source - the EventList that provides the elements
diposeSource - true if the source list should be disposed when disposing this model, false otherwise
Method Detail

listChanged

public void listChanged(ListEvent<E> listChanges)
For implementing the ListEventListener interface. This sends changes to the table which can repaint the table cells. It's checked that all natural calls to this method arrive on the Swing thread.

This always sends discrete changes for the complete size of the list. It may be more efficient to implement a threshhold where a large list of changes are grouped together as a single change. This is how the ListTable accepts large change events.

Specified by:
listChanged in interface ListEventListener<E>
Parameters:
listChanges - a ListEvent describing the changes to the list

getElementAt

public Object getElementAt(int index)
Returns the value at the specified index.

Specified by:
getElementAt in interface ListModel
Parameters:
index - the requested index
Returns:
the value at index

getSize

public int getSize()
Gets the size of the list.

Specified by:
getSize in interface ListModel

addListDataListener

public void addListDataListener(ListDataListener listDataListener)
Registers the specified ListDataListener to receive updates whenever this list changes.

The specified ListDataListener must not save a reference to the ListDataEvent beyond the end of the notification method. This is because the ListDataEvent is re-used to increase the performance of this implementation.

Specified by:
addListDataListener in interface ListModel

removeListDataListener

public void removeListDataListener(ListDataListener listDataListener)
Deregisters the specified ListDataListener from receiving updates whenever this list changes.

Specified by:
removeListDataListener in interface ListModel

fireListDataEvent

protected void fireListDataEvent(ListDataEvent listDataEvent)
Notifies all ListDataListeners about one block of changes in the list.


dispose

public void dispose()
Releases the resources consumed by this DefaultEventListModel so that it may eventually be garbage collected.

An DefaultEventListModel will be garbage collected without a call to dispose(), but not before its source EventList is garbage collected. By calling dispose(), you allow the DefaultEventListModel to be garbage collected before its source EventList. This is necessary for situations where an DefaultEventListModel is short-lived but its source EventList is long-lived.

Warning: It is an error to call any method on an DefaultEventListModel after it has been disposed. As such, this DefaultEventListModel should be detached from its corresponding Component before it is disposed.



Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by hbrands at 2013-02-12 20:58