1. /*
  2. * @(#)PaintEvent.java 1.20 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.awt.event;
  8. import java.awt.Component;
  9. import java.awt.Event;
  10. import java.awt.Rectangle;
  11. /**
  12. * The component-level paint event.
  13. * This event is a special type which is used to ensure that
  14. * paint/update method calls are serialized along with the other
  15. * events delivered from the event queue. This event is not
  16. * designed to be used with the Event Listener model; programs
  17. * should continue to override paint/update methods in order
  18. * render themselves properly.
  19. *
  20. * @author Amy Fowler
  21. * @version 1.20, 12/19/03
  22. * @since 1.1
  23. */
  24. public class PaintEvent extends ComponentEvent {
  25. /**
  26. * Marks the first integer id for the range of paint event ids.
  27. */
  28. public static final int PAINT_FIRST = 800;
  29. /**
  30. * Marks the last integer id for the range of paint event ids.
  31. */
  32. public static final int PAINT_LAST = 801;
  33. /**
  34. * The paint event type.
  35. */
  36. public static final int PAINT = PAINT_FIRST;
  37. /**
  38. * The update event type.
  39. */
  40. public static final int UPDATE = PAINT_FIRST + 1; //801
  41. /**
  42. * This is the rectangle that represents the area on the source
  43. * component that requires a repaint.
  44. * This rectangle should be non null.
  45. *
  46. * @serial
  47. * @see java.awt.Rectangle
  48. * @see #setUpdateRect(Rectangle)
  49. * @see #getUpdateRect()
  50. */
  51. Rectangle updateRect;
  52. /*
  53. * JDK 1.1 serialVersionUID
  54. */
  55. private static final long serialVersionUID = 1267492026433337593L;
  56. /**
  57. * Constructs a <code>PaintEvent</code> object with the specified
  58. * source component and type.
  59. * <p>Note that passing in an invalid <code>id</code> results in
  60. * unspecified behavior. This method throws an
  61. * <code>IllegalArgumentException</code> if <code>source</code>
  62. * is <code>null</code>.
  63. *
  64. * @param source the object where the event originated
  65. * @param id the event type
  66. * @param updateRect the rectangle area which needs to be repainted
  67. * @throws IllegalArgumentException if <code>source</code> is null
  68. */
  69. public PaintEvent(Component source, int id, Rectangle updateRect) {
  70. super(source, id);
  71. this.updateRect = updateRect;
  72. }
  73. /**
  74. * Returns the rectangle representing the area which needs to be
  75. * repainted in response to this event.
  76. */
  77. public Rectangle getUpdateRect() {
  78. return updateRect;
  79. }
  80. /**
  81. * Sets the rectangle representing the area which needs to be
  82. * repainted in response to this event.
  83. * @param updateRect the rectangle area which needs to be repainted
  84. */
  85. public void setUpdateRect(Rectangle updateRect) {
  86. this.updateRect = updateRect;
  87. }
  88. public String paramString() {
  89. String typeStr;
  90. switch(id) {
  91. case PAINT:
  92. typeStr = "PAINT";
  93. break;
  94. case UPDATE:
  95. typeStr = "UPDATE";
  96. break;
  97. default:
  98. typeStr = "unknown type";
  99. }
  100. return typeStr + ",updateRect="+(updateRect != null ? updateRect.toString() : "null");
  101. }
  102. }