/*
 * @(#)PropertyChangeForwardingListener.java    1.0  5 May 2003
 *
 * Copyright 2004
 * College of Computer and Information Science
 * Northeastern University
 * Boston, MA  02115
 *
 * The Java Power Tools software may be used for educational
 * purposes as long as this copyright notice is retained intact
 * at the top of all source files.
 *
 * To discuss possible commercial use of this software, 
 * contact Richard Rasala at Northeastern University, 
 * College of Computer and Information Science,
 * 617-373-2462 or rasala@ccs.neu.edu.
 *
 * The Java Power Tools software has been designed and built
 * in collaboration with Viera Proulx and Jeff Raab.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either
 * in whole or in part without explicit permission.
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

package edu.neu.ccs.gui;

import java.beans.*;

/**
 * <P>A <CODE>PropertyChangeForwardingListener</CODE> is a
 * <CODE>PropertyChangeListener</CODE> that forwards a
 * <CODE>PropertyChangeEvent</CODE> event that it receives
 * to an object that implements the interface
 * <CODE>SupportsPropertyChange</CODE> by causing that
 * object to fire the same event to its own listeners.</P>
 *
 * <P>This class is intended to permit
 * <CODE>PropertyChangeEvent</CODE> events that are fired
 * within a composite object to be handled by the listeners
 * for the entire object.</P>
 *
 * <P>More generally, this class may be used to forward
 * events to any appropriate object that implements the
 * interface <CODE>SupportsPropertyChange</CODE>.</P>
 *
 * @author  Richard Rasala
 * @version 2.3
 * @since   2.3
 */
public class PropertyChangeForwardingListener
    implements PropertyChangeListener
{
    /** The object to which events will be forwarded. */
    private SupportsPropertyChange spc;
    
    
    /** 
     * The constructor that sets the associated object that implements
     * <CODE>SupportsPropertyChange</CODE>.
     */
    public PropertyChangeForwardingListener(SupportsPropertyChange spc) {
        this.spc = spc;
    }
    
    
    /**
     * Returns the object that implements <CODE>SupportsPropertyChange</CODE>.
     *
     * @return the object that implements <CODE>SupportsPropertyChange</CODE>
     */
    public final SupportsPropertyChange getSupportsPropertyChange() {
        return spc;
    }
    
    
    // PropertyChangeListener //
    
    /**
     * Handles the given <CODE>PropertyChangeEvent</CODE> by firing a property
     * change for the <CODE>SupportsPropertyChange</CODE> object referenced by
     * this listener.
     *
     * @param evt the <CODE>PropertyChangeEvent</CODE> that triggers this method
     */
    public final void propertyChange(PropertyChangeEvent evt) {
        if ((evt != null) && (spc != null))
            spc.firePropertyChange(evt);
    }
}
