6837446: Introduce Window.isOpaque() method
Reviewed-by: art, alexp
This commit is contained in:
parent
d116d7aa47
commit
565f4998b5
@ -374,7 +374,7 @@ public final class AWTUtilities {
|
|||||||
"The window argument should not be null.");
|
"The window argument should not be null.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return AWTAccessor.getWindowAccessor().isOpaque(window);
|
return window.isOpaque();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2370,12 +2370,10 @@ public abstract class Component implements ImageObserver, MenuContainer,
|
|||||||
* rectangular region. A non-opaque component paints only some of
|
* rectangular region. A non-opaque component paints only some of
|
||||||
* its pixels, allowing the pixels underneath it to "show through".
|
* its pixels, allowing the pixels underneath it to "show through".
|
||||||
* A component that does not fully paint its pixels therefore
|
* A component that does not fully paint its pixels therefore
|
||||||
* provides a degree of transparency. Only lightweight
|
* provides a degree of transparency.
|
||||||
* components can be transparent.
|
|
||||||
* <p>
|
* <p>
|
||||||
* Subclasses that guarantee to always completely paint their
|
* Subclasses that guarantee to always completely paint their
|
||||||
* contents should override this method and return true. All
|
* contents should override this method and return true.
|
||||||
* of the "heavyweight" AWT components are opaque.
|
|
||||||
*
|
*
|
||||||
* @return true if this component is completely opaque
|
* @return true if this component is completely opaque
|
||||||
* @see #isLightweight
|
* @see #isLightweight
|
||||||
|
@ -281,8 +281,8 @@ public abstract class GraphicsDevice {
|
|||||||
if (w.getOpacity() < 1.0f) {
|
if (w.getOpacity() < 1.0f) {
|
||||||
w.setOpacity(1.0f);
|
w.setOpacity(1.0f);
|
||||||
}
|
}
|
||||||
Color bgColor = w.getBackground();
|
if (!w.isOpaque()) {
|
||||||
if ((bgColor != null) && (bgColor.getAlpha() < 255)) {
|
Color bgColor = w.getBackground();
|
||||||
bgColor = new Color(bgColor.getRed(), bgColor.getGreen(),
|
bgColor = new Color(bgColor.getRed(), bgColor.getGreen(),
|
||||||
bgColor.getBlue(), 255);
|
bgColor.getBlue(), 255);
|
||||||
w.setBackground(bgColor);
|
w.setBackground(bgColor);
|
||||||
|
@ -3521,6 +3521,7 @@ public class Window extends Container implements Accessible {
|
|||||||
* @return this component's background color
|
* @return this component's background color
|
||||||
*
|
*
|
||||||
* @see Window#setBackground
|
* @see Window#setBackground
|
||||||
|
* @see Window#isOpaque
|
||||||
* @see GraphicsDevice.WindowTranslucency
|
* @see GraphicsDevice.WindowTranslucency
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -3583,6 +3584,7 @@ public class Window extends Container implements Accessible {
|
|||||||
* PERPIXEL_TRANSLUCENT} translucency is not supported
|
* PERPIXEL_TRANSLUCENT} translucency is not supported
|
||||||
*
|
*
|
||||||
* @see Window#getBackground
|
* @see Window#getBackground
|
||||||
|
* @see Window#isOpaque
|
||||||
* @see Window#setOpacity()
|
* @see Window#setOpacity()
|
||||||
* @see Window#setShape()
|
* @see Window#setShape()
|
||||||
* @see GraphicsDevice.WindowTranslucency
|
* @see GraphicsDevice.WindowTranslucency
|
||||||
@ -3623,6 +3625,25 @@ public class Window extends Container implements Accessible {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates if the window is currently opaque.
|
||||||
|
* <p>
|
||||||
|
* The method returns {@code false} if the background color of the window
|
||||||
|
* is not {@code null} and the alpha component of the color is less than
|
||||||
|
* 1.0f. The method returns {@code true} otherwise.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the window is opaque, {@code false} otherwise
|
||||||
|
*
|
||||||
|
* @see Window#getBackground
|
||||||
|
* @see Window#setBackground
|
||||||
|
* @since 1.7
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean isOpaque() {
|
||||||
|
Color bg = getBackground();
|
||||||
|
return bg != null ? bg.getAlpha() == 255 : true;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateWindow() {
|
private void updateWindow() {
|
||||||
synchronized (getTreeLock()) {
|
synchronized (getTreeLock()) {
|
||||||
WindowPeer peer = (WindowPeer)getPeer();
|
WindowPeer peer = (WindowPeer)getPeer();
|
||||||
@ -3639,12 +3660,11 @@ public class Window extends Container implements Accessible {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
Color bgColor = getBackground();
|
if (!isOpaque()) {
|
||||||
if ((bgColor != null) && (bgColor.getAlpha() < 255)) {
|
|
||||||
Graphics gg = g.create();
|
Graphics gg = g.create();
|
||||||
try {
|
try {
|
||||||
if (gg instanceof Graphics2D) {
|
if (gg instanceof Graphics2D) {
|
||||||
gg.setColor(bgColor);
|
gg.setColor(getBackground());
|
||||||
((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
|
((Graphics2D)gg).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
|
||||||
gg.fillRect(0, 0, getWidth(), getHeight());
|
gg.fillRect(0, 0, getWidth(), getHeight());
|
||||||
}
|
}
|
||||||
@ -3749,10 +3769,6 @@ public class Window extends Container implements Accessible {
|
|||||||
public void setShape(Window window, Shape shape) {
|
public void setShape(Window window, Shape shape) {
|
||||||
window.setShape(shape);
|
window.setShape(shape);
|
||||||
}
|
}
|
||||||
public boolean isOpaque(Window window) {
|
|
||||||
Color bg = window.getBackground();
|
|
||||||
return (bg != null) ? bg.getAlpha() == 255 : true;
|
|
||||||
}
|
|
||||||
public void setOpaque(Window window, boolean opaque) {
|
public void setOpaque(Window window, boolean opaque) {
|
||||||
Color bg = window.getBackground();
|
Color bg = window.getBackground();
|
||||||
if (bg == null) {
|
if (bg == null) {
|
||||||
|
@ -708,7 +708,7 @@ public class DefaultDesktopManager implements DesktopManager, java.io.Serializab
|
|||||||
// update window if it's non-opaque
|
// update window if it's non-opaque
|
||||||
Window topLevel = SwingUtilities.getWindowAncestor(f);
|
Window topLevel = SwingUtilities.getWindowAncestor(f);
|
||||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||||
if (!AWTAccessor.getWindowAccessor().isOpaque(topLevel) &&
|
if (!topLevel.isOpaque() &&
|
||||||
(tk instanceof SunToolkit) &&
|
(tk instanceof SunToolkit) &&
|
||||||
((SunToolkit)tk).needUpdateWindow())
|
((SunToolkit)tk).needUpdateWindow())
|
||||||
{
|
{
|
||||||
|
@ -732,7 +732,7 @@ public class RepaintManager
|
|||||||
(Window)dirty :
|
(Window)dirty :
|
||||||
SwingUtilities.getWindowAncestor(dirty);
|
SwingUtilities.getWindowAncestor(dirty);
|
||||||
if (window != null &&
|
if (window != null &&
|
||||||
!AWTAccessor.getWindowAccessor().isOpaque(window))
|
!window.isOpaque())
|
||||||
{
|
{
|
||||||
windows.add(window);
|
windows.add(window);
|
||||||
}
|
}
|
||||||
@ -996,7 +996,7 @@ public class RepaintManager
|
|||||||
|
|
||||||
// If the window is non-opaque, it's double-buffered at peer's level
|
// If the window is non-opaque, it's double-buffered at peer's level
|
||||||
Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
|
Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
|
||||||
if (!AWTAccessor.getWindowAccessor().isOpaque(w)) {
|
if (!w.isOpaque()) {
|
||||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||||
if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
|
if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
|
||||||
return null;
|
return null;
|
||||||
@ -1032,7 +1032,7 @@ public class RepaintManager
|
|||||||
|
|
||||||
// If the window is non-opaque, it's double-buffered at peer's level
|
// If the window is non-opaque, it's double-buffered at peer's level
|
||||||
Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
|
Window w = (c instanceof Window) ? (Window)c : SwingUtilities.getWindowAncestor(c);
|
||||||
if (!AWTAccessor.getWindowAccessor().isOpaque(w)) {
|
if (!w.isOpaque()) {
|
||||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||||
if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
|
if ((tk instanceof SunToolkit) && (((SunToolkit)tk).needUpdateWindow())) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -136,11 +136,6 @@ public final class AWTAccessor {
|
|||||||
* Set a shape to the given window.
|
* Set a shape to the given window.
|
||||||
*/
|
*/
|
||||||
void setShape(Window window, Shape shape);
|
void setShape(Window window, Shape shape);
|
||||||
/*
|
|
||||||
* Identify whether the given window is opaque (true)
|
|
||||||
* or translucent (false).
|
|
||||||
*/
|
|
||||||
boolean isOpaque(Window window);
|
|
||||||
/*
|
/*
|
||||||
* Set the opaque preoperty to the given window.
|
* Set the opaque preoperty to the given window.
|
||||||
*/
|
*/
|
||||||
|
@ -1985,8 +1985,7 @@ public abstract class SunToolkit extends Toolkit
|
|||||||
*/
|
*/
|
||||||
public static boolean isContainingTopLevelOpaque(Component c) {
|
public static boolean isContainingTopLevelOpaque(Component c) {
|
||||||
Window w = getContainingWindow(c);
|
Window w = getContainingWindow(c);
|
||||||
return w != null && ((Window)w).getBackground() != null &&
|
return w != null && w.isOpaque();
|
||||||
((Window)w).getBackground().getAlpha() == 255;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,8 +194,7 @@ public class WWindowPeer extends WPanelPeer implements WindowPeer,
|
|||||||
// default value of a boolean field is 'false', so set isOpaque to
|
// default value of a boolean field is 'false', so set isOpaque to
|
||||||
// true here explicitly
|
// true here explicitly
|
||||||
this.isOpaque = true;
|
this.isOpaque = true;
|
||||||
Color bgColor = ((Window)target).getBackground();
|
setOpaque(((Window)target).isOpaque());
|
||||||
setOpaque((bgColor == null) || (bgColor.getAlpha() == 255));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user