jdk/src/share/classes/java/beans/PropertyChangeEvent.java
author lana
Tue, 01 Jun 2010 14:17:38 -0700
changeset 5597 ab490f66d2cf
parent 5506 202f599c92aa
child 11089 e23e7a5faad5
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4960
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.beans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * A "PropertyChange" event gets delivered whenever a bean changes a "bound"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * or "constrained" property.  A PropertyChangeEvent object is sent as an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * argument to the PropertyChangeListener and VetoableChangeListener methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Normally PropertyChangeEvents are accompanied by the name and the old
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * and new value of the changed property.  If the new value is a primitive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * type (such as int or boolean) it must be wrapped as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * corresponding java.lang.* Object type (such as Integer or Boolean).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Null values may be provided for the old and the new values if their
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * true values are not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * An event source may send a null object as the name to indicate that an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * arbitrary set of if its properties have changed.  In this case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * old and new values should also be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class PropertyChangeEvent extends java.util.EventObject {
2482
77898184e343 4769844: classes in java.beans that are serializable but don't define serialVersionUID
malenkov
parents: 2
diff changeset
    47
    private static final long serialVersionUID = 7042693688939648123L;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Constructs a new <code>PropertyChangeEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * @param source  The bean that fired the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * @param propertyName  The programmatic name of the property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *          that was changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @param oldValue  The old value of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * @param newValue  The new value of the property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public PropertyChangeEvent(Object source, String propertyName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                                     Object oldValue, Object newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        super(source);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        this.propertyName = propertyName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        this.newValue = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        this.oldValue = oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Gets the programmatic name of the property that was changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @return  The programmatic name of the property that was changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *          May be null if multiple properties have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public String getPropertyName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        return propertyName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Gets the new value for the property, expressed as an Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @return  The new value for the property, expressed as an Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *          May be null if multiple properties have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public Object getNewValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Gets the old value for the property, expressed as an Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @return  The old value for the property, expressed as an Object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *          May be null if multiple properties have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public Object getOldValue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Sets the propagationId object for the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param propagationId  The propagationId object for the event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public void setPropagationId(Object propagationId) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        this.propagationId = propagationId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * The "propagationId" field is reserved for future use.  In Beans 1.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * the sole requirement is that if a listener catches a PropertyChangeEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * and then fires a PropertyChangeEvent of its own, then it should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * make sure that it propagates the propagationId field from its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * incoming event to its outgoing event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @return the propagationId object associated with a bound/constrained
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *          property update.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public Object getPropagationId() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        return propagationId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * name of the property that changed.  May be null, if not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private String propertyName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * New value for property.  May be null if not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private Object newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Previous value for property.  May be null if not known.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private Object oldValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Propagation ID.  May be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @see #getPropagationId
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private Object propagationId;
4960
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   143
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   144
    /**
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   145
     * Returns a string representation of the object.
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   146
     *
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   147
     * @return a string representation of the object
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   148
     *
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   149
     * @since 1.7
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   150
     */
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   151
    public String toString() {
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   152
        StringBuilder sb = new StringBuilder(getClass().getName());
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   153
        sb.append("[propertyName=").append(getPropertyName());
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   154
        appendTo(sb);
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   155
        sb.append("; oldValue=").append(getOldValue());
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   156
        sb.append("; newValue=").append(getNewValue());
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   157
        sb.append("; propagationId=").append(getPropagationId());
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   158
        sb.append("; source=").append(getSource());
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   159
        return sb.append("]").toString();
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   160
    }
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   161
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   162
    void appendTo(StringBuilder sb) {
99ac74ca2f2f 4498236: RFE: Provide a toString method for PropertyChangeEvent and other classes
malenkov
parents: 2482
diff changeset
   163
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
}