7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar

Reviewed-by: anthony, art
This commit is contained in:
Sergey Bylokhov 2012-07-04 15:36:48 +04:00
parent a433c60a8a
commit e3a1dad2c0
7 changed files with 116 additions and 14 deletions

View File

@ -32,10 +32,20 @@ import javax.swing.plaf.basic.BasicPanelUI;
import com.apple.laf.AquaUtils.RecyclableSingleton;
import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
import java.awt.Graphics;
public class AquaPanelUI extends BasicPanelUI {
static RecyclableSingleton<AquaPanelUI> instance = new RecyclableSingletonFromDefaultConstructor<AquaPanelUI>(AquaPanelUI.class);
public static ComponentUI createUI(final JComponent c) {
return instance.get();
}
@Override
public final void update(final Graphics g, final JComponent c) {
if (c.isOpaque()) {
AquaUtils.fillRect(g, c);
}
paint(g, c);
}
}

View File

@ -319,4 +319,12 @@ public class AquaRootPaneUI extends BasicRootPaneUI implements AncestorListener,
updateComponentTreeUIActivation(element, active);
}
}
@Override
public final void update(final Graphics g, final JComponent c) {
if (c.isOpaque()) {
AquaUtils.fillRect(g, c);
}
paint(g, c);
}
}

View File

@ -73,9 +73,7 @@ public class AquaToolBarUI extends BasicToolBarUI implements SwingConstants {
g.translate(x, y);
if (c.isOpaque()) {
final Color background = c.getBackground();
g.setColor(background);
g.fillRect(0, 0, w - 1, h - 1);
AquaUtils.fillRect(g, c, c.getBackground(), 0, 0, w - 1, h - 1);
}
final Color oldColor = g.getColor();
@ -137,4 +135,12 @@ public class AquaToolBarUI extends BasicToolBarUI implements SwingConstants {
return true;
}
}
@Override
public final void update(final Graphics g, final JComponent c) {
if (c.isOpaque()) {
AquaUtils.fillRect(g, c);
}
paint(g, c);
}
}

View File

@ -28,18 +28,19 @@ package com.apple.laf;
import java.awt.*;
import java.awt.image.*;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.security.PrivilegedAction;
import java.util.*;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.plaf.UIResource;
import sun.awt.AppContext;
import sun.lwawt.macosx.CImage;
import sun.lwawt.macosx.CImage.Creator;
import sun.lwawt.macosx.CPlatformWindow;
import sun.swing.SwingUtilities2;
import com.apple.laf.AquaImageFactory.SlicedImageControl;
@ -389,4 +390,51 @@ public class AquaUtils {
return false;
}
}
protected static boolean isWindowTextured(final Component c) {
if (!(c instanceof JComponent)) {
return false;
}
final JRootPane pane = ((JComponent) c).getRootPane();
if (pane == null) {
return false;
}
Object prop = pane.getClientProperty(
CPlatformWindow.WINDOW_BRUSH_METAL_LOOK);
if (prop != null) {
return Boolean.parseBoolean(prop.toString());
}
prop = pane.getClientProperty(CPlatformWindow.WINDOW_STYLE);
return prop != null && "textured".equals(prop);
}
private static Color resetAlpha(final Color color) {
return new Color(color.getRed(), color.getGreen(), color.getBlue(), 0);
}
protected static void fillRect(final Graphics g, final Component c) {
fillRect(g, c, c.getBackground(), 0, 0, c.getWidth(), c.getHeight());
}
protected static void fillRect(final Graphics g, final Component c,
final Color color, final int x, final int y,
final int w, final int h) {
if (!(g instanceof Graphics2D)) {
return;
}
final Graphics2D cg = (Graphics2D) g.create();
try {
if (color instanceof UIResource && isWindowTextured(c)
&& color.equals(SystemColor.window)) {
cg.setComposite(AlphaComposite.Src);
cg.setColor(resetAlpha(color));
} else {
cg.setColor(color);
}
cg.fillRect(x, y, w, h);
} finally {
cg.dispose();
}
}
}

View File

@ -112,6 +112,8 @@ public class LWWindowPeer
private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
private volatile boolean textured;
/**
* Current modal blocker or null.
*
@ -442,9 +444,23 @@ public class LWWindowPeer
public void updateWindow() {
}
public final boolean isTextured() {
return textured;
}
public final void setTextured(final boolean isTextured) {
textured = isTextured;
}
public final boolean isTranslucent() {
synchronized (getStateLock()) {
return !isOpaque || isShaped();
/*
* Textured window is a special case of translucent window.
* The difference is only in nswindow background. So when we set
* texture property our peer became fully translucent. It doesn't
* fill background, create non opaque backbuffers and layer etc.
*/
return !isOpaque || isShaped() || isTextured();
}
}
@ -613,11 +629,13 @@ public class LWWindowPeer
g.setColor(nonOpaqueBackground);
g.fillRect(0, 0, w, h);
}
if (g instanceof SunGraphics2D) {
SG2DConstraint((SunGraphics2D) g, getRegion());
if (!isTextured()) {
if (g instanceof SunGraphics2D) {
SG2DConstraint((SunGraphics2D) g, getRegion());
}
g.setColor(getBackground());
g.fillRect(0, 0, w, h);
}
g.setColor(getBackground());
g.fillRect(0, 0, w, h);
} finally {
g.dispose();
}
@ -982,8 +1000,10 @@ public class LWWindowPeer
if (g instanceof SunGraphics2D) {
SG2DConstraint((SunGraphics2D) g, getRegion());
}
g.setColor(getBackground());
g.fillRect(0, 0, r.width, r.height);
if (!isTextured()) {
g.setColor(getBackground());
g.fillRect(0, 0, r.width, r.height);
}
if (oldBB != null) {
// Draw the old back buffer to the new one
g.drawImage(oldBB, 0, 0, null);

View File

@ -298,7 +298,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
// If the target is a dialog, popup or tooltip we want it to ignore the brushed metal look.
if (isPopup) {
styleBits = SET(styleBits, TEXTURED, true);
styleBits = SET(styleBits, TEXTURED, false);
// Popups in applets don't activate applet's process
styleBits = SET(styleBits, NONACTIVATING, true);
}
@ -372,6 +372,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
}
}
peer.setTextured(IS(TEXTURED, styleBits));
return styleBits;
}
@ -733,7 +735,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override
public void setOpaque(boolean isOpaque) {
CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
if (!isOpaque) {
if (!isOpaque && !peer.isTextured()) {
long clearColor = CWrapper.NSColor.clearColor();
CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor);
}

View File

@ -1586,10 +1586,18 @@ public class JViewport extends JComponent implements Accessible
int bdx = blitToX - blitFromX;
int bdy = blitToY - blitFromY;
Composite oldComposite = null;
// Shift the scrolled region
if (g instanceof Graphics2D) {
Graphics2D g2d = (Graphics2D) g;
oldComposite = g2d.getComposite();
g2d.setComposite(AlphaComposite.Src);
}
rm.copyArea(this, g, blitFromX, blitFromY, blitW, blitH, bdx, bdy,
false);
if (oldComposite != null) {
((Graphics2D) g).setComposite(oldComposite);
}
// Paint the newly exposed region.
int x = view.getX();
int y = view.getY();