001: /*
002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003: * Distributed under the terms of either:
004: * - the common development and distribution license (CDDL), v1.0; or
005: * - the GNU Lesser General Public License, v2.1 or later
006: * $Id: AbstractPropertyChangeSupport.java 3634 2007-01-08 21:42:24Z gbevin $
007: */
008: package com.uwyn.rife.tools;
009:
010: import com.uwyn.rife.tools.exceptions.SourceBeanRequiredException;
011: import java.beans.PropertyChangeEvent;
012: import java.beans.PropertyChangeListener;
013: import java.beans.PropertyChangeSupport;
014: import java.util.logging.Logger;
015:
016: public abstract class AbstractPropertyChangeSupport implements
017: Cloneable {
018: private PropertyChangeSupport mPropertyChangeSupport = null;
019:
020: protected AbstractPropertyChangeSupport() {
021: }
022:
023: protected void setSource(Object sourceBean) {
024: mPropertyChangeSupport = new PropertyChangeSupport(sourceBean);
025: }
026:
027: private void ensureSourceBean() {
028: if (null == mPropertyChangeSupport) {
029: throw new SourceBeanRequiredException(getClass());
030: }
031: }
032:
033: /**
034: * @see PropertyChangeSupport#addPropertyChangeListener(String, PropertyChangeListener)
035: */
036: public void addPropertyChangeListener(String propertyName,
037: PropertyChangeListener listener) {
038: ensureSourceBean();
039: mPropertyChangeSupport.addPropertyChangeListener(propertyName,
040: listener);
041: }
042:
043: /**
044: * @see PropertyChangeSupport#addPropertyChangeListener(PropertyChangeListener)
045: */
046: public void addPropertyChangeListener(
047: PropertyChangeListener listener) {
048: ensureSourceBean();
049: mPropertyChangeSupport.addPropertyChangeListener(listener);
050: }
051:
052: /**
053: * @see PropertyChangeSupport#firePropertyChange(String, boolean, boolean)
054: */
055: public void firePropertyChange(String propertyName,
056: boolean oldValue, boolean newValue) {
057: ensureSourceBean();
058: mPropertyChangeSupport.firePropertyChange(propertyName,
059: oldValue, newValue);
060: }
061:
062: /**
063: * @see PropertyChangeSupport#firePropertyChange(String, int, int)
064: */
065: public void firePropertyChange(String propertyName, int oldValue,
066: int newValue) {
067: ensureSourceBean();
068: mPropertyChangeSupport.firePropertyChange(propertyName,
069: oldValue, newValue);
070: }
071:
072: /**
073: * @see PropertyChangeSupport#firePropertyChange(PropertyChangeEvent)
074: */
075: public void firePropertyChange(PropertyChangeEvent evt) {
076: ensureSourceBean();
077: mPropertyChangeSupport.firePropertyChange(evt);
078: }
079:
080: /**
081: * @see PropertyChangeSupport#firePropertyChange(String, Object, Object)
082: */
083: public void firePropertyChange(String propertyName,
084: Object oldValue, Object newValue) {
085: ensureSourceBean();
086: mPropertyChangeSupport.firePropertyChange(propertyName,
087: oldValue, newValue);
088: }
089:
090: /**
091: * @see PropertyChangeSupport#getPropertyChangeListeners(String)
092: */
093: public PropertyChangeListener[] getPropertyChangeListeners(
094: String propertyName) {
095: ensureSourceBean();
096: return mPropertyChangeSupport
097: .getPropertyChangeListeners(propertyName);
098: }
099:
100: /**
101: * @see PropertyChangeSupport#getPropertyChangeListeners()
102: */
103: public PropertyChangeListener[] getPropertyChangeListeners() {
104: ensureSourceBean();
105: return mPropertyChangeSupport.getPropertyChangeListeners();
106: }
107:
108: /**
109: * @see PropertyChangeSupport#hasListeners(String)
110: */
111: public boolean hasListeners(String propertyName) {
112: ensureSourceBean();
113: return mPropertyChangeSupport.hasListeners(propertyName);
114: }
115:
116: /**
117: * @see PropertyChangeSupport#removePropertyChangeListener(String, PropertyChangeListener)
118: */
119: public void removePropertyChangeListener(String propertyName,
120: PropertyChangeListener listener) {
121: ensureSourceBean();
122: mPropertyChangeSupport.removePropertyChangeListener(
123: propertyName, listener);
124: }
125:
126: /**
127: * @see PropertyChangeSupport#removePropertyChangeListener(PropertyChangeListener)
128: */
129: public void removePropertyChangeListener(
130: PropertyChangeListener listener) {
131: ensureSourceBean();
132: mPropertyChangeSupport.removePropertyChangeListener(listener);
133: }
134:
135: public AbstractPropertyChangeSupport clone() {
136: AbstractPropertyChangeSupport new_object = null;
137: try {
138: new_object = (AbstractPropertyChangeSupport) super .clone();
139: } catch (CloneNotSupportedException e) {
140: ///CLOVER:OFF
141: // should never happen
142: Logger.getLogger("com.uwyn.rife.tools").severe(
143: ExceptionUtils.getExceptionStackTrace(e));
144: ///CLOVER:ON
145: }
146:
147: new_object.mPropertyChangeSupport = new PropertyChangeSupport(
148: new_object);
149:
150: return new_object;
151: }
152: }
|