mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Add RowIconPaintTest
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 487 B |
Binary file not shown.
|
After Width: | Height: | Size: 1004 B |
Binary file not shown.
|
After Width: | Height: | Size: 4.2 KiB |
@@ -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<BufferedImage, Graphics2D> pair = createImageAndGraphics(sysScale, scaledIcon.getIconWidth(), scaledIcon.getIconHeight());
|
||||
private void test(Icon scaledIcon, ScaleContext ctx) {
|
||||
Pair<BufferedImage, Graphics2D> 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";
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user