[vcs-log] do not shorten refs if there is enough space for them IDEA-162214
authorJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Sun, 16 Oct 2016 04:42:54 +0000 (07:42 +0300)
committerJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Thu, 27 Oct 2016 15:19:37 +0000 (18:19 +0300)
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/LabelPainter.java
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/RectangleReferencePainter.java
platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/ReferencePainter.java

index 2bcdf1c0b84a79544badf3f045fbaa873ea9fb19..ce7f02dd894823da3551eb74aefee814eadee68e 100644 (file)
@@ -92,7 +92,8 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
     GraphCommitCell cell = getValue(value);
     Collection<VcsRef> refs = cell.getRefsToThisCommit();
     if (!refs.isEmpty()) {
-      myTooltipPainter.customizePainter(myComponent, refs, myComponent.getBackground(), myComponent.getForeground());
+      myTooltipPainter
+        .customizePainter(myComponent, refs, myComponent.getBackground(), myComponent.getForeground(), myComponent.getWidth());
       if (myTooltipPainter.getSize().getWidth() - LabelPainter.GRADIENT_WIDTH >= width - point.getX()) {
         return new TooltipReferencesPanel(myLogData, myTooltipPainter, refs);
       }
@@ -108,7 +109,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
     GraphCommitCell cell = getValue(myGraphTable.getModel().getValueAt(row, GraphTableModel.COMMIT_COLUMN));
     Collection<VcsRef> refs = cell.getRefsToThisCommit();
     if (!refs.isEmpty()) {
-      int labelWidth = LabelPainter.calculateWidth(myLogData, refs, myComponent, getPreferredHeight());
+      int labelWidth = LabelPainter.calculateWidth(myLogData, refs, myComponent, getPreferredHeight(), true);
       TableColumn commitColumn = myGraphTable.getColumnModel().getColumn(GraphTableModel.COMMIT_COLUMN);
       return commitColumn.getWidth() - (labelWidth - LabelPainter.GRADIENT_WIDTH) / 2;
     }
@@ -176,12 +177,22 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
 
       Collection<VcsRef> refs = cell.getRefsToThisCommit();
       Color baseForeground = ObjectUtils.assertNotNull(myGraphTable.getBaseStyle(row, column, hasFocus, isSelected).getForeground());
-      myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground);
 
-      setBorder(null);
-      append("");
-      appendTextPadding(myGraphImage.getWidth() + (myReferencePainter.isLeftAligned() ? myReferencePainter.getSize().width : 0));
-      myIssueLinkRenderer.appendTextWithLinks(cell.getText(), style);
+      append(""); // appendTextPadding wont work without this
+      int columnWidth = myGraphTable.getColumnModel().getColumn(column).getWidth();
+      if (myReferencePainter.isLeftAligned()) {
+        myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground,
+                                            0 /*left aligned painter does not use available width*/);
+
+        appendTextPadding(myGraphImage.getWidth() + myReferencePainter.getSize().width);
+        myIssueLinkRenderer.appendTextWithLinks(cell.getText(), style);
+      }
+      else {
+        appendTextPadding(myGraphImage.getWidth());
+        myIssueLinkRenderer.appendTextWithLinks(cell.getText(), style);
+        myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground,
+                                            Math.min(columnWidth - super.getPreferredSize().width, columnWidth / 3));
+      }
     }
 
     private int calculateHeight() {
@@ -255,13 +266,13 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
         int prevWidth = 0;
         if (row > 0) {
           GraphCommitCell commitCell = getValue(table.getValueAt(row - 1, column));
-          prevWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight());
+          prevWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight(), true);
         }
 
         int nextWidth = 0;
         if (row < table.getRowCount() - 1) {
           GraphCommitCell commitCell = getValue(table.getValueAt(row + 1, column));
-          nextWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight());
+          nextWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight(), true);
         }
 
         myWidth = Math.max(Math.max(prevWidth, nextWidth), LabelPainter.GRADIENT_WIDTH);
index 365ce4d5e20356ae4a1be969567ac6164fde4b87..719649a7381a385edaac80d51139d358523bbf83 100644 (file)
@@ -82,7 +82,8 @@ public class LabelPainter implements ReferencePainter {
   public void customizePainter(@NotNull JComponent component,
                                @NotNull Collection<VcsRef> references,
                                @NotNull Color background,
-                               @NotNull Color foreground) {
+                               @NotNull Color foreground,
+                               int availableWidth) {
     myBackground = background;
     myForeground = foreground;
 
@@ -91,17 +92,21 @@ public class LabelPainter implements ReferencePainter {
 
     VcsLogRefManager manager = ReferencePainter.getRefManager(myLogData, references);
     List<RefGroup> refGroups = manager == null ? ContainerUtil.emptyList() : manager.groupForTable(references);
-    Pair<List<Pair<String, LabelIcon>>, Integer> presentation = calculatePresentation(refGroups, metrics, myHeight, myBackground);
+    Pair<List<Pair<String, LabelIcon>>, Integer> presentation = calculatePresentation(refGroups, metrics, myHeight, myBackground, false);
+    if (presentation.second - GRADIENT_WIDTH > availableWidth) {
+      presentation = calculatePresentation(refGroups, metrics, myHeight, myBackground, true);
+    }
 
     myLabels = presentation.first;
     myWidth = presentation.second;
   }
 
   @NotNull
-  private static Pair<List<Pair<String, LabelIcon>>, Integer> calculatePresentation(@NotNull List<RefGroup> refGroups,
-                                                                                    @NotNull FontMetrics fontMetrics,
-                                                                                    int height,
-                                                                                    @NotNull Color background) {
+  public static Pair<List<Pair<String, LabelIcon>>, Integer> calculatePresentation(@NotNull List<RefGroup> refGroups,
+                                                                                   @NotNull FontMetrics fontMetrics,
+                                                                                   int height,
+                                                                                   @NotNull Color background,
+                                                                                   boolean shorten) {
     int width = GRADIENT_WIDTH + RIGHT_PADDING;
 
     List<Pair<String, LabelIcon>> labels = ContainerUtil.newArrayList();
@@ -111,7 +116,7 @@ public class LabelPainter implements ReferencePainter {
       if (group.isExpanded()) {
         for (VcsRef ref : group.getRefs()) {
           LabelIcon labelIcon = new LabelIcon(height, background, ref.getType().getBackgroundColor());
-          String text = shortenRefName(ref.getName());
+          String text = shorten ? shortenRefName(ref.getName()) : ref.getName();
 
           labels.add(Pair.create(text, labelIcon));
           width += labelIcon.getIconWidth() + fontMetrics.stringWidth(text) + MIDDLE_PADDING;
@@ -119,7 +124,7 @@ public class LabelPainter implements ReferencePainter {
       }
       else {
         LabelIcon labelIcon = new LabelIcon(height, background, getGroupColors(group));
-        String text = shortenRefName(group.getName());
+        String text = shorten ? shortenRefName(group.getName()) : group.getName();
 
         labels.add(Pair.create(text, labelIcon));
         width += labelIcon.getIconWidth() + fontMetrics.stringWidth(text) + MIDDLE_PADDING;
@@ -132,10 +137,11 @@ public class LabelPainter implements ReferencePainter {
   public static int calculateWidth(@NotNull VcsLogData logData,
                                    @NotNull Collection<VcsRef> references,
                                    @NotNull JComponent component,
-                                   int height) {
+                                   int height, boolean shorten) {
     VcsLogRefManager manager = ReferencePainter.getRefManager(logData, references);
     List<RefGroup> refGroups = manager == null ? ContainerUtil.emptyList() : manager.groupForTable(references);
-    return calculatePresentation(refGroups, component.getFontMetrics(RectanglePainter.getFont()), height, JBColor.white/*bg color does not affect width*/).second;
+    return calculatePresentation(refGroups, component.getFontMetrics(RectanglePainter.getFont()), height, JBColor.white/*bg color does not affect width*/,
+                                 shorten).second;
   }
 
   @NotNull
index a86cd5f86397d2dfa048709edce174b2b8e935ed..16a31f613c9da156df880a13ac5957f991277cfe 100644 (file)
@@ -57,7 +57,8 @@ public class RectangleReferencePainter implements ReferencePainter {
   public void customizePainter(@NotNull JComponent component,
                                @NotNull Collection<VcsRef> references,
                                @NotNull Color background,
-                               @NotNull Color foreground) {
+                               @NotNull Color foreground,
+                               int availableWidth) {
     FontMetrics metrics = component.getFontMetrics(getReferenceFont());
     myHeight = metrics.getHeight() + RectanglePainter.TOP_TEXT_PADDING + RectanglePainter.BOTTOM_TEXT_PADDING;
     myWidth = 2 * PaintParameters.LABEL_PADDING;
index 536b0ace9b2bff09b6736dd8ff6397d51a8ac734..b5452f8085b1d32bf6694941f87acda517fcb039 100644 (file)
@@ -32,7 +32,8 @@ public interface ReferencePainter {
   void customizePainter(@NotNull JComponent component,
                         @NotNull Collection<VcsRef> references,
                         @NotNull Color background,
-                        @NotNull Color foreground);
+                        @NotNull Color foreground,
+                        int availableWidth);
 
   void paint(@NotNull Graphics2D g2, int x, int y, int height);