1 29 30 package nextapp.echo2.app.list; 31 32 import java.util.ArrayList ; 33 import java.util.List ; 34 35 38 public class DefaultListModel extends AbstractListModel { 39 40 private List items = new ArrayList (); 41 42 46 public DefaultListModel() { 47 super(); 48 } 49 50 56 public DefaultListModel(Object [] itemArray) { 57 this(); 58 59 for (int i = 0; i < itemArray.length; ++i) { 60 add(itemArray[i]); 61 } 62 } 63 64 69 public void add(Object item) { 70 items.add(item); 71 int index = items.size() - 1; 72 fireIntervalAdded(index, index); 73 } 74 75 81 public void add(int index, Object item) { 82 items.add(index, item); 83 fireIntervalAdded(index, index); 84 } 85 86 92 public Object get(int index) { 93 return items.get(index); 94 } 95 96 102 public int indexOf(Object item) { 103 return items.indexOf(item); 104 } 105 106 111 public void remove(int index) { 112 items.remove(index); 113 fireIntervalRemoved(index, index); 114 } 115 116 121 public void remove(Object item) { 122 int index = items.indexOf(item); 123 items.remove(item); 124 fireIntervalRemoved(index, index); 125 } 126 127 130 public void removeAll() { 131 int size = items.size(); 132 if (size > 0) { 133 items.clear(); 134 fireIntervalRemoved(0, size - 1); 135 } 136 } 137 138 143 public int size() { 144 return items.size(); 145 } 146 } 147 | Popular Tags |