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. package java.util.prefs;
  8. import java.io.NotSerializableException;
  9. /**
  10. * An event emitted by a <tt>Preferences</tt> node to indicate that
  11. * a preference has been added, removed or has had its value changed.<p>
  12. *
  13. * Note, that although PreferenceChangeEvent inherits Serializable interface
  14. * from EventObject, it is not intended to be Serializable. Appropriate
  15. * serialization methods are implemented to throw NotSerializableException.
  16. *
  17. * @author Josh Bloch
  18. * @version 1.6, 12/19/03
  19. * @see Preferences
  20. * @see PreferenceChangeListener
  21. * @see NodeChangeEvent
  22. * @since 1.4
  23. * @serial exclude
  24. */
  25. public class PreferenceChangeEvent extends java.util.EventObject {
  26. /**
  27. * Key of the preference that changed.
  28. *
  29. * @serial
  30. */
  31. private String key;
  32. /**
  33. * New value for preference, or <tt>null</tt> if it was removed.
  34. *
  35. * @serial
  36. */
  37. private String newValue;
  38. /**
  39. * Constructs a new <code>PreferenceChangeEvent</code> instance.
  40. *
  41. * @param node The Preferences node that emitted the event.
  42. * @param key The key of the preference that was changed.
  43. * @param newValue The new value of the preference, or <tt>null</tt>
  44. * if the preference is being removed.
  45. */
  46. public PreferenceChangeEvent(Preferences node, String key,
  47. String newValue) {
  48. super(node);
  49. this.key = key;
  50. this.newValue = newValue;
  51. }
  52. /**
  53. * Returns the preference node that emitted the event.
  54. *
  55. * @return The preference node that emitted the event.
  56. */
  57. public Preferences getNode() {
  58. return (Preferences) getSource();
  59. }
  60. /**
  61. * Returns the key of the preference that was changed.
  62. *
  63. * @return The key of the preference that was changed.
  64. */
  65. public String getKey() {
  66. return key;
  67. }
  68. /**
  69. * Returns the new value for the preference.
  70. *
  71. * @return The new value for the preference, or <tt>null</tt> if the
  72. * preference was removed.
  73. */
  74. public String getNewValue() {
  75. return newValue;
  76. }
  77. /**
  78. * Throws NotSerializableException, since NodeChangeEvent objects
  79. * are not intended to be serializable.
  80. */
  81. private void writeObject(java.io.ObjectOutputStream out)
  82. throws NotSerializableException {
  83. throw new NotSerializableException("Not serializable.");
  84. }
  85. /**
  86. * Throws NotSerializableException, since PreferenceChangeEvent objects
  87. * are not intended to be serializable.
  88. */
  89. private void readObject(java.io.ObjectInputStream in)
  90. throws NotSerializableException {
  91. throw new NotSerializableException("Not serializable.");
  92. }
  93. // Defined so that this class isn't flagged as a potential problem when
  94. // searches for missing serialVersionUID fields are done.
  95. private static final long serialVersionUID = 793724513368024975L;
  96. }