1 7 8 package javax.swing; 9 10 import java.util.Vector ; 11 import java.util.Enumeration ; 12 13 import javax.swing.event.*; 14 15 16 36 public class DefaultListModel extends AbstractListModel 37 { 38 private Vector delegate = new Vector (); 39 40 51 public int getSize() { 52 return delegate.size(); 53 } 54 55 69 public Object getElementAt(int index) { 70 return delegate.elementAt(index); 71 } 72 73 81 public void copyInto(Object anArray[]) { 82 delegate.copyInto(anArray); 83 } 84 85 90 public void trimToSize() { 91 delegate.trimToSize(); 92 } 93 94 102 public void ensureCapacity(int minCapacity) { 103 delegate.ensureCapacity(minCapacity); 104 } 105 106 112 public void setSize(int newSize) { 113 int oldSize = delegate.size(); 114 delegate.setSize(newSize); 115 if (oldSize > newSize) { 116 fireIntervalRemoved(this, newSize, oldSize-1); 117 } 118 else if (oldSize < newSize) { 119 fireIntervalAdded(this, oldSize, newSize-1); 120 } 121 } 122 123 129 public int capacity() { 130 return delegate.capacity(); 131 } 132 133 139 public int size() { 140 return delegate.size(); 141 } 142 143 151 public boolean isEmpty() { 152 return delegate.isEmpty(); 153 } 154 155 161 public Enumeration <?> elements() { 162 return delegate.elements(); 163 } 164 165 173 public boolean contains(Object elem) { 174 return delegate.contains(elem); 175 } 176 177 185 public int indexOf(Object elem) { 186 return delegate.indexOf(elem); 187 } 188 189 200 public int indexOf(Object elem, int index) { 201 return delegate.indexOf(elem, index); 202 } 203 204 212 public int lastIndexOf(Object elem) { 213 return delegate.lastIndexOf(elem); 214 } 215 216 227 public int lastIndexOf(Object elem, int index) { 228 return delegate.lastIndexOf(elem, index); 229 } 230 231 246 public Object elementAt(int index) { 247 return delegate.elementAt(index); 248 } 249 250 257 public Object firstElement() { 258 return delegate.firstElement(); 259 } 260 261 269 public Object lastElement() { 270 return delegate.lastElement(); 271 } 272 273 291 public void setElementAt(Object obj, int index) { 292 delegate.setElementAt(obj, index); 293 fireContentsChanged(this, index, index); 294 } 295 296 311 public void removeElementAt(int index) { 312 delegate.removeElementAt(index); 313 fireIntervalRemoved(this, index, index); 314 } 315 316 334 public void insertElementAt(Object obj, int index) { 335 delegate.insertElementAt(obj, index); 336 fireIntervalAdded(this, index, index); 337 } 338 339 345 public void addElement(Object obj) { 346 int index = delegate.size(); 347 delegate.addElement(obj); 348 fireIntervalAdded(this, index, index); 349 } 350 351 360 public boolean removeElement(Object obj) { 361 int index = indexOf(obj); 362 boolean rv = delegate.removeElement(obj); 363 if (index >= 0) { 364 fireIntervalRemoved(this, index, index); 365 } 366 return rv; 367 } 368 369 370 381 public void removeAllElements() { 382 int index1 = delegate.size()-1; 383 delegate.removeAllElements(); 384 if (index1 >= 0) { 385 fireIntervalRemoved(this, 0, index1); 386 } 387 } 388 389 390 396 public String toString() { 397 return delegate.toString(); 398 } 399 400 401 404 405 412 public Object [] toArray() { 413 Object [] rv = new Object [delegate.size()]; 414 delegate.copyInto(rv); 415 return rv; 416 } 417 418 427 public Object get(int index) { 428 return delegate.elementAt(index); 429 } 430 431 443 public Object set(int index, Object element) { 444 Object rv = delegate.elementAt(index); 445 delegate.setElementAt(element, index); 446 fireContentsChanged(this, index, index); 447 return rv; 448 } 449 450 460 public void add(int index, Object element) { 461 delegate.insertElementAt(element, index); 462 fireIntervalAdded(this, index, index); 463 } 464 465 475 public Object remove(int index) { 476 Object rv = delegate.elementAt(index); 477 delegate.removeElementAt(index); 478 fireIntervalRemoved(this, index, index); 479 return rv; 480 } 481 482 486 public void clear() { 487 int index1 = delegate.size()-1; 488 delegate.removeAllElements(); 489 if (index1 >= 0) { 490 fireIntervalRemoved(this, 0, index1); 491 } 492 } 493 494 509 public void removeRange(int fromIndex, int toIndex) { 510 if (fromIndex > toIndex) { 511 throw new IllegalArgumentException ("fromIndex must be <= toIndex"); 512 } 513 for(int i = toIndex; i >= fromIndex; i--) { 514 delegate.removeElementAt(i); 515 } 516 fireIntervalRemoved(this, fromIndex, toIndex); 517 } 518 519 526 } 527 | Popular Tags |