Path: blob/master/src/java.desktop/share/classes/sun/awt/PaintEventDispatcher.java
41152 views
/*1* Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/24package sun.awt;2526import java.awt.Component;27import java.awt.Rectangle;28import java.awt.event.PaintEvent;2930/**31* PaintEventDispatcher is responsible for dispatching PaintEvents. There32* can be only one PaintEventDispatcher active at a particular time.33*34*/35public class PaintEventDispatcher {36/**37* Singleton dispatcher.38*/39private static PaintEventDispatcher dispatcher;4041/**42* Sets the current {@code PaintEventDispatcher}.43*44* @param dispatcher PaintEventDispatcher45*/46public static void setPaintEventDispatcher(47PaintEventDispatcher dispatcher) {48synchronized(PaintEventDispatcher.class) {49PaintEventDispatcher.dispatcher = dispatcher;50}51}5253/**54* Returns the currently active {@code PaintEventDispatcher}. This55* will never return null.56*57* @return PaintEventDispatcher58*/59public static PaintEventDispatcher getPaintEventDispatcher() {60synchronized(PaintEventDispatcher.class) {61if (dispatcher == null) {62dispatcher = new PaintEventDispatcher();63}64return dispatcher;65}66}6768/**69* Creates and returns the {@code PaintEvent} that should be70* dispatched for the specified component. If this returns null71* no {@code PaintEvent} is dispatched.72* <p>73* <b>WARNING:</b> This is invoked from the native thread, be careful74* what methods you end up invoking here.75*/76public PaintEvent createPaintEvent(Component target, int x, int y, int w,77int h) {7879return new PaintEvent(target, PaintEvent.PAINT,80new Rectangle(x, y, w, h));81}8283/**84* Returns true if a native background erase should be done for85* the specified Component.86*/87public boolean shouldDoNativeBackgroundErase(Component c) {88return true;89}9091/**92* This method is invoked from the toolkit thread when the surface93* data of the component needs to be replaced. The method run() of94* the Runnable argument performs surface data replacing, run()95* should be invoked on the EDT of this component's AppContext.96* Returns true if the Runnable has been enqueued to be invoked97* on the EDT.98* (Fix 6255371.)99*/100public boolean queueSurfaceDataReplacing(Component c, Runnable r) {101return false;102}103}104105106