Color icon disappears when change editor font size

This commit is contained in:
Konstantin Bulenkov
2016-03-01 12:43:34 +01:00
parent 2695cd3d3b
commit 73ee1e62c1
@@ -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.
@@ -18,6 +18,7 @@ package com.intellij.util.ui;
import com.intellij.ui.Gray;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
/**
@@ -27,7 +28,7 @@ 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);
@@ -53,18 +54,36 @@ public class ColorIcon extends EmptyIcon {
final int iconWidth = getIconWidth();
final int iconHeight = getIconHeight();
g.setColor(getIconColor());
final int size = getColorSize();
final int x = i + (iconWidth - size) / 2;
final int y = j + (iconHeight - size) / 2;
final int x = i + (iconWidth - myColorSize) / 2;
final int y = j + (iconHeight - myColorSize) / 2;
g.fillRect(x, y, myColorSize, myColorSize);
g.fillRect(x, y, size, size);
if (myBorder) {
g.setColor(Gray.x00.withAlpha(40));
g.drawRect(x, y, myColorSize, myColorSize);
g.drawRect(x, y, size, size);
}
}
protected int getColorSize() {
return scale == 1f ? myColorSize : (int)(myColorSize * scale);
}
@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;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;