[macosx] Improve system menu icons quality

Swing can't paint correctly our HiDPI icons at the system menu. It scales them down (from 2x to 1x) downgrading the quality. An ideal fix would be to add appropriate functionality to Swing. So far the fix is to pass Swing 1x icons.
This commit is contained in:
Anton Tarasov
2016-09-29 14:14:28 +03:00
parent 8cc5b37118
commit aff263f489
2 changed files with 24 additions and 0 deletions
@@ -247,6 +247,17 @@ public class ActionMenuItem extends JBCheckBoxMenuItem {
}
}
@Override
public void setIcon(Icon icon) {
if (SystemInfo.isMacSystemMenu && ActionPlaces.MAIN_MENU.equals(myPlace)) {
if (icon instanceof IconLoader.LazyIcon) {
// [tav] JDK can't paint correctly our HiDPI icons at the system menu bar
icon = ((IconLoader.LazyIcon)icon).inNormalScale(false);
}
}
super.setIcon(icon);
}
public boolean isToggleable() {
return myToggleable;
}
@@ -573,6 +573,19 @@ public final class IconLoader {
}
protected abstract Icon compute();
public Icon inNormalScale(boolean isRetina) {
Icon icon = getOrComputeIcon();
if (icon != null) {
if (icon instanceof CachedImageIcon) {
Image img = ((CachedImageIcon)icon).myScaledIconsCache.getOrigImage(isRetina);
if (img != null) {
icon = new ImageIcon(img);
}
}
}
return icon;
}
}
private static class LabelHolder {