2008-03-02 17:02:37 +00:00
|
|
|
|
|
|
|
package net.sourceforge.tuned.ui;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.swing.AbstractListModel;
|
|
|
|
|
|
|
|
|
|
|
|
public class SimpleListModel extends AbstractListModel {
|
|
|
|
|
2008-03-19 22:14:38 +00:00
|
|
|
private final List<Object> list;
|
2008-03-02 17:02:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
public SimpleListModel() {
|
|
|
|
list = Collections.synchronizedList(new ArrayList<Object>());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public SimpleListModel(Collection<? extends Object> collection) {
|
|
|
|
list = Collections.synchronizedList(new ArrayList<Object>(collection));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getElementAt(int index) {
|
|
|
|
return list.get(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSize() {
|
|
|
|
return list.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void add(Object object) {
|
|
|
|
int index = list.size();
|
|
|
|
list.add(object);
|
|
|
|
fireIntervalAdded(this, index, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void add(int index, Object object) {
|
|
|
|
list.add(index, object);
|
|
|
|
fireIntervalAdded(this, index, index);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void addAll(Collection<? extends Object> c) {
|
|
|
|
int begin = list.size();
|
|
|
|
list.addAll(c);
|
|
|
|
int end = list.size() - 1;
|
|
|
|
|
|
|
|
if (end >= 0) {
|
|
|
|
fireIntervalAdded(this, begin, end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void clear() {
|
|
|
|
int end = list.size() - 1;
|
|
|
|
list.clear();
|
|
|
|
|
|
|
|
if (end >= 0) {
|
|
|
|
fireIntervalRemoved(this, 0, end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean contains(Object o) {
|
|
|
|
return list.contains(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int indexOf(Object o) {
|
|
|
|
return list.indexOf(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isEmpty() {
|
|
|
|
return list.isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int lastIndexOf(Object o) {
|
|
|
|
return list.lastIndexOf(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Object remove(int index) {
|
|
|
|
Object object = list.remove(index);
|
|
|
|
|
|
|
|
fireIntervalRemoved(this, index, index);
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void remove(Object object) {
|
2008-03-21 01:45:21 +00:00
|
|
|
synchronized (list) {
|
|
|
|
remove(indexOf(object));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void sort() {
|
|
|
|
synchronized (list) {
|
|
|
|
Collections.sort(list, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
fireContentsChanged(this, 0, list.size());
|
2008-03-02 17:02:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public List<? extends Object> getCopy() {
|
|
|
|
synchronized (list) {
|
|
|
|
return new ArrayList<Object>(list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void set(Collection<? extends Object> c) {
|
|
|
|
int end = Math.max(list.size(), c.size()) - 1;
|
|
|
|
|
2008-03-21 01:45:21 +00:00
|
|
|
synchronized (list) {
|
|
|
|
list.clear();
|
|
|
|
list.addAll(c);
|
|
|
|
}
|
2008-03-02 17:02:37 +00:00
|
|
|
|
|
|
|
if (end >= 0) {
|
|
|
|
fireContentsChanged(this, 0, end);
|
|
|
|
}
|
|
|
|
}
|
2008-03-16 01:05:06 +00:00
|
|
|
|
2008-03-02 17:02:37 +00:00
|
|
|
}
|