KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > util > PropertyChangeEvent


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jface.util;
12
13 import java.util.EventObject JavaDoc;
14 import org.eclipse.core.runtime.Assert;
15
16 /**
17  * An event object describing a change to a named property.
18  * <p>
19  * This concrete class was designed to be instantiated, but may
20  * also be subclassed if required.
21  * </p>
22  * <p>
23  * The JFace frameworks contain classes that report property
24  * change events for internal state changes that may be of interest
25  * to external parties. A special listener interface
26  * (<code>IPropertyChangeListener</code>) is defined for this purpose,
27  * and a typical class allow listeners to be registered via
28  * an <code>addPropertyChangeListener</code> method.
29  * </p>
30  *
31  * @see IPropertyChangeListener
32  */

33 public class PropertyChangeEvent extends EventObject JavaDoc {
34
35     /**
36      * Generated serial version UID for this class.
37      * @since 3.1
38      */

39     private static final long serialVersionUID = 3256726173533811256L;
40
41     /**
42      * The name of the changed property.
43      */

44     private String JavaDoc propertyName;
45
46     /**
47      * The old value of the changed property, or <code>null</code> if
48      * not known or not relevant.
49      */

50     private Object JavaDoc oldValue;
51
52     /**
53      * The new value of the changed property, or <code>null</code> if
54      * not known or not relevant.
55      */

56     private Object JavaDoc newValue;
57
58     /**
59      * Creates a new property change event.
60      *
61      * @param source the object whose property has changed
62      * @param property the property that has changed (must not be <code>null</code>)
63      * @param oldValue the old value of the property, or <code>null</code> if none
64      * @param newValue the new value of the property, or <code>null</code> if none
65      */

66     public PropertyChangeEvent(Object JavaDoc source, String JavaDoc property, Object JavaDoc oldValue,
67             Object JavaDoc newValue) {
68         super(source);
69         Assert.isNotNull(property);
70         this.propertyName = property;
71         this.oldValue = oldValue;
72         this.newValue = newValue;
73     }
74
75     /**
76      * Returns the new value of the property.
77      *
78      * @return the new value, or <code>null</code> if not known
79      * or not relevant (for instance if the property was removed).
80      */

81     public Object JavaDoc getNewValue() {
82         return newValue;
83     }
84
85     /**
86      * Returns the old value of the property.
87      *
88      * @return the old value, or <code>null</code> if not known
89      * or not relevant (for instance if the property was just
90      * added and there was no old value).
91      */

92     public Object JavaDoc getOldValue() {
93         return oldValue;
94     }
95
96     /**
97      * Returns the name of the property that changed.
98      * <p>
99      * Warning: there is no guarantee that the property name returned
100      * is a constant string. Callers must compare property names using
101      * equals, not ==.
102      * </p>
103      *
104      * @return the name of the property that changed
105      */

106     public String JavaDoc getProperty() {
107         return propertyName;
108     }
109 }
110
Popular Tags