gov.nasa.gsfc.drl.rtstps.library
Class AListModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by gov.nasa.gsfc.drl.rtstps.library.AListModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.ListModel

public class AListModel
extends javax.swing.AbstractListModel

This class implements a list model to be used by JList and JComboBox. It also possesses features so that it can be used by AComboModel.

AListModel combines a java.util.List with an AbstractListModel so that you can use it as a java List and also plug it into a JList. AbstractListModel does not give you these features. This is not an abstract class, so you can use it to create a model.

You can add, change, or remove items in the list through AListModel, or you can change the list directly. However, if you modify the list outside of AListModel, you must call AListModel's fireContentsChanged method afterwards to force the graphics component (JList or JComboBox) to update its view.

The model has property change methods that tell listeners if the model has switched from empty to non-empty or non-empty to empty state. Although not directly used by JList or JComboBox, other listeners can use the property to enable or disable a JList or JComboBox depending on available list data. Attach a property change listener and wait for the "empty" property to change to true or false.

See Also:
Serialized Form

Field Summary
protected  java.util.List<java.lang.String> data
           
private  javax.swing.event.SwingPropertyChangeSupport propSupport
           
private static long serialVersionUID
           
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
AListModel()
          An empty constructor.
AListModel(java.util.Collection<java.lang.String> c)
          This AListModel constructor creates a model constructed from the passed collection.
AListModel(int initialCapacity)
          Construct an AListModel.
AListModel(java.util.List<java.lang.String> list)
          Construct an AListModel using the passed list as a container.
 
Method Summary
 void add(int index, java.lang.String obj)
          Add an object to the model but only if it is not a duplicate (via isEquals).
 void add(java.lang.String obj)
          Append an object to the model but only if it is not a duplicate (via isEquals).
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Add a property change listener to listen for the "empty" property.
 void clear()
          Remove all elements from the model.
 boolean contains(java.lang.Object obj)
          Determine if the model contains the object via the equals method.
 java.lang.Object find(java.lang.Object obj)
          Find an object in the model via the equals method.
 void fireContentsChanged()
          Notify the model that the contents have changed.
 java.lang.Object get(int index)
          Get the element at index index.
 java.lang.Object getElementAt(int index)
          Get the element at index index.
 int getSize()
          Get the current number of elements in the model.
 int indexOf(java.lang.Object obj)
          Get the array index of an object.
 boolean isEmpty()
          Determine if the model has no elements.
 void remove(int index)
          Remove an object from the model.
 void remove(java.lang.Object obj)
          Remove an object from the model.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          Remove a property change listener to listen for the "empty" property.
 void setData(java.util.List<java.lang.String> list)
          Change the underlying collection to a different list.
 void sort()
          Sort the objects in natural order.
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected java.util.List<java.lang.String> data

propSupport

private javax.swing.event.SwingPropertyChangeSupport propSupport

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

AListModel

public AListModel()
An empty constructor. The initial capacity is 10 elements.


AListModel

public AListModel(int initialCapacity)
Construct an AListModel.

Parameters:
initialCapacity - The initial list capacity.

AListModel

public AListModel(java.util.Collection<java.lang.String> c)
This AListModel constructor creates a model constructed from the passed collection.


AListModel

public AListModel(java.util.List<java.lang.String> list)
Construct an AListModel using the passed list as a container.

Method Detail

getSize

public int getSize()
Get the current number of elements in the model. This method satisfies the ListModel interface.


setData

public void setData(java.util.List<java.lang.String> list)
Change the underlying collection to a different list. The model is notified of the change, and property change listeners will receive a property change if the state changes from empty to non-empty or non-empty to empty.


clear

public void clear()
Remove all elements from the model. Property change listeners will receive a property change event if the state changes from non-empty to empty.


getElementAt

public java.lang.Object getElementAt(int index)
Get the element at index index. This method satisfies the ListModel interface. It is the same as get(int).


get

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


fireContentsChanged

public void fireContentsChanged()
Notify the model that the contents have changed. If you change this model's list outside of this model, you must call this method after you change the list.


isEmpty

public boolean isEmpty()
Determine if the model has no elements.


indexOf

public int indexOf(java.lang.Object obj)
Get the array index of an object. The object matches via the equals method.

Returns:
-1 if the object is not in the model.

contains

public boolean contains(java.lang.Object obj)
Determine if the model contains the object via the equals method.


find

public java.lang.Object find(java.lang.Object obj)
Find an object in the model via the equals method.


sort

public void sort()
Sort the objects in natural order. The objects must implement the Comparable interface.

See Also:
Comparable

add

public void add(java.lang.String obj)
Append an object to the model but only if it is not a duplicate (via isEquals). It ignores duplicates. Property change listeners will receive an event message if the state changes from empty to non-empty.


add

public void add(int index,
                java.lang.String obj)
Add an object to the model but only if it is not a duplicate (via isEquals). It ignores duplicates. Property change listeners will receive an event message if the state changes from empty to non-empty.

Parameters:
index - The object is placed at this index location.

remove

public void remove(int index)
Remove an object from the model. Property change listeners will receive an event message if the state changes from non-empty to empty.

Parameters:
index - Remove the object at the index location.

remove

public void remove(java.lang.Object obj)
Remove an object from the model. If the object is not in the model, nothing changes. Property change listeners will receive an event message if the state changes from non-empty to empty.


addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Add a property change listener to listen for the "empty" property.


removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Remove a property change listener to listen for the "empty" property.