1. /*
  2. * @(#)PropertyChangeEvent.java 1.30 00/02/02
  3. *
  4. * Copyright 1996-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.beans;
  11. /**
  12. * A "PropertyChange" event gets delivered whenever a bean changes a "bound"
  13. * or "constrained" property. A PropertyChangeEvent object is sent as an
  14. * argument to the PropertyChangeListener and VetoableChangeListener methods.
  15. * <P>
  16. * Normally PropertyChangeEvents are accompanied by the name and the old
  17. * and new value of the changed property. If the new value is a primitive
  18. * type (such as int or boolean) it must be wrapped as the
  19. * corresponding java.lang.* Object type (such as Integer or Boolean).
  20. * <P>
  21. * Null values may be provided for the old and the new values if their
  22. * true values are not known.
  23. * <P>
  24. * An event source may send a null object as the name to indicate that an
  25. * arbitrary set of if its properties have changed. In this case the
  26. * old and new values should also be null.
  27. */
  28. public class PropertyChangeEvent extends java.util.EventObject {
  29. /**
  30. * Constructs a new <code>PropertyChangeEvent</code>.
  31. *
  32. * @param source The bean that fired the event.
  33. * @param propertyName The programmatic name of the property
  34. * that was changed.
  35. * @param oldValue The old value of the property.
  36. * @param newValue The new value of the property.
  37. */
  38. public PropertyChangeEvent(Object source, String propertyName,
  39. Object oldValue, Object newValue) {
  40. super(source);
  41. this.propertyName = propertyName;
  42. this.newValue = newValue;
  43. this.oldValue = oldValue;
  44. }
  45. /**
  46. * Gets the programmatic name of the property that was changed.
  47. *
  48. * @return The programmatic name of the property that was changed.
  49. * May be null if multiple properties have changed.
  50. */
  51. public String getPropertyName() {
  52. return propertyName;
  53. }
  54. /**
  55. * Sets the new value for the property, expressed as an Object.
  56. *
  57. * @return The new value for the property, expressed as an Object.
  58. * May be null if multiple properties have changed.
  59. */
  60. public Object getNewValue() {
  61. return newValue;
  62. }
  63. /**
  64. * Gets the old value for the property, expressed as an Object.
  65. *
  66. * @return The old value for the property, expressed as an Object.
  67. * May be null if multiple properties have changed.
  68. */
  69. public Object getOldValue() {
  70. return oldValue;
  71. }
  72. /**
  73. * Sets the propagationId object for the event.
  74. *
  75. * @param propagationId The propagationId object for the event.
  76. */
  77. public void setPropagationId(Object propagationId) {
  78. this.propagationId = propagationId;
  79. }
  80. /**
  81. * The "propagationId" field is reserved for future use. In Beans 1.0
  82. * the sole requirement is that if a listener catches a PropertyChangeEvent
  83. * and then fires a PropertyChangeEvent of its own, then it should
  84. * make sure that it propagates the propagationId field from its
  85. * incoming event to its outgoing event.
  86. *
  87. * @return the propagationId object associated with a bound/constrained
  88. * property update.
  89. */
  90. public Object getPropagationId() {
  91. return propagationId;
  92. }
  93. /**
  94. * name of the property that changed. May be null, if not known.
  95. * @serial
  96. */
  97. private String propertyName;
  98. /**
  99. * New value for property. May be null if not known.
  100. * @serial
  101. */
  102. private Object newValue;
  103. /**
  104. * Previous value for property. May be null if not known.
  105. * @serial
  106. */
  107. private Object oldValue;
  108. /**
  109. * Propagation ID. May be null.
  110. * @serial
  111. * @see #getPropagationId.
  112. */
  113. private Object propagationId;
  114. }