make EmptyIcon scalable

This commit is contained in:
Konstantin Bulenkov
2016-02-01 10:44:05 +01:00
parent e6c22e2779
commit 4cdfaa46ec
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
package com.intellij.util.ui;
import com.intellij.openapi.util.ScalableIcon;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
@@ -30,7 +31,7 @@ import java.util.Map;
*
* @see com.intellij.util.ui.ColorIcon
*/
public class EmptyIcon implements Icon {
public class EmptyIcon implements Icon, ScalableIcon {
private static final Map<Integer, Icon> cache = new HashMap<Integer, Icon>();
public static final Icon ICON_16 = create(16);
@@ -40,6 +41,7 @@ public class EmptyIcon implements Icon {
private final int width;
private final int height;
private float scale = 1f;
public static Icon create(int size) {
Icon icon = cache.get(size);
@@ -98,6 +100,7 @@ public class EmptyIcon implements Icon {
if (height != icon.height) return false;
if (width != icon.width) return false;
if (scale != icon.scale) return false;
return true;
}
@@ -111,9 +114,23 @@ public class EmptyIcon implements Icon {
return new EmptyIconUIResource(this);
}
@Override
public Icon scale(float scaleFactor) {
if (scaleFactor != scale) {
EmptyIcon icon = this instanceof UIResource ? new EmptyIconUIResource(width, height) : new EmptyIcon(width, height);
icon.scale = scaleFactor;
return icon;
}
return this;
}
public static class EmptyIconUIResource extends EmptyIcon implements UIResource {
public EmptyIconUIResource(EmptyIcon icon) {
super(icon.width, icon.height);
}
private EmptyIconUIResource(int width, int height) {
super(width, height);
}
}
}