001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.swing;
019:
020: import java.util.Enumeration;
021: import java.util.Vector;
022:
023: import org.apache.harmony.x.swing.internal.nls.Messages;
024:
025: /**
026: * <p>
027: * <i>DefaultListModel</i>
028: * </p>
029: * <h3>Implementation Notes:</h3>
030: * <ul>
031: * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
032: * optimization, not as a guarantee of serialization compatibility.</li>
033: * </ul>
034: */
035: public class DefaultListModel extends AbstractListModel {
036: private static final long serialVersionUID = 7987079759213724557L;
037:
038: private Vector<Object> internalStorage = new Vector<Object>();
039:
040: public void add(int index, Object element) {
041: internalStorage.add(index, element);
042: fireIntervalAdded(this , index, index);
043: }
044:
045: public void addElement(Object element) {
046: internalStorage.addElement(element);
047: fireIntervalAdded(this , internalStorage.size() - 1,
048: internalStorage.size() - 1);
049: }
050:
051: public int capacity() {
052: return internalStorage.capacity();
053: }
054:
055: public void clear() {
056: int size = getSize();
057: if (size > 0) {
058: internalStorage.clear();
059: fireIntervalRemoved(this , 0, size - 1);
060: }
061: }
062:
063: public boolean contains(Object element) {
064: return internalStorage.contains(element);
065: }
066:
067: public void copyInto(Object[] array) {
068: internalStorage.copyInto(array);
069: }
070:
071: public Object elementAt(int index) {
072: return internalStorage.elementAt(index);
073: }
074:
075: public Enumeration<?> elements() {
076: return internalStorage.elements();
077: }
078:
079: public void ensureCapacity(int minCapacity) {
080: internalStorage.ensureCapacity(minCapacity);
081: }
082:
083: public Object firstElement() {
084: return internalStorage.firstElement();
085: }
086:
087: public Object get(int index) {
088: return internalStorage.get(index);
089: }
090:
091: public Object getElementAt(int index) {
092: return get(index);
093: }
094:
095: public int getSize() {
096: return internalStorage.size();
097: }
098:
099: public int indexOf(Object element) {
100: return internalStorage.indexOf(element);
101: }
102:
103: public int indexOf(Object element, int index) {
104: return internalStorage.indexOf(element, index);
105: }
106:
107: public void insertElementAt(Object element, int index) {
108: internalStorage.insertElementAt(element, index);
109: fireIntervalAdded(this , index, index);
110: }
111:
112: public boolean isEmpty() {
113: return internalStorage.isEmpty();
114: }
115:
116: public Object lastElement() {
117: return internalStorage.lastElement();
118: }
119:
120: public int lastIndexOf(Object element) {
121: return internalStorage.lastIndexOf(element);
122: }
123:
124: public int lastIndexOf(Object element, int index) {
125: return internalStorage.lastIndexOf(element, index);
126: }
127:
128: public Object remove(int index) {
129: Object result = internalStorage.remove(index);
130: fireIntervalRemoved(this , index, index);
131: return result;
132: }
133:
134: public void removeAllElements() {
135: clear();
136: }
137:
138: public boolean removeElement(Object element) {
139: int index = internalStorage.indexOf(element);
140: boolean result = internalStorage.removeElement(element);
141: if (index != -1) {
142: fireIntervalRemoved(this , index, index);
143: }
144: return result;
145: }
146:
147: public void removeElementAt(int index) {
148: remove(index);
149: }
150:
151: public void removeRange(int fromIndex, int toIndex) {
152: if (fromIndex > toIndex) {
153: throw new IllegalArgumentException(Messages
154: .getString("swing.01")); //$NON-NLS-1$
155: }
156: for (int i = 0; i < toIndex - fromIndex + 1; i++) {
157: internalStorage.remove(fromIndex);
158: }
159: fireIntervalRemoved(this , fromIndex, toIndex);
160: }
161:
162: public Object set(int index, Object element) {
163: Object result = internalStorage.set(index, element);
164: fireContentsChanged(this , index, index);
165: return result;
166: }
167:
168: public void setElementAt(Object element, int index) {
169: set(index, element);
170: }
171:
172: public void setSize(int size) {
173: internalStorage.setSize(size);
174: }
175:
176: public int size() {
177: return internalStorage.size();
178: }
179:
180: public Object[] toArray() {
181: return internalStorage.toArray();
182: }
183:
184: @Override
185: public String toString() {
186: return internalStorage.toString();
187: }
188:
189: public void trimToSize() {
190: internalStorage.trimToSize();
191: }
192: }
|