mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-163208: fixed dark icons usage
call getDarkIcon from EDT (otherwise edt-asserts failed) recursively obtain origin from RetrievableIcon
This commit is contained in:
@@ -19,6 +19,7 @@ import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.ScalableIcon;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -29,7 +30,7 @@ import static java.lang.Math.floor;
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class SizedIcon extends JBUI.CachingScalableJBIcon implements IconLoader.MenuBarIconProvider {
|
||||
public class SizedIcon extends JBUI.CachingScalableJBIcon implements IconLoader.MenuBarIconProvider, RetrievableIcon {
|
||||
private final int myWidth;
|
||||
private final int myHeight;
|
||||
private final Icon myDelegate;
|
||||
@@ -73,6 +74,10 @@ public class SizedIcon extends JBUI.CachingScalableJBIcon implements IconLoader.
|
||||
return new SizedIcon(IconLoader.getMenuBarIcon(myDelegate, isDark), myWidth, myHeight);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Icon retrieveIcon() { return myDelegate; }
|
||||
|
||||
@Override
|
||||
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||
Icon icon = myScaledIcon();
|
||||
|
||||
@@ -4,7 +4,6 @@ package com.intellij.ui.mac.touchbar;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.ui.mac.foundation.ID;
|
||||
@@ -234,7 +233,6 @@ public class NST {
|
||||
if (icon == null)
|
||||
return null;
|
||||
|
||||
icon = IconLoader.getDarkIcon(icon, true);
|
||||
final int w = Math.round(icon.getIconWidth()*scale);
|
||||
final int h = Math.round(icon.getIconHeight()*scale);
|
||||
final WritableRaster
|
||||
|
||||
@@ -4,6 +4,7 @@ package com.intellij.ui.mac.touchbar;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.ui.mac.foundation.ID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -24,6 +25,8 @@ class TBItemButton extends TBItem {
|
||||
TBItemButton(@NotNull String uid, @Nullable ItemListener listener) { super(uid, listener); }
|
||||
|
||||
TBItemButton setIcon(Icon icon) {
|
||||
if (icon != null) icon = IconLoader.getDarkIcon(icon, true);
|
||||
|
||||
if (!_equals(icon, myIcon)) {
|
||||
myIcon = icon;
|
||||
if (myNativePeer != ID.NIL) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ui.mac.touchbar;
|
||||
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.ui.mac.foundation.ID;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -17,7 +18,7 @@ class TBItemPopover extends TBItem {
|
||||
// NOTE: make popover with 'flexible' width when widthInPix <= 0
|
||||
TBItemPopover(@NotNull String uid, @Nullable ItemListener listener, Icon icon, String text, int widthInPix, TouchBar expandTB, TouchBar tapAndHoldTB) {
|
||||
super(uid, listener);
|
||||
myIcon = icon;
|
||||
myIcon = icon != null ? IconLoader.getDarkIcon(icon, true) : null;
|
||||
myText = text;
|
||||
myWidthPix = widthInPix;
|
||||
myExpandTB = expandTB;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ui.mac.touchbar;
|
||||
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.ui.mac.foundation.ID;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -31,6 +32,8 @@ class TBItemScrubber extends TBItem {
|
||||
};
|
||||
if (icon instanceof EmptyIcon)
|
||||
icon = null;
|
||||
else if (icon != null)
|
||||
icon = IconLoader.getDarkIcon(icon, true);
|
||||
myItems.add(new ItemData(icon, text, nativeAction));
|
||||
updateNativePeer();
|
||||
return this;
|
||||
|
||||
@@ -494,7 +494,7 @@ public final class IconLoader {
|
||||
*/
|
||||
public static Icon getDarkIcon(Icon icon, boolean dark) {
|
||||
if (icon instanceof RetrievableIcon) {
|
||||
icon = ((RetrievableIcon)icon).retrieveIcon();
|
||||
icon = getOrigin((RetrievableIcon)icon);
|
||||
}
|
||||
if (icon instanceof CachedImageIcon) {
|
||||
icon = ((CachedImageIcon)icon).copy();
|
||||
@@ -799,6 +799,18 @@ public final class IconLoader {
|
||||
Icon getMenuBarIcon(boolean isDark);
|
||||
}
|
||||
|
||||
private static Icon getOrigin(RetrievableIcon icon) {
|
||||
final int maxDeep = 10;
|
||||
Icon origin = icon.retrieveIcon();
|
||||
int level = 0;
|
||||
while (origin instanceof RetrievableIcon && level < maxDeep) {
|
||||
++level;
|
||||
origin = ((RetrievableIcon)origin).retrieveIcon();
|
||||
}
|
||||
if (origin instanceof RetrievableIcon && level >= maxDeep)
|
||||
LOG.error("can't calculate origin icon (too deep in hierarchy), src: " + icon);
|
||||
return origin;
|
||||
}
|
||||
|
||||
private static class LabelHolder {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user