1 /*
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
230
231 @Override
232 protected Image getInstance() {
233 return Toolkit.getDefaultToolkit().getImage("NSImage://" + namedImage);
234 }
235 }
236
237 static class IconUIResourceSingleton extends RecyclableSingleton<IconUIResource> {
238 final NamedImageSingleton holder;
239
240 public IconUIResourceSingleton(final NamedImageSingleton holder) {
241 this.holder = holder;
242 }
243
244 @Override
245 protected IconUIResource getInstance() {
246 return new IconUIResource(new ImageIcon(holder.get()));
247 }
248 }
249
250 static class InvertableImageIcon extends ImageIcon implements InvertableIcon, UIResource {
251 Icon invertedImage;
252 public InvertableImageIcon(final Image image) {
253 super(image);
254 }
255
256 @Override
257 public Icon getInvertedIcon() {
258 if (invertedImage != null) return invertedImage;
259 return invertedImage = new IconUIResource(new ImageIcon(AquaUtils.generateLightenedImage(getImage(), 100)));
260 }
261 }
262
263 protected static final NamedImageSingleton northArrow = new NamedImageSingleton("NSMenuScrollUp");
264 protected static final IconUIResourceSingleton northArrowIcon = new IconUIResourceSingleton(northArrow);
265 protected static final NamedImageSingleton southArrow = new NamedImageSingleton("NSMenuScrollDown");
266 protected static final IconUIResourceSingleton southArrowIcon = new IconUIResourceSingleton(southArrow);
267 protected static final NamedImageSingleton westArrow = new NamedImageSingleton("NSMenuSubmenuLeft");
268 protected static final IconUIResourceSingleton westArrowIcon = new IconUIResourceSingleton(westArrow);
269 protected static final NamedImageSingleton eastArrow = new NamedImageSingleton("NSMenuSubmenu");
446 }
447 }
448
449 public abstract static class RecyclableSlicedImageControl extends RecyclableObject<SlicedImageControl> {
450 final NineSliceMetrics metrics;
451
452 public RecyclableSlicedImageControl(final NineSliceMetrics metrics) {
453 this.metrics = metrics;
454 }
455
456 @Override
457 protected SlicedImageControl create() {
458 return new SlicedImageControl(createTemplateImage(metrics.minW, metrics.minH), metrics);
459 }
460
461 protected abstract Image createTemplateImage(final int width, final int height);
462 }
463
464 // when we use SystemColors, we need to proxy the color with something that implements UIResource,
465 // so that it will be uninstalled when the look and feel is changed.
466 private static class SystemColorProxy extends Color implements UIResource {
467 final Color color;
468 public SystemColorProxy(final Color color) {
469 super(color.getRGB());
470 this.color = color;
471 }
472
473 public int getRGB() {
474 return color.getRGB();
475 }
476 }
477
478 public static Color getWindowBackgroundColorUIResource() {
479 //return AquaNativeResources.getWindowBackgroundColorUIResource();
480 return new SystemColorProxy(SystemColor.window);
481 }
482
483 public static Color getTextSelectionBackgroundColorUIResource() {
484 return new SystemColorProxy(SystemColor.textHighlight);
485 }
|
1 /*
2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
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
230
231 @Override
232 protected Image getInstance() {
233 return Toolkit.getDefaultToolkit().getImage("NSImage://" + namedImage);
234 }
235 }
236
237 static class IconUIResourceSingleton extends RecyclableSingleton<IconUIResource> {
238 final NamedImageSingleton holder;
239
240 public IconUIResourceSingleton(final NamedImageSingleton holder) {
241 this.holder = holder;
242 }
243
244 @Override
245 protected IconUIResource getInstance() {
246 return new IconUIResource(new ImageIcon(holder.get()));
247 }
248 }
249
250 @SuppressWarnings("serial") // Superclass is not serializable across versions
251 static class InvertableImageIcon extends ImageIcon implements InvertableIcon, UIResource {
252 Icon invertedImage;
253 public InvertableImageIcon(final Image image) {
254 super(image);
255 }
256
257 @Override
258 public Icon getInvertedIcon() {
259 if (invertedImage != null) return invertedImage;
260 return invertedImage = new IconUIResource(new ImageIcon(AquaUtils.generateLightenedImage(getImage(), 100)));
261 }
262 }
263
264 protected static final NamedImageSingleton northArrow = new NamedImageSingleton("NSMenuScrollUp");
265 protected static final IconUIResourceSingleton northArrowIcon = new IconUIResourceSingleton(northArrow);
266 protected static final NamedImageSingleton southArrow = new NamedImageSingleton("NSMenuScrollDown");
267 protected static final IconUIResourceSingleton southArrowIcon = new IconUIResourceSingleton(southArrow);
268 protected static final NamedImageSingleton westArrow = new NamedImageSingleton("NSMenuSubmenuLeft");
269 protected static final IconUIResourceSingleton westArrowIcon = new IconUIResourceSingleton(westArrow);
270 protected static final NamedImageSingleton eastArrow = new NamedImageSingleton("NSMenuSubmenu");
447 }
448 }
449
450 public abstract static class RecyclableSlicedImageControl extends RecyclableObject<SlicedImageControl> {
451 final NineSliceMetrics metrics;
452
453 public RecyclableSlicedImageControl(final NineSliceMetrics metrics) {
454 this.metrics = metrics;
455 }
456
457 @Override
458 protected SlicedImageControl create() {
459 return new SlicedImageControl(createTemplateImage(metrics.minW, metrics.minH), metrics);
460 }
461
462 protected abstract Image createTemplateImage(final int width, final int height);
463 }
464
465 // when we use SystemColors, we need to proxy the color with something that implements UIResource,
466 // so that it will be uninstalled when the look and feel is changed.
467 @SuppressWarnings("serial") // JDK implementation class
468 private static class SystemColorProxy extends Color implements UIResource {
469 final Color color;
470 public SystemColorProxy(final Color color) {
471 super(color.getRGB());
472 this.color = color;
473 }
474
475 public int getRGB() {
476 return color.getRGB();
477 }
478 }
479
480 public static Color getWindowBackgroundColorUIResource() {
481 //return AquaNativeResources.getWindowBackgroundColorUIResource();
482 return new SystemColorProxy(SystemColor.window);
483 }
484
485 public static Color getTextSelectionBackgroundColorUIResource() {
486 return new SystemColorProxy(SystemColor.textHighlight);
487 }
|