src/macosx/classes/com/apple/laf/AquaImageFactory.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 2012, 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


 231 
 232         @Override
 233         protected Image getInstance() {
 234             return getNSIcon(namedImage);
 235         }
 236     }
 237 
 238     static class IconUIResourceSingleton extends RecyclableSingleton<IconUIResource> {
 239         final NamedImageSingleton holder;
 240 
 241         public IconUIResourceSingleton(final NamedImageSingleton holder) {
 242             this.holder = holder;
 243         }
 244 
 245         @Override
 246         protected IconUIResource getInstance() {
 247             return new IconUIResource(new ImageIcon(holder.get()));
 248         }
 249     }
 250 

 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");


 463         }
 464     }
 465 
 466     public abstract static class RecyclableSlicedImageControl extends RecyclableObject<SlicedImageControl> {
 467         final NineSliceMetrics metrics;
 468 
 469         public RecyclableSlicedImageControl(final NineSliceMetrics metrics) {
 470             this.metrics = metrics;
 471         }
 472 
 473         @Override
 474         protected SlicedImageControl create() {
 475             return new SlicedImageControl(createTemplateImage(metrics.minW, metrics.minH), metrics);
 476         }
 477 
 478         protected abstract Image createTemplateImage(final int width, final int height);
 479     }
 480 
 481     // when we use SystemColors, we need to proxy the color with something that implements UIResource,
 482     // so that it will be uninstalled when the look and feel is changed.

 483     private static class SystemColorProxy extends Color implements UIResource {
 484         final Color color;
 485         public SystemColorProxy(final Color color) {
 486             super(color.getRGB());
 487             this.color = color;
 488         }
 489 
 490         public int getRGB() {
 491             return color.getRGB();
 492         }
 493     }
 494 
 495     public static Color getWindowBackgroundColorUIResource() {
 496         //return AquaNativeResources.getWindowBackgroundColorUIResource();
 497         return new SystemColorProxy(SystemColor.window);
 498     }
 499 
 500     public static Color getTextSelectionBackgroundColorUIResource() {
 501         return new SystemColorProxy(SystemColor.textHighlight);
 502     }


   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


 231 
 232         @Override
 233         protected Image getInstance() {
 234             return getNSIcon(namedImage);
 235         }
 236     }
 237 
 238     static class IconUIResourceSingleton extends RecyclableSingleton<IconUIResource> {
 239         final NamedImageSingleton holder;
 240 
 241         public IconUIResourceSingleton(final NamedImageSingleton holder) {
 242             this.holder = holder;
 243         }
 244 
 245         @Override
 246         protected IconUIResource getInstance() {
 247             return new IconUIResource(new ImageIcon(holder.get()));
 248         }
 249     }
 250 
 251     @SuppressWarnings("serial") // Superclass is not serializable across versions
 252     static class InvertableImageIcon extends ImageIcon implements InvertableIcon, UIResource {
 253         Icon invertedImage;
 254         public InvertableImageIcon(final Image image) {
 255             super(image);
 256         }
 257 
 258         @Override
 259         public Icon getInvertedIcon() {
 260             if (invertedImage != null) return invertedImage;
 261             return invertedImage = new IconUIResource(new ImageIcon(AquaUtils.generateLightenedImage(getImage(), 100)));
 262         }
 263     }
 264 
 265     protected static final NamedImageSingleton northArrow = new NamedImageSingleton("NSMenuScrollUp");
 266     protected static final IconUIResourceSingleton northArrowIcon = new IconUIResourceSingleton(northArrow);
 267     protected static final NamedImageSingleton southArrow = new NamedImageSingleton("NSMenuScrollDown");
 268     protected static final IconUIResourceSingleton southArrowIcon = new IconUIResourceSingleton(southArrow);
 269     protected static final NamedImageSingleton westArrow = new NamedImageSingleton("NSMenuSubmenuLeft");
 270     protected static final IconUIResourceSingleton westArrowIcon = new IconUIResourceSingleton(westArrow);
 271     protected static final NamedImageSingleton eastArrow = new NamedImageSingleton("NSMenuSubmenu");


 464         }
 465     }
 466 
 467     public abstract static class RecyclableSlicedImageControl extends RecyclableObject<SlicedImageControl> {
 468         final NineSliceMetrics metrics;
 469 
 470         public RecyclableSlicedImageControl(final NineSliceMetrics metrics) {
 471             this.metrics = metrics;
 472         }
 473 
 474         @Override
 475         protected SlicedImageControl create() {
 476             return new SlicedImageControl(createTemplateImage(metrics.minW, metrics.minH), metrics);
 477         }
 478 
 479         protected abstract Image createTemplateImage(final int width, final int height);
 480     }
 481 
 482     // when we use SystemColors, we need to proxy the color with something that implements UIResource,
 483     // so that it will be uninstalled when the look and feel is changed.
 484     @SuppressWarnings("serial") // JDK implementation class
 485     private static class SystemColorProxy extends Color implements UIResource {
 486         final Color color;
 487         public SystemColorProxy(final Color color) {
 488             super(color.getRGB());
 489             this.color = color;
 490         }
 491 
 492         public int getRGB() {
 493             return color.getRGB();
 494         }
 495     }
 496 
 497     public static Color getWindowBackgroundColorUIResource() {
 498         //return AquaNativeResources.getWindowBackgroundColorUIResource();
 499         return new SystemColorProxy(SystemColor.window);
 500     }
 501 
 502     public static Color getTextSelectionBackgroundColorUIResource() {
 503         return new SystemColorProxy(SystemColor.textHighlight);
 504     }