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
  23  * questions.
  24  */
  25 
  26 package com.apple.laf;
  27 
  28 import java.awt.*;
  29 import java.awt.image.BufferedImage;
  30 import java.security.PrivilegedAction;
  31 
  32 import javax.swing.*;
  33 import javax.swing.plaf.*;
  34 
  35 import sun.lwawt.macosx.LWCToolkit;
  36 import apple.laf.JRSUIConstants.AlignmentHorizontal;
  37 import apple.laf.JRSUIConstants.AlignmentVertical;
  38 import apple.laf.JRSUIConstants.Direction;
  39 import apple.laf.JRSUIConstants.State;
  40 import apple.laf.JRSUIConstants.Widget;
  41 import apple.laf.*;
  42 
  43 import com.apple.eio.FileManager;
  44 import com.apple.laf.AquaIcon.InvertableIcon;
  45 import com.apple.laf.AquaIcon.JRSUIControlSpec;
  46 import com.apple.laf.AquaIcon.SystemIcon;
  47 import com.apple.laf.AquaUtils.RecyclableObject;
  48 import com.apple.laf.AquaUtils.RecyclableSingleton;
  49 import java.util.Arrays;
  50 import java.util.List;
  51 import sun.awt.image.MultiResolutionBufferedImage;
  52 import sun.awt.image.MultiResolutionImage;
  53 
  54 public class AquaImageFactory {
  55     public static IconUIResource getConfirmImageIcon() {
  56         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
  57 
  58         return new IconUIResource(new AquaIcon.CachingScalingIcon(kAlertIconSize, kAlertIconSize) {
  59             Image createImage() {
  60                 return getThisApplicationsIcon(kAlertIconSize, kAlertIconSize);
  61             }
  62         });
  63     }
  64 
  65     public static IconUIResource getCautionImageIcon() {
  66         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
  67         return getAppIconCompositedOn(AquaIcon.SystemIcon.getCautionIcon());
  68     }
  69 
  70     public static IconUIResource getStopImageIcon() {
  71         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
  72         return getAppIconCompositedOn(AquaIcon.SystemIcon.getStopIcon());
  73     }
  74 
  75     public static IconUIResource getLockImageIcon() {
  76         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
  77         if (JRSUIUtils.Images.shouldUseLegacySecurityUIPath()) {
  78             final Image lockIcon = AquaUtils.getCImageCreator().createImageFromFile("/System/Library/CoreServices/SecurityAgent.app/Contents/Resources/Security.icns", kAlertIconSize, kAlertIconSize);
  79             return getAppIconCompositedOn(lockIcon);
  80         }
  81 
  82         final Image lockIcon = Toolkit.getDefaultToolkit().getImage("NSImage://NSSecurity");
  83         return getAppIconCompositedOn(lockIcon);
  84     }
  85 
  86     static Image getThisApplicationsIcon(final int width, final int height) {
  87         final String path = getPathToThisApplication();
  88 
  89         if (path == null) {
  90             return getGenericJavaIcon();
  91         }
  92 
  93         if (path.endsWith("/Home/bin")) {
  94             return getGenericJavaIcon();
  95         }
  96 
  97         if (path.startsWith("/usr/bin")) {
  98             return getGenericJavaIcon();
  99         }
 100 
 101         return AquaUtils.getCImageCreator().createImageOfFile(path, height, width);
 102     }
 103 
 104     static Image getGenericJavaIcon() {
 105         return java.security.AccessController.doPrivileged(new PrivilegedAction<Image>() {
 106             public Image run() {
 107                 return com.apple.eawt.Application.getApplication().getDockIconImage();
 108             }
 109         });
 110     }
 111 
 112     static String getPathToThisApplication() {
 113         return java.security.AccessController.doPrivileged(new PrivilegedAction<String>() {
 114             public String run() {
 115                 return FileManager.getPathToApplicationBundle();
 116             }
 117         });
 118     }
 119 
 120     static IconUIResource getAppIconCompositedOn(final SystemIcon systemIcon) {
 121         systemIcon.setSize(kAlertIconSize, kAlertIconSize);
 122         return getAppIconCompositedOn(systemIcon.createImage());
 123     }
 124 
 125     private static final int kAlertIconSize = 64;
 126     static IconUIResource getAppIconCompositedOn(final Image background) {
 127 
 128         if (background instanceof MultiResolutionBufferedImage) {
 129             int width = background.getWidth(null);
 130             Image mrIconImage = ((MultiResolutionBufferedImage) background).map(
 131                     rv -> getAppIconImageCompositedOn(rv, rv.getWidth(null) / width));
 132             return new IconUIResource(new ImageIcon(mrIconImage));
 133         }
 134 
 135         BufferedImage iconImage = getAppIconImageCompositedOn(background, 1);
 136         return new IconUIResource(new ImageIcon(iconImage));
 137     }
 138 
 139     static BufferedImage getAppIconImageCompositedOn(final Image background, int scaleFactor) {
 140 
 141         final int scaledAlertIconSize = kAlertIconSize * scaleFactor;
 142         final int kAlertSubIconSize = (int) (scaledAlertIconSize * 0.5);
 143         final int kAlertSubIconInset = scaledAlertIconSize - kAlertSubIconSize;
 144         final Icon smallAppIconScaled = new AquaIcon.CachingScalingIcon(
 145                 kAlertSubIconSize, kAlertSubIconSize) {
 146                     Image createImage() {
 147                         return getThisApplicationsIcon(kAlertSubIconSize, kAlertSubIconSize);
 148                     }
 149                 };
 150 
 151         final BufferedImage image = new BufferedImage(scaledAlertIconSize,
 152                 scaledAlertIconSize, BufferedImage.TYPE_INT_ARGB);
 153         final Graphics g = image.getGraphics();
 154         g.drawImage(background, 0, 0,
 155                 scaledAlertIconSize, scaledAlertIconSize, null);
 156         if (g instanceof Graphics2D) {
 157             // improves icon rendering quality in Quartz
 158             ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_RENDERING,
 159                     RenderingHints.VALUE_RENDER_QUALITY);
 160         }
 161 
 162         smallAppIconScaled.paintIcon(null, g,
 163                 kAlertSubIconInset, kAlertSubIconInset);
 164         g.dispose();
 165 
 166         return image;
 167     }
 168 
 169     public static IconUIResource getTreeFolderIcon() {
 170         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
 171         return AquaIcon.SystemIcon.getFolderIconUIResource();
 172     }
 173 
 174     public static IconUIResource getTreeOpenFolderIcon() {
 175         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
 176         return AquaIcon.SystemIcon.getOpenFolderIconUIResource();
 177     }
 178 
 179     public static IconUIResource getTreeDocumentIcon() {
 180         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
 181         return AquaIcon.SystemIcon.getDocumentIconUIResource();
 182     }
 183 
 184     public static UIResource getTreeExpandedIcon() {
 185         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
 186         return AquaIcon.getIconFor(new JRSUIControlSpec() {
 187             public void initIconPainter(final AquaPainter<? extends JRSUIState> painter) {
 188                 painter.state.set(Widget.DISCLOSURE_TRIANGLE);
 189                 painter.state.set(State.ACTIVE);
 190                 painter.state.set(Direction.DOWN);
 191                 painter.state.set(AlignmentHorizontal.CENTER);
 192                 painter.state.set(AlignmentVertical.CENTER);
 193             }
 194         }, 20, 20);
 195     }
 196 
 197     public static UIResource getTreeCollapsedIcon() {
 198         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
 199         return AquaIcon.getIconFor(new JRSUIControlSpec() {
 200             public void initIconPainter(final AquaPainter<? extends JRSUIState> painter) {
 201                 painter.state.set(Widget.DISCLOSURE_TRIANGLE);
 202                 painter.state.set(State.ACTIVE);
 203                 painter.state.set(Direction.RIGHT);
 204                 painter.state.set(AlignmentHorizontal.CENTER);
 205                 painter.state.set(AlignmentVertical.CENTER);
 206             }
 207         }, 20, 20);
 208     }
 209 
 210     public static UIResource getTreeRightToLeftCollapsedIcon() {
 211         // public, because UIDefaults.ProxyLazyValue uses reflection to get this value
 212         return AquaIcon.getIconFor(new JRSUIControlSpec() {
 213             public void initIconPainter(final AquaPainter<? extends JRSUIState> painter) {
 214                 painter.state.set(Widget.DISCLOSURE_TRIANGLE);
 215                 painter.state.set(State.ACTIVE);
 216                 painter.state.set(Direction.LEFT);
 217                 painter.state.set(AlignmentHorizontal.CENTER);
 218                 painter.state.set(AlignmentVertical.CENTER);
 219             }
 220         }, 20, 20);
 221     }
 222 
 223     static class NamedImageSingleton extends RecyclableSingleton<Image> {
 224         final String namedImage;
 225 
 226         NamedImageSingleton(final String namedImage) {
 227             this.namedImage = namedImage;
 228         }
 229 
 230         @Override
 231         protected Image getInstance() {
 232             return getNSIcon(namedImage);
 233         }
 234     }
 235 
 236     static class IconUIResourceSingleton extends RecyclableSingleton<IconUIResource> {
 237         final NamedImageSingleton holder;
 238 
 239         public IconUIResourceSingleton(final NamedImageSingleton holder) {
 240             this.holder = holder;
 241         }
 242 
 243         @Override
 244         protected IconUIResource getInstance() {
 245             return new IconUIResource(new ImageIcon(holder.get()));
 246         }
 247     }
 248 
 249     static class InvertableImageIcon extends ImageIcon implements InvertableIcon, UIResource {
 250         Icon invertedImage;
 251         public InvertableImageIcon(final Image image) {
 252             super(image);
 253         }
 254 
 255         @Override
 256         public Icon getInvertedIcon() {
 257             if (invertedImage != null) return invertedImage;
 258             return invertedImage = new IconUIResource(new ImageIcon(AquaUtils.generateLightenedImage(getImage(), 100)));
 259         }
 260     }
 261 
 262     protected static final NamedImageSingleton northArrow = new NamedImageSingleton("NSMenuScrollUp");
 263     protected static final IconUIResourceSingleton northArrowIcon = new IconUIResourceSingleton(northArrow);
 264     protected static final NamedImageSingleton southArrow = new NamedImageSingleton("NSMenuScrollDown");
 265     protected static final IconUIResourceSingleton southArrowIcon = new IconUIResourceSingleton(southArrow);
 266     protected static final NamedImageSingleton westArrow = new NamedImageSingleton("NSMenuSubmenuLeft");
 267     protected static final IconUIResourceSingleton westArrowIcon = new IconUIResourceSingleton(westArrow);
 268     protected static final NamedImageSingleton eastArrow = new NamedImageSingleton("NSMenuSubmenu");
 269     protected static final IconUIResourceSingleton eastArrowIcon = new IconUIResourceSingleton(eastArrow);
 270 
 271     static Image getArrowImageForDirection(final int direction) {
 272         switch(direction) {
 273             case SwingConstants.NORTH: return northArrow.get();
 274             case SwingConstants.SOUTH: return southArrow.get();
 275             case SwingConstants.EAST: return eastArrow.get();
 276             case SwingConstants.WEST: return westArrow.get();
 277         }
 278         return null;
 279     }
 280 
 281     static Icon getArrowIconForDirection(int direction) {
 282         switch(direction) {
 283             case SwingConstants.NORTH: return northArrowIcon.get();
 284             case SwingConstants.SOUTH: return southArrowIcon.get();
 285             case SwingConstants.EAST: return eastArrowIcon.get();
 286             case SwingConstants.WEST: return westArrowIcon.get();
 287         }
 288         return null;
 289     }
 290 
 291     public static Icon getMenuArrowIcon() {
 292         return new InvertableImageIcon(AquaUtils.generateLightenedImage(eastArrow.get(), 25));
 293     }
 294 
 295     public static Icon getMenuItemCheckIcon() {
 296         return new InvertableImageIcon(AquaUtils.generateLightenedImage(
 297                 getNSIcon("NSMenuItemSelection"), 25));
 298     }
 299 
 300     public static Icon getMenuItemDashIcon() {
 301         return new InvertableImageIcon(AquaUtils.generateLightenedImage(
 302                 getNSIcon("NSMenuMixedState"), 25));
 303     }
 304 
 305     private static Image getNSIcon(String imageName) {
 306         Image icon = Toolkit.getDefaultToolkit()
 307                 .getImage("NSImage://" + imageName);
 308 
 309         if (icon instanceof MultiResolutionImage) {
 310             return icon;
 311         }
 312 
 313         int w = icon.getWidth(null);
 314         int h = icon.getHeight(null);
 315 
 316         Dimension[] sizes = new Dimension[]{
 317             new Dimension(w, h), new Dimension(2 * w, 2 * h)
 318         };
 319 
 320         return new MultiResolutionBufferedImage(icon, sizes, (width, height) ->
 321                 AquaUtils.getCImageCreator().createImageFromName(
 322                         imageName, width, height));
 323     }
 324 
 325     public static class NineSliceMetrics {
 326         public final int wCut, eCut, nCut, sCut;
 327         public final int minW, minH;
 328         public final boolean showMiddle, stretchH, stretchV;
 329 
 330         public NineSliceMetrics(final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut) {
 331             this(minWidth, minHeight, westCut, eastCut, northCut, southCut, true);
 332         }
 333 
 334         public NineSliceMetrics(final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean showMiddle) {
 335             this(minWidth, minHeight, westCut, eastCut, northCut, southCut, showMiddle, true, true);
 336         }
 337 
 338         public NineSliceMetrics(final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean showMiddle, final boolean stretchHorizontally, final boolean stretchVertically) {
 339             this.wCut = westCut; this.eCut = eastCut; this.nCut = northCut; this.sCut = southCut;
 340             this.minW = minWidth; this.minH = minHeight;
 341             this.showMiddle = showMiddle; this.stretchH = stretchHorizontally; this.stretchV = stretchVertically;
 342         }
 343     }
 344 
 345     /*
 346      * A "paintable" which holds nine images, which represent a sliced up initial
 347      * image that can be streched from its middles.
 348      */
 349     public static class SlicedImageControl {
 350         final BufferedImage NW, N, NE;
 351         final BufferedImage W, C, E;
 352         final BufferedImage SW, S, SE;
 353 
 354         final NineSliceMetrics metrics;
 355 
 356         final int totalWidth, totalHeight;
 357         final int centerColWidth, centerRowHeight;
 358 
 359         public SlicedImageControl(final Image img, final int westCut, final int eastCut, final int northCut, final int southCut) {
 360             this(img, westCut, eastCut, northCut, southCut, true);
 361         }
 362 
 363         public SlicedImageControl(final Image img, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean useMiddle) {
 364             this(img, westCut, eastCut, northCut, southCut, useMiddle, true, true);
 365         }
 366 
 367         public SlicedImageControl(final Image img, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean useMiddle, final boolean stretchHorizontally, final boolean stretchVertically) {
 368             this(img, new NineSliceMetrics(img.getWidth(null), img.getHeight(null), westCut, eastCut, northCut, southCut, useMiddle, stretchHorizontally, stretchVertically));
 369         }
 370 
 371         public SlicedImageControl(final Image img, final NineSliceMetrics metrics) {
 372             this.metrics = metrics;
 373 
 374             if (img.getWidth(null) != metrics.minW || img.getHeight(null) != metrics.minH) {
 375                 throw new IllegalArgumentException("SlicedImageControl: template image and NineSliceMetrics don't agree on minimum dimensions");
 376             }
 377 
 378             totalWidth = metrics.minW;
 379             totalHeight = metrics.minH;
 380             centerColWidth = totalWidth - metrics.wCut - metrics.eCut;
 381             centerRowHeight = totalHeight - metrics.nCut - metrics.sCut;
 382 
 383             NW = createSlice(img, 0, 0, metrics.wCut, metrics.nCut);
 384             N = createSlice(img, metrics.wCut, 0, centerColWidth, metrics.nCut);
 385             NE = createSlice(img, totalWidth - metrics.eCut, 0, metrics.eCut, metrics.nCut);
 386             W = createSlice(img, 0, metrics.nCut, metrics.wCut, centerRowHeight);
 387             C = metrics.showMiddle ? createSlice(img, metrics.wCut, metrics.nCut, centerColWidth, centerRowHeight) : null;
 388             E = createSlice(img, totalWidth - metrics.eCut, metrics.nCut, metrics.eCut, centerRowHeight);
 389             SW = createSlice(img, 0, totalHeight - metrics.sCut, metrics.wCut, metrics.sCut);
 390             S = createSlice(img, metrics.wCut, totalHeight - metrics.sCut, centerColWidth, metrics.sCut);
 391             SE = createSlice(img, totalWidth - metrics.eCut, totalHeight - metrics.sCut, metrics.eCut, metrics.sCut);
 392         }
 393 
 394         static BufferedImage createSlice(final Image img, final int x, final int y, final int w, final int h) {
 395             if (w == 0 || h == 0) return null;
 396 
 397             final BufferedImage slice = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
 398             final Graphics2D g2d = slice.createGraphics();
 399             g2d.drawImage(img, 0, 0, w, h, x, y, x + w, y + h, null);
 400             g2d.dispose();
 401 
 402             return slice;
 403         }
 404 
 405         public void paint(final Graphics g, final int x, final int y, final int w, final int h) {
 406             g.translate(x, y);
 407 
 408             if (w < totalWidth || h < totalHeight) {
 409                 paintCompressed(g, w, h);
 410             } else {
 411                 paintStretchedMiddles(g, w, h);
 412             }
 413 
 414             g.translate(-x, -y);
 415         }
 416 
 417         void paintStretchedMiddles(final Graphics g, final int w, final int h) {
 418             int baseX = metrics.stretchH ? 0 : ((w / 2) - (totalWidth / 2));
 419             int baseY = metrics.stretchV ? 0 : ((h / 2) - (totalHeight / 2));
 420             int adjustedWidth = metrics.stretchH ? w : totalWidth;
 421             int adjustedHeight = metrics.stretchV ? h : totalHeight;
 422 
 423             if (NW != null) g.drawImage(NW, baseX, baseY, null);
 424             if (N != null) g.drawImage(N, baseX + metrics.wCut, baseY, adjustedWidth - metrics.eCut - metrics.wCut, metrics.nCut, null);
 425             if (NE != null) g.drawImage(NE, baseX + adjustedWidth - metrics.eCut, baseY, null);
 426             if (W != null) g.drawImage(W, baseX, baseY + metrics.nCut, metrics.wCut, adjustedHeight - metrics.nCut - metrics.sCut, null);
 427             if (C != null) g.drawImage(C, baseX + metrics.wCut, baseY + metrics.nCut, adjustedWidth - metrics.eCut - metrics.wCut, adjustedHeight - metrics.nCut - metrics.sCut, null);
 428             if (E != null) g.drawImage(E, baseX + adjustedWidth - metrics.eCut, baseY + metrics.nCut, metrics.eCut, adjustedHeight - metrics.nCut - metrics.sCut, null);
 429             if (SW != null) g.drawImage(SW, baseX, baseY + adjustedHeight - metrics.sCut, null);
 430             if (S != null) g.drawImage(S, baseX + metrics.wCut, baseY + adjustedHeight - metrics.sCut, adjustedWidth - metrics.eCut - metrics.wCut, metrics.sCut, null);
 431             if (SE != null) g.drawImage(SE, baseX + adjustedWidth - metrics.eCut, baseY + adjustedHeight - metrics.sCut, null);
 432 
 433             /*
 434             if (NW != null) {g.setColor(Color.GREEN); g.fillRect(baseX, baseY, NW.getWidth(), NW.getHeight());}
 435             if (N != null) {g.setColor(Color.RED); g.fillRect(baseX + metrics.wCut, baseY, adjustedWidth - metrics.eCut - metrics.wCut, metrics.nCut);}
 436             if (NE != null) {g.setColor(Color.BLUE); g.fillRect(baseX + adjustedWidth - metrics.eCut, baseY, NE.getWidth(), NE.getHeight());}
 437             if (W != null) {g.setColor(Color.PINK); g.fillRect(baseX, baseY + metrics.nCut, metrics.wCut, adjustedHeight - metrics.nCut - metrics.sCut);}
 438             if (C != null) {g.setColor(Color.ORANGE); g.fillRect(baseX + metrics.wCut, baseY + metrics.nCut, adjustedWidth - metrics.eCut - metrics.wCut, adjustedHeight - metrics.nCut - metrics.sCut);}
 439             if (E != null) {g.setColor(Color.CYAN); g.fillRect(baseX + adjustedWidth - metrics.eCut, baseY + metrics.nCut, metrics.eCut, adjustedHeight - metrics.nCut - metrics.sCut);}
 440             if (SW != null) {g.setColor(Color.MAGENTA); g.fillRect(baseX, baseY + adjustedHeight - metrics.sCut, SW.getWidth(), SW.getHeight());}
 441             if (S != null) {g.setColor(Color.DARK_GRAY); g.fillRect(baseX + metrics.wCut, baseY + adjustedHeight - metrics.sCut, adjustedWidth - metrics.eCut - metrics.wCut, metrics.sCut);}
 442             if (SE != null) {g.setColor(Color.YELLOW); g.fillRect(baseX + adjustedWidth - metrics.eCut, baseY + adjustedHeight - metrics.sCut, SE.getWidth(), SE.getHeight());}
 443             */
 444         }
 445 
 446         void paintCompressed(final Graphics g, final int w, final int h) {
 447             final double heightRatio = h > totalHeight ? 1.0 : (double)h / (double)totalHeight;
 448             final double widthRatio = w > totalWidth ? 1.0 : (double)w / (double)totalWidth;
 449 
 450             final int northHeight = (int)(metrics.nCut * heightRatio);
 451             final int southHeight = (int)(metrics.sCut * heightRatio);
 452             final int centerHeight = h - northHeight - southHeight;
 453 
 454             final int westWidth = (int)(metrics.wCut * widthRatio);
 455             final int eastWidth = (int)(metrics.eCut * widthRatio);
 456             final int centerWidth = w - westWidth - eastWidth;
 457 
 458             if (NW != null) g.drawImage(NW, 0, 0, westWidth, northHeight, null);
 459             if (N != null) g.drawImage(N, westWidth, 0, centerWidth, northHeight, null);
 460             if (NE != null) g.drawImage(NE, w - eastWidth, 0, eastWidth, northHeight, null);
 461             if (W != null) g.drawImage(W, 0, northHeight, westWidth, centerHeight, null);
 462             if (C != null) g.drawImage(C, westWidth, northHeight, centerWidth, centerHeight, null);
 463             if (E != null) g.drawImage(E, w - eastWidth, northHeight, eastWidth, centerHeight, null);
 464             if (SW != null) g.drawImage(SW, 0, h - southHeight, westWidth, southHeight, null);
 465             if (S != null) g.drawImage(S, westWidth, h - southHeight, centerWidth, southHeight, null);
 466             if (SE != null) g.drawImage(SE, w - eastWidth, h - southHeight, eastWidth, southHeight, null);
 467         }
 468     }
 469 
 470     public abstract static class RecyclableSlicedImageControl extends RecyclableObject<SlicedImageControl> {
 471         final NineSliceMetrics metrics;
 472 
 473         public RecyclableSlicedImageControl(final NineSliceMetrics metrics) {
 474             this.metrics = metrics;
 475         }
 476 
 477         @Override
 478         protected SlicedImageControl create() {
 479             return new SlicedImageControl(createTemplateImage(metrics.minW, metrics.minH), metrics);
 480         }
 481 
 482         protected abstract Image createTemplateImage(final int width, final int height);
 483     }
 484 
 485     // when we use SystemColors, we need to proxy the color with something that implements UIResource,
 486     // so that it will be uninstalled when the look and feel is changed.
 487     private static class SystemColorProxy extends Color implements UIResource {
 488         final Color color;
 489         public SystemColorProxy(final Color color) {
 490             super(color.getRGB());
 491             this.color = color;
 492         }
 493 
 494         public int getRGB() {
 495             return color.getRGB();
 496         }
 497     }
 498 
 499     public static Color getWindowBackgroundColorUIResource() {
 500         //return AquaNativeResources.getWindowBackgroundColorUIResource();
 501         return new SystemColorProxy(SystemColor.window);
 502     }
 503 
 504     public static Color getTextSelectionBackgroundColorUIResource() {
 505         return new SystemColorProxy(SystemColor.textHighlight);
 506     }
 507 
 508     public static Color getTextSelectionForegroundColorUIResource() {
 509         return new SystemColorProxy(SystemColor.textHighlightText);
 510     }
 511 
 512     public static Color getSelectionBackgroundColorUIResource() {
 513         return new SystemColorProxy(SystemColor.controlHighlight);
 514     }
 515 
 516     public static Color getSelectionForegroundColorUIResource() {
 517         return new SystemColorProxy(SystemColor.controlLtHighlight);
 518     }
 519 
 520     public static Color getFocusRingColorUIResource() {
 521         return new SystemColorProxy(LWCToolkit.getAppleColor(LWCToolkit.KEYBOARD_FOCUS_COLOR));
 522     }
 523 
 524     public static Color getSelectionInactiveBackgroundColorUIResource() {
 525         return new SystemColorProxy(LWCToolkit.getAppleColor(LWCToolkit.INACTIVE_SELECTION_BACKGROUND_COLOR));
 526     }
 527 
 528     public static Color getSelectionInactiveForegroundColorUIResource() {
 529         return new SystemColorProxy(LWCToolkit.getAppleColor(LWCToolkit.INACTIVE_SELECTION_FOREGROUND_COLOR));
 530     }
 531 }