From 310ad3453d5777f5feaf8029147d6cff153394bf Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 1 Mar 2016 13:42:31 +0100 Subject: [PATCH] EmptyIcon: move scaled cache to parent --- .../src/com/intellij/util/ui/ColorIcon.java | 17 +++------- .../src/com/intellij/util/ui/EmptyIcon.java | 31 +++++++++++++------ 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/platform/util/src/com/intellij/util/ui/ColorIcon.java b/platform/util/src/com/intellij/util/ui/ColorIcon.java index 323a0a1433fb..9182dd4cc2bd 100644 --- a/platform/util/src/com/intellij/util/ui/ColorIcon.java +++ b/platform/util/src/com/intellij/util/ui/ColorIcon.java @@ -18,7 +18,6 @@ package com.intellij.util.ui; import com.intellij.ui.Gray; import org.jetbrains.annotations.NotNull; -import javax.swing.*; import java.awt.*; /** @@ -28,7 +27,6 @@ public class ColorIcon extends EmptyIcon { private final Color myColor; private boolean myBorder; private int myColorSize; - private ColorIcon myScaledCache; public ColorIcon(int size, int colorSize, @NotNull Color color, final boolean border) { super(size, size); @@ -68,20 +66,13 @@ public class ColorIcon extends EmptyIcon { } protected int getColorSize() { - return scale == 1f ? myColorSize : (int)(myColorSize * scale); + return scale(myColorSize); } + @Override - public Icon scale(float scaleFactor) { - if (scale == scaleFactor) { - return this; - } - if (myScaledCache != null && myScaledCache.scale == scaleFactor) { - return myScaledCache; - } - myScaledCache = new ColorIcon(getIconWidth(), myColorSize, myColor, myBorder); - myScaledCache.scale = scaleFactor; - return myScaledCache; + protected EmptyIcon createScaledInstance(float scale) { + return new ColorIcon(getIconWidth(), myColorSize, myColor, myBorder); } @Override diff --git a/platform/util/src/com/intellij/util/ui/EmptyIcon.java b/platform/util/src/com/intellij/util/ui/EmptyIcon.java index b77ddba23dfa..843eb9a08a05 100644 --- a/platform/util/src/com/intellij/util/ui/EmptyIcon.java +++ b/platform/util/src/com/intellij/util/ui/EmptyIcon.java @@ -42,6 +42,7 @@ public class EmptyIcon implements Icon, ScalableIcon { private final int width; private final int height; protected float scale = 1f; + private EmptyIcon myScaledCache; public static Icon create(int size) { Icon icon = cache.get(size); @@ -123,17 +124,27 @@ public class EmptyIcon implements Icon, ScalableIcon { @Override public Icon scale(float scaleFactor) { - if (scaleFactor != scale) { - EmptyIcon icon; - if (scale != 1f) { - icon = this; - } else { - icon = this instanceof UIResource ? new EmptyIconUIResource(width, height) : new EmptyIcon(width, height); - } - icon.scale = scaleFactor; - return icon; + if (scale == scaleFactor) { + return this; } - return this; + + if (myScaledCache != null && myScaledCache.scale == scaleFactor) { + return myScaledCache; + } + + myScaledCache = createScaledInstance(scaleFactor); + myScaledCache.scale = scaleFactor; + return myScaledCache; + } + + protected EmptyIcon createScaledInstance(float scale) { + final EmptyIcon icon; + if (scale != 1f) { + icon = this; + } else { + icon = this instanceof UIResource ? new EmptyIconUIResource(width, height) : new EmptyIcon(width, height); + } + return icon; } public static class EmptyIconUIResource extends EmptyIcon implements UIResource {