mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Color icon disappears when change editor font size
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user