[vcs-log] better tag colors

This commit is contained in:
Julia Beliaeva
2016-09-07 20:03:48 +03:00
parent ef7903ab3d
commit bd93e7f6c9
3 changed files with 40 additions and 6 deletions
@@ -61,6 +61,28 @@ public class ColorUtil {
return Color.getHSBColor(hsb[0], hsb[1], brightness);
}
@NotNull
public static Color saturate(@NotNull Color color, int tones) {
final float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
float saturation = hsb[1];
for (int i = 0; i < tones; i++) {
saturation = Math.min(1, saturation * 1.1F);
if (saturation == 1) break;
}
return Color.getHSBColor(hsb[0], saturation, hsb[2]);
}
@NotNull
public static Color desaturate(@NotNull Color color, int tones) {
final float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
float saturation = hsb[1];
for (int i = 0; i < tones; i++) {
saturation = Math.max(0, saturation / 1.1F);
if (saturation == 0) break;
}
return Color.getHSBColor(hsb[0], saturation, hsb[2]);
}
public static Color dimmer(@NotNull Color color) {
float[] rgb = color.getRGBColorComponents(null);
@@ -40,6 +40,7 @@ import com.intellij.vcs.log.data.LoadingDetails;
import com.intellij.vcs.log.data.VcsLogData;
import com.intellij.vcs.log.ui.VcsLogColorManager;
import com.intellij.vcs.log.ui.render.TagIcon;
import com.intellij.vcs.log.ui.render.TagLabelPainter;
import com.intellij.vcs.log.ui.render.TextLabelPainter;
import com.intellij.vcs.log.util.VcsUserUtil;
import org.jetbrains.annotations.NotNull;
@@ -505,9 +506,9 @@ class CommitPanel extends JBPanel {
for (VcsRef reference : typeAndRefs.getValue()) {
Icon icon = null;
if (index == 0) {
Color color = TagLabelPainter.getTagColor(type);
icon = new TagIcon(height, getBackground(),
typeAndRefs.getValue().size() > 1 ? new Color[]{type.getBackgroundColor(),
type.getBackgroundColor()} : new Color[]{type.getBackgroundColor()});
typeAndRefs.getValue().size() > 1 ? new Color[]{color, color} : new Color[]{color});
}
JBLabel label =
new JBLabel(reference.getName() + (index != typeAndRefs.getValue().size() - 1 ? "," : ""),
@@ -32,7 +32,7 @@ package com.intellij.vcs.log.ui.render;
import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.openapi.util.Pair;
import com.intellij.ui.JBColor;
import com.intellij.ui.ColorUtil;
import com.intellij.ui.SimpleColoredComponent;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
@@ -78,9 +78,8 @@ public class TagLabelPainter {
VcsRef firstRef = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(typeAndRefs.getValue()));
VcsRefType type = typeAndRefs.getKey();
boolean multiple = typeAndRefs.getValue().size() > 1;
TagIcon tagIcon = new TagIcon(myHeight, myBackground, multiple
? new Color[]{type.getBackgroundColor(), type.getBackgroundColor()}
: new Color[]{type.getBackgroundColor()});
Color color = getTagColor(type);
TagIcon tagIcon = new TagIcon(myHeight, myBackground, multiple ? new Color[]{color, color} : new Color[]{color});
String text = firstRef.getName() + (multiple ? " +" : "");
myLabels.add(Pair.create(text, tagIcon));
@@ -89,6 +88,18 @@ public class TagLabelPainter {
}
}
@NotNull
public static Color getTagColor(@NotNull VcsRefType type) {
Color color = type.getBackgroundColor();
if (UIUtil.isUnderDarcula()) {
color = ColorUtil.brighter(color, 2);
}
else {
color = ColorUtil.darker(color, 2);
}
return ColorUtil.saturate(color, 5);
}
public void paint(@NotNull Graphics2D g2, int x, int y, int height) {
if (myLabels.isEmpty()) return;