rt/emul/compact/src/main/java/java/beans/PropertyChangeEvent.java
changeset 772 d382dacfd73f
parent 601 5198affdb915
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rt/emul/compact/src/main/java/java/beans/PropertyChangeEvent.java	Tue Feb 26 16:54:16 2013 +0100
     1.3 @@ -0,0 +1,164 @@
     1.4 +/*
     1.5 + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package java.beans;
    1.30 +
    1.31 +/**
    1.32 + * A "PropertyChange" event gets delivered whenever a bean changes a "bound"
    1.33 + * or "constrained" property.  A PropertyChangeEvent object is sent as an
    1.34 + * argument to the PropertyChangeListener and VetoableChangeListener methods.
    1.35 + * <P>
    1.36 + * Normally PropertyChangeEvents are accompanied by the name and the old
    1.37 + * and new value of the changed property.  If the new value is a primitive
    1.38 + * type (such as int or boolean) it must be wrapped as the
    1.39 + * corresponding java.lang.* Object type (such as Integer or Boolean).
    1.40 + * <P>
    1.41 + * Null values may be provided for the old and the new values if their
    1.42 + * true values are not known.
    1.43 + * <P>
    1.44 + * An event source may send a null object as the name to indicate that an
    1.45 + * arbitrary set of if its properties have changed.  In this case the
    1.46 + * old and new values should also be null.
    1.47 + */
    1.48 +
    1.49 +public class PropertyChangeEvent extends java.util.EventObject {
    1.50 +    private static final long serialVersionUID = 7042693688939648123L;
    1.51 +
    1.52 +    /**
    1.53 +     * Constructs a new <code>PropertyChangeEvent</code>.
    1.54 +     *
    1.55 +     * @param source  The bean that fired the event.
    1.56 +     * @param propertyName  The programmatic name of the property
    1.57 +     *          that was changed.
    1.58 +     * @param oldValue  The old value of the property.
    1.59 +     * @param newValue  The new value of the property.
    1.60 +     */
    1.61 +    public PropertyChangeEvent(Object source, String propertyName,
    1.62 +                                     Object oldValue, Object newValue) {
    1.63 +        super(source);
    1.64 +        this.propertyName = propertyName;
    1.65 +        this.newValue = newValue;
    1.66 +        this.oldValue = oldValue;
    1.67 +    }
    1.68 +
    1.69 +    /**
    1.70 +     * Gets the programmatic name of the property that was changed.
    1.71 +     *
    1.72 +     * @return  The programmatic name of the property that was changed.
    1.73 +     *          May be null if multiple properties have changed.
    1.74 +     */
    1.75 +    public String getPropertyName() {
    1.76 +        return propertyName;
    1.77 +    }
    1.78 +
    1.79 +    /**
    1.80 +     * Gets the new value for the property, expressed as an Object.
    1.81 +     *
    1.82 +     * @return  The new value for the property, expressed as an Object.
    1.83 +     *          May be null if multiple properties have changed.
    1.84 +     */
    1.85 +    public Object getNewValue() {
    1.86 +        return newValue;
    1.87 +    }
    1.88 +
    1.89 +    /**
    1.90 +     * Gets the old value for the property, expressed as an Object.
    1.91 +     *
    1.92 +     * @return  The old value for the property, expressed as an Object.
    1.93 +     *          May be null if multiple properties have changed.
    1.94 +     */
    1.95 +    public Object getOldValue() {
    1.96 +        return oldValue;
    1.97 +    }
    1.98 +
    1.99 +    /**
   1.100 +     * Sets the propagationId object for the event.
   1.101 +     *
   1.102 +     * @param propagationId  The propagationId object for the event.
   1.103 +     */
   1.104 +    public void setPropagationId(Object propagationId) {
   1.105 +        this.propagationId = propagationId;
   1.106 +    }
   1.107 +
   1.108 +    /**
   1.109 +     * The "propagationId" field is reserved for future use.  In Beans 1.0
   1.110 +     * the sole requirement is that if a listener catches a PropertyChangeEvent
   1.111 +     * and then fires a PropertyChangeEvent of its own, then it should
   1.112 +     * make sure that it propagates the propagationId field from its
   1.113 +     * incoming event to its outgoing event.
   1.114 +     *
   1.115 +     * @return the propagationId object associated with a bound/constrained
   1.116 +     *          property update.
   1.117 +     */
   1.118 +    public Object getPropagationId() {
   1.119 +        return propagationId;
   1.120 +    }
   1.121 +
   1.122 +    /**
   1.123 +     * name of the property that changed.  May be null, if not known.
   1.124 +     * @serial
   1.125 +     */
   1.126 +    private String propertyName;
   1.127 +
   1.128 +    /**
   1.129 +     * New value for property.  May be null if not known.
   1.130 +     * @serial
   1.131 +     */
   1.132 +    private Object newValue;
   1.133 +
   1.134 +    /**
   1.135 +     * Previous value for property.  May be null if not known.
   1.136 +     * @serial
   1.137 +     */
   1.138 +    private Object oldValue;
   1.139 +
   1.140 +    /**
   1.141 +     * Propagation ID.  May be null.
   1.142 +     * @serial
   1.143 +     * @see #getPropagationId
   1.144 +     */
   1.145 +    private Object propagationId;
   1.146 +
   1.147 +    /**
   1.148 +     * Returns a string representation of the object.
   1.149 +     *
   1.150 +     * @return a string representation of the object
   1.151 +     *
   1.152 +     * @since 1.7
   1.153 +     */
   1.154 +    public String toString() {
   1.155 +        StringBuilder sb = new StringBuilder(getClass().getName());
   1.156 +        sb.append("[propertyName=").append(getPropertyName());
   1.157 +        appendTo(sb);
   1.158 +        sb.append("; oldValue=").append(getOldValue());
   1.159 +        sb.append("; newValue=").append(getNewValue());
   1.160 +        sb.append("; propagationId=").append(getPropagationId());
   1.161 +        sb.append("; source=").append(getSource());
   1.162 +        return sb.append("]").toString();
   1.163 +    }
   1.164 +
   1.165 +    void appendTo(StringBuilder sb) {
   1.166 +    }
   1.167 +}