1 26 27 package swingwtx.swing; 28 29 import java.util.*; 30 import swingwtx.swing.event.*; 31 32 public abstract class AbstractListModel implements ListModel { 33 34 protected Vector listenerList = new Vector(); 35 36 public void addListDataListener(ListDataListener l) { 37 listenerList.add(l); 38 } 39 40 public void removeListDataListener(ListDataListener l) { 41 listenerList.remove(l); 42 } 43 44 public Object [] getListDataListeners() { 45 return listenerList.toArray(); 46 } 47 48 protected void fireContentsChanged(Object source, int index0, int index1) { 49 ListDataEvent e = new ListDataEvent(source, ListDataEvent.CONTENTS_CHANGED, index0, index1); 50 for (int i = 0; i < listenerList.size(); i++) { 51 ((ListDataListener) listenerList.get(i)).contentsChanged(e); 52 } 53 } 54 55 protected void fireIntervalAdded(Object source, int index0, int index1) { 56 ListDataEvent e = new ListDataEvent(source, ListDataEvent.INTERVAL_ADDED, index0, index1); 57 for (int i = 0; i < listenerList.size(); i++) { 58 ((ListDataListener) listenerList.get(i)).intervalAdded(e); 59 } 60 } 61 62 protected void fireIntervalRemoved(Object source, int index0, int index1) { 63 ListDataEvent e = new ListDataEvent(source, ListDataEvent.INTERVAL_REMOVED, index0, index1); 64 for (int i = 0; i < listenerList.size(); i++) { 65 ((ListDataListener) listenerList.get(i)).intervalRemoved(e); 66 } 67 } 68 69 public Object [] getListeners(Class listenerType) { 70 return listenerList.toArray(); 71 } 72 } 73 74 | Popular Tags |