001: /*
002: * Copyright 2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package sun.awt;
026:
027: import java.awt.Component;
028: import java.awt.Rectangle;
029: import java.awt.event.PaintEvent;
030:
031: /**
032: * PaintEventDispatcher is responsible for dispatching PaintEvents. There
033: * can be only one PaintEventDispatcher active at a particular time.
034: *
035: * @version 1.9, 05/05/07
036: */
037: public class PaintEventDispatcher {
038: /**
039: * Singleton dispatcher.
040: */
041: private static PaintEventDispatcher dispatcher;
042:
043: /**
044: * Sets the current <code>PaintEventDispatcher</code>.
045: *
046: * @param dispatcher PaintEventDispatcher
047: */
048: public static void setPaintEventDispatcher(
049: PaintEventDispatcher dispatcher) {
050: synchronized (PaintEventDispatcher.class) {
051: PaintEventDispatcher.dispatcher = dispatcher;
052: }
053: }
054:
055: /**
056: * Returns the currently active <code>PaintEventDispatcher</code>. This
057: * will never return null.
058: *
059: * @return PaintEventDispatcher
060: */
061: public static PaintEventDispatcher getPaintEventDispatcher() {
062: synchronized (PaintEventDispatcher.class) {
063: if (dispatcher == null) {
064: dispatcher = new PaintEventDispatcher();
065: }
066: return dispatcher;
067: }
068: }
069:
070: /**
071: * Creates and returns the <code>PaintEvent</code> that should be
072: * dispatched for the specified component. If this returns null
073: * no <code>PaintEvent</code> is dispatched.
074: * <p>
075: * <b>WARNING:</b> This is invoked from the native thread, be careful
076: * what methods you end up invoking here.
077: */
078: public PaintEvent createPaintEvent(Component target, int x, int y,
079: int w, int h) {
080:
081: return new PaintEvent((Component) target, PaintEvent.PAINT,
082: new Rectangle(x, y, w, h));
083: }
084:
085: /**
086: * Returns true if a native background erase should be done for
087: * the specified Component.
088: */
089: public boolean shouldDoNativeBackgroundErase(Component c) {
090: return true;
091: }
092:
093: /**
094: * This method is invoked from the toolkit thread when the surface
095: * data of the component needs to be replaced. The method run() of
096: * the Runnable argument performs surface data replacing, run()
097: * should be invoked on the EDT of this component's AppContext.
098: * Returns true if the Runnable has been enqueued to be invoked
099: * on the EDT.
100: * (Fix 6255371.)
101: */
102: public boolean queueSurfaceDataReplacing(Component c, Runnable r) {
103: return false;
104: }
105: }
|