1 7 8 package javax.swing; 9 10 import java.util.*; 11 import javax.swing.event.*; 12 13 14 31 public abstract class AbstractSpinnerModel implements SpinnerModel 32 { 33 34 39 private transient ChangeEvent changeEvent = null; 40 41 42 46 protected EventListenerList listenerList = new EventListenerList(); 47 48 49 57 public void addChangeListener(ChangeListener l) { 58 listenerList.add(ChangeListener.class, l); 59 } 60 61 62 69 public void removeChangeListener(ChangeListener l) { 70 listenerList.remove(ChangeListener.class, l); 71 } 72 73 74 82 public ChangeListener[] getChangeListeners() { 83 return (ChangeListener[])listenerList.getListeners( 84 ChangeListener.class); 85 } 86 87 88 94 protected void fireStateChanged() 95 { 96 Object [] listeners = listenerList.getListenerList(); 97 for (int i = listeners.length - 2; i >= 0; i -=2 ) { 98 if (listeners[i] == ChangeListener.class) { 99 if (changeEvent == null) { 100 changeEvent = new ChangeEvent(this); 101 } 102 ((ChangeListener)listeners[i+1]).stateChanged(changeEvent); 103 } 104 } 105 } 106 107 108 120 public <T extends EventListener> T[] getListeners(Class <T> listenerType) { 121 return listenerList.getListeners(listenerType); 122 } 123 } 124 125 | Popular Tags |