001: /*
002: * $RCSfile: PropertyChangeSupportJAI.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:16 $
010: * $State: Exp $
011: */
012: package javax.media.jai;
013:
014: import java.beans.PropertyChangeEvent;
015: import java.beans.PropertyChangeListener;
016: import java.beans.PropertyChangeSupport;
017:
018: /**
019: * Extension of the beans utility class <code>PropertyChangeSupport</code>
020: * which adds an accessor for the parameter passed to the constructor. All
021: * events fired by the <code>firePropertyChange()</code> methods of this
022: * class are instances of <code>PropertyChangeEventJAI</code>; consequently
023: * all property names are forced to lower case for recognition purposes.
024: * The property name-specific <code>PropertyChangeListener</code> registration
025: * and unregistration methods defined in this class also force the supplied
026: * property name to lower case.
027: *
028: * @see PropertyChangeSupport
029: *
030: * @since JAI 1.1
031: */
032: public final class PropertyChangeSupportJAI extends
033: PropertyChangeSupport {
034: /**
035: * The <code>PropertyChangeEvent</code> source.
036: */
037: protected Object propertyChangeEventSource;
038:
039: /**
040: * Constructs a <code>PropertyChangeSupportJAI</code> object. The
041: * parameter is cached for later use and retrieval.
042: *
043: * @param propertyChangeEventSource The property change event source.
044: * @throws If <code>propertyChangeEventSource</code> is <code>null</code>
045: * then a <code>NullPointerException</code> will be thrown
046: * in the superclass.
047: */
048: public PropertyChangeSupportJAI(Object propertyChangeEventSource) {
049: // if propertyChangeEventSource is null, a NullPointerException
050: // is thrown in the superclass.
051: super (propertyChangeEventSource);
052:
053: this .propertyChangeEventSource = propertyChangeEventSource;
054: }
055:
056: /**
057: * Retrieve the parameter passed to the constructor.
058: *
059: * @return The property change event source.
060: */
061: public Object getPropertyChangeEventSource() {
062: return propertyChangeEventSource;
063: }
064:
065: /**
066: * Add a <code>PropertyChangeListener</code> for a specific property.
067: * The <code>propertyName</code> is forced to lower case.
068: *
069: * @exception IllegalArgumentException if <code>propertyName</code> is
070: * <code>null</code>.
071: */
072: public void addPropertyChangeListener(String propertyName,
073: PropertyChangeListener listener) {
074:
075: if (propertyName == null) {
076: throw new IllegalArgumentException(JaiI18N
077: .getString("Generic0"));
078: }
079:
080: super .addPropertyChangeListener(propertyName.toLowerCase(),
081: listener);
082: }
083:
084: /**
085: * Remove a <code>PropertyChangeListener</code> for a specific property.
086: * The <code>propertyName</code> is forced to lower case.
087: *
088: * @exception IllegalArgumentException if <code>propertyName</code> is
089: * <code>null</code>.
090: */
091: public void removePropertyChangeListener(String propertyName,
092: PropertyChangeListener listener) {
093:
094: if (propertyName == null) {
095: throw new IllegalArgumentException(JaiI18N
096: .getString("Generic0"));
097: }
098:
099: super .removePropertyChangeListener(propertyName.toLowerCase(),
100: listener);
101: }
102:
103: /**
104: * Report a bound property update to any registered listeners.
105: * If the supplied object is not a <code>PropertyChangeEventJAI</code>
106: * then a <code>PropertyChangeEventJAI</code> is constructed from the
107: * event object's accessors and fired instead.
108: *
109: * @param evt The <code>PropertyChangeEvent</code> object.
110: */
111: public void firePropertyChange(PropertyChangeEvent evt) {
112: if (!(evt instanceof PropertyChangeEventJAI)) {
113: evt = new PropertyChangeEventJAI(evt.getSource(), evt
114: .getPropertyName(), evt.getOldValue(), evt
115: .getNewValue());
116: }
117: super .firePropertyChange(evt);
118: }
119:
120: /**
121: * Report a bound property update to any registered listeners.
122: * A <code>PropertyChangeEventJAI</code> is created from the cached
123: * property event source and the supplied parameters and fired using
124: * the superclass <code>firePropertyChange(PropertyChangeEvent)</code>
125: * method.
126: *
127: * @param propertyName The name of the changed property.
128: * @param oldValue The old value of the property.
129: * @param newValue The new value of the property.
130: */
131: public void firePropertyChange(String propertyName,
132: Object oldValue, Object newValue) {
133: PropertyChangeEventJAI evt = new PropertyChangeEventJAI(
134: propertyChangeEventSource, propertyName, oldValue,
135: newValue);
136: super .firePropertyChange(evt);
137: }
138:
139: /**
140: * Check whether there are any listeners for a specific property.
141: * The <code>propertyName</code> is forced to lower case.
142: *
143: * @param propertyName The name of the property.
144: * @return <code>true</code> if there are one or more listeners for
145: * the given property
146: */
147: public synchronized boolean hasListeners(String propertyName) {
148: return super.hasListeners(propertyName.toLowerCase());
149: }
150: }
|