jview
Class MyList.MyListModel

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by jview.MyList.MyListModel
All Implemented Interfaces:
Serializable, ListModel
Enclosing class:
MyList

public static class MyList.MyListModel
extends AbstractListModel

A list model that is based on a true array list. Allows also multiple replacements without notifying the listeners on every single add.

See Also:
Serialized Form

Field Summary
private  List<Object> delegate
          We are backing up with this list.
 
Fields inherited from class javax.swing.AbstractListModel
listenerList
 
Constructor Summary
MyList.MyListModel()
           
MyList.MyListModel(List<Object> pre)
          Supported constructor either with a predfined list.
 
Method Summary
 void add(int index, Object obj)
          Inserts the specified object as a component in this list at the specified index.
 void add(Object obj)
          Adds the specified component to the end of this list.
 void addAll(Collection<Object> c)
           
 void clear()
          Removes all components from this list and sets its size to zero.
 boolean contains(Object elem)
          Tests whether the specified object is a component in this list.
 Object getElementAt(int index)
          Returns the component at the specified index.
 int getSize()
          Returns the number of components in this list.
 int indexOf(Object elem)
          Searches for the first occurrence of elem.
 boolean isEmpty()
          Tests whether this list has any components.
 int lastIndexOf(Object elem)
          Returns the index of the last occurrence of elem.
 void remove(int index)
          Deletes the component at the specified index.
 boolean remove(Object obj)
          Removes the first (lowest-indexed) occurrence of the argument from this list.
 void set(int index, Object obj)
          Sets the component at the specified index of this list to be the specified object.
 int size()
          Returns the number of components in this list.
 String toString()
          Returns a string that displays and identifies this object's properties.
 
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, wait, wait, wait
 

Field Detail

delegate

private List<Object> delegate
We are backing up with this list.

Constructor Detail

MyList.MyListModel

public MyList.MyListModel(List<Object> pre)
Supported constructor either with a predfined list. Objects are copied.


MyList.MyListModel

public MyList.MyListModel()
Method Detail

getSize

public int getSize()
Returns the number of components in this list.

This method is identical to size, which implements the List interface defined in the 1.2 Collections framework. This method exists in conjunction with setSize so that size is identifiable as a JavaBean property.

Returns:
the number of components in this list
See Also:
size()

getElementAt

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

Parameters:
index - an index into this list
Returns:
the component at the specified index
Throws:
ArrayIndexOutOfBoundsException - if the index is negative or greater than the current size of this list
See Also:
#get(int)

size

public int size()
Returns the number of components in this list.

Returns:
the number of components in this list
See Also:
Vector#size()

isEmpty

public boolean isEmpty()
Tests whether this list has any components.

Returns:
true if and only if this list has no components, that is, its size is zero; false otherwise
See Also:
Vector#isEmpty()

contains

public boolean contains(Object elem)
Tests whether the specified object is a component in this list.

Parameters:
elem - an object
Returns:
true if the specified object is the same as a component in this list
See Also:
Vector#contains(Object)

indexOf

public int indexOf(Object elem)
Searches for the first occurrence of elem.

Parameters:
elem - an object
Returns:
the index of the first occurrence of the argument in this list; returns -1 if the object is not found
See Also:
Vector#indexOf(Object)

lastIndexOf

public int lastIndexOf(Object elem)
Returns the index of the last occurrence of elem.

Parameters:
elem - the desired component
Returns:
the index of the last occurrence of elem in the list; returns -1 if the object is not found
See Also:
Vector#lastIndexOf(Object)

set

public void set(int index,
                Object obj)
Sets the component at the specified index of this list to be the specified object. The previous component at that position is discarded.

Throws an ArrayIndexOutOfBoundsException if the index is invalid.

Parameters:
obj - what the component is to be set to
index - the specified index
See Also:
set(int,Object), Vector#setElementAt(Object,int)

remove

public void remove(int index)
Deletes the component at the specified index.

Throws an ArrayIndexOutOfBoundsException if the index is invalid.

Parameters:
index - the index of the object to remove
See Also:
remove(int), Vector#removeElementAt(int)

add

public void add(int index,
                Object obj)
Inserts the specified object as a component in this list at the specified index.

Throws an ArrayIndexOutOfBoundsException if the index is invalid.

Parameters:
obj - the component to insert
index - where to insert the new component
Throws:
ArrayIndexOutOfBoundsException - if the index was invalid
See Also:
add(int,Object), Vector#insertElementAt(Object,int)

add

public void add(Object obj)
Adds the specified component to the end of this list.

Parameters:
obj - the component to be added
See Also:
Vector#addElement(Object)

remove

public boolean remove(Object obj)
Removes the first (lowest-indexed) occurrence of the argument from this list.

Parameters:
obj - the component to be removed
Returns:
true if the argument was a component of this list; false otherwise
See Also:
Vector#removeElement(Object)

clear

public void clear()
Removes all components from this list and sets its size to zero.

See Also:
Vector#removeAllElements()

toString

public String toString()
Returns a string that displays and identifies this object's properties.

Overrides:
toString in class Object
Returns:
a String representation of this object

addAll

public void addAll(Collection<Object> c)