[vcs-log] adjust label icon width and label placement

1. Label icon have size 7x8, so that label is centered.
2. Drawing is more precise.
3. Change inter-label space (more space in non-compact mode).
4. Proper icon size in tooltip (icon width is used in constructor).
This commit is contained in:
Julia Beliaeva
2016-12-13 00:31:54 +03:00
parent a5d1531fe7
commit 1e0fdbf82c
3 changed files with 10 additions and 8 deletions
@@ -55,16 +55,16 @@ public class LabelIcon implements Icon {
for (int i = myColors.length - 1; i >= 0; i--) {
if (i != myColors.length - 1) {
g2.setColor(myBgColor);
paintTag(g2, scale, Math.round(scale * 2) * i + 1, 0);
paintTag(g2, scale, scale * 2 * i + 1, 0);
}
g2.setColor(myColors[i]);
paintTag(g2, scale, Math.round(scale * 2) * i, 0);
paintTag(g2, scale, scale * 2 * i, 0);
}
config.restore();
}
public void paintTag(Graphics2D g2, float scale, int x, int y) {
public void paintTag(Graphics2D g2, float scale, float x, float y) {
Path2D.Float path = new Path2D.Float();
path.moveTo(x + 1 * scale, y + 2 * scale);
path.lineTo(x + 3 * scale, y + 2 * scale);
@@ -89,7 +89,8 @@ public class LabelIcon implements Icon {
}
public static int getWidth(int height, int labelsCount) {
return height + (height * (labelsCount - 1) / 4);
float scale = height / 8.0f;
return (int)Math.ceil((7 + 2 * (labelsCount - 1)) * scale);
}
@Override
@@ -62,7 +62,8 @@ public class LabelPainter {
public static final int BOTTOM_TEXT_PADDING = JBUI.scale(2);
public static final int RIGHT_PADDING = JBUI.scale(2);
public static final int LEFT_PADDING = JBUI.scale(2);
public static final int MIDDLE_PADDING = JBUI.scale(2);
public static final int COMPACT_MIDDLE_PADDING = JBUI.scale(2);
public static final int MIDDLE_PADDING = JBUI.scale(6);
private static final int MAX_LENGTH = 22;
private static final String THREE_DOTS = "...";
private static final String TWO_DOTS = "..";
@@ -154,7 +155,7 @@ public class LabelPainter {
for (RefGroup group : refGroups) {
List<Color> colors = group.getColors();
LabelIcon labelIcon = new LabelIcon(height, background, colors.toArray(new Color[colors.size()]));
int newWidth = width + labelIcon.getIconWidth() + MIDDLE_PADDING;
int newWidth = width + labelIcon.getIconWidth() + COMPACT_MIDDLE_PADDING;
String text = shortenRefName(group.getName(), fontMetrics, availableWidth - newWidth);
newWidth += fontMetrics.stringWidth(text);
@@ -335,7 +336,7 @@ public class LabelPainter {
g2.setColor(myForeground);
g2.drawString(text, x, y + baseLine);
x += fontMetrics.stringWidth(text) + MIDDLE_PADDING;
x += fontMetrics.stringWidth(text) + (myCompact ? COMPACT_MIDDLE_PADDING : MIDDLE_PADDING);
}
config.restore();
@@ -52,13 +52,13 @@ class TooltipReferencesPanel extends ReferencesPanel {
@Override
public void update() {
super.update();
myHasGroupWithMultipleRefs = false;
for (Map.Entry<VcsRefType, Collection<VcsRef>> typeAndRefs : myGroupedVisibleReferences.entrySet()) {
if (typeAndRefs.getValue().size() > 1) {
myHasGroupWithMultipleRefs = true;
}
}
super.update();
}
@NotNull