1 /* SwingPropertyChangeSupport.java --
2 Copyright (C) 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax
.swing
.event
;
46 * SwingPropertyChangeSupport
47 * @author Andrew Selkirk
49 public final class SwingPropertyChangeSupport
50 extends PropertyChangeSupport
{
52 private static final long serialVersionUID
= 7162625831330845068L;
54 //-------------------------------------------------------------
55 // Variables --------------------------------------------------
56 //-------------------------------------------------------------
61 private transient EventListenerList listeners
;
66 private Hashtable propertyListeners
;
71 private Object source
;
74 //-------------------------------------------------------------
75 // Initialization ---------------------------------------------
76 //-------------------------------------------------------------
79 * Constructor SwingPropertyChangeSupport
82 public SwingPropertyChangeSupport(Object source
) {
85 this.listeners
= new EventListenerList();
86 this.propertyListeners
= new Hashtable();
87 } // SwingPropertyChangeSupport()
90 //-------------------------------------------------------------
91 // Methods ----------------------------------------------------
92 //-------------------------------------------------------------
97 * @exception IOException TODO
99 private void writeObject(ObjectOutputStream stream
) throws IOException
{
106 * @exception ClassNotFoundException TODO
107 * @exception IOException TODO
109 private void readObject(ObjectInputStream stream
) throws ClassNotFoundException
, IOException
{
114 * addPropertyChangeListener
115 * @param listener TODO
117 public synchronized void addPropertyChangeListener(PropertyChangeListener listener
) {
118 listeners
.add(PropertyChangeListener
.class, listener
);
119 } // addPropertyChangeListener()
122 * addPropertyChangeListener
123 * @param propertyName TODO
124 * @param listener TODO
126 public synchronized void addPropertyChangeListener(String propertyName
, PropertyChangeListener listener
) {
129 EventListenerList list
;
132 list
= (EventListenerList
) propertyListeners
.get(propertyName
);
134 list
= new EventListenerList();
135 propertyListeners
.put(propertyName
, list
);
139 list
.add(PropertyChangeListener
.class, listener
);
141 } // addPropertyChangeListener()
144 * removePropertyChangeListener
145 * @param listener TODO
147 public synchronized void removePropertyChangeListener(PropertyChangeListener listener
) {
148 listeners
.remove(PropertyChangeListener
.class, listener
);
149 } // removePropertyChangeListener()
152 * removePropertyChangeListener
153 * @param propertyName TODO
154 * @param listener TODO
156 public synchronized void removePropertyChangeListener(String propertyName
, PropertyChangeListener listener
) {
159 EventListenerList list
;
162 list
= (EventListenerList
) propertyListeners
.get(propertyName
);
168 list
.remove(PropertyChangeListener
.class, listener
);
170 // Clean up propertyListeners
171 if (list
.getListenerCount() == 0) {
172 propertyListeners
.remove(propertyName
);
175 } // removePropertyChangeListener()
179 * @param propertyName TODO
180 * @param oldValue TODO
181 * @param newValue TODO
183 public void firePropertyChange(String propertyName
, Object oldValue
, Object newValue
) {
186 PropertyChangeEvent event
;
188 // Create Property Change Event
189 event
= new PropertyChangeEvent(source
, propertyName
, oldValue
, newValue
);
192 firePropertyChange(event
);
194 } // firePropertyChange()
200 public void firePropertyChange(PropertyChangeEvent event
) {
203 EventListenerList list
;
204 EventListener
[] listenerList
;
206 PropertyChangeListener listener
;
208 // Check Values if they are equal
209 if (event
.getOldValue() == null || event
.getNewValue() == null ||
210 event
.getOldValue().equals(event
.getNewValue()) == true) {
214 // Process Main Listener List
215 listenerList
= listeners
.getListeners(PropertyChangeListener
.class);
216 for (index
= 0; index
< listenerList
.length
; index
++) {
217 listener
= (PropertyChangeListener
) listenerList
[index
];
218 listener
.propertyChange(event
);
221 // Process Property Listener List
222 list
= (EventListenerList
) propertyListeners
.get(event
.getPropertyName());
224 listenerList
= list
.getListeners(PropertyChangeListener
.class);
225 for (index
= 0; index
< listenerList
.length
; index
++) {
226 listener
= (PropertyChangeListener
) listenerList
[index
];
227 listener
.propertyChange(event
);
231 } // firePropertyChange()
235 * @param propertyName TODO
238 public synchronized boolean hasListeners(String propertyName
) {
241 if (propertyListeners
.get(propertyName
) == null) {
250 } // SwingPropertyChangeSupport