T
- Type of data being reorderedpublic class ReorderListModel<T>
extends java.lang.Object
implements javax.swing.ListModel
Title: ReorderListModel
Description: ListModel with ability to reorder the list
Copyright: Copyright (c) 2004-2014, David Read
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Modifier and Type | Field and Description |
---|---|
private java.util.List<T> |
data
List of objects that can be reordered
|
private java.util.List<javax.swing.event.ListDataListener> |
listeners
Listeners to notify if the list is reordered
|
Constructor and Description |
---|
ReorderListModel(java.util.List<T> theData)
Constructor takes a List prepopulated with information to be presented in the GUI list.
|
Modifier and Type | Method and Description |
---|---|
void |
addListDataListener(javax.swing.event.ListDataListener l)
Add a ListDataListener
|
T |
getElementAt(int index)
Get the object at the given position.
|
java.util.List<T> |
getList()
Get the list which backs this model.
|
int |
getSize()
Get the number of items in the list.
|
void |
moveDown(int index)
Move the object at the given position to the next higher position
(next index value) in the list.
|
void |
moveUp(int index)
Move the object at the given position to the next lower position
(previous index value) in the list.
|
private void |
notifyListeners()
Notify all registered listeners that the list has changed.
|
void |
removeListDataListener(javax.swing.event.ListDataListener l)
Remove a ListDataListener
|
private java.util.List<T> data
private java.util.List<javax.swing.event.ListDataListener> listeners
public ReorderListModel(java.util.List<T> theData)
theData
- List of objects to be represented in the GUI list.public int getSize()
getSize
in interface javax.swing.ListModel
public T getElementAt(int index)
getElementAt
in interface javax.swing.ListModel
index
- int The index in the list containing the object to be returned.public void addListDataListener(javax.swing.event.ListDataListener l)
addListDataListener
in interface javax.swing.ListModel
l
- ListDataListener listening for events on this instancepublic void removeListDataListener(javax.swing.event.ListDataListener l)
removeListDataListener
in interface javax.swing.ListModel
l
- ListDataListener The listener to be removed from the list of listeners
being notified when the list changes.public void moveUp(int index)
index
- int The index of the object to be moved up the list.public void moveDown(int index)
index
- int The index of the object to be moved down the list.public java.util.List<T> getList()
private void notifyListeners()