ca.odell.glazedlists.swing

Class EventListModel<E>

Implemented Interfaces:
EventListener, ListEventListener<E>, ListModel
Known Direct Subclasses:
EventComboBoxModel<E>

public class EventListModel<E>
extends java.lang.Object
implements ListEventListener<E>, ListModel

An EventListModel 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 EventListModel 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).

Author:
Jesse Wilson
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

Constructor Summary

EventListModel(EventList source)
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 EventListModel 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)
Retrieves the value at the specified location from the table.
int
getSize()
Gets the size of the list.
void
listChanged(ListEvent listChanges)
For implementing the ListEventListener interface.
void
removeListDataListener(ListDataListener listDataListener)
Deregisters the specified ListDataListener from receiving updates whenever this list changes.

Field Details

listDataEvent

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

Constructor Details

EventListModel

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

Method Details

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.


dispose

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

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

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


fireListDataEvent

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

getElementAt

public Object getElementAt(int index)
Retrieves the value at the specified location from the table. Before every get, we need to validate the row because there may be an update waiting in the event queue. For example, it is possible that the source list has been updated by a database thread. Such a change may have been sent as notification, but after this request in the event queue. In the case where a row is no longer available, null is returned. The value returned is insignificant in this case because the Event queue will very shortly be repainting (or removing) the row anyway.

getSize

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

listChanged

public void listChanged(ListEvent listChanges)
For implementing the ListEventListener interface. This sends changes to the table which can repaint the table cells. Because this class uses a EventThreadProxy, it is guaranteed that all natural calls to this method use 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>

removeListDataListener

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

Glazed Lists, Copyright © 2003 publicobject.com, O'Dell Engineering.
Documentation build by pbuilder at 2009-07-14 22:05