KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > swing > SwingPaintEventDispatcher


1 /*
2  * @(#)SwingPaintEventDispatcher.java 1.3 05/11/30
3  *
4  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package javax.swing;
8
9 import java.awt.Component JavaDoc;
10 import java.awt.Container JavaDoc;
11 import java.awt.Rectangle JavaDoc;
12 import java.awt.event.PaintEvent JavaDoc;
13 import java.security.AccessController JavaDoc;
14 import sun.awt.AppContext;
15 import sun.awt.SunToolkit;
16 import sun.awt.event.IgnorePaintEvent;
17 import sun.security.action.GetBooleanAction;
18 import sun.security.action.GetPropertyAction;
19
20 /**
21  * Swing's PaintEventDispatcher. If the component specified by the PaintEvent
22  * is a top level Swing component (JFrame, JWindow, JDialog, JApplet), this
23  * will forward the request to the RepaintManager for eventual painting.
24  *
25  * @version 1.3, 11/30/05
26  */

27 class SwingPaintEventDispatcher extends sun.awt.PaintEventDispatcher {
28     private static final boolean SHOW_FROM_DOUBLE_BUFFER;
29     private static final boolean ERASE_BACKGROUND;
30
31     static {
32         SHOW_FROM_DOUBLE_BUFFER = "true".equals(AccessController.doPrivileged(
33               new GetPropertyAction("swing.showFromDoubleBuffer", "true")));
34         ERASE_BACKGROUND = AccessController.doPrivileged(
35                                  new GetBooleanAction("swing.nativeErase"));
36     }
37
38     public PaintEvent JavaDoc createPaintEvent(Component JavaDoc component, int x, int y,
39                                          int w, int h) {
40         if (component instanceof RootPaneContainer JavaDoc) {
41             AppContext appContext = SunToolkit.targetToAppContext(component);
42             RepaintManager JavaDoc rm = RepaintManager.currentManager(appContext);
43             if (!SHOW_FROM_DOUBLE_BUFFER ||
44                   !rm.show((Container JavaDoc)component, x, y, w, h)) {
45                 rm.nativeAddDirtyRegion(appContext, (Container JavaDoc)component,
46                                         x, y, w, h);
47             }
48             // For backward compatibility generate an empty paint
49
// event. Not doing this broke parts of Netbeans.
50
return new IgnorePaintEvent(component, PaintEvent.PAINT,
51                                         new Rectangle JavaDoc(x, y, w, h));
52         }
53         else if (component instanceof SwingHeavyWeight JavaDoc) {
54             AppContext appContext = SunToolkit.targetToAppContext(component);
55             RepaintManager JavaDoc rm = RepaintManager.currentManager(appContext);
56             rm.nativeAddDirtyRegion(appContext, (Container JavaDoc)component,
57                                     x, y, w, h);
58             return new IgnorePaintEvent(component, PaintEvent.PAINT,
59                                         new Rectangle JavaDoc(x, y, w, h));
60         }
61         return super.createPaintEvent(component, x, y, w, h);
62     }
63
64     public boolean shouldDoNativeBackgroundErase(Component JavaDoc c) {
65         return ERASE_BACKGROUND || !(c instanceof RootPaneContainer JavaDoc);
66     }
67
68     public boolean queueSurfaceDataReplacing(Component JavaDoc c, Runnable JavaDoc r) {
69         if (c instanceof RootPaneContainer JavaDoc) {
70             AppContext appContext = SunToolkit.targetToAppContext(c);
71             RepaintManager.currentManager(appContext).
72                     nativeQueueSurfaceDataRunnable(appContext, c, r);
73             return true;
74         }
75         return super.queueSurfaceDataReplacing(c, r);
76     }
77 }
78
Popular Tags