1 20 package org.enhydra.barracuda.core.comp; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.apache.log4j.*; 26 27 31 public class DefaultListModel extends AbstractListModel implements List, Cloneable , Serializable { 34 protected static final Logger logger = Logger.getLogger(DefaultListModel.class.getName()); 36 37 protected List items = new ArrayList(); 38 39 46 public Object getItemAt(int index) { 48 return get(index); 49 } 50 51 57 public int getSize() { 58 return size(); 59 } 60 61 62 63 64 71 public int size() { 72 return items.size(); 73 } 74 75 81 public boolean isEmpty() { 82 return items.isEmpty(); 83 } 84 85 93 public boolean contains(Object o) { 94 return items.contains(o); 95 } 96 97 103 public Iterator iterator() { 104 return items.iterator(); 105 } 106 107 116 public Object [] toArray() { 117 return items.toArray(); 118 } 119 120 135 public Object [] toArray(Object a[]) { 136 return items.toArray(a); 137 } 138 139 154 public boolean add(Object o) { 155 boolean result = items.add(o); 156 if (result) { 157 fireModelChanged(); 160 } 161 return result; 162 } 163 164 175 public boolean remove(Object o) { 176 int pos = items.indexOf(o); 177 boolean result = items.remove(o); 178 if (result) fireModelChanged(); 180 return result; 181 } 182 183 193 public boolean containsAll(Collection c) { 194 return items.containsAll(c); 195 } 196 197 213 public boolean addAll(Collection c) { 214 int start = items.size()-1; 215 boolean result = items.addAll(c); 216 if (result) fireModelChanged(); 218 return result; 219 } 220 221 243 public boolean addAll(int index, Collection c) { 244 boolean result = items.addAll(index, c); 245 if (result) fireModelChanged(); 247 return result; 248 } 249 250 261 public boolean removeAll(Collection c) { 262 boolean result = items.removeAll(c); 263 if (result) fireModelChanged(); 265 return result; 266 } 267 268 281 public boolean retainAll(Collection c) { 282 boolean result = items.retainAll(c); 283 if (result) fireModelChanged(); 285 return result; 286 } 287 288 295 public void clear() { 296 items.clear(); 297 } 298 299 309 public boolean equals(Object o) { 310 return items.equals(o); 311 } 312 313 319 public int hashCode() { 320 return items.hashCode(); 321 } 322 323 332 public Object get(int index) { 333 return items.get(index); 334 } 335 336 353 public Object set(int index, Object element) { 354 Object result = items.set(index, element); 355 if (result!=null) fireModelChanged(); 357 return result; 358 } 359 360 378 public void add(int index, Object element) { 379 items.add(index, element); 380 fireModelChanged(); 382 } 383 384 398 public Object remove(int index) { 399 Object result = items.remove(index); 400 if (result!=null) fireModelChanged(); 402 return result; 403 } 404 405 414 public int indexOf(Object o) { 415 return items.indexOf(o); 416 } 417 418 427 public int lastIndexOf(Object o) { 428 return items.lastIndexOf(o); 429 } 430 431 439 public ListIterator listIterator() { 440 return items.listIterator(); 441 } 442 443 455 public ListIterator listIterator(int index) { 456 return items.listIterator(index); 457 } 458 459 475 public List subList(int fromIndex, int toIndex) { 476 return items.subList(fromIndex, toIndex); 477 } 478 479 480 481 482 491 public String toString() { 492 StringBuffer sb = new StringBuffer (500); 493 String sep = ""; 494 Iterator it = items.iterator(); 495 while (it.hasNext()) { 496 sb.append(sep+it.next().toString()); 497 sep = ", "; 498 } 499 String result = sb.toString().trim(); 500 if (result==null || result.length()<1) result = "[empty list]"; 501 return result; 502 } 503 504 513 public Object clone() throws CloneNotSupportedException { 514 DefaultListModel clone = (DefaultListModel) super.clone(); 515 clone.items = new ArrayList(items); 516 clone.listeners = new ArrayList(); 517 return clone; 518 } 519 } | Popular Tags |