IDEA-160868 [follow-up] Product icon disappears from Dock on macOS

Take into account that app icon is retina-unaware by com.apple.eawt.Application.getDockIconImage()
This commit is contained in:
Anton Tarasov
2016-09-07 13:05:32 +03:00
parent 94b65a546b
commit 41c5dbcd71
2 changed files with 39 additions and 3 deletions
@@ -177,7 +177,8 @@ public abstract class AppIcon {
int width = appImage.getWidth(null);
int height = appImage.getHeight(null);
BufferedImage img = UIUtil.createImage(width, height, BufferedImage.TYPE_INT_ARGB);
// Note, appImage is retina-unaware, retrieved in device coordinate space.
BufferedImage img = UIUtil.createImage(width, height, BufferedImage.TYPE_INT_ARGB, false);
Graphics2D g2d = img.createGraphics();
g2d.drawImage(appImage, null, null);
myAppImage = img;
@@ -335,7 +336,8 @@ public abstract class AppIcon {
private AppImage createAppImage() {
BufferedImage appImage = getAppImage();
assert appImage != null;
BufferedImage current = UIUtil.createImage(appImage.getWidth(), appImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
// Note, appImage is retina-unaware, retrieved in device coordinate space.
BufferedImage current = UIUtil.createImage(appImage.getWidth(), appImage.getHeight(), BufferedImage.TYPE_INT_ARGB, false);
Graphics2D g = current.createGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
UIUtil.drawImage(g, appImage, 0, 0, null);
@@ -1779,15 +1779,49 @@ public class UIUtil {
}
}
/**
* Creates a HiDPI-aware BufferedImage
*
* @param width the width in user coordinate space
* @param height the height in user coordinate space
* @param type the type of the image
*
* @return a HiDPI-aware image
*/
@NotNull
public static BufferedImage createImage(int width, int height, int type) {
if (isRetina()) {
return createImage(width, height, type, true);
}
/**
* Creates a HiDPI-aware or plain BufferedImage
*
* @param width the width in user or device coordinate space
* @param height the height in user or device coordinate space
* @param type the type of the image
* @param hidpiAware whether the image should be HiDPI-aware
*
* @return a HiDPI-aware or plain image
*/
@NotNull
public static BufferedImage createImage(int width, int height, int type, boolean hidpiAware) {
if (hidpiAware && isRetina()) {
return RetinaImage.create(width, height, type);
}
//noinspection UndesirableClassUsage
return new BufferedImage(width, height, type);
}
/**
* Creates a BufferedImage with HiDPI-awareness matching the graphics.
*
* @param g the graphics to match
* @param width the width in user coordinate space
* @param height the height in user coordinate space
* @param type the type of the image
*
* @return an image matching the graphics
*/
@NotNull
public static BufferedImage createImageForGraphics(Graphics2D g, int width, int height, int type) {
if (isRetina(g)) {