01: /*
02: * Copyright 2000,2005 wingS development team.
03: *
04: * This file is part of wingS (http://wingsframework.org).
05: *
06: * wingS is free software; you can redistribute it and/or modify
07: * it under the terms of the GNU Lesser General Public License
08: * as published by the Free Software Foundation; either version 2.1
09: * of the License, or (at your option) any later version.
10: *
11: * Please see COPYING for the complete licence.
12: */
13: package org.wings;
14:
15: import javax.swing.*;
16: import java.util.ArrayList;
17: import java.util.Collections;
18: import java.util.Enumeration;
19: import java.util.List;
20:
21: /**
22: * Default implementation of a {@link ListModel}.
23: *
24: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
25: */
26: public class SDefaultListModel extends AbstractListModel {
27: protected final ArrayList data = new ArrayList(2);
28:
29: public SDefaultListModel(List d) {
30: data.clear();
31: if (d != null) {
32: for (int i = 0; i < d.size(); i++)
33: data.add(d.get(i));
34: }
35: }
36:
37: public SDefaultListModel(Object[] d) {
38: data.clear();
39: if (d != null) {
40: for (int i = 0; i < d.length; i++)
41: data.add(d[i]);
42: }
43: }
44:
45: public SDefaultListModel() {
46: // default constructor
47: }
48:
49: public int getSize() {
50: return data.size();
51: }
52:
53: public Object getElementAt(int i) {
54: return data.get(i);
55: }
56:
57: public int indexOf(Object element) {
58: return data.indexOf(element);
59: }
60:
61: public Enumeration elements() {
62: return Collections.enumeration(data);
63: }
64:
65: public void clear() {
66: data.clear();
67: }
68:
69: public void addElement(Object element) {
70: data.add(element);
71: }
72: }
|