KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > beans > PropertyChangeEvent


1 /*
2  * @(#)PropertyChangeEvent.java 1.33 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package java.beans;
9
10 /**
11  * A "PropertyChange" event gets delivered whenever a bean changes a "bound"
12  * or "constrained" property. A PropertyChangeEvent object is sent as an
13  * argument to the PropertyChangeListener and VetoableChangeListener methods.
14  * <P>
15  * Normally PropertyChangeEvents are accompanied by the name and the old
16  * and new value of the changed property. If the new value is a primitive
17  * type (such as int or boolean) it must be wrapped as the
18  * corresponding java.lang.* Object type (such as Integer or Boolean).
19  * <P>
20  * Null values may be provided for the old and the new values if their
21  * true values are not known.
22  * <P>
23  * An event source may send a null object as the name to indicate that an
24  * arbitrary set of if its properties have changed. In this case the
25  * old and new values should also be null.
26  */

27
28 public class PropertyChangeEvent extends java.util.EventObject JavaDoc {
29
30     /**
31      * Constructs a new <code>PropertyChangeEvent</code>.
32      *
33      * @param source The bean that fired the event.
34      * @param propertyName The programmatic name of the property
35      * that was changed.
36      * @param oldValue The old value of the property.
37      * @param newValue The new value of the property.
38      */

39     public PropertyChangeEvent(Object JavaDoc source, String JavaDoc propertyName,
40                      Object JavaDoc oldValue, Object JavaDoc newValue) {
41     super(source);
42     this.propertyName = propertyName;
43     this.newValue = newValue;
44     this.oldValue = oldValue;
45     }
46
47     /**
48      * Gets the programmatic name of the property that was changed.
49      *
50      * @return The programmatic name of the property that was changed.
51      * May be null if multiple properties have changed.
52      */

53     public String JavaDoc getPropertyName() {
54     return propertyName;
55     }
56     
57     /**
58      * Sets the new value for the property, expressed as an Object.
59      *
60      * @return The new value for the property, expressed as an Object.
61      * May be null if multiple properties have changed.
62      */

63     public Object JavaDoc getNewValue() {
64     return newValue;
65     }
66
67     /**
68      * Gets the old value for the property, expressed as an Object.
69      *
70      * @return The old value for the property, expressed as an Object.
71      * May be null if multiple properties have changed.
72      */

73     public Object JavaDoc getOldValue() {
74     return oldValue;
75     }
76
77     /**
78      * Sets the propagationId object for the event.
79      *
80      * @param propagationId The propagationId object for the event.
81      */

82     public void setPropagationId(Object JavaDoc propagationId) {
83     this.propagationId = propagationId;
84     }
85
86     /**
87      * The "propagationId" field is reserved for future use. In Beans 1.0
88      * the sole requirement is that if a listener catches a PropertyChangeEvent
89      * and then fires a PropertyChangeEvent of its own, then it should
90      * make sure that it propagates the propagationId field from its
91      * incoming event to its outgoing event.
92      *
93      * @return the propagationId object associated with a bound/constrained
94      * property update.
95      */

96     public Object JavaDoc getPropagationId() {
97     return propagationId;
98     }
99
100     /**
101      * name of the property that changed. May be null, if not known.
102      * @serial
103      */

104     private String JavaDoc propertyName;
105
106     /**
107      * New value for property. May be null if not known.
108      * @serial
109      */

110     private Object JavaDoc newValue;
111
112     /**
113      * Previous value for property. May be null if not known.
114      * @serial
115      */

116     private Object JavaDoc oldValue;
117
118     /**
119      * Propagation ID. May be null.
120      * @serial
121      * @see #getPropagationId.
122      */

123     private Object JavaDoc propagationId;
124 }
125
Popular Tags