KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > util > prefs > PreferenceChangeEvent


1 /*
2  * @(#)PreferenceChangeEvent.java 1.6 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.util.prefs;
9
10 import java.io.NotSerializableException JavaDoc;
11
12 /**
13  * An event emitted by a <tt>Preferences</tt> node to indicate that
14  * a preference has been added, removed or has had its value changed.<p>
15  *
16  * Note, that although PreferenceChangeEvent inherits Serializable interface
17  * from EventObject, it is not intended to be Serializable. Appropriate
18  * serialization methods are implemented to throw NotSerializableException.
19  *
20  * @author Josh Bloch
21  * @version 1.6, 12/19/03
22  * @see Preferences
23  * @see PreferenceChangeListener
24  * @see NodeChangeEvent
25  * @since 1.4
26  * @serial exclude
27  */

28 public class PreferenceChangeEvent extends java.util.EventObject JavaDoc {
29
30     /**
31      * Key of the preference that changed.
32      *
33      * @serial
34      */

35     private String JavaDoc key;
36
37     /**
38      * New value for preference, or <tt>null</tt> if it was removed.
39      *
40      * @serial
41      */

42     private String JavaDoc newValue;
43
44     /**
45      * Constructs a new <code>PreferenceChangeEvent</code> instance.
46      *
47      * @param node The Preferences node that emitted the event.
48      * @param key The key of the preference that was changed.
49      * @param newValue The new value of the preference, or <tt>null</tt>
50      * if the preference is being removed.
51      */

52     public PreferenceChangeEvent(Preferences JavaDoc node, String JavaDoc key,
53                                  String JavaDoc newValue) {
54     super(node);
55     this.key = key;
56     this.newValue = newValue;
57     }
58
59     /**
60      * Returns the preference node that emitted the event.
61      *
62      * @return The preference node that emitted the event.
63      */

64     public Preferences JavaDoc getNode() {
65         return (Preferences JavaDoc) getSource();
66     }
67
68     /**
69      * Returns the key of the preference that was changed.
70      *
71      * @return The key of the preference that was changed.
72      */

73     public String JavaDoc getKey() {
74     return key;
75     }
76     
77     /**
78      * Returns the new value for the preference.
79      *
80      * @return The new value for the preference, or <tt>null</tt> if the
81      * preference was removed.
82      */

83     public String JavaDoc getNewValue() {
84     return newValue;
85     }
86
87     /**
88      * Throws NotSerializableException, since NodeChangeEvent objects
89      * are not intended to be serializable.
90      */

91      private void writeObject(java.io.ObjectOutputStream JavaDoc out)
92                                                throws NotSerializableException JavaDoc {
93          throw new NotSerializableException JavaDoc("Not serializable.");
94      }
95
96     /**
97      * Throws NotSerializableException, since PreferenceChangeEvent objects
98      * are not intended to be serializable.
99      */

100      private void readObject(java.io.ObjectInputStream JavaDoc in)
101                                                throws NotSerializableException JavaDoc {
102          throw new NotSerializableException JavaDoc("Not serializable.");
103      }
104
105     // Defined so that this class isn't flagged as a potential problem when
106
// searches for missing serialVersionUID fields are done.
107
private static final long serialVersionUID = 793724513368024975L;
108 }
109
Popular Tags