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