home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / Java2 / src / java / beans / PropertyChangeEvent.java < prev    next >
Encoding:
Java Source  |  1999-05-28  |  4.0 KB  |  132 lines  |  [TEXT/CWIE]

  1. /*
  2.  * @(#)PropertyChangeEvent.java    1.28 98/09/21
  3.  *
  4.  * Copyright 1996-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  * 
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.beans;
  16.  
  17. /**
  18.  * A "PropertyChange" event gets delivered whenever a bean changes a "bound"
  19.  * or "constrained" property.  A PropertyChangeEvent object is sent as an
  20.  * argument to the PropertyChangeListener and VetoableChangeListener methods.
  21.  * <P>
  22.  * Normally PropertyChangeEvents are accompanied by the name and the old
  23.  * and new value of the changed property.  If the new value is a primitive
  24.  * type (such as int or boolean) it must be wrapped as the 
  25.  * corresponding java.lang.* Object type (such as Integer or Boolean).
  26.  * <P>
  27.  * Null values may be provided for the old and the new values if their
  28.  * true values are not known.
  29.  * <P>
  30.  * An event source may send a null object as the name to indicate that an
  31.  * arbitrary set of if its properties have changed.  In this case the
  32.  * old and new values should also be null.
  33.  */
  34.  
  35. public class PropertyChangeEvent extends java.util.EventObject {
  36.  
  37.     /**
  38.      * Constructs a new <code>PropertyChangeEvent</code>.
  39.      *
  40.      * @param source  The bean that fired the event.
  41.      * @param propertyName  The programmatic name of the property
  42.      *        that was changed.
  43.      * @param oldValue  The old value of the property.
  44.      * @param newValue  The new value of the property.
  45.      */
  46.     public PropertyChangeEvent(Object source, String propertyName,
  47.                      Object oldValue, Object newValue) {
  48.     super(source);
  49.     this.propertyName = propertyName;
  50.     this.newValue = newValue;
  51.     this.oldValue = oldValue;
  52.     }
  53.  
  54.     /**
  55.      * Gets the programmatic name of the property that was changed.
  56.      *
  57.      * @return  The programmatic name of the property that was changed.
  58.      *        May be null if multiple properties have changed.
  59.      */
  60.     public String getPropertyName() {
  61.     return propertyName;
  62.     }
  63.     
  64.     /**
  65.      * Sets the new value for the property, expressed as an Object.
  66.      *
  67.      * @return  The new value for the property, expressed as an Object.
  68.      *        May be null if multiple properties have changed.
  69.      */
  70.     public Object getNewValue() {
  71.     return newValue;
  72.     }
  73.  
  74.     /**
  75.      * Gets the old value for the property, expressed as an Object.
  76.      *
  77.      * @return  The old value for the property, expressed as an Object.
  78.      *        May be null if multiple properties have changed.
  79.      */
  80.     public Object getOldValue() {
  81.     return oldValue;
  82.     }
  83.  
  84.     /**
  85.      * Sets the propagationId object for the event.
  86.      *
  87.      * @param propagationId  The propagationId object for the event.
  88.      */
  89.     public void setPropagationId(Object propagationId) {
  90.     this.propagationId = propagationId;
  91.     }
  92.  
  93.     /**
  94.      * The "propagationId" field is reserved for future use.  In Beans 1.0
  95.      * the sole requirement is that if a listener catches a PropertyChangeEvent
  96.      * and then fires a PropertyChangeEvent of its own, then it should
  97.      * make sure that it propagates the propagationId field from its
  98.      * incoming event to its outgoing event.
  99.      *
  100.      * @return the propagationId object associated with a bound/constrained
  101.      *        property update.
  102.      */
  103.     public Object getPropagationId() {
  104.     return propagationId;
  105.     }
  106.  
  107.     /**
  108.      * name of the property that changed.  May be null, if not known.
  109.      * @serial
  110.      */
  111.     private String propertyName;
  112.  
  113.     /**
  114.      * New value for property.  May be null if not known.
  115.      * @serial
  116.      */
  117.     private Object newValue;
  118.  
  119.     /**
  120.      * Previous value for property.  May be null if not known.
  121.      * @serial
  122.      */
  123.     private Object oldValue;
  124.  
  125.     /**
  126.      * Propagation ID.  May be null.
  127.      * @serial
  128.      * @see #getPropagationId.
  129.      */
  130.     private Object propagationId;
  131. }
  132.