KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > event > PaintEvent


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
8 package java.awt.event;
9
10 import java.awt.Component JavaDoc;
11 import java.awt.Event JavaDoc;
12 import java.awt.Rectangle JavaDoc;
13
14 /**
15  * The component-level paint event.
16  * This event is a special type which is used to ensure that
17  * paint/update method calls are serialized along with the other
18  * events delivered from the event queue. This event is not
19  * designed to be used with the Event Listener model; programs
20  * should continue to override paint/update methods in order
21  * render themselves properly.
22  *
23  * @author Amy Fowler
24  * @version 1.20, 12/19/03
25  * @since 1.1
26  */

27 public class PaintEvent extends ComponentEvent JavaDoc {
28
29     /**
30      * Marks the first integer id for the range of paint event ids.
31      */

32     public static final int PAINT_FIRST = 800;
33
34     /**
35      * Marks the last integer id for the range of paint event ids.
36      */

37     public static final int PAINT_LAST = 801;
38
39     /**
40      * The paint event type.
41      */

42     public static final int PAINT = PAINT_FIRST;
43
44     /**
45      * The update event type.
46      */

47     public static final int UPDATE = PAINT_FIRST + 1; //801
48

49     /**
50      * This is the rectangle that represents the area on the source
51      * component that requires a repaint.
52      * This rectangle should be non null.
53      *
54      * @serial
55      * @see java.awt.Rectangle
56      * @see #setUpdateRect(Rectangle)
57      * @see #getUpdateRect()
58      */

59     Rectangle JavaDoc updateRect;
60
61     /*
62      * JDK 1.1 serialVersionUID
63      */

64     private static final long serialVersionUID = 1267492026433337593L;
65
66     /**
67      * Constructs a <code>PaintEvent</code> object with the specified
68      * source component and type.
69      * <p>Note that passing in an invalid <code>id</code> results in
70      * unspecified behavior. This method throws an
71      * <code>IllegalArgumentException</code> if <code>source</code>
72      * is <code>null</code>.
73      *
74      * @param source the object where the event originated
75      * @param id the event type
76      * @param updateRect the rectangle area which needs to be repainted
77      * @throws IllegalArgumentException if <code>source</code> is null
78      */

79     public PaintEvent(Component JavaDoc source, int id, Rectangle JavaDoc updateRect) {
80         super(source, id);
81         this.updateRect = updateRect;
82     }
83
84     /**
85      * Returns the rectangle representing the area which needs to be
86      * repainted in response to this event.
87      */

88     public Rectangle JavaDoc getUpdateRect() {
89         return updateRect;
90     }
91
92     /**
93      * Sets the rectangle representing the area which needs to be
94      * repainted in response to this event.
95      * @param updateRect the rectangle area which needs to be repainted
96      */

97     public void setUpdateRect(Rectangle JavaDoc updateRect) {
98         this.updateRect = updateRect;
99     }
100
101     public String JavaDoc paramString() {
102         String JavaDoc typeStr;
103         switch(id) {
104           case PAINT:
105               typeStr = "PAINT";
106               break;
107           case UPDATE:
108               typeStr = "UPDATE";
109               break;
110           default:
111               typeStr = "unknown type";
112         }
113         return typeStr + ",updateRect="+(updateRect != null ? updateRect.toString() : "null");
114     }
115 }
116
Popular Tags