1 7 8 package javax.swing; 9 10 import javax.swing.event.*; 11 import java.io.Serializable ; 12 import java.util.EventListener ; 13 14 30 public abstract class AbstractListModel implements ListModel , Serializable 31 { 32 protected EventListenerList listenerList = new EventListenerList(); 33 34 35 41 public void addListDataListener(ListDataListener l) { 42 listenerList.add(ListDataListener.class, l); 43 } 44 45 46 52 public void removeListDataListener(ListDataListener l) { 53 listenerList.remove(ListDataListener.class, l); 54 } 55 56 57 70 public ListDataListener[] getListDataListeners() { 71 return (ListDataListener[])listenerList.getListeners( 72 ListDataListener.class); 73 } 74 75 76 90 protected void fireContentsChanged(Object source, int index0, int index1) 91 { 92 Object [] listeners = listenerList.getListenerList(); 93 ListDataEvent e = null; 94 95 for (int i = listeners.length - 2; i >= 0; i -= 2) { 96 if (listeners[i] == ListDataListener.class) { 97 if (e == null) { 98 e = new ListDataEvent(source, ListDataEvent.CONTENTS_CHANGED, index0, index1); 99 } 100 ((ListDataListener)listeners[i+1]).contentsChanged(e); 101 } 102 } 103 } 104 105 106 120 protected void fireIntervalAdded(Object source, int index0, int index1) 121 { 122 Object [] listeners = listenerList.getListenerList(); 123 ListDataEvent e = null; 124 125 for (int i = listeners.length - 2; i >= 0; i -= 2) { 126 if (listeners[i] == ListDataListener.class) { 127 if (e == null) { 128 e = new ListDataEvent(source, ListDataEvent.INTERVAL_ADDED, index0, index1); 129 } 130 ((ListDataListener)listeners[i+1]).intervalAdded(e); 131 } 132 } 133 } 134 135 136 151 protected void fireIntervalRemoved(Object source, int index0, int index1) 152 { 153 Object [] listeners = listenerList.getListenerList(); 154 ListDataEvent e = null; 155 156 for (int i = listeners.length - 2; i >= 0; i -= 2) { 157 if (listeners[i] == ListDataListener.class) { 158 if (e == null) { 159 e = new ListDataEvent(source, ListDataEvent.INTERVAL_REMOVED, index0, index1); 160 } 161 ((ListDataListener)listeners[i+1]).intervalRemoved(e); 162 } 163 } 164 } 165 166 201 public <T extends EventListener > T[] getListeners(Class <T> listenerType) { 202 return listenerList.getListeners(listenerType); 203 } 204 } 205 | Popular Tags |