Remove Subversion $Id$ tag.
[jSite.git] / src / de / todesbaum / util / swing / SortedListModel.java
1 /*
2  * todesbaum-lib -
3  * Copyright (C) 2006 David Roden
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 package de.todesbaum.util.swing;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.Iterator;
26 import java.util.List;
27 import java.util.ListIterator;
28
29 import javax.swing.AbstractListModel;
30
31
32 /**
33  * @author David Roden <droden@gmail.com>
34  */
35 public class SortedListModel extends AbstractListModel implements List {
36
37         private List elements = new ArrayList();
38
39         /**
40          * {@inheritDoc}
41          */
42         public int getSize() {
43                 return size();
44         }
45
46         /**
47          * {@inheritDoc}
48          */
49         public Object getElementAt(int index) {
50                 return elements.get(index);
51         }
52
53         /**
54          * {@inheritDoc}
55          */
56         public void add(int index, Object element) {
57                 elements.add(index, element);
58                 Collections.sort(elements);
59                 fireContentsChanged(this, 0, size());
60         }
61
62         /**
63          * {@inheritDoc}
64          */
65         public boolean add(Object o) {
66                 boolean result = elements.add(o);
67                 Collections.sort(elements);
68                 fireContentsChanged(this, 0, size());
69                 return result;
70         }
71
72         /**
73          * {@inheritDoc}
74          */
75         public boolean addAll(Collection c) {
76                 boolean result = elements.addAll(c);
77                 Collections.sort(elements);
78                 fireContentsChanged(this, 0, size());
79                 return result;
80         }
81
82         /**
83          * {@inheritDoc}
84          */
85         public boolean addAll(int index, Collection c) {
86                 boolean result = elements.addAll(index, c);
87                 Collections.sort(elements);
88                 fireContentsChanged(this, 0, size());
89                 return result;
90         }
91
92         /**
93          * {@inheritDoc}
94          */
95         public void clear() {
96                 elements.clear();
97                 fireContentsChanged(this, 0, size());
98         }
99
100         /**
101          * {@inheritDoc}
102          */
103         public boolean contains(Object o) {
104                 return elements.contains(o);
105         }
106
107         /**
108          * {@inheritDoc}
109          */
110         public boolean containsAll(Collection c) {
111                 return elements.containsAll(c);
112         }
113
114         /**
115          * {@inheritDoc}
116          */
117         public boolean equals(Object o) {
118                 return elements.equals(o);
119         }
120
121         /**
122          * {@inheritDoc}
123          */
124         public Object get(int index) {
125                 return elements.get(index);
126         }
127
128         /**
129          * {@inheritDoc}
130          */
131         public int hashCode() {
132                 return elements.hashCode();
133         }
134
135         /**
136          * {@inheritDoc}
137          */
138         public int indexOf(Object o) {
139                 return elements.indexOf(o);
140         }
141
142         /**
143          * {@inheritDoc}
144          */
145         public boolean isEmpty() {
146                 return elements.isEmpty();
147         }
148
149         /**
150          * {@inheritDoc}
151          */
152         public Iterator iterator() {
153                 return elements.iterator();
154         }
155
156         /**
157          * {@inheritDoc}
158          */
159         public int lastIndexOf(Object o) {
160                 return elements.lastIndexOf(o);
161         }
162
163         /**
164          * {@inheritDoc}
165          */
166         public ListIterator listIterator() {
167                 return elements.listIterator();
168         }
169
170         /**
171          * {@inheritDoc}
172          */
173         public ListIterator listIterator(int index) {
174                 return elements.listIterator(index);
175         }
176
177         /**
178          * {@inheritDoc}
179          */
180         public Object remove(int index) {
181                 fireContentsChanged(this, 0, size());
182                 return elements.remove(index);
183         }
184
185         /**
186          * {@inheritDoc}
187          */
188         public boolean remove(Object o) {
189                 fireContentsChanged(this, 0, size());
190                 return elements.remove(o);
191         }
192
193         /**
194          * {@inheritDoc}
195          */
196         public boolean removeAll(Collection c) {
197                 fireContentsChanged(this, 0, size());
198                 return elements.removeAll(c);
199         }
200
201         /**
202          * {@inheritDoc}
203          */
204         public boolean retainAll(Collection c) {
205                 fireContentsChanged(this, 0, size());
206                 return elements.retainAll(c);
207         }
208
209         /**
210          * {@inheritDoc}
211          */
212         public Object set(int index, Object element) {
213                 Object result = elements.set(index, element);
214                 Collections.sort(elements);
215                 fireContentsChanged(this, 0, size());
216                 return result;
217         }
218
219         /**
220          * {@inheritDoc}
221          */
222         public int size() {
223                 return elements.size();
224         }
225
226         /**
227          * {@inheritDoc}
228          */
229         public List subList(int fromIndex, int toIndex) {
230                 return elements.subList(fromIndex, toIndex);
231         }
232
233         /**
234          * {@inheritDoc}
235          */
236         public Object[] toArray() {
237                 return elements.toArray();
238         }
239
240         /**
241          * {@inheritDoc}
242          */
243         public Object[] toArray(Object[] a) {
244                 return elements.toArray(a);
245         }
246
247 }