1 17 package swingwtx.swing.event; 18 19 import java.beans.PropertyChangeEvent ; 20 import java.beans.PropertyChangeListener ; 21 22 26 public class SwingPropertyChangeSupport 27 { 28 protected EventListenerList listenerList = new EventListenerList(); 29 30 private Object source; 32 33 36 public SwingPropertyChangeSupport(Object source) 37 { 38 this.source = source; 39 } 40 41 46 public void firePropertyChange(String propertyName, Object oldValue, Object newValue) 47 { 48 PropertyChangeEvent propertyChangeEvent = new PropertyChangeEvent (source, propertyName, oldValue, newValue); 49 PropertyChangeListener [] listeners = (PropertyChangeListener []) listenerList. 50 getListeners(PropertyChangeListener .class); 51 for (int i = 0; i < listeners.length; i += 2) 52 { 53 listeners[i].propertyChange(propertyChangeEvent); 54 } 55 } 56 57 60 public void addPropertyChangeListener(PropertyChangeListener listener) 61 { 62 listenerList.add(PropertyChangeListener .class, listener); 63 } 64 65 68 public void removePropertyChangeListener(PropertyChangeListener listener) 69 { 70 listenerList.remove(PropertyChangeListener .class, listener); 71 } 72 73 76 public PropertyChangeListener [] getPropertyChangeListeners() 77 { 78 return (PropertyChangeListener []) listenerList.getListeners(PropertyChangeListener .class); 79 } 80 81 } | Popular Tags |