1/*
2 * Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.util.prefs;
27
28import java.io.NotSerializableException;
29
30/**
31 * An event emitted by a <tt>Preferences</tt> node to indicate that
32 * a preference has been added, removed or has had its value changed.<p>
33 *
34 * Note, that although PreferenceChangeEvent inherits Serializable interface
35 * from EventObject, it is not intended to be Serializable. Appropriate
36 * serialization methods are implemented to throw NotSerializableException.
37 *
38 * @author  Josh Bloch
39 * @see Preferences
40 * @see PreferenceChangeListener
41 * @see NodeChangeEvent
42 * @since   1.4
43 * @serial exclude
44 */
45public class PreferenceChangeEvent extends java.util.EventObject {
46
47    /**
48     * Key of the preference that changed.
49     *
50     * @serial
51     */
52    private String key;
53
54    /**
55     * New value for preference, or <tt>null</tt> if it was removed.
56     *
57     * @serial
58     */
59    private String newValue;
60
61    /**
62     * Constructs a new <code>PreferenceChangeEvent</code> instance.
63     *
64     * @param node  The Preferences node that emitted the event.
65     * @param key  The key of the preference that was changed.
66     * @param newValue  The new value of the preference, or <tt>null</tt>
67     *                  if the preference is being removed.
68     */
69    public PreferenceChangeEvent(Preferences node, String key,
70                                 String newValue) {
71        super(node);
72        this.key = key;
73        this.newValue = newValue;
74    }
75
76    /**
77     * Returns the preference node that emitted the event.
78     *
79     * @return  The preference node that emitted the event.
80     */
81    public Preferences getNode() {
82        return (Preferences) getSource();
83    }
84
85    /**
86     * Returns the key of the preference that was changed.
87     *
88     * @return  The key of the preference that was changed.
89     */
90    public String getKey() {
91        return key;
92    }
93
94    /**
95     * Returns the new value for the preference.
96     *
97     * @return  The new value for the preference, or <tt>null</tt> if the
98     *          preference was removed.
99     */
100    public String getNewValue() {
101        return newValue;
102    }
103
104    /**
105     * Throws NotSerializableException, since NodeChangeEvent objects
106     * are not intended to be serializable.
107     */
108     private void writeObject(java.io.ObjectOutputStream out)
109                                               throws NotSerializableException {
110         throw new NotSerializableException("Not serializable.");
111     }
112
113    /**
114     * Throws NotSerializableException, since PreferenceChangeEvent objects
115     * are not intended to be serializable.
116     */
117     private void readObject(java.io.ObjectInputStream in)
118                                               throws NotSerializableException {
119         throw new NotSerializableException("Not serializable.");
120     }
121
122    // Defined so that this class isn't flagged as a potential problem when
123    // searches for missing serialVersionUID fields are done.
124    private static final long serialVersionUID = 793724513368024975L;
125}
126