jaroslav@601: /* jaroslav@601: * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved. jaroslav@601: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jaroslav@601: * jaroslav@601: * This code is free software; you can redistribute it and/or modify it jaroslav@601: * under the terms of the GNU General Public License version 2 only, as jaroslav@601: * published by the Free Software Foundation. Oracle designates this jaroslav@601: * particular file as subject to the "Classpath" exception as provided jaroslav@601: * by Oracle in the LICENSE file that accompanied this code. jaroslav@601: * jaroslav@601: * This code is distributed in the hope that it will be useful, but WITHOUT jaroslav@601: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jaroslav@601: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jaroslav@601: * version 2 for more details (a copy is included in the LICENSE file that jaroslav@601: * accompanied this code). jaroslav@601: * jaroslav@601: * You should have received a copy of the GNU General Public License version jaroslav@601: * 2 along with this work; if not, write to the Free Software Foundation, jaroslav@601: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jaroslav@601: * jaroslav@601: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jaroslav@601: * or visit www.oracle.com if you need additional information or have any jaroslav@601: * questions. jaroslav@601: */ jaroslav@601: jaroslav@601: package java.beans; jaroslav@601: jaroslav@601: /** jaroslav@601: * A "PropertyChange" event gets delivered whenever a bean changes a "bound" jaroslav@601: * or "constrained" property. A PropertyChangeEvent object is sent as an jaroslav@601: * argument to the PropertyChangeListener and VetoableChangeListener methods. jaroslav@601: *
jaroslav@601: * Normally PropertyChangeEvents are accompanied by the name and the old jaroslav@601: * and new value of the changed property. If the new value is a primitive jaroslav@601: * type (such as int or boolean) it must be wrapped as the jaroslav@601: * corresponding java.lang.* Object type (such as Integer or Boolean). jaroslav@601: *
jaroslav@601: * Null values may be provided for the old and the new values if their jaroslav@601: * true values are not known. jaroslav@601: *
jaroslav@601: * An event source may send a null object as the name to indicate that an
jaroslav@601: * arbitrary set of if its properties have changed. In this case the
jaroslav@601: * old and new values should also be null.
jaroslav@601: */
jaroslav@601:
jaroslav@601: public class PropertyChangeEvent extends java.util.EventObject {
jaroslav@601: private static final long serialVersionUID = 7042693688939648123L;
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * Constructs a new PropertyChangeEvent
.
jaroslav@601: *
jaroslav@601: * @param source The bean that fired the event.
jaroslav@601: * @param propertyName The programmatic name of the property
jaroslav@601: * that was changed.
jaroslav@601: * @param oldValue The old value of the property.
jaroslav@601: * @param newValue The new value of the property.
jaroslav@601: */
jaroslav@601: public PropertyChangeEvent(Object source, String propertyName,
jaroslav@601: Object oldValue, Object newValue) {
jaroslav@601: super(source);
jaroslav@601: this.propertyName = propertyName;
jaroslav@601: this.newValue = newValue;
jaroslav@601: this.oldValue = oldValue;
jaroslav@601: }
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * Gets the programmatic name of the property that was changed.
jaroslav@601: *
jaroslav@601: * @return The programmatic name of the property that was changed.
jaroslav@601: * May be null if multiple properties have changed.
jaroslav@601: */
jaroslav@601: public String getPropertyName() {
jaroslav@601: return propertyName;
jaroslav@601: }
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * Gets the new value for the property, expressed as an Object.
jaroslav@601: *
jaroslav@601: * @return The new value for the property, expressed as an Object.
jaroslav@601: * May be null if multiple properties have changed.
jaroslav@601: */
jaroslav@601: public Object getNewValue() {
jaroslav@601: return newValue;
jaroslav@601: }
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * Gets the old value for the property, expressed as an Object.
jaroslav@601: *
jaroslav@601: * @return The old value for the property, expressed as an Object.
jaroslav@601: * May be null if multiple properties have changed.
jaroslav@601: */
jaroslav@601: public Object getOldValue() {
jaroslav@601: return oldValue;
jaroslav@601: }
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * Sets the propagationId object for the event.
jaroslav@601: *
jaroslav@601: * @param propagationId The propagationId object for the event.
jaroslav@601: */
jaroslav@601: public void setPropagationId(Object propagationId) {
jaroslav@601: this.propagationId = propagationId;
jaroslav@601: }
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * The "propagationId" field is reserved for future use. In Beans 1.0
jaroslav@601: * the sole requirement is that if a listener catches a PropertyChangeEvent
jaroslav@601: * and then fires a PropertyChangeEvent of its own, then it should
jaroslav@601: * make sure that it propagates the propagationId field from its
jaroslav@601: * incoming event to its outgoing event.
jaroslav@601: *
jaroslav@601: * @return the propagationId object associated with a bound/constrained
jaroslav@601: * property update.
jaroslav@601: */
jaroslav@601: public Object getPropagationId() {
jaroslav@601: return propagationId;
jaroslav@601: }
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * name of the property that changed. May be null, if not known.
jaroslav@601: * @serial
jaroslav@601: */
jaroslav@601: private String propertyName;
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * New value for property. May be null if not known.
jaroslav@601: * @serial
jaroslav@601: */
jaroslav@601: private Object newValue;
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * Previous value for property. May be null if not known.
jaroslav@601: * @serial
jaroslav@601: */
jaroslav@601: private Object oldValue;
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * Propagation ID. May be null.
jaroslav@601: * @serial
jaroslav@601: * @see #getPropagationId
jaroslav@601: */
jaroslav@601: private Object propagationId;
jaroslav@601:
jaroslav@601: /**
jaroslav@601: * Returns a string representation of the object.
jaroslav@601: *
jaroslav@601: * @return a string representation of the object
jaroslav@601: *
jaroslav@601: * @since 1.7
jaroslav@601: */
jaroslav@601: public String toString() {
jaroslav@601: StringBuilder sb = new StringBuilder(getClass().getName());
jaroslav@601: sb.append("[propertyName=").append(getPropertyName());
jaroslav@601: appendTo(sb);
jaroslav@601: sb.append("; oldValue=").append(getOldValue());
jaroslav@601: sb.append("; newValue=").append(getNewValue());
jaroslav@601: sb.append("; propagationId=").append(getPropagationId());
jaroslav@601: sb.append("; source=").append(getSource());
jaroslav@601: return sb.append("]").toString();
jaroslav@601: }
jaroslav@601:
jaroslav@601: void appendTo(StringBuilder sb) {
jaroslav@601: }
jaroslav@601: }