提交 447217eb 编写于 作者: A anthony

6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails

Summary: Support painting heavyweight components in transparent windows.
Reviewed-by: art, alexp
上级 af71f085
......@@ -795,7 +795,6 @@ public abstract class JComponent extends Container implements Serializable,
* @see java.awt.Container#paint
*/
protected void paintChildren(Graphics g) {
boolean isJComponent;
Graphics sg = g;
synchronized(getTreeLock()) {
......@@ -826,12 +825,21 @@ public abstract class JComponent extends Container implements Serializable,
}
}
boolean printing = getFlag(IS_PRINTING);
final Window window = SwingUtilities.getWindowAncestor(this);
final boolean isWindowOpaque = window == null || window.isOpaque();
for (; i >= 0 ; i--) {
Component comp = getComponent(i);
isJComponent = (comp instanceof JComponent);
if (comp != null &&
(isJComponent || isLightweightComponent(comp)) &&
(comp.isVisible() == true)) {
if (comp == null) {
continue;
}
final boolean isJComponent = comp instanceof JComponent;
// Enable painting of heavyweights in non-opaque windows.
// See 6884960
if ((!isWindowOpaque || isJComponent ||
isLightweightComponent(comp)) && comp.isVisible())
{
Rectangle cr;
cr = comp.getBounds(tmpRect);
......@@ -887,6 +895,8 @@ public abstract class JComponent extends Container implements Serializable,
}
}
} else {
// The component is either lightweight, or
// heavyweight in a non-opaque window
if (!printing) {
comp.paint(cg);
}
......
......@@ -551,8 +551,34 @@ public abstract class WComponentPeer extends WObjectPeer
final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
public Graphics getGraphics() {
if (isDisposed()) {
return null;
}
Component target = (Component)getTarget();
Window window = SunToolkit.getContainingWindow(target);
if (window != null && !window.isOpaque()) {
// Non-opaque windows do not support heavyweight children.
// Redirect all painting to the Window's Graphics instead.
// The caller is responsible for calling the
// WindowPeer.updateWindow() after painting has finished.
int x = 0, y = 0;
for (Component c = target; c != window; c = c.getParent()) {
x += c.getX();
y += c.getY();
}
Graphics g =
((WWindowPeer)window.getPeer()).getTranslucentGraphics();
g.translate(x, y);
g.clipRect(0, 0, target.getWidth(), target.getHeight());
return g;
}
SurfaceData surfaceData = this.surfaceData;
if (!isDisposed() && surfaceData != null) {
if (surfaceData != null) {
/* Fix for bug 4746122. Color and Font shouldn't be null */
Color bgColor = background;
if (bgColor == null) {
......
......@@ -578,11 +578,17 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
}
}
public final Graphics getTranslucentGraphics() {
synchronized (getStateLock()) {
return isOpaque ? null : painter.getBackBuffer(false).getGraphics();
}
}
@Override
public Graphics getGraphics() {
synchronized (getStateLock()) {
if (!isOpaque) {
return painter.getBackBuffer(false).getGraphics();
return getTranslucentGraphics();
}
}
return super.getGraphics();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册