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 final BufferedImage iconImage = getAppIconImageCompositedOn(background, 1); 129 130 if (background instanceof MultiResolutionIconImage) { 131 BufferedImage background2x 132 = ((MultiResolutionIconImage) background).resolutionVariant; 133 BufferedImage icon2xImage = getAppIconImageCompositedOn(background2x, 2); 134 135 return new IconUIResource(new ImageIcon( 136 new MultiResolutionIconImage(iconImage, icon2xImage))); 137 } 138 return new IconUIResource(new ImageIcon(iconImage)); 139 } 140 141 static BufferedImage getAppIconImageCompositedOn(final Image background, int scaleFactor) { 142 143 final int scaledAlertIconSize = kAlertIconSize * scaleFactor; 144 final int kAlertSubIconSize = (int) (scaledAlertIconSize * 0.5); 145 final int kAlertSubIconInset = scaledAlertIconSize - kAlertSubIconSize; 146 final Icon smallAppIconScaled = new AquaIcon.CachingScalingIcon( 147 kAlertSubIconSize, kAlertSubIconSize) { 148 Image createImage() { 149 return getThisApplicationsIcon(kAlertSubIconSize, kAlertSubIconSize); 150 } 151 }; 152 153 final BufferedImage image = new BufferedImage(scaledAlertIconSize, 154 scaledAlertIconSize, BufferedImage.TYPE_INT_ARGB); 155 final Graphics g = image.getGraphics(); 156 g.drawImage(background, 0, 0, 157 scaledAlertIconSize, scaledAlertIconSize, null); 295 } 296 297 public static Icon getMenuItemCheckIcon() { 298 return new InvertableImageIcon(AquaUtils.generateLightenedImage( 299 getNSIcon("NSMenuItemSelection"), 25)); 300 } 301 302 public static Icon getMenuItemDashIcon() { 303 return new InvertableImageIcon(AquaUtils.generateLightenedImage( 304 getNSIcon("NSMenuMixedState"), 25)); 305 } 306 307 private static Image getNSIcon(String imageName) { 308 Image icon = Toolkit.getDefaultToolkit() 309 .getImage("NSImage://" + imageName); 310 311 if (icon instanceof MultiResolutionImage) { 312 return icon; 313 } 314 315 Image icon2x = AquaUtils.getCImageCreator().createImageFromName( 316 imageName, 2 * icon.getWidth(null), 2 * icon.getHeight(null)); 317 return new MultiResolutionBufferedImage( 318 BufferedImage.TYPE_INT_ARGB_PRE, 0, icon, icon2x); 319 } 320 321 public static class NineSliceMetrics { 322 public final int wCut, eCut, nCut, sCut; 323 public final int minW, minH; 324 public final boolean showMiddle, stretchH, stretchV; 325 326 public NineSliceMetrics(final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut) { 327 this(minWidth, minHeight, westCut, eastCut, northCut, southCut, true); 328 } 329 330 public NineSliceMetrics(final int minWidth, final int minHeight, final int westCut, final int eastCut, final int northCut, final int southCut, final boolean showMiddle) { 331 this(minWidth, minHeight, westCut, eastCut, northCut, southCut, showMiddle, true, 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, final boolean stretchHorizontally, final boolean stretchVertically) { 335 this.wCut = westCut; this.eCut = eastCut; this.nCut = northCut; this.sCut = southCut; 336 this.minW = minWidth; this.minH = minHeight; 337 this.showMiddle = showMiddle; this.stretchH = stretchHorizontally; this.stretchV = stretchVertically; 338 } 507 508 public static Color getSelectionBackgroundColorUIResource() { 509 return new SystemColorProxy(SystemColor.controlHighlight); 510 } 511 512 public static Color getSelectionForegroundColorUIResource() { 513 return new SystemColorProxy(SystemColor.controlLtHighlight); 514 } 515 516 public static Color getFocusRingColorUIResource() { 517 return new SystemColorProxy(LWCToolkit.getAppleColor(LWCToolkit.KEYBOARD_FOCUS_COLOR)); 518 } 519 520 public static Color getSelectionInactiveBackgroundColorUIResource() { 521 return new SystemColorProxy(LWCToolkit.getAppleColor(LWCToolkit.INACTIVE_SELECTION_BACKGROUND_COLOR)); 522 } 523 524 public static Color getSelectionInactiveForegroundColorUIResource() { 525 return new SystemColorProxy(LWCToolkit.getAppleColor(LWCToolkit.INACTIVE_SELECTION_FOREGROUND_COLOR)); 526 } 527 528 static class MultiResolutionIconImage extends BufferedImage 529 implements MultiResolutionImage { 530 531 BufferedImage resolutionVariant; 532 533 public MultiResolutionIconImage(BufferedImage image, BufferedImage resolutionVariant) { 534 super(image.getWidth(), image.getHeight(), image.getType()); 535 this.resolutionVariant = resolutionVariant; 536 Graphics g = getGraphics(); 537 g.drawImage(image, 0, 0, null); 538 g.dispose(); 539 } 540 541 @Override 542 public Image getResolutionVariant(int width, int height) { 543 return ((width <= getWidth() && height <= getHeight())) 544 ? this : resolutionVariant; 545 } 546 547 @Override 548 public List<Image> getResolutionVariants() { 549 return Arrays.asList(this, resolutionVariant); 550 } 551 } 552 } | 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); 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 } 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 } |