J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package java.awt.event; |
| 27 | |
| 28 | import java.awt.Component; |
| 29 | import java.awt.Rectangle; |
| 30 | |
| 31 | /** |
| 32 | * The component-level paint event. |
| 33 | * This event is a special type which is used to ensure that |
| 34 | * paint/update method calls are serialized along with the other |
| 35 | * events delivered from the event queue. This event is not |
| 36 | * designed to be used with the Event Listener model; programs |
| 37 | * should continue to override paint/update methods in order |
| 38 | * render themselves properly. |
| 39 | * |
| 40 | * @author Amy Fowler |
| 41 | * @since 1.1 |
| 42 | */ |
| 43 | public class PaintEvent extends ComponentEvent { |
| 44 | |
| 45 | /** |
| 46 | * Marks the first integer id for the range of paint event ids. |
| 47 | */ |
| 48 | public static final int PAINT_FIRST = 800; |
| 49 | |
| 50 | /** |
| 51 | * Marks the last integer id for the range of paint event ids. |
| 52 | */ |
| 53 | public static final int PAINT_LAST = 801; |
| 54 | |
| 55 | /** |
| 56 | * The paint event type. |
| 57 | */ |
| 58 | public static final int PAINT = PAINT_FIRST; |
| 59 | |
| 60 | /** |
| 61 | * The update event type. |
| 62 | */ |
| 63 | public static final int UPDATE = PAINT_FIRST + 1; //801 |
| 64 | |
| 65 | /** |
| 66 | * This is the rectangle that represents the area on the source |
| 67 | * component that requires a repaint. |
| 68 | * This rectangle should be non null. |
| 69 | * |
| 70 | * @serial |
| 71 | * @see java.awt.Rectangle |
| 72 | * @see #setUpdateRect(Rectangle) |
| 73 | * @see #getUpdateRect() |
| 74 | */ |
| 75 | Rectangle updateRect; |
| 76 | |
| 77 | /* |
| 78 | * JDK 1.1 serialVersionUID |
| 79 | */ |
| 80 | private static final long serialVersionUID = 1267492026433337593L; |
| 81 | |
| 82 | /** |
| 83 | * Constructs a <code>PaintEvent</code> object with the specified |
| 84 | * source component and type. |
| 85 | * <p>Note that passing in an invalid <code>id</code> results in |
| 86 | * unspecified behavior. This method throws an |
| 87 | * <code>IllegalArgumentException</code> if <code>source</code> |
| 88 | * is <code>null</code>. |
| 89 | * |
| 90 | * @param source the object where the event originated |
| 91 | * @param id the event type |
| 92 | * @param updateRect the rectangle area which needs to be repainted |
| 93 | * @throws IllegalArgumentException if <code>source</code> is null |
| 94 | */ |
| 95 | public PaintEvent(Component source, int id, Rectangle updateRect) { |
| 96 | super(source, id); |
| 97 | this.updateRect = updateRect; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Returns the rectangle representing the area which needs to be |
| 102 | * repainted in response to this event. |
| 103 | */ |
| 104 | public Rectangle getUpdateRect() { |
| 105 | return updateRect; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Sets the rectangle representing the area which needs to be |
| 110 | * repainted in response to this event. |
| 111 | * @param updateRect the rectangle area which needs to be repainted |
| 112 | */ |
| 113 | public void setUpdateRect(Rectangle updateRect) { |
| 114 | this.updateRect = updateRect; |
| 115 | } |
| 116 | |
| 117 | public String paramString() { |
| 118 | String typeStr; |
| 119 | switch(id) { |
| 120 | case PAINT: |
| 121 | typeStr = "PAINT"; |
| 122 | break; |
| 123 | case UPDATE: |
| 124 | typeStr = "UPDATE"; |
| 125 | break; |
| 126 | default: |
| 127 | typeStr = "unknown type"; |
| 128 | } |
| 129 | return typeStr + ",updateRect="+(updateRect != null ? updateRect.toString() : "null"); |
| 130 | } |
| 131 | } |