diff --git a/platform/platform-tests/testData/ui/gold_RowIcon@1x.png b/platform/platform-tests/testData/ui/gold_RowIcon@1x.png new file mode 100644 index 000000000000..89c446f6269c Binary files /dev/null and b/platform/platform-tests/testData/ui/gold_RowIcon@1x.png differ diff --git a/platform/platform-tests/testData/ui/gold_RowIcon@2x.png b/platform/platform-tests/testData/ui/gold_RowIcon@2x.png new file mode 100644 index 000000000000..4246f1440920 Binary files /dev/null and b/platform/platform-tests/testData/ui/gold_RowIcon@2x.png differ diff --git a/platform/platform-tests/testData/ui/gold_RowIcon@4x.png b/platform/platform-tests/testData/ui/gold_RowIcon@4x.png new file mode 100644 index 000000000000..24e6e7c43d45 Binary files /dev/null and b/platform/platform-tests/testData/ui/gold_RowIcon@4x.png differ diff --git a/platform/platform-tests/testSrc/com/intellij/util/ui/LayeredIconPaintTest.java b/platform/platform-tests/testSrc/com/intellij/util/ui/LayeredIconPaintTest.java index 6a6bca0b84bc..2655e18c4903 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/ui/LayeredIconPaintTest.java +++ b/platform/platform-tests/testSrc/com/intellij/util/ui/LayeredIconPaintTest.java @@ -3,6 +3,7 @@ package com.intellij.util.ui; import com.intellij.openapi.util.IconLoader.CachedImageIcon; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.ScalableIcon; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.ui.LayeredIcon; import com.intellij.util.ui.JBUI.ScaleContext; @@ -16,9 +17,7 @@ import java.awt.image.BufferedImage; import java.io.File; import java.net.MalformedURLException; -import static com.intellij.util.ui.JBUI.ScaleType.PIX_SCALE; -import static com.intellij.util.ui.JBUI.ScaleType.SYS_SCALE; -import static com.intellij.util.ui.JBUI.ScaleType.USR_SCALE; +import static com.intellij.util.ui.JBUI.ScaleType.*; /** * Tests {@link com.intellij.ui.LayeredIcon} painting. @@ -37,21 +36,28 @@ public class LayeredIconPaintTest extends TestScaleHelper { test(2, 2); } - public void test(int usrScale, int sysScale) throws MalformedURLException { - LayeredIcon icon = new LayeredIcon(2); + private void test(int iconScale, int sysScale) throws MalformedURLException { CachedImageIcon icon1 = new CachedImageIcon(new File(getIcon1Path()).toURI().toURL()); CachedImageIcon icon2 = new CachedImageIcon(new File(getIcon2Path()).toURI().toURL()); - ScaleContext ctx = ScaleContext.create(USR_SCALE.of(usrScale), SYS_SCALE.of(sysScale)); + ScaleContext ctx = ScaleContext.create(SYS_SCALE.of(sysScale)); icon1.updateScaleContext(ctx.copy()); icon2.updateScaleContext(ctx.copy()); + Icon icon = createAndSetIcons(icon1, icon2).scale(iconScale); + ctx.update(OBJ_SCALE.of(iconScale)); + test(icon, ctx); + } + + protected ScalableIcon createAndSetIcons(Icon icon1, Icon icon2) { + LayeredIcon icon = new LayeredIcon(2); icon.setIcon(icon1, 0); icon.setIcon(icon2, 1, 10, 6); + return icon; + } - Icon scaledIcon = icon.scale(usrScale); - - Pair pair = createImageAndGraphics(sysScale, scaledIcon.getIconWidth(), scaledIcon.getIconHeight()); + private void test(Icon scaledIcon, ScaleContext ctx) { + Pair pair = createImageAndGraphics(ctx.getScale(SYS_SCALE), scaledIcon.getIconWidth(), scaledIcon.getIconHeight()); BufferedImage iconImage = pair.first; Graphics2D g2d = pair.second; @@ -65,7 +71,7 @@ public class LayeredIconPaintTest extends TestScaleHelper { new AASmootherComparator(0.1, 0.1, new Color(0, 0, 0, 0)), goldImage, iconImage, null); } - private static String getGoldImagePath(int scale) { + protected String getGoldImagePath(int scale) { return PlatformTestUtil.getPlatformTestDataPath() + "ui/gold_LayeredIcon@" + scale + "x.png"; } diff --git a/platform/platform-tests/testSrc/com/intellij/util/ui/RowIconPaintTest.java b/platform/platform-tests/testSrc/com/intellij/util/ui/RowIconPaintTest.java new file mode 100644 index 000000000000..32b3487abd61 --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/util/ui/RowIconPaintTest.java @@ -0,0 +1,36 @@ +// 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.util.ui; + +import com.intellij.openapi.util.ScalableIcon; +import com.intellij.testFramework.PlatformTestUtil; +import com.intellij.ui.RowIcon; +import org.junit.Test; + +import javax.swing.*; +import java.net.MalformedURLException; + +/** + * Tests {@link com.intellij.ui.RowIcon} painting. + * + * @author tav + */ +public class RowIconPaintTest extends LayeredIconPaintTest { + @Test + @Override + public void test() throws MalformedURLException { + super.test(); + } + + @Override + protected ScalableIcon createAndSetIcons(Icon icon1, Icon icon2) { + RowIcon icon = new RowIcon(2); + icon.setIcon(icon1, 0); + icon.setIcon(icon2, 1); + return icon; + } + + @Override + protected String getGoldImagePath(int scale) { + return PlatformTestUtil.getPlatformTestDataPath() + "ui/gold_RowIcon@" + scale + "x.png"; + } +}