author | prr |
Wed, 03 Oct 2018 11:10:09 -0700 | |
changeset 52242 | 7bd9745e8e15 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
20835 | 2 |
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
12047 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
package com.apple.laf; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.image.*; |
|
30 |
import java.lang.ref.SoftReference; |
|
31 |
import java.lang.reflect.Method; |
|
20835 | 32 |
import java.security.AccessController; |
12047 | 33 |
import java.security.PrivilegedAction; |
34 |
import java.util.*; |
|
35 |
||
36 |
import javax.swing.*; |
|
37 |
import javax.swing.border.Border; |
|
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
38 |
import javax.swing.plaf.UIResource; |
12047 | 39 |
|
40 |
import sun.awt.AppContext; |
|
41 |
||
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
42 |
import sun.lwawt.macosx.CPlatformWindow; |
20835 | 43 |
import sun.reflect.misc.ReflectUtil; |
44 |
import sun.security.action.GetPropertyAction; |
|
12047 | 45 |
import sun.swing.SwingUtilities2; |
46 |
||
47 |
import com.apple.laf.AquaImageFactory.SlicedImageControl; |
|
24532
24831bd48764
8040279: [macosx] Do not use the base image in the MultiResolutionBufferedImage
alexsch
parents:
23666
diff
changeset
|
48 |
import sun.awt.image.MultiResolutionCachedImage; |
40719
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
40707
diff
changeset
|
49 |
import sun.swing.SwingAccessor; |
12047 | 50 |
|
20835 | 51 |
final class AquaUtils { |
52 |
||
53 |
private static final String ANIMATIONS_PROPERTY = "swing.enableAnimations"; |
|
12047 | 54 |
|
20835 | 55 |
/** |
56 |
* Suppresses default constructor, ensuring non-instantiability. |
|
57 |
*/ |
|
58 |
private AquaUtils() { |
|
59 |
} |
|
60 |
||
61 |
/** |
|
12047 | 62 |
* Convenience function for determining ComponentOrientation. Helps us |
63 |
* avoid having Munge directives throughout the code. |
|
64 |
*/ |
|
20835 | 65 |
static boolean isLeftToRight(final Component c) { |
12047 | 66 |
return c.getComponentOrientation().isLeftToRight(); |
67 |
} |
|
68 |
||
20835 | 69 |
static void enforceComponentOrientation(final Component c, final ComponentOrientation orientation) { |
12047 | 70 |
c.setComponentOrientation(orientation); |
71 |
if (c instanceof Container) { |
|
20835 | 72 |
for (final Component child : ((Container)c).getComponents()) { |
12047 | 73 |
enforceComponentOrientation(child, orientation); |
74 |
} |
|
75 |
} |
|
76 |
} |
|
77 |
||
20835 | 78 |
static Image generateSelectedDarkImage(final Image image) { |
40707
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
79 |
final ImageFilter filter = new IconImageFilter() { |
20835 | 80 |
@Override |
12047 | 81 |
int getGreyFor(final int gray) { |
82 |
return gray * 75 / 100; |
|
83 |
} |
|
40707
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
84 |
}; |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
85 |
return map(image, filter); |
12047 | 86 |
} |
87 |
||
20835 | 88 |
static Image generateDisabledImage(final Image image) { |
40707
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
89 |
final ImageFilter filter = new IconImageFilter() { |
20835 | 90 |
@Override |
12047 | 91 |
int getGreyFor(final int gray) { |
92 |
return 255 - ((255 - gray) * 65 / 100); |
|
93 |
} |
|
40707
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
94 |
}; |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
95 |
return map(image, filter); |
12047 | 96 |
} |
97 |
||
20835 | 98 |
static Image generateLightenedImage(final Image image, final int percent) { |
12047 | 99 |
final GrayFilter filter = new GrayFilter(true, percent); |
40707
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
100 |
return map(image, filter); |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
101 |
} |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
102 |
|
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
103 |
static Image generateFilteredImage(Image image, ImageFilter filter) { |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
104 |
final ImageProducer prod = new FilteredImageSource(image.getSource(), filter); |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
105 |
return Toolkit.getDefaultToolkit().createImage(prod); |
23318
7da69afd4ffe
8031573: [macosx] Checkmarks of JCheckBoxMenuItems aren't rendered in high resolution on Retina
alexsch
parents:
20835
diff
changeset
|
106 |
} |
7da69afd4ffe
8031573: [macosx] Checkmarks of JCheckBoxMenuItems aren't rendered in high resolution on Retina
alexsch
parents:
20835
diff
changeset
|
107 |
|
40707
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
108 |
private static Image map(Image image, ImageFilter filter) { |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
109 |
if (image instanceof MultiResolutionImage) { |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
110 |
return MultiResolutionCachedImage |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
111 |
.map((MultiResolutionImage) image, |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
112 |
(img) -> generateFilteredImage(img, filter)); |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
113 |
} |
8b0d53520355
8151303: [macosx] [hidpi] JButton's low-res. icon is visible when clicking on it
alexsch
parents:
36511
diff
changeset
|
114 |
return generateFilteredImage(image, filter); |
12047 | 115 |
} |
116 |
||
20835 | 117 |
private abstract static class IconImageFilter extends RGBImageFilter { |
118 |
IconImageFilter() { |
|
12047 | 119 |
super(); |
120 |
canFilterIndexColorModel = true; |
|
121 |
} |
|
122 |
||
20835 | 123 |
@Override |
124 |
public final int filterRGB(final int x, final int y, final int rgb) { |
|
12047 | 125 |
final int red = (rgb >> 16) & 0xff; |
126 |
final int green = (rgb >> 8) & 0xff; |
|
127 |
final int blue = rgb & 0xff; |
|
128 |
final int gray = getGreyFor((int)((0.30 * red + 0.59 * green + 0.11 * blue) / 3)); |
|
129 |
||
130 |
return (rgb & 0xff000000) | (grayTransform(red, gray) << 16) | (grayTransform(green, gray) << 8) | (grayTransform(blue, gray) << 0); |
|
131 |
} |
|
132 |
||
133 |
private static int grayTransform(final int color, final int gray) { |
|
134 |
int result = color - gray; |
|
135 |
if (result < 0) result = 0; |
|
136 |
if (result > 255) result = 255; |
|
137 |
return result; |
|
138 |
} |
|
139 |
||
20835 | 140 |
abstract int getGreyFor(int gray); |
12047 | 141 |
} |
142 |
||
20835 | 143 |
abstract static class RecyclableObject<T> { |
144 |
private SoftReference<T> objectRef; |
|
12047 | 145 |
|
20835 | 146 |
T get() { |
147 |
T referent; |
|
12047 | 148 |
if (objectRef != null && (referent = objectRef.get()) != null) return referent; |
149 |
referent = create(); |
|
150 |
objectRef = new SoftReference<T>(referent); |
|
151 |
return referent; |
|
152 |
} |
|
153 |
||
154 |
protected abstract T create(); |
|
155 |
} |
|
156 |
||
20835 | 157 |
abstract static class RecyclableSingleton<T> { |
158 |
final T get() { |
|
23666
a54bf43b5ba9
8035069: [macosx] Loading resolution variants by demand
alexsch
parents:
23318
diff
changeset
|
159 |
return AppContext.getSoftReferenceValue(this, () -> getInstance()); |
12047 | 160 |
} |
161 |
||
20835 | 162 |
void reset() { |
163 |
AppContext.getAppContext().remove(this); |
|
12047 | 164 |
} |
165 |
||
20835 | 166 |
abstract T getInstance(); |
12047 | 167 |
} |
168 |
||
20835 | 169 |
static class RecyclableSingletonFromDefaultConstructor<T> extends RecyclableSingleton<T> { |
170 |
private final Class<T> clazz; |
|
12047 | 171 |
|
20835 | 172 |
RecyclableSingletonFromDefaultConstructor(final Class<T> clazz) { |
12047 | 173 |
this.clazz = clazz; |
174 |
} |
|
175 |
||
20835 | 176 |
@Override |
42218
35e0972b2533
8169887: javax/swing/JEditorPane/8080972/TestJEditor.java, javax/swing/text/View/8080972/TestObjectView.java are failing
prr
parents:
42208
diff
changeset
|
177 |
@SuppressWarnings("deprecation") |
20835 | 178 |
T getInstance() { |
12047 | 179 |
try { |
20835 | 180 |
ReflectUtil.checkPackageAccess(clazz); |
42218
35e0972b2533
8169887: javax/swing/JEditorPane/8080972/TestJEditor.java, javax/swing/text/View/8080972/TestObjectView.java are failing
prr
parents:
42208
diff
changeset
|
181 |
return clazz.newInstance(); |
42208
7c1017f0ade5
8155874: Fix java.desktop deprecation warnings about Class.newInstance
prr
parents:
40719
diff
changeset
|
182 |
} catch (ReflectiveOperationException ignored) { |
12047 | 183 |
} |
184 |
return null; |
|
185 |
} |
|
186 |
} |
|
187 |
||
20835 | 188 |
abstract static class LazyKeyedSingleton<K, V> { |
189 |
private Map<K, V> refs; |
|
12047 | 190 |
|
20835 | 191 |
V get(final K key) { |
192 |
if (refs == null) refs = new HashMap<>(); |
|
12047 | 193 |
|
194 |
final V cachedValue = refs.get(key); |
|
195 |
if (cachedValue != null) return cachedValue; |
|
196 |
||
197 |
final V value = getInstance(key); |
|
198 |
refs.put(key, value); |
|
199 |
return value; |
|
200 |
} |
|
201 |
||
20835 | 202 |
protected abstract V getInstance(K key); |
12047 | 203 |
} |
204 |
||
20835 | 205 |
private static final RecyclableSingleton<Boolean> enableAnimations = new RecyclableSingleton<Boolean>() { |
12047 | 206 |
@Override |
207 |
protected Boolean getInstance() { |
|
20835 | 208 |
final String sizeProperty = (String) AccessController.doPrivileged((PrivilegedAction<?>)new GetPropertyAction( |
209 |
ANIMATIONS_PROPERTY)); |
|
210 |
return !"false".equals(sizeProperty); // should be true by default |
|
12047 | 211 |
} |
212 |
}; |
|
20835 | 213 |
private static boolean animationsEnabled() { |
12047 | 214 |
return enableAnimations.get(); |
215 |
} |
|
216 |
||
20835 | 217 |
private static final int MENU_BLINK_DELAY = 50; // 50ms == 3/60 sec, according to the spec |
218 |
static void blinkMenu(final Selectable selectable) { |
|
12047 | 219 |
if (!animationsEnabled()) return; |
220 |
try { |
|
221 |
selectable.paintSelected(false); |
|
222 |
Thread.sleep(MENU_BLINK_DELAY); |
|
223 |
selectable.paintSelected(true); |
|
224 |
Thread.sleep(MENU_BLINK_DELAY); |
|
20835 | 225 |
} catch (final InterruptedException ignored) { } |
12047 | 226 |
} |
227 |
||
228 |
interface Selectable { |
|
20835 | 229 |
void paintSelected(boolean selected); |
12047 | 230 |
} |
231 |
||
232 |
interface JComponentPainter { |
|
20835 | 233 |
void paint(JComponent c, Graphics g, int x, int y, int w, int h); |
12047 | 234 |
} |
235 |
||
236 |
interface Painter { |
|
20835 | 237 |
void paint(Graphics g, int x, int y, int w, int h); |
12047 | 238 |
} |
239 |
||
20835 | 240 |
static void paintDropShadowText(final Graphics g, final JComponent c, final Font font, final FontMetrics metrics, final int x, final int y, final int offsetX, final int offsetY, final Color textColor, final Color shadowColor, final String text) { |
12047 | 241 |
g.setFont(font); |
242 |
g.setColor(shadowColor); |
|
243 |
SwingUtilities2.drawString(c, g, text, x + offsetX, y + offsetY + metrics.getAscent()); |
|
244 |
g.setColor(textColor); |
|
245 |
SwingUtilities2.drawString(c, g, text, x, y + metrics.getAscent()); |
|
246 |
} |
|
247 |
||
20835 | 248 |
static class ShadowBorder implements Border { |
249 |
private final Painter prePainter; |
|
250 |
private final Painter postPainter; |
|
12047 | 251 |
|
20835 | 252 |
private final int offsetX; |
253 |
private final int offsetY; |
|
254 |
private final float distance; |
|
255 |
private final int blur; |
|
256 |
private final Insets insets; |
|
257 |
private final ConvolveOp blurOp; |
|
12047 | 258 |
|
20835 | 259 |
ShadowBorder(final Painter prePainter, final Painter postPainter, final int offsetX, final int offsetY, final float distance, final float intensity, final int blur) { |
12047 | 260 |
this.prePainter = prePainter; this.postPainter = postPainter; |
261 |
this.offsetX = offsetX; this.offsetY = offsetY; this.distance = distance; this.blur = blur; |
|
262 |
final int halfBlur = blur / 2; |
|
20835 | 263 |
insets = new Insets(halfBlur - offsetY, halfBlur - offsetX, halfBlur + offsetY, halfBlur + offsetX); |
12047 | 264 |
|
265 |
final float blurry = intensity / (blur * blur); |
|
266 |
final float[] blurKernel = new float[blur * blur]; |
|
267 |
for (int i = 0; i < blurKernel.length; i++) blurKernel[i] = blurry; |
|
268 |
blurOp = new ConvolveOp(new Kernel(blur, blur, blurKernel)); |
|
269 |
} |
|
270 |
||
20835 | 271 |
@Override |
272 |
public final boolean isBorderOpaque() { |
|
12047 | 273 |
return false; |
274 |
} |
|
275 |
||
20835 | 276 |
@Override |
277 |
public final Insets getBorderInsets(final Component c) { |
|
12047 | 278 |
return insets; |
279 |
} |
|
280 |
||
20835 | 281 |
@Override |
12047 | 282 |
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { |
283 |
final BufferedImage img = new BufferedImage(width + blur * 2, height + blur * 2, BufferedImage.TYPE_INT_ARGB_PRE); |
|
284 |
paintToImage(img, x, y, width, height); |
|
285 |
g.drawImage(img, -blur, -blur, null); |
|
286 |
} |
|
287 |
||
20835 | 288 |
private void paintToImage(final BufferedImage img, final int x, final int y, final int width, final int height) { |
12047 | 289 |
// clear the prior image |
290 |
Graphics2D imgG = (Graphics2D)img.getGraphics(); |
|
291 |
imgG.setComposite(AlphaComposite.Clear); |
|
292 |
imgG.setColor(Color.black); |
|
293 |
imgG.fillRect(0, 0, width + blur * 2, height + blur * 2); |
|
294 |
||
295 |
final int adjX = (int)(x + blur + offsetX + (insets.left * distance)); |
|
296 |
final int adjY = (int)(y + blur + offsetY + (insets.top * distance)); |
|
297 |
final int adjW = (int)(width - (insets.left + insets.right) * distance); |
|
298 |
final int adjH = (int)(height - (insets.top + insets.bottom) * distance); |
|
299 |
||
300 |
// let the delegate paint whatever they want to be blurred |
|
301 |
imgG.setComposite(AlphaComposite.DstAtop); |
|
302 |
if (prePainter != null) prePainter.paint(imgG, adjX, adjY, adjW, adjH); |
|
303 |
imgG.dispose(); |
|
304 |
||
305 |
// blur the prior image back into the same pixels |
|
306 |
imgG = (Graphics2D)img.getGraphics(); |
|
307 |
imgG.setComposite(AlphaComposite.DstAtop); |
|
308 |
imgG.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); |
|
309 |
imgG.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY); |
|
310 |
imgG.drawImage(img, blurOp, 0, 0); |
|
311 |
||
312 |
if (postPainter != null) postPainter.paint(imgG, adjX, adjY, adjW, adjH); |
|
313 |
imgG.dispose(); |
|
314 |
} |
|
315 |
} |
|
316 |
||
20835 | 317 |
static class SlicedShadowBorder extends ShadowBorder { |
318 |
private final SlicedImageControl slices; |
|
12047 | 319 |
|
20835 | 320 |
SlicedShadowBorder(final Painter prePainter, final Painter postPainter, final int offsetX, final int offsetY, final float distance, final float intensity, final int blur, final int templateWidth, final int templateHeight, final int leftCut, final int topCut, final int rightCut, final int bottomCut) { |
12047 | 321 |
super(prePainter, postPainter, offsetX, offsetY, distance, intensity, blur); |
322 |
||
323 |
final BufferedImage i = new BufferedImage(templateWidth, templateHeight, BufferedImage.TYPE_INT_ARGB_PRE); |
|
324 |
super.paintBorder(null, i.getGraphics(), 0, 0, templateWidth, templateHeight); |
|
325 |
slices = new SlicedImageControl(i, leftCut, topCut, rightCut, bottomCut, false); |
|
326 |
} |
|
327 |
||
20835 | 328 |
@Override |
12047 | 329 |
public void paintBorder(final Component c, final Graphics g, final int x, final int y, final int width, final int height) { |
330 |
slices.paint(g, x, y, width, height); |
|
331 |
} |
|
332 |
} |
|
333 |
||
20835 | 334 |
private static final RecyclableSingleton<Method> getJComponentGetFlagMethod = new RecyclableSingleton<Method>() { |
335 |
@Override |
|
12047 | 336 |
protected Method getInstance() { |
20835 | 337 |
return AccessController.doPrivileged( |
12047 | 338 |
new PrivilegedAction<Method>() { |
20835 | 339 |
@Override |
12047 | 340 |
public Method run() { |
341 |
try { |
|
25762
c4a3548120c6
8044862: Fix raw and unchecked lint warnings in macosx specific code
henryjen
parents:
24532
diff
changeset
|
342 |
final Method method = JComponent.class.getDeclaredMethod( |
c4a3548120c6
8044862: Fix raw and unchecked lint warnings in macosx specific code
henryjen
parents:
24532
diff
changeset
|
343 |
"getFlag", new Class<?>[] { int.class }); |
12047 | 344 |
method.setAccessible(true); |
345 |
return method; |
|
20835 | 346 |
} catch (final Throwable ignored) { |
12047 | 347 |
return null; |
348 |
} |
|
349 |
} |
|
350 |
} |
|
351 |
); |
|
352 |
} |
|
353 |
}; |
|
354 |
||
40719
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
40707
diff
changeset
|
355 |
private static final int OPAQUE_SET_FLAG = 24; // private int JComponent.OPAQUE_SET |
20835 | 356 |
static boolean hasOpaqueBeenExplicitlySet(final JComponent c) { |
40719
4ae72a69bd3b
8129854: Remove reflection from AWT/Swing classes
alexsch
parents:
40707
diff
changeset
|
357 |
return SwingAccessor.getJComponentAccessor().getFlag(c, OPAQUE_SET_FLAG); |
12047 | 358 |
} |
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
359 |
|
20835 | 360 |
private static boolean isWindowTextured(final Component c) { |
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
361 |
if (!(c instanceof JComponent)) { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
362 |
return false; |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
363 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
364 |
final JRootPane pane = ((JComponent) c).getRootPane(); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
365 |
if (pane == null) { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
366 |
return false; |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
367 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
368 |
Object prop = pane.getClientProperty( |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
369 |
CPlatformWindow.WINDOW_BRUSH_METAL_LOOK); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
370 |
if (prop != null) { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
371 |
return Boolean.parseBoolean(prop.toString()); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
372 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
373 |
prop = pane.getClientProperty(CPlatformWindow.WINDOW_STYLE); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
374 |
return prop != null && "textured".equals(prop); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
375 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
376 |
|
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
377 |
private static Color resetAlpha(final Color color) { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
378 |
return new Color(color.getRed(), color.getGreen(), color.getBlue(), 0); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
379 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
380 |
|
20835 | 381 |
static void fillRect(final Graphics g, final Component c) { |
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
382 |
fillRect(g, c, c.getBackground(), 0, 0, c.getWidth(), c.getHeight()); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
383 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
384 |
|
20835 | 385 |
static void fillRect(final Graphics g, final Component c, final Color color, |
386 |
final int x, final int y, final int w, final int h) { |
|
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
387 |
if (!(g instanceof Graphics2D)) { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
388 |
return; |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
389 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
390 |
final Graphics2D cg = (Graphics2D) g.create(); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
391 |
try { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
392 |
if (color instanceof UIResource && isWindowTextured(c) |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
393 |
&& color.equals(SystemColor.window)) { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
394 |
cg.setComposite(AlphaComposite.Src); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
395 |
cg.setColor(resetAlpha(color)); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
396 |
} else { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
397 |
cg.setColor(color); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
398 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
399 |
cg.fillRect(x, y, w, h); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
400 |
} finally { |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
401 |
cg.dispose(); |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
402 |
} |
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
403 |
} |
12047 | 404 |
} |
13234
9437e5985d73
7124513: [macosx] Support NSTexturedBackgroundWindowMask/different titlebar styles to create unified toolbar
serb
parents:
12047
diff
changeset
|
405 |