KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > swingwtx > swing > event > SwingPropertyChangeSupport


1 /*
2    SwingWT
3    Copyright(c)2003-2004, R. Rawson-Tetley
4
5    For more information on distributing and using this program, please
6    see the accompanying "COPYING" file.
7
8    Contact me by electronic mail: bobintetley@users.sourceforge.net
9
10    $Log: SwingPropertyChangeSupport.java,v $
11    Revision 1.2 2004/04/15 11:24:33 bobintetley
12    (Dan Naab) ComponentUI, UIDefaults/UIManager and Accessibility support.
13    (Antonio Weber) TableColumnModelListener implementation and support
14
15
16 */

17 package swingwtx.swing.event;
18
19 import java.beans.PropertyChangeEvent JavaDoc;
20 import java.beans.PropertyChangeListener JavaDoc;
21
22 /**
23  * @author Daniel Spiewak
24  * @author Daniel Naab
25  */

26  public class SwingPropertyChangeSupport
27  {
28      protected EventListenerList listenerList = new EventListenerList();
29  
30      // Source object responsible for managing property changes
31
private Object JavaDoc source;
32  
33      /**
34       * @param source
35       */

36      public SwingPropertyChangeSupport(Object JavaDoc source)
37      {
38          this.source = source;
39      }
40  
41      /**
42       * @param propertyName
43       * @param oldValue
44       * @param newValue
45       */

46      public void firePropertyChange(String JavaDoc propertyName, Object JavaDoc oldValue, Object JavaDoc newValue)
47      {
48          PropertyChangeEvent JavaDoc propertyChangeEvent = new PropertyChangeEvent JavaDoc(source, propertyName, oldValue, newValue);
49          PropertyChangeListener JavaDoc[] listeners = (PropertyChangeListener JavaDoc[]) listenerList.
50                  getListeners(PropertyChangeListener JavaDoc.class);
51          for (int i = 0; i < listeners.length; i += 2)
52          {
53              listeners[i].propertyChange(propertyChangeEvent);
54          }
55      }
56  
57      /**
58       * @param listener
59       */

60      public void addPropertyChangeListener(PropertyChangeListener JavaDoc listener)
61      {
62          listenerList.add(PropertyChangeListener JavaDoc.class, listener);
63      }
64  
65      /**
66       * @param listener
67       */

68      public void removePropertyChangeListener(PropertyChangeListener JavaDoc listener)
69      {
70          listenerList.remove(PropertyChangeListener JavaDoc.class, listener);
71      }
72  
73      /**
74       * @return
75       */

76      public PropertyChangeListener JavaDoc[] getPropertyChangeListeners()
77      {
78          return (PropertyChangeListener JavaDoc[]) listenerList.getListeners(PropertyChangeListener JavaDoc.class);
79      }
80      
81  }
Popular Tags