6884960: java/awt/Window/TranslucentJAppletTest/TranslucentJAppletTest.java fails
Support painting heavyweight components in transparent windows. Reviewed-by: art, alexp
This commit is contained in:
parent
b32d27a253
commit
e507e02d67
@ -795,7 +795,6 @@ public abstract class JComponent extends Container implements Serializable,
|
|||||||
* @see java.awt.Container#paint
|
* @see java.awt.Container#paint
|
||||||
*/
|
*/
|
||||||
protected void paintChildren(Graphics g) {
|
protected void paintChildren(Graphics g) {
|
||||||
boolean isJComponent;
|
|
||||||
Graphics sg = g;
|
Graphics sg = g;
|
||||||
|
|
||||||
synchronized(getTreeLock()) {
|
synchronized(getTreeLock()) {
|
||||||
@ -826,12 +825,21 @@ public abstract class JComponent extends Container implements Serializable,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean printing = getFlag(IS_PRINTING);
|
boolean printing = getFlag(IS_PRINTING);
|
||||||
|
final Window window = SwingUtilities.getWindowAncestor(this);
|
||||||
|
final boolean isWindowOpaque = window == null || window.isOpaque();
|
||||||
for (; i >= 0 ; i--) {
|
for (; i >= 0 ; i--) {
|
||||||
Component comp = getComponent(i);
|
Component comp = getComponent(i);
|
||||||
isJComponent = (comp instanceof JComponent);
|
if (comp == null) {
|
||||||
if (comp != null &&
|
continue;
|
||||||
(isJComponent || isLightweightComponent(comp)) &&
|
}
|
||||||
(comp.isVisible() == true)) {
|
|
||||||
|
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;
|
Rectangle cr;
|
||||||
|
|
||||||
cr = comp.getBounds(tmpRect);
|
cr = comp.getBounds(tmpRect);
|
||||||
@ -887,6 +895,8 @@ public abstract class JComponent extends Container implements Serializable,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// The component is either lightweight, or
|
||||||
|
// heavyweight in a non-opaque window
|
||||||
if (!printing) {
|
if (!printing) {
|
||||||
comp.paint(cg);
|
comp.paint(cg);
|
||||||
}
|
}
|
||||||
|
@ -551,8 +551,34 @@ public abstract class WComponentPeer extends WObjectPeer
|
|||||||
final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
|
final static Font defaultFont = new Font(Font.DIALOG, Font.PLAIN, 12);
|
||||||
|
|
||||||
public Graphics getGraphics() {
|
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;
|
SurfaceData surfaceData = this.surfaceData;
|
||||||
if (!isDisposed() && surfaceData != null) {
|
if (surfaceData != null) {
|
||||||
/* Fix for bug 4746122. Color and Font shouldn't be null */
|
/* Fix for bug 4746122. Color and Font shouldn't be null */
|
||||||
Color bgColor = background;
|
Color bgColor = background;
|
||||||
if (bgColor == null) {
|
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
|
@Override
|
||||||
public Graphics getGraphics() {
|
public Graphics getGraphics() {
|
||||||
synchronized (getStateLock()) {
|
synchronized (getStateLock()) {
|
||||||
if (!isOpaque) {
|
if (!isOpaque) {
|
||||||
return painter.getBackBuffer(false).getGraphics();
|
return getTranslucentGraphics();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return super.getGraphics();
|
return super.getGraphics();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user