equal
deleted
inserted
replaced
81 */ |
81 */ |
82 public class PropertyChangeSupport implements Serializable { |
82 public class PropertyChangeSupport implements Serializable { |
83 private PropertyChangeListenerMap map = new PropertyChangeListenerMap(); |
83 private PropertyChangeListenerMap map = new PropertyChangeListenerMap(); |
84 |
84 |
85 /** |
85 /** |
86 * Constructs a <code>PropertyChangeSupport</code> object. |
86 * Constructs a {@code PropertyChangeSupport} object. |
87 * |
87 * |
88 * @param sourceBean The bean to be given as the source for any events. |
88 * @param sourceBean The bean to be given as the source for any events. |
89 */ |
89 */ |
90 public PropertyChangeSupport(Object sourceBean) { |
90 public PropertyChangeSupport(Object sourceBean) { |
91 if (sourceBean == null) { |
91 if (sourceBean == null) { |
97 /** |
97 /** |
98 * Add a PropertyChangeListener to the listener list. |
98 * Add a PropertyChangeListener to the listener list. |
99 * The listener is registered for all properties. |
99 * The listener is registered for all properties. |
100 * The same listener object may be added more than once, and will be called |
100 * The same listener object may be added more than once, and will be called |
101 * as many times as it is added. |
101 * as many times as it is added. |
102 * If <code>listener</code> is null, no exception is thrown and no action |
102 * If {@code listener} is null, no exception is thrown and no action |
103 * is taken. |
103 * is taken. |
104 * |
104 * |
105 * @param listener The PropertyChangeListener to be added |
105 * @param listener The PropertyChangeListener to be added |
106 */ |
106 */ |
107 public void addPropertyChangeListener(PropertyChangeListener listener) { |
107 public void addPropertyChangeListener(PropertyChangeListener listener) { |
121 |
121 |
122 /** |
122 /** |
123 * Remove a PropertyChangeListener from the listener list. |
123 * Remove a PropertyChangeListener from the listener list. |
124 * This removes a PropertyChangeListener that was registered |
124 * This removes a PropertyChangeListener that was registered |
125 * for all properties. |
125 * for all properties. |
126 * If <code>listener</code> was added more than once to the same event |
126 * If {@code listener} was added more than once to the same event |
127 * source, it will be notified one less time after being removed. |
127 * source, it will be notified one less time after being removed. |
128 * If <code>listener</code> is null, or was never added, no exception is |
128 * If {@code listener} is null, or was never added, no exception is |
129 * thrown and no action is taken. |
129 * thrown and no action is taken. |
130 * |
130 * |
131 * @param listener The PropertyChangeListener to be removed |
131 * @param listener The PropertyChangeListener to be removed |
132 */ |
132 */ |
133 public void removePropertyChangeListener(PropertyChangeListener listener) { |
133 public void removePropertyChangeListener(PropertyChangeListener listener) { |
149 * Returns an array of all the listeners that were added to the |
149 * Returns an array of all the listeners that were added to the |
150 * PropertyChangeSupport object with addPropertyChangeListener(). |
150 * PropertyChangeSupport object with addPropertyChangeListener(). |
151 * <p> |
151 * <p> |
152 * If some listeners have been added with a named property, then |
152 * If some listeners have been added with a named property, then |
153 * the returned array will be a mixture of PropertyChangeListeners |
153 * the returned array will be a mixture of PropertyChangeListeners |
154 * and <code>PropertyChangeListenerProxy</code>s. If the calling |
154 * and {@code PropertyChangeListenerProxy}s. If the calling |
155 * method is interested in distinguishing the listeners then it must |
155 * method is interested in distinguishing the listeners then it must |
156 * test each element to see if it's a |
156 * test each element to see if it's a |
157 * <code>PropertyChangeListenerProxy</code>, perform the cast, and examine |
157 * {@code PropertyChangeListenerProxy}, perform the cast, and examine |
158 * the parameter. |
158 * the parameter. |
159 * |
159 * |
160 * <pre>{@code |
160 * <pre>{@code |
161 * PropertyChangeListener[] listeners = bean.getPropertyChangeListeners(); |
161 * PropertyChangeListener[] listeners = bean.getPropertyChangeListeners(); |
162 * for (int i = 0; i < listeners.length; i++) { |
162 * for (int i = 0; i < listeners.length; i++) { |
170 * } |
170 * } |
171 * } |
171 * } |
172 * }</pre> |
172 * }</pre> |
173 * |
173 * |
174 * @see PropertyChangeListenerProxy |
174 * @see PropertyChangeListenerProxy |
175 * @return all of the <code>PropertyChangeListeners</code> added or an |
175 * @return all of the {@code PropertyChangeListeners} added or an |
176 * empty array if no listeners have been added |
176 * empty array if no listeners have been added |
177 * @since 1.4 |
177 * @since 1.4 |
178 */ |
178 */ |
179 public PropertyChangeListener[] getPropertyChangeListeners() { |
179 public PropertyChangeListener[] getPropertyChangeListeners() { |
180 return this.map.getListeners(); |
180 return this.map.getListeners(); |
185 * will be invoked only when a call on firePropertyChange names that |
185 * will be invoked only when a call on firePropertyChange names that |
186 * specific property. |
186 * specific property. |
187 * The same listener object may be added more than once. For each |
187 * The same listener object may be added more than once. For each |
188 * property, the listener will be invoked the number of times it was added |
188 * property, the listener will be invoked the number of times it was added |
189 * for that property. |
189 * for that property. |
190 * If <code>propertyName</code> or <code>listener</code> is null, no |
190 * If {@code propertyName} or {@code listener} is null, no |
191 * exception is thrown and no action is taken. |
191 * exception is thrown and no action is taken. |
192 * |
192 * |
193 * @param propertyName The name of the property to listen on. |
193 * @param propertyName The name of the property to listen on. |
194 * @param listener The PropertyChangeListener to be added |
194 * @param listener The PropertyChangeListener to be added |
195 * @since 1.2 |
195 * @since 1.2 |
206 } |
206 } |
207 } |
207 } |
208 |
208 |
209 /** |
209 /** |
210 * Remove a PropertyChangeListener for a specific property. |
210 * Remove a PropertyChangeListener for a specific property. |
211 * If <code>listener</code> was added more than once to the same event |
211 * If {@code listener} was added more than once to the same event |
212 * source for the specified property, it will be notified one less time |
212 * source for the specified property, it will be notified one less time |
213 * after being removed. |
213 * after being removed. |
214 * If <code>propertyName</code> is null, no exception is thrown and no |
214 * If {@code propertyName} is null, no exception is thrown and no |
215 * action is taken. |
215 * action is taken. |
216 * If <code>listener</code> is null, or was never added for the specified |
216 * If {@code listener} is null, or was never added for the specified |
217 * property, no exception is thrown and no action is taken. |
217 * property, no exception is thrown and no action is taken. |
218 * |
218 * |
219 * @param propertyName The name of the property that was listened on. |
219 * @param propertyName The name of the property that was listened on. |
220 * @param listener The PropertyChangeListener to be removed |
220 * @param listener The PropertyChangeListener to be removed |
221 * @since 1.2 |
221 * @since 1.2 |
235 /** |
235 /** |
236 * Returns an array of all the listeners which have been associated |
236 * Returns an array of all the listeners which have been associated |
237 * with the named property. |
237 * with the named property. |
238 * |
238 * |
239 * @param propertyName The name of the property being listened to |
239 * @param propertyName The name of the property being listened to |
240 * @return all of the <code>PropertyChangeListeners</code> associated with |
240 * @return all of the {@code PropertyChangeListeners} associated with |
241 * the named property. If no such listeners have been added, |
241 * the named property. If no such listeners have been added, |
242 * or if <code>propertyName</code> is null, an empty array is |
242 * or if {@code propertyName} is null, an empty array is |
243 * returned. |
243 * returned. |
244 * @since 1.4 |
244 * @since 1.4 |
245 */ |
245 */ |
246 public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { |
246 public PropertyChangeListener[] getPropertyChangeListeners(String propertyName) { |
247 return this.map.getListeners(propertyName); |
247 return this.map.getListeners(propertyName); |
409 } |
409 } |
410 } |
410 } |
411 |
411 |
412 /** |
412 /** |
413 * Check if there are any listeners for a specific property, including |
413 * Check if there are any listeners for a specific property, including |
414 * those registered on all properties. If <code>propertyName</code> |
414 * those registered on all properties. If {@code propertyName} |
415 * is null, only check for listeners registered on all properties. |
415 * is null, only check for listeners registered on all properties. |
416 * |
416 * |
417 * @param propertyName the property name. |
417 * @param propertyName the property name. |
418 * @return true if there are one or more listeners for the given property |
418 * @return true if there are one or more listeners for the given property |
419 * @since 1.2 |
419 * @since 1.2 |
421 public boolean hasListeners(String propertyName) { |
421 public boolean hasListeners(String propertyName) { |
422 return this.map.hasListeners(propertyName); |
422 return this.map.hasListeners(propertyName); |
423 } |
423 } |
424 |
424 |
425 /** |
425 /** |
426 * @serialData Null terminated list of <code>PropertyChangeListeners</code>. |
426 * @serialData Null terminated list of {@code PropertyChangeListeners}. |
427 * <p> |
427 * <p> |
428 * At serialization time we skip non-serializable listeners and |
428 * At serialization time we skip non-serializable listeners and |
429 * only serialize the serializable listeners. |
429 * only serialize the serializable listeners. |
430 */ |
430 */ |
431 private void writeObject(ObjectOutputStream s) throws IOException { |
431 private void writeObject(ObjectOutputStream s) throws IOException { |