jSite: First commit : verion 4.0 (written by Bombe)
[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  * @version $Id: SortedListModel.java 338 2006-03-20 15:40:48Z bombe $
35  */
36 public class SortedListModel extends AbstractListModel implements List {
37         
38         private List elements = new ArrayList();
39         
40         /**
41          * {@inheritDoc}
42          */
43         public int getSize() {
44                 return size();
45         }
46
47         /**
48          * {@inheritDoc}
49          */
50         public Object getElementAt(int index) {
51                 return elements.get(index);
52         }
53
54         /**
55          * {@inheritDoc}
56          */
57         public void add(int index, Object element) {
58                 elements.add(index, element);
59                 Collections.sort(elements);
60                 fireContentsChanged(this, 0, size());
61         }
62
63         /**
64          * {@inheritDoc}
65          */
66         public boolean add(Object o) {
67                 boolean result = elements.add(o);
68                 Collections.sort(elements);
69                 fireContentsChanged(this, 0, size());
70                 return result;
71         }
72
73         /**
74          * {@inheritDoc}
75          */
76         public boolean addAll(Collection c) {
77                 boolean result = elements.addAll(c);
78                 Collections.sort(elements);
79                 fireContentsChanged(this, 0, size());
80                 return result;
81         }
82
83         /**
84          * {@inheritDoc}
85          */
86         public boolean addAll(int index, Collection c) {
87                 boolean result = elements.addAll(index, c);
88                 Collections.sort(elements);
89                 fireContentsChanged(this, 0, size());
90                 return result;
91         }
92
93         /**
94          * {@inheritDoc}
95          */
96         public void clear() {
97                 elements.clear();
98                 fireContentsChanged(this, 0, size());
99         }
100
101         /**
102          * {@inheritDoc}
103          */
104         public boolean contains(Object o) {
105                 return elements.contains(o);
106         }
107
108         /**
109          * {@inheritDoc}
110          */
111         public boolean containsAll(Collection c) {
112                 return elements.containsAll(c);
113         }
114
115         /**
116          * {@inheritDoc}
117          */
118         public boolean equals(Object o) {
119                 return elements.equals(o);
120         }
121
122         /**
123          * {@inheritDoc}
124          */
125         public Object get(int index) {
126                 return elements.get(index);
127         }
128
129         /**
130          * {@inheritDoc}
131          */
132         public int hashCode() {
133                 return elements.hashCode();
134         }
135
136         /**
137          * {@inheritDoc}
138          */
139         public int indexOf(Object o) {
140                 return elements.indexOf(o);
141         }
142
143         /**
144          * {@inheritDoc}
145          */
146         public boolean isEmpty() {
147                 return elements.isEmpty();
148         }
149
150         /**
151          * {@inheritDoc}
152          */
153         public Iterator iterator() {
154                 return elements.iterator();
155         }
156
157         /**
158          * {@inheritDoc}
159          */
160         public int lastIndexOf(Object o) {
161                 return elements.lastIndexOf(o);
162         }
163
164         /**
165          * {@inheritDoc}
166          */
167         public ListIterator listIterator() {
168                 return elements.listIterator();
169         }
170
171         /**
172          * {@inheritDoc}
173          */
174         public ListIterator listIterator(int index) {
175                 return elements.listIterator(index);
176         }
177
178         /**
179          * {@inheritDoc}
180          */
181         public Object remove(int index) {
182                 fireContentsChanged(this, 0, size());
183                 return elements.remove(index);
184         }
185
186         /**
187          * {@inheritDoc}
188          */
189         public boolean remove(Object o) {
190                 fireContentsChanged(this, 0, size());
191                 return elements.remove(o);
192         }
193
194         /**
195          * {@inheritDoc}
196          */
197         public boolean removeAll(Collection c) {
198                 fireContentsChanged(this, 0, size());
199                 return elements.removeAll(c);
200         }
201
202         /**
203          * {@inheritDoc}
204          */
205         public boolean retainAll(Collection c) {
206                 fireContentsChanged(this, 0, size());
207                 return elements.retainAll(c);
208         }
209
210         /**
211          * {@inheritDoc}
212          */
213         public Object set(int index, Object element) {
214                 Object result = elements.set(index, element);
215                 Collections.sort(elements);
216                 fireContentsChanged(this, 0, size());
217                 return result;
218         }
219
220         /**
221          * {@inheritDoc}
222          */
223         public int size() {
224                 return elements.size();
225         }
226
227         /**
228          * {@inheritDoc}
229          */
230         public List subList(int fromIndex, int toIndex) {
231                 return elements.subList(fromIndex, toIndex);
232         }
233
234         /**
235          * {@inheritDoc}
236          */
237         public Object[] toArray() {
238                 return elements.toArray();
239         }
240
241         /**
242          * {@inheritDoc}
243          */
244         public Object[] toArray(Object[] a) {
245                 return elements.toArray(a);
246         }
247
248 }