Path: blob/master/src/java.prefs/share/classes/java/util/prefs/PreferenceChangeEvent.java
41159 views
/*1* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package java.util.prefs;2627import java.io.NotSerializableException;2829/**30* An event emitted by a {@code Preferences} node to indicate that31* a preference has been added, removed or has had its value changed.<p>32*33* Note, that although PreferenceChangeEvent inherits Serializable interface34* from EventObject, it is not intended to be Serializable. Appropriate35* serialization methods are implemented to throw NotSerializableException.36*37* @author Josh Bloch38* @see Preferences39* @see PreferenceChangeListener40* @see NodeChangeEvent41* @since 1.442* @serial exclude43*/44public class PreferenceChangeEvent extends java.util.EventObject {4546/**47* Key of the preference that changed.48*49* @serial50*/51private String key;5253/**54* New value for preference, or {@code null} if it was removed.55*56* @serial57*/58private String newValue;5960/**61* Constructs a new {@code PreferenceChangeEvent} instance.62*63* @param node The Preferences node that emitted the event.64* @param key The key of the preference that was changed.65* @param newValue The new value of the preference, or {@code null}66* if the preference is being removed.67*/68public PreferenceChangeEvent(Preferences node, String key,69String newValue) {70super(node);71this.key = key;72this.newValue = newValue;73}7475/**76* Returns the preference node that emitted the event.77*78* @return The preference node that emitted the event.79*/80public Preferences getNode() {81return (Preferences) getSource();82}8384/**85* Returns the key of the preference that was changed.86*87* @return The key of the preference that was changed.88*/89public String getKey() {90return key;91}9293/**94* Returns the new value for the preference.95*96* @return The new value for the preference, or {@code null} if the97* preference was removed.98*/99public String getNewValue() {100return newValue;101}102103/**104* Throws NotSerializableException, since NodeChangeEvent objects105* are not intended to be serializable.106*/107private void writeObject(java.io.ObjectOutputStream out)108throws NotSerializableException {109throw new NotSerializableException("Not serializable.");110}111112/**113* Throws NotSerializableException, since PreferenceChangeEvent objects114* are not intended to be serializable.115*/116private void readObject(java.io.ObjectInputStream in)117throws NotSerializableException {118throw new NotSerializableException("Not serializable.");119}120121// Defined so that this class isn't flagged as a potential problem when122// searches for missing serialVersionUID fields are done.123private static final long serialVersionUID = 793724513368024975L;124}125126127