01: package net.sourceforge.squirrel_sql.fw.util;
02:
03: /*
04: * Copyright (C) 2001-2003 Colin Bell
05: * colbell@users.sourceforge.net
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: *
17: * You should have received a copy of the GNU Lesser General Public
18: * License along with this library; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20: */
21: import java.beans.PropertyChangeListener;
22: import java.beans.PropertyChangeSupport;
23: import java.io.Serializable;
24:
25: public class PropertyChangeReporter implements Serializable {
26: private static final long serialVersionUID = 1L;
27:
28: private boolean _notify = true;
29: private Object _srcBean;
30: private PropertyChangeSupport _propChgNotifier;
31:
32: public PropertyChangeReporter(Object srcBean)
33: throws IllegalArgumentException {
34: super ();
35: if (srcBean == null) {
36: throw new IllegalArgumentException("Null srcBean passed");
37: }
38: _srcBean = srcBean;
39: }
40:
41: public void setNotify(boolean value) {
42: _notify = value;
43: }
44:
45: public synchronized void addPropertyChangeListener(
46: PropertyChangeListener listener) {
47: getPropertyChangeNotifier().addPropertyChangeListener(listener);
48: }
49:
50: public synchronized void removePropertyChangeListener(
51: PropertyChangeListener listener) {
52: getPropertyChangeNotifier().removePropertyChangeListener(
53: listener);
54: }
55:
56: public void firePropertyChange(String propName, Object oldValue,
57: Object newValue) {
58: if (_notify) {
59: getPropertyChangeNotifier().firePropertyChange(propName,
60: oldValue, newValue);
61: }
62: }
63:
64: public void firePropertyChange(String propName, boolean oldValue,
65: boolean newValue) {
66: if (_notify) {
67: getPropertyChangeNotifier().firePropertyChange(propName,
68: oldValue, newValue);
69: }
70: }
71:
72: public void firePropertyChange(String propName, int oldValue,
73: int newValue) {
74: if (_notify) {
75: getPropertyChangeNotifier().firePropertyChange(propName,
76: oldValue, newValue);
77: }
78: }
79:
80: private PropertyChangeSupport getPropertyChangeNotifier() {
81: if (_propChgNotifier == null) {
82: _propChgNotifier = new PropertyChangeSupport(_srcBean);
83: }
84: return _propChgNotifier;
85: }
86: }
|