Class DefaultEventListModel<E>
- java.lang.Object
-
- ca.odell.glazedlists.swing.DefaultEventListModel<E>
-
- All Implemented Interfaces:
ListEventListener<E>,java.util.EventListener,javax.swing.ListModel
- Direct Known Subclasses:
DefaultEventComboBoxModel,EventListModel
public class DefaultEventListModel<E> extends java.lang.Object implements ListEventListener<E>, javax.swing.ListModel
A DefaultEventListModel adapts an EventList to the ListModel interface making it appropriate for use with aJList. Each element of the list corresponds to an element in theListModel.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) usingGlazedListsSwing.swingThreadProxyList(EventList).- Author:
- Jesse Wilson, Holger Brands
- See Also:
- Bug 14,
Bug 146,
Bug 177,
Bug 228,
SwingUtilities.invokeAndWait(Runnable)
-
-
Field Summary
Fields Modifier and Type Field Description protected ca.odell.glazedlists.swing.MutableListDataEventlistDataEventrecycle the list data event to prevent unnecessary object creationprotected EventList<E>sourcethe source EventList
-
Constructor Summary
Constructors Modifier Constructor Description DefaultEventListModel(EventList<E> source)Creates a new model that contains all objects located in the givensourceand reacts to any changes in the givensource.protectedDefaultEventListModel(EventList<E> source, boolean disposeSource)Creates a new model that contains all objects located in the givensourceand reacts to any changes in the givensource.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListDataListener(javax.swing.event.ListDataListener listDataListener)Registers the specified ListDataListener to receive updates whenever this list changes.voiddispose()Releases the resources consumed by thisDefaultEventListModelso that it may eventually be garbage collected.protected voidfireListDataEvent(javax.swing.event.ListDataEvent listDataEvent)Notifies all ListDataListeners about one block of changes in the list.java.lang.ObjectgetElementAt(int index)Returns the value at the specified index.intgetSize()Gets the size of the list.voidlistChanged(ListEvent<E> listChanges)For implementing the ListEventListener interface.voidremoveListDataListener(javax.swing.event.ListDataListener listDataListener)Deregisters the specified ListDataListener from receiving updates whenever this list changes.
-
-
-
Constructor Detail
-
DefaultEventListModel
public DefaultEventListModel(EventList<E> source)
Creates a new model that contains all objects located in the givensourceand reacts to any changes in the givensource.- 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 givensourceand reacts to any changes in the givensource.- Parameters:
source- the EventList that provides the elementsdiposeSource-trueif the source list should be disposed when disposing this model,falseotherwise
-
-
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:
listChangedin interfaceListEventListener<E>- Parameters:
listChanges- aListEventdescribing the changes to the list
-
getElementAt
public java.lang.Object getElementAt(int index)
Returns the value at the specified index.- Specified by:
getElementAtin interfacejavax.swing.ListModel<E>- Parameters:
index- the requested index- Returns:
- the value at
index
-
getSize
public int getSize()
Gets the size of the list.- Specified by:
getSizein interfacejavax.swing.ListModel<E>
-
addListDataListener
public void addListDataListener(javax.swing.event.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:
addListDataListenerin interfacejavax.swing.ListModel<E>
-
removeListDataListener
public void removeListDataListener(javax.swing.event.ListDataListener listDataListener)
Deregisters the specified ListDataListener from receiving updates whenever this list changes.- Specified by:
removeListDataListenerin interfacejavax.swing.ListModel<E>
-
fireListDataEvent
protected void fireListDataEvent(javax.swing.event.ListDataEvent listDataEvent)
Notifies all ListDataListeners about one block of changes in the list.
-
dispose
public void dispose()
Releases the resources consumed by thisDefaultEventListModelso that it may eventually be garbage collected.An
DefaultEventListModelwill be garbage collected without a call todispose(), but not before its sourceEventListis garbage collected. By callingdispose(), you allow theDefaultEventListModelto be garbage collected before its sourceEventList. This is necessary for situations where anDefaultEventListModelis short-lived but its sourceEventListis long-lived.Warning: It is an error to call any method on an
DefaultEventListModelafter it has been disposed. As such, thisDefaultEventListModelshould be detached from its corresponding Component before it is disposed.
-
-