1 /*
   2  * Copyright (c) 1996, 2013, Oracle and/or its affiliates. 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * 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  * <p>
  40  * An unspecified behavior will be caused if the {@code id} parameter
  41  * of any particular {@code PaintEvent} instance is not
  42  * in the range from {@code PAINT_FIRST} to {@code PAINT_LAST}.
  43  *
  44  * @author Amy Fowler
  45  * @since 1.1
  46  */
  47 public class PaintEvent extends ComponentEvent {
  48 
  49     /**
  50      * Marks the first integer id for the range of paint event ids.
  51      */
  52     public static final int PAINT_FIRST         = 800;
  53 
  54     /**
  55      * Marks the last integer id for the range of paint event ids.
  56      */
  57     public static final int PAINT_LAST          = 801;
  58 
  59     /**
  60      * The paint event type.
  61      */
  62     public static final int PAINT = PAINT_FIRST;
  63 
  64     /**
  65      * The update event type.
  66      */
  67     public static final int UPDATE = PAINT_FIRST + 1; //801
  68 
  69     /**
  70      * This is the rectangle that represents the area on the source
  71      * component that requires a repaint.
  72      * This rectangle should be non null.
  73      *
  74      * @serial
  75      * @see java.awt.Rectangle
  76      * @see #setUpdateRect(Rectangle)
  77      * @see #getUpdateRect()
  78      */
  79     Rectangle updateRect;
  80 
  81     /*
  82      * JDK 1.1 serialVersionUID
  83      */
  84     private static final long serialVersionUID = 1267492026433337593L;
  85 
  86     /**
  87      * Constructs a <code>PaintEvent</code> object with the specified
  88      * source component and type.
  89      * <p> This method throws an
  90      * <code>IllegalArgumentException</code> if <code>source</code>
  91      * is <code>null</code>.
  92      *
  93      * @param source     The object where the event originated
  94      * @param id           The integer that identifies the event type.
  95      *                     For information on allowable values, see
  96      *                     the class description for {@link PaintEvent}
  97      * @param updateRect The rectangle area which needs to be repainted
  98      * @throws IllegalArgumentException if <code>source</code> is null
  99      * @see #getSource()
 100      * @see #getID()
 101      * @see #getUpdateRect()
 102      */
 103     public PaintEvent(Component source, int id, Rectangle updateRect) {
 104         super(source, id);
 105         this.updateRect = updateRect;
 106     }
 107 
 108     /**
 109      * Returns the rectangle representing the area which needs to be
 110      * repainted in response to this event.
 111      * @return the rectangle representing the area which needs to be
 112      * repainted in response to this event
 113      */
 114     public Rectangle getUpdateRect() {
 115         return updateRect;
 116     }
 117 
 118     /**
 119      * Sets the rectangle representing the area which needs to be
 120      * repainted in response to this event.
 121      * @param updateRect the rectangle area which needs to be repainted
 122      */
 123     public void setUpdateRect(Rectangle updateRect) {
 124         this.updateRect = updateRect;
 125     }
 126 
 127     public String paramString() {
 128         String typeStr;
 129         switch(id) {
 130           case PAINT:
 131               typeStr = "PAINT";
 132               break;
 133           case UPDATE:
 134               typeStr = "UPDATE";
 135               break;
 136           default:
 137               typeStr = "unknown type";
 138         }
 139         return typeStr + ",updateRect="+(updateRect != null ? updateRect.toString() : "null");
 140     }
 141 }