com.jgoodies.binding.list
Class LinkedListModel<E>
LinkedList
com.jgoodies.binding.list.LinkedListModel<E>
- List, ListModel, ObservableList<E>
public final class LinkedListModel<E>
extends LinkedList
Adds javax.swing.ListModel
capabilities to its superclass
LinkedList
, i. e. allows to observe changes in the content and
structure. Useful for lists that are bound to list views, for example
JList, JComboBox and JTable.
LinkedListModel() - Constructs an empty linked list.
|
LinkedListModel(E> c) - Constructs a linked list containing the elements of the specified
collection, in the order they are returned by the collection's
iterator.
|
@Override | E remove(int index) - Removes the element at the specified position in this list.
|
@Override | E removeFirst() - Removes and returns the first element from this list.
|
@Override | E removeLast() - Removes and returns the last element from this list.
|
@Override | E set(int index, E element) - Replaces the element at the specified position in this list with
the specified element.
|
@Override | ListIterator listIterator(int index) - Returns a list-iterator of the elements in this list (in proper
sequence), starting at the specified position in the list.
|
void | addListDataListener(ListDataListener l) - Adds a listener to the list that's notified each time a change
to the data model occurs.
|
@Override | boolean add(E e) - Appends the specified element to the end of this list.
|
@Override | boolean addAll(int index, E> c) - Inserts all of the elements in the specified Collection into this
list, starting at the specified position.
|
@Override | boolean remove(Object o) - Removes a single instance of the specified element from this
collection, if it is present (optional operation).
|
void | fireContentsChanged(int index) - Notifies all registered
ListDataListeners that the element
at the specified index has changed.
|
E | getElementAt(int index) - Returns the value at the specified index.
|
ListDataListener[] | getListDataListeners() - Returns an array of all the list data listeners
registered on this
LinkedListModel .
|
int | getSize() - Returns the length of the list or 0 if there's no list.
|
void | removeListDataListener(ListDataListener l) - Removes a listener from the list that's notified each time a
change to the data model occurs.
|
@Override | void add(int index, E element) - Inserts the specified element at the specified position in this
list.
|
@Override | void addFirst(E e) - Inserts the given element at the beginning of this list.
|
@Override | void addLast(E e) - Appends the given element to the end of this list.
|
@Override | void clear() - Removes all of the elements from this list.
|
protected @Override | void removeRange(int fromIndex, int toIndex) - Removes from this List all of the elements whose index is between
fromIndex, inclusive and toIndex, exclusive.
|
LinkedListModel
public LinkedListModel()
Constructs an empty linked list.
LinkedListModel
public LinkedListModel(E> c)
Constructs a linked list containing the elements of the specified
collection, in the order they are returned by the collection's
iterator.
c
- the collection whose elements are to be placed into this list.
E remove
public @Override E remove(int index)
Removes the element at the specified position in this list.
Shifts any subsequent elements to the left (subtracts one from their
indices).
index
- the index of the element to removed.
- the element that was removed from the list.
E removeFirst
public @Override E removeFirst()
Removes and returns the first element from this list.
- the first element from this list.
E removeLast
public @Override E removeLast()
Removes and returns the last element from this list.
- the last element from this list.
E set
public @Override E set(int index,
E element)
Replaces the element at the specified position in this list with
the specified element.
index
- index of element to replace.element
- element to be stored at the specified position.
- the element previously at the specified position.
ListIterator listIterator
public @Override ListIterator listIterator(int index)
Returns a list-iterator of the elements in this list (in proper
sequence), starting at the specified position in the list.
Obeys the general contract of
List.listIterator(int).
The list-iterator is
fail-fast: if the list is structurally
modified at any time after the Iterator is created, in any way except
through the list-iterator's own
remove or
add
methods, the list-iterator will throw a
ConcurrentModificationException. Thus, in the face of
concurrent modification, the iterator fails quickly and cleanly, rather
than risking arbitrary, non-deterministic behavior at an undetermined
time in the future.
index
- index of first element to be returned from the
list-iterator (by a call to next).
- a ListIterator of the elements in this list (in proper
sequence), starting at the specified position in the list.
java.util.List.listIterator(int)
addListDataListener
public void addListDataListener(ListDataListener l)
Adds a listener to the list that's notified each time a change
to the data model occurs.
l
- the ListDataListener
to be added
boolean add
public @Override boolean add(E e)
Appends the specified element to the end of this list.
e
- element to be appended to this list.
true
(as per the general contract of Collection.add).
boolean addAll
public @Override boolean addAll(int index,
E> c)
Inserts all of the elements in the specified Collection into this
list, starting at the specified position. Shifts the element
currently at that position (if any) and any subsequent elements to
the right (increases their indices). The new elements will appear
in the list in the order that they are returned by the
specified Collection's iterator.
index
- index at which to insert first element
from the specified collection.c
- elements to be inserted into this list.
true
if this list changed as a result of the call.
boolean remove
public @Override boolean remove(Object o)
Removes a single instance of the specified element from this
collection, if it is present (optional operation). More formally,
removes an element
e
such that
(o==null ? e==null :
o.equals(e))
, if the collection contains one or more such
elements. Returns
true
if the collection contained the
specified element (or equivalently, if the collection changed as a
result of the call).
This implementation iterates over the collection looking for the
specified element. If it finds the element, it removes the element
from the collection using the iterator's remove method.
Note that this implementation throws an
UnsupportedOperationException
if the iterator returned by this
collection's iterator method does not implement the
remove
method and this collection contains the specified object.
o
- element to be removed from this collection, if present.
true
if the collection contained the specified
element.
fireContentsChanged
public void fireContentsChanged(int index)
Notifies all registered
ListDataListeners
that the element
at the specified index has changed. Useful if there's a content change
without any structural change.
This method must be called
after the element of the list changes.
index
- the index of the element that has changed
getElementAt
public E getElementAt(int index)
Returns the value at the specified index.
index
- the requested index
getListDataListeners
public ListDataListener[] getListDataListeners()
Returns an array of all the list data listeners
registered on this LinkedListModel
.
- all of this model's
ListDataListener
s,
or an empty array if no list data listeners
are currently registered
getSize
public int getSize()
Returns the length of the list or 0 if there's no list.
- the length of the list or 0 if there's no list
removeListDataListener
public void removeListDataListener(ListDataListener l)
Removes a listener from the list that's notified each time a
change to the data model occurs.
l
- the ListDataListener
to be removed
void add
public @Override void add(int index,
E element)
Inserts the specified element at the specified position in this
list. Shifts the element currently at that position (if any) and
any subsequent elements to the right (adds one to their indices).
index
- index at which the specified element is to be inserted.element
- element to be inserted.
void addFirst
public @Override void addFirst(E e)
Inserts the given element at the beginning of this list.
e
- the element to be inserted at the beginning of this list.
void addLast
public @Override void addLast(E e)
Appends the given element to the end of this list. (Identical in
function to the add
method; included only for consistency.)
e
- the element to be inserted at the end of this list.
void clear
public @Override void clear()
Removes all of the elements from this list. The list will
be empty after this call returns.
void removeRange
protected @Override void removeRange(int fromIndex,
int toIndex)
Removes from this List all of the elements whose index is between
fromIndex, inclusive and toIndex, exclusive. Shifts any succeeding
elements to the left (reduces their index).
This call shortens the list by (toIndex - fromIndex)
elements.
(If toIndex==fromIndex
, this operation has no effect.)
fromIndex
- index of first element to be removed.toIndex
- index after last element to be removed.
Copyright © 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.