blob: 92fe7397196f797c43ddc7b12f943275b16ba27a [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2005 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 */
25package sun.awt;
26
27import java.awt.Component;
28import java.awt.Rectangle;
29import java.awt.event.PaintEvent;
30
31/**
32 * PaintEventDispatcher is responsible for dispatching PaintEvents. There
33 * can be only one PaintEventDispatcher active at a particular time.
34 *
35 */
36public class PaintEventDispatcher {
37 /**
38 * Singleton dispatcher.
39 */
40 private static PaintEventDispatcher dispatcher;
41
42 /**
43 * Sets the current <code>PaintEventDispatcher</code>.
44 *
45 * @param dispatcher PaintEventDispatcher
46 */
47 public static void setPaintEventDispatcher(
48 PaintEventDispatcher dispatcher) {
49 synchronized(PaintEventDispatcher.class) {
50 PaintEventDispatcher.dispatcher = dispatcher;
51 }
52 }
53
54 /**
55 * Returns the currently active <code>PaintEventDispatcher</code>. This
56 * will never return null.
57 *
58 * @return PaintEventDispatcher
59 */
60 public static PaintEventDispatcher getPaintEventDispatcher() {
61 synchronized(PaintEventDispatcher.class) {
62 if (dispatcher == null) {
63 dispatcher = new PaintEventDispatcher();
64 }
65 return dispatcher;
66 }
67 }
68
69 /**
70 * Creates and returns the <code>PaintEvent</code> that should be
71 * dispatched for the specified component. If this returns null
72 * no <code>PaintEvent</code> is dispatched.
73 * <p>
74 * <b>WARNING:</b> This is invoked from the native thread, be careful
75 * what methods you end up invoking here.
76 */
77 public PaintEvent createPaintEvent(Component target, int x, int y, int w,
78 int h) {
79
80 return new PaintEvent((Component)target, PaintEvent.PAINT,
81 new Rectangle(x, y, w, h));
82 }
83
84 /**
85 * Returns true if a native background erase should be done for
86 * the specified Component.
87 */
88 public boolean shouldDoNativeBackgroundErase(Component c) {
89 return true;
90 }
91
92 /**
93 * This method is invoked from the toolkit thread when the surface
94 * data of the component needs to be replaced. The method run() of
95 * the Runnable argument performs surface data replacing, run()
96 * should be invoked on the EDT of this component's AppContext.
97 * Returns true if the Runnable has been enqueued to be invoked
98 * on the EDT.
99 * (Fix 6255371.)
100 */
101 public boolean queueSurfaceDataReplacing(Component c, Runnable r) {
102 return false;
103 }
104}