com.jgoodies.binding.extras
Class ListModelHolder

java.lang.Object
  extended by com.jgoodies.binding.extras.ListModelHolder
All Implemented Interfaces:
com.jgoodies.binding.value.ValueModel, javax.swing.ListModel

public final class ListModelHolder
extends java.lang.Object
implements com.jgoodies.binding.value.ValueModel, javax.swing.ListModel

A ValueHolder implementation that holds instances of ListModel and that is a ListModel itself.

Note: This class is not yet part of the binary Binding library; it comes with the Binding distributions as an extra. The API is work in progress and may change without notice; this class may even be completely removed from future distributions. If you want to use this class, you may consider copying it into your codebase.

Version:
$Revision: 1.2 $
Author:
Karsten Lentzsch, Mattias Neuling

Field Summary
protected  javax.swing.event.EventListenerList listenerList
           
 
Constructor Summary
ListModelHolder(javax.swing.ListModel listModel)
          Constructs a ListModelHolder on the given ListModel.
 
Method Summary
 void addListDataListener(javax.swing.event.ListDataListener l)
          Adds a listener to the list that's notified each time a change to the data model occurs.
 void addValueChangeListener(java.beans.PropertyChangeListener listener)
          Adds the given PropertyChangeListener that will be notified if the value has been changed.
 java.lang.Object getElementAt(int index)
          Returns the value at the specified index, or null if the current value is null
 javax.swing.event.ListDataListener[] getListDataListeners()
          Returns an array of all the list data listeners registered on this ArrayListModel.
 int getSize()
          Returns the length of the list or 0 if there's no list.
 java.lang.Object getValue()
          Returns the observed value.
 void removeListDataListener(javax.swing.event.ListDataListener l)
          Removes a listener from the list that's notified each time a change to the data model occurs.
 void removeValueChangeListener(java.beans.PropertyChangeListener listener)
          Removes the given PropertyChangeListener.
 void setListModel(javax.swing.ListModel newListModel)
          Sets a new list model and notifies any registered value listeners if it has changed.
 void setValue(java.lang.Object newValue)
          Sets a new value and notifies any registered value listeners if the value has changed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listenerList

protected javax.swing.event.EventListenerList listenerList
Constructor Detail

ListModelHolder

public ListModelHolder(javax.swing.ListModel listModel)
Constructs a ListModelHolder on the given ListModel.

Parameters:
listModel - the initial list model
Method Detail

getValue

public java.lang.Object getValue()
Returns the observed value. In case of a write-only value, implementors may choose to either reject this operation or to do nothing.

Specified by:
getValue in interface com.jgoodies.binding.value.ValueModel
Returns:
the observed value

setValue

public void setValue(java.lang.Object newValue)
Sets a new value and notifies any registered value listeners if the value has changed.

Specified by:
setValue in interface com.jgoodies.binding.value.ValueModel
Parameters:
newValue - the ListModel to be set
Throws:
java.lang.ClassCastException - if the new value is not a ListModel

setListModel

public void setListModel(javax.swing.ListModel newListModel)
Sets a new list model and notifies any registered value listeners if it has changed.

Parameters:
newListModel - the ListModel to be set

addValueChangeListener

public void addValueChangeListener(java.beans.PropertyChangeListener listener)
Adds the given PropertyChangeListener that will be notified if the value has been changed.

Changes in the value are checked using == not #equals. This ensures that this class' internal ListDataListener can be moved properly whenever the ListModel instance changes.

Specified by:
addValueChangeListener in interface com.jgoodies.binding.value.ValueModel
Parameters:
listener - the listener to be added
See Also:
ExtendedPropertyChangeSupport

removeValueChangeListener

public void removeValueChangeListener(java.beans.PropertyChangeListener listener)
Removes the given PropertyChangeListener.

Specified by:
removeValueChangeListener in interface com.jgoodies.binding.value.ValueModel
Parameters:
listener - the listener to be removed

addListDataListener

public void addListDataListener(javax.swing.event.ListDataListener l)
Adds a listener to the list that's notified each time a change to the data model occurs.

Specified by:
addListDataListener in interface javax.swing.ListModel
Parameters:
l - the ListDataListener to be added

removeListDataListener

public void removeListDataListener(javax.swing.event.ListDataListener l)
Removes a listener from the list that's notified each time a change to the data model occurs.

Specified by:
removeListDataListener in interface javax.swing.ListModel
Parameters:
l - the ListDataListener to be removed

getElementAt

public java.lang.Object getElementAt(int index)
Returns the value at the specified index, or null if the current value is null

Specified by:
getElementAt in interface javax.swing.ListModel
Parameters:
index - the requested index
Returns:
the value at index or null if the current value is null

getSize

public int getSize()
Returns the length of the list or 0 if there's no list.

Specified by:
getSize in interface javax.swing.ListModel
Returns:
the length of the list or 0 if there's no list

getListDataListeners

public javax.swing.event.ListDataListener[] getListDataListeners()
Returns an array of all the list data listeners registered on this ArrayListModel.

Returns:
all of this model's ListDataListeners, or an empty array if no list data listeners are currently registered
See Also:
addListDataListener(ListDataListener), removeListDataListener(ListDataListener)