net.sf.magicproject.ui
Class MListModel<T extends MCardCompare>

java.lang.Object
  extended by javax.swing.AbstractListModel
      extended by net.sf.magicproject.ui.MListModel<T>
Type Parameters:
T - the model type.
All Implemented Interfaces:
java.io.Serializable, javax.swing.ListModel

public class MListModel<T extends MCardCompare>
extends javax.swing.AbstractListModel

Since:
0.94
Author:
Fabrice Daugan
See Also:
Serialized Form

Field Summary
 java.util.Vector<T> delegate
          The content.
 java.util.List<T> removedDelegate
          The original content.
 
Constructor Summary
MListModel(javax.swing.JLabel linkedAmount, boolean deepSum)
          Create a new instance of this class.
 
Method Summary
 void add(T obj)
          Adds the specified component to the end of this list.
 boolean addAll(java.util.Collection<T> c)
          Appends all of the elements in the specified Collection to the end of this Vector, in the order that they are returned by the specified Collection's Iterator.
 void clear()
          Removes all of the elements from this list.
 boolean contains(T elem)
          Tests whether the specified object is a component in this list.
 T elementAt(int index)
          Returns the component at the specified index.
 T get(int index)
          Returns the element at the specified position in this list.
 T getElementAt(int index)
          Returns the component at the specified index.
 int getSize()
          Returns the number of components in this list.
 int indexOf(java.lang.String elem)
          Searches for the first occurrence of elem.
 int indexOf(T elem)
          Searches for the first occurrence of elem.
 void insertElementAt(T obj, int index)
          Inserts the specified object as a component in this list at the specified index.
 boolean isEmpty()
          Tests whether this list has any components.
 java.util.Iterator<T> iterator()
          Returns an enumeration of the components of this list.
 int lastIndexOf(T elem)
          Returns the index of the last occurrence of elem.
 T remove(int index)
          Removes the element at the specified position in this list.
 boolean remove(T obj)
          Removes the first (lowest-indexed) occurrence of the argument from this list.
 boolean removeAll(java.util.Collection<T> c)
          Removes from this Vector all of its elements that are contained in the specified Collection.
 T set(int index, T element)
          Replaces the element at the specified position in this list with the specified element.
 void setElementAt(T obj, int index)
          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.
 T[] toArray()
          Returns an array containing all of the elements in this list in proper sequence (from first to last element).
 java.lang.String toString()
          Returns a string that displays and identifies this object's properties.
 
Methods inherited from class javax.swing.AbstractListModel
addListDataListener, getListDataListeners, getListeners, removeListDataListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

delegate

public final java.util.Vector<T extends MCardCompare> delegate
The content.


removedDelegate

public final java.util.List<T extends MCardCompare> removedDelegate
The original content.

Constructor Detail

MListModel

public MListModel(javax.swing.JLabel linkedAmount,
                  boolean deepSum)
Create a new instance of this class.

Parameters:
linkedAmount - the label reflecting the amount of this list.
deepSum - if true the amount lable is updated with the internal amount.
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 T getElementAt(int index)
Returns the component at the specified index.
Note: Although this method is not deprecated, the preferred method to use is get(int), which implements the List interface defined in the 1.2 Collections framework.

Parameters:
index - an index into this list
Returns:
the component at the specified index
Throws:
java.lang.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:
List.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:
List.isEmpty()

iterator

public java.util.Iterator<T> iterator()
Returns an enumeration of the components of this list.

Returns:
an enumeration of the components of this list
See Also:
List.iterator()

contains

public boolean contains(T 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:
List.contains(Object)

indexOf

public int indexOf(T 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:
List.indexOf(Object)

indexOf

public int indexOf(java.lang.String 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:
List.indexOf(Object)

lastIndexOf

public int lastIndexOf(T 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:
List.lastIndexOf(Object)

elementAt

public T elementAt(int index)
Returns the component at the specified index. Throws an ArrayIndexOutOfBoundsException if the index is negative or not less than the size of the list.
Note: Although this method is not deprecated, the preferred method to use is get(int), which implements the List interface defined in the 1.2 Collections framework.

Parameters:
index - an index into this list
Returns:
the component at the specified index
See Also:
get(int), List.get(int)

setElementAt

public void setElementAt(T obj,
                         int index)
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.

Note: Although this method is not deprecated, the preferred method to use is set(int,Object), which implements the List interface defined in the 1.2 Collections framework.

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

add

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

Parameters:
obj - the component to be added
See Also:
List.add(Object)

remove

public boolean remove(T 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:
List.remove(Object)

toString

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

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

get

public T get(int index)
Returns the element at the specified position in this list.

Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).

Parameters:
index - index of element to return
Returns:
the object.

set

public T set(int index,
             T element)
Replaces the element at the specified position in this list with the specified element.

Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).

Parameters:
index - index of element to replace
element - element to be stored at the specified position
Returns:
the element previously at the specified position

insertElementAt

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

Throws an ArrayIndexOutOfBoundsException if the index is invalid.

Note: Although this method is not deprecated, the preferred method to use is add(int,Object), which implements the List interface defined in the 1.2 Collections framework.

Parameters:
obj - the component to insert
index - where to insert the new component
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid

remove

public T remove(int index)
Removes the element at the specified position in this list. Returns the element that was removed from the list.

Throws an ArrayIndexOutOfBoundsException if the index is out of range (index < 0 || index >= size()).

Parameters:
index - the index of the element to removed
Returns:
the removed object.

clear

public void clear()
Removes all of the elements from this list. The list will be empty after this call returns (unless it throws an exception).


toArray

public T[] toArray()
Returns an array containing all of the elements in this list in proper sequence (from first to last element).

The returned array will be "safe" in that no references to it are maintained by this list. (In other words, this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify the returned array.

This method acts as bridge between array-based and collection-based APIs.

Returns:
an array containing all of the elements in this list in proper sequence
See Also:
Arrays.asList(Object[])

removeAll

public boolean removeAll(java.util.Collection<T> c)
Removes from this Vector all of its elements that are contained in the specified Collection.

Parameters:
c - a collection of elements to be removed from the Vector
Returns:
true if this Vector changed as a result of the call
Throws:
java.lang.ClassCastException - if the types of one or more elements in this vector are incompatible with the specified collection (optional)
java.lang.NullPointerException - if this vector contains one or more null elements and the specified collection does not support null elements (optional), or if the specified collection is null
Since:
1.2

addAll

public boolean addAll(java.util.Collection<T> c)
Appends all of the elements in the specified Collection to the end of this Vector, in the order that they are returned by the specified Collection's Iterator. The behavior of this operation is undefined if the specified Collection is modified while the operation is in progress. (This implies that the behavior of this call is undefined if the specified Collection is this Vector, and this Vector is nonempty.)

Parameters:
c - elements to be inserted into this Vector
Returns:
true if this Vector changed as a result of the call
Throws:
java.lang.NullPointerException - if the specified collection is null
Since:
1.2


Copyright © 2003-2007 Magic-Project. All Rights Reserved.