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.RecyclableSingleton;
import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor; import com.apple.laf.AquaUtils.RecyclableSingletonFromDefaultConstructor;
import java.awt.Graphics;
public class AquaPanelUI extends BasicPanelUI { public class AquaPanelUI extends BasicPanelUI {
static RecyclableSingleton<AquaPanelUI> instance = new RecyclableSingletonFromDefaultConstructor<AquaPanelUI>(AquaPanelUI.class); static RecyclableSingleton<AquaPanelUI> instance = new RecyclableSingletonFromDefaultConstructor<AquaPanelUI>(AquaPanelUI.class);
public static ComponentUI createUI(final JComponent c) { public static ComponentUI createUI(final JComponent c) {
return instance.get(); 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); 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); g.translate(x, y);
if (c.isOpaque()) { if (c.isOpaque()) {
final Color background = c.getBackground(); AquaUtils.fillRect(g, c, c.getBackground(), 0, 0, w - 1, h - 1);
g.setColor(background);
g.fillRect(0, 0, w - 1, h - 1);
} }
final Color oldColor = g.getColor(); final Color oldColor = g.getColor();
@ -137,4 +135,12 @@ public class AquaToolBarUI extends BasicToolBarUI implements SwingConstants {
return true; 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.*;
import java.awt.image.*; import java.awt.image.*;
import java.lang.ref.SoftReference; import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.plaf.UIResource;
import sun.awt.AppContext; import sun.awt.AppContext;
import sun.lwawt.macosx.CImage; import sun.lwawt.macosx.CImage;
import sun.lwawt.macosx.CImage.Creator; import sun.lwawt.macosx.CImage.Creator;
import sun.lwawt.macosx.CPlatformWindow;
import sun.swing.SwingUtilities2; import sun.swing.SwingUtilities2;
import com.apple.laf.AquaImageFactory.SlicedImageControl; import com.apple.laf.AquaImageFactory.SlicedImageControl;
@ -389,4 +390,51 @@ public class AquaUtils {
return false; 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 static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
private volatile boolean textured;
/** /**
* Current modal blocker or null. * Current modal blocker or null.
* *
@ -442,9 +444,23 @@ public class LWWindowPeer
public void updateWindow() { public void updateWindow() {
} }
public final boolean isTextured() {
return textured;
}
public final void setTextured(final boolean isTextured) {
textured = isTextured;
}
public final boolean isTranslucent() { public final boolean isTranslucent() {
synchronized (getStateLock()) { 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.setColor(nonOpaqueBackground);
g.fillRect(0, 0, w, h); g.fillRect(0, 0, w, h);
} }
if (!isTextured()) {
if (g instanceof SunGraphics2D) { if (g instanceof SunGraphics2D) {
SG2DConstraint((SunGraphics2D) g, getRegion()); SG2DConstraint((SunGraphics2D) g, getRegion());
} }
g.setColor(getBackground()); g.setColor(getBackground());
g.fillRect(0, 0, w, h); g.fillRect(0, 0, w, h);
}
} finally { } finally {
g.dispose(); g.dispose();
} }
@ -982,8 +1000,10 @@ public class LWWindowPeer
if (g instanceof SunGraphics2D) { if (g instanceof SunGraphics2D) {
SG2DConstraint((SunGraphics2D) g, getRegion()); SG2DConstraint((SunGraphics2D) g, getRegion());
} }
if (!isTextured()) {
g.setColor(getBackground()); g.setColor(getBackground());
g.fillRect(0, 0, r.width, r.height); g.fillRect(0, 0, r.width, r.height);
}
if (oldBB != null) { if (oldBB != null) {
// Draw the old back buffer to the new one // Draw the old back buffer to the new one
g.drawImage(oldBB, 0, 0, null); 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 the target is a dialog, popup or tooltip we want it to ignore the brushed metal look.
if (isPopup) { if (isPopup) {
styleBits = SET(styleBits, TEXTURED, true); styleBits = SET(styleBits, TEXTURED, false);
// Popups in applets don't activate applet's process // Popups in applets don't activate applet's process
styleBits = SET(styleBits, NONACTIVATING, true); styleBits = SET(styleBits, NONACTIVATING, true);
} }
@ -372,6 +372,8 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
} }
} }
peer.setTextured(IS(TEXTURED, styleBits));
return styleBits; return styleBits;
} }
@ -733,7 +735,7 @@ public class CPlatformWindow extends CFRetainedResource implements PlatformWindo
@Override @Override
public void setOpaque(boolean isOpaque) { public void setOpaque(boolean isOpaque) {
CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque); CWrapper.NSWindow.setOpaque(getNSWindowPtr(), isOpaque);
if (!isOpaque) { if (!isOpaque && !peer.isTextured()) {
long clearColor = CWrapper.NSColor.clearColor(); long clearColor = CWrapper.NSColor.clearColor();
CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor); CWrapper.NSWindow.setBackgroundColor(getNSWindowPtr(), clearColor);
} }

View File

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