2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
24 |
*/
|
|
25 |
package javax.swing;
|
|
26 |
|
|
27 |
import java.awt.Component;
|
|
28 |
import java.awt.Container;
|
|
29 |
import java.awt.Rectangle;
|
|
30 |
import java.awt.event.PaintEvent;
|
|
31 |
import java.security.AccessController;
|
|
32 |
import sun.awt.AppContext;
|
|
33 |
import sun.awt.SunToolkit;
|
|
34 |
import sun.awt.event.IgnorePaintEvent;
|
|
35 |
import sun.security.action.GetBooleanAction;
|
|
36 |
import sun.security.action.GetPropertyAction;
|
|
37 |
|
|
38 |
/**
|
|
39 |
* Swing's PaintEventDispatcher. If the component specified by the PaintEvent
|
|
40 |
* is a top level Swing component (JFrame, JWindow, JDialog, JApplet), this
|
|
41 |
* will forward the request to the RepaintManager for eventual painting.
|
|
42 |
*
|
|
43 |
*/
|
|
44 |
class SwingPaintEventDispatcher extends sun.awt.PaintEventDispatcher {
|
|
45 |
private static final boolean SHOW_FROM_DOUBLE_BUFFER;
|
|
46 |
private static final boolean ERASE_BACKGROUND;
|
|
47 |
|
|
48 |
static {
|
|
49 |
SHOW_FROM_DOUBLE_BUFFER = "true".equals(AccessController.doPrivileged(
|
|
50 |
new GetPropertyAction("swing.showFromDoubleBuffer", "true")));
|
|
51 |
ERASE_BACKGROUND = AccessController.doPrivileged(
|
|
52 |
new GetBooleanAction("swing.nativeErase"));
|
|
53 |
}
|
|
54 |
|
|
55 |
public PaintEvent createPaintEvent(Component component, int x, int y,
|
|
56 |
int w, int h) {
|
|
57 |
if (component instanceof RootPaneContainer) {
|
|
58 |
AppContext appContext = SunToolkit.targetToAppContext(component);
|
|
59 |
RepaintManager rm = RepaintManager.currentManager(appContext);
|
|
60 |
if (!SHOW_FROM_DOUBLE_BUFFER ||
|
|
61 |
!rm.show((Container)component, x, y, w, h)) {
|
|
62 |
rm.nativeAddDirtyRegion(appContext, (Container)component,
|
|
63 |
x, y, w, h);
|
|
64 |
}
|
|
65 |
// For backward compatibility generate an empty paint
|
|
66 |
// event. Not doing this broke parts of Netbeans.
|
|
67 |
return new IgnorePaintEvent(component, PaintEvent.PAINT,
|
|
68 |
new Rectangle(x, y, w, h));
|
|
69 |
}
|
|
70 |
else if (component instanceof SwingHeavyWeight) {
|
|
71 |
AppContext appContext = SunToolkit.targetToAppContext(component);
|
|
72 |
RepaintManager rm = RepaintManager.currentManager(appContext);
|
|
73 |
rm.nativeAddDirtyRegion(appContext, (Container)component,
|
|
74 |
x, y, w, h);
|
|
75 |
return new IgnorePaintEvent(component, PaintEvent.PAINT,
|
|
76 |
new Rectangle(x, y, w, h));
|
|
77 |
}
|
|
78 |
return super.createPaintEvent(component, x, y, w, h);
|
|
79 |
}
|
|
80 |
|
|
81 |
public boolean shouldDoNativeBackgroundErase(Component c) {
|
|
82 |
return ERASE_BACKGROUND || !(c instanceof RootPaneContainer);
|
|
83 |
}
|
|
84 |
|
|
85 |
public boolean queueSurfaceDataReplacing(Component c, Runnable r) {
|
|
86 |
if (c instanceof RootPaneContainer) {
|
|
87 |
AppContext appContext = SunToolkit.targetToAppContext(c);
|
|
88 |
RepaintManager.currentManager(appContext).
|
|
89 |
nativeQueueSurfaceDataRunnable(appContext, c, r);
|
|
90 |
return true;
|
|
91 |
}
|
|
92 |
return super.queueSurfaceDataReplacing(c, r);
|
|
93 |
}
|
|
94 |
}
|