com.gsoft.titration.client
Class StringListModel

java.lang.Object
  |
  +--javax.swing.AbstractListModel
        |
        +--com.gsoft.titration.client.StringListModel
Direct Known Subclasses:
StringComboBoxModel

public class StringListModel
extends AbstractListModel
implements Serializable

A ListModel for String objects.


Field Summary
 protected Vectordelegate
          Storage for the String data items.

Fields inherited from class javax.swing.AbstractListModel
listenerList

Constructor Summary
StringListModel()
          Constructs a empty StringListModel.

Method Summary
 voidadd(int index, Object element)
          Inserts the given value into the list at the specified index.
 voidaddElement(Object obj)
          Appends the value to the end of the list.
 intcapacity()
          Returns the current capacity of the Vector containing the list values.
 voidclear()
          Removes all values saved in the list.
 booleancontains(Object elem)
          Returns true if the given element is one of the values in the list.
 voidcopyInto(Object[] anArray)
          Copies the list values into the given array.
 ObjectelementAt(int index)
          Gets the value at the specified list index.
 Enumerationelements()
          Returns an Enumeration of all of the values in the list.
 voidensureCapacity(int minCapacity)
          Ensures the Vector containing the list values
has enough capacity for the specified number of elements.
 VectorfetchItems()
          Grab a copy of the Vector containing all the items
 ObjectfirstElement()
          Returns the first value in the list.
 Objectget(int index)
          Gets a specific list value.
 ObjectgetElementAt(int index)
          Returns the String as the specified list position.
 String[]getItems()
          Returns an array of the String items in the list.
 intgetSize()
          Returns the number of (String) items in the list.
 intindexOf(Object elem)
          Determines the index of the the first occurance of the specified element.
 intindexOf(Object elem, int index)
          Determines the index of the next occurance of the specified element,
starting the search at the given index.
 voidinsertElementAt(Object obj, int index)
          Inserts the a new value into the list at the specified index.
 booleanisEmpty()
          Returns true if there are no list values present.
 ObjectlastElement()
          Returns the last value in the list.
 intlastIndexOf(Object elem)
          Determines the index of the last occurance of the specified element.
 intlastIndexOf(Object elem, int index)
          Determines the index of the last occurance of the specified element,
searching backwards starting at the given index.
 Objectremove(int index)
          Removes the value saved in the list at the specified index and returns it.
 voidremoveAllElements()
          Removes all values from the list.
 booleanremoveElement(Object obj)
          Removes the specified value from the list.
 voidremoveElementAt(int index)
          Removes the value saved in the list at the specified index.
 voidremoveRange(int fromIndex, int toIndex)
          Removes a range of values from the list.
 Objectset(int index, Object element)
          Sets the list value at the specified index.
 voidsetElementAt(Object obj, int index)
          Sets the value saved in the list at the specified index.
 voidsetItems(String[] items)
          Sets the value of the list to the specified String items.
 voidsetSize(int newSize)
          Sets the size Vector containing the list values
to the specified size.
 intsize()
          Returns the current number of values in the Vector containing the list values.
 Object[]toArray()
          Returns an array contains the list values.
 StringtoString()
          Returns a String representation of the list.
 voidtrimToSize()
          Shrinks the Vector containing the list values to the
minimum required size.

Methods inherited from class javax.swing.AbstractListModel
addListDataListener, removeListDataListener, fireContentsChanged, fireIntervalAdded, fireIntervalRemoved, getListeners

Methods inherited from class java.lang.Object
getClass, hashCode, equals, clone, notify, notifyAll, wait, wait, wait, finalize

Field Detail

delegate

protected Vector delegate
Storage for the String data items.
See Also:
getItems(), setItems(java.lang.String[])
Constructor Detail

StringListModel

public StringListModel()
Constructs a empty StringListModel.
Method Detail

add

public void add(int index, Object element)
Inserts the given value into the list at the specified index.
Parameters:
index the 0-based list index
element the new value
See Also:
setElementAt(java.lang.Object,int), set(int,java.lang.Object)

addElement

public void addElement(Object obj)
Appends the value to the end of the list.
Parameters:
obj the new value
See Also:
setElementAt(java.lang.Object,int), insertElementAt(java.lang.Object,int), removeElement(java.lang.Object), removeElementAt(int), removeAllElements(), elementAt(int)

capacity

public int capacity()
Returns the current capacity of the Vector containing the list values.
See Also:
ensureCapacity(int), size()

clear

public void clear()
Removes all values saved in the list.
See Also:
remove(int), add(int,java.lang.Object), set(int,java.lang.Object), removeAllElements()

contains

public boolean contains(Object elem)
Returns true if the given element is one of the values in the list.

copyInto

public void copyInto(Object[] anArray)
Copies the list values into the given array.
The array must be large enough to contain all of the list values.
Parameters:
anArray the destination array
See Also:
getSize()

elementAt

public Object elementAt(int index)
Gets the value at the specified list index.
Parameters:
index the 0-based list index
Returns: the list value at that index
See Also:
setElementAt(java.lang.Object,int)

elements

public Enumeration elements()
Returns an Enumeration of all of the values in the list.

ensureCapacity

public void ensureCapacity(int minCapacity)
Ensures the Vector containing the list values
has enough capacity for the specified number of elements.
Parameters:
minCapacity the minimum list size
See Also:
capacity(), setSize(int)

fetchItems

public Vector fetchItems()
Grab a copy of the Vector containing all the items
Returns: Vector

firstElement

public Object firstElement()
Returns the first value in the list.
See Also:
lastElement(), elementAt(int)

get

public Object get(int index)
Gets a specific list value.
Parameters:
index the 0-based list index
Returns: the value at the specified index
See Also:
elementAt(int), toArray()

getElementAt

public Object getElementAt(int index)
Returns the String as the specified list position.
Parameters:
index the 0-based index of the list item
See Also:
getItems()

getItems

public String[] getItems()
Returns an array of the String items in the list.
See Also:
getElementAt(int), setItems(java.lang.String[])

getSize

public int getSize()
Returns the number of (String) items in the list.

indexOf

public int indexOf(Object elem)
Determines the index of the the first occurance of the specified element.
Parameters:
elem the value to look for
Returns: the 0-based index of the value in the list, or -1 if the value is not found
See Also:
indexOf(java.lang.Object,int), lastIndexOf(java.lang.Object), lastIndexOf(java.lang.Object,int)

indexOf

public int indexOf(Object elem, int index)
Determines the index of the next occurance of the specified element,
starting the search at the given index.
Parameters:
elem the value to look for
index the 0-based index from which to start searching
Returns: the 0-based index of the value in the list, or -1 if the value is not found
See Also:
indexOf(java.lang.Object), lastIndexOf(java.lang.Object), lastIndexOf(java.lang.Object,int)

insertElementAt

public void insertElementAt(Object obj, int index)
Inserts the a new value into the list at the specified index.
Parameters:
obj the new value
index the 0-based list index
See Also:
addElement(java.lang.Object), setElementAt(java.lang.Object,int), removeElement(java.lang.Object), removeElementAt(int), removeAllElements(), elementAt(int)

isEmpty

public boolean isEmpty()
Returns true if there are no list values present.

lastElement

public Object lastElement()
Returns the last value in the list.
See Also:
firstElement(), elementAt(int)

lastIndexOf

public int lastIndexOf(Object elem)
Determines the index of the last occurance of the specified element.
Parameters:
elem the value to look for
Returns: the 0-based index of the value in the list, or -1 if the value is not found
See Also:
lastIndexOf(java.lang.Object,int), indexOf(java.lang.Object), indexOf(java.lang.Object,int)

lastIndexOf

public int lastIndexOf(Object elem, int index)
Determines the index of the last occurance of the specified element,
searching backwards starting at the given index.
Parameters:
elem the value to look for
index the 0-based index from which to start searching
Returns: the 0-based index of the value in the list, or -1 if the value is not found
See Also:
lastIndexOf(java.lang.Object), indexOf(java.lang.Object), indexOf(java.lang.Object,int)

remove

public Object remove(int index)
Removes the value saved in the list at the specified index and returns it.
Parameters:
index the 0-based list index
Returns: the removed value
See Also:
removeElementAt(int), removeElement(java.lang.Object), removeAllElements(), add(int,java.lang.Object), set(int,java.lang.Object)

removeAllElements

public void removeAllElements()
Removes all values from the list.
See Also:
removeElement(java.lang.Object), removeElementAt(int), addElement(java.lang.Object), setElementAt(java.lang.Object,int), insertElementAt(java.lang.Object,int), elementAt(int)

removeElement

public boolean removeElement(Object obj)
Removes the specified value from the list.
Only the first occurance of the value will be removed from the list.
Parameters:
obj the value to remove
See Also:
removeElementAt(int), removeAllElements(), addElement(java.lang.Object), setElementAt(java.lang.Object,int), insertElementAt(java.lang.Object,int), elementAt(int)

removeElementAt

public void removeElementAt(int index)
Removes the value saved in the list at the specified index.
Parameters:
index the 0-based list index
See Also:
removeElement(java.lang.Object), removeAllElements(), addElement(java.lang.Object), setElementAt(java.lang.Object,int), insertElementAt(java.lang.Object,int), elementAt(int)

removeRange

public void removeRange(int fromIndex, int toIndex)
Removes a range of values from the list.
Parameters:
fromIndex the 0-based index of the first value to remove
toIndex the 0-based index of the last value to remove
See Also:
clear(), remove(int), add(int,java.lang.Object), set(int,java.lang.Object)

set

public Object set(int index, Object element)
Sets the list value at the specified index.
Parameters:
index the 0-based list index
element the new value
See Also:
setElementAt(java.lang.Object,int), add(int,java.lang.Object)

setElementAt

public void setElementAt(Object obj, int index)
Sets the value saved in the list at the specified index.
Parameters:
obj the new value
index the 0-based list index
See Also:
addElement(java.lang.Object), insertElementAt(java.lang.Object,int), removeElement(java.lang.Object), removeElementAt(int), removeAllElements(), elementAt(int)

setItems

public void setItems(String[] items)
Sets the value of the list to the specified String items.
Parameters:
items the new values
See Also:
getItems()

setSize

public void setSize(int newSize)
Sets the size Vector containing the list values
to the specified size.
Parameters:
newSize the new list size
See Also:
size(), ensureCapacity(int)

size

public int size()
Returns the current number of values in the Vector containing the list values.
See Also:
setSize(int), capacity()

toArray

public Object[] toArray()
Returns an array contains the list values.
See Also:
get(int), elementAt(int)

toString

public String toString()
Returns a String representation of the list.

trimToSize

public void trimToSize()
Shrinks the Vector containing the list values to the
minimum required size.