[vcs-log] introduce static method calculateWidth so it could be used for calculating...
authorJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Tue, 18 Oct 2016 15:09:35 +0000 (18:09 +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

index 001897f25026e544c439020209a6a7a424afd77a..2bcdf1c0b84a79544badf3f045fbaa873ea9fb19 100644 (file)
@@ -3,7 +3,6 @@ package com.intellij.vcs.log.ui.render;
 import com.intellij.openapi.ui.GraphicsConfig;
 import com.intellij.openapi.util.registry.Registry;
 import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkRenderer;
-import com.intellij.ui.JBColor;
 import com.intellij.ui.SimpleColoredRenderer;
 import com.intellij.ui.SimpleTextAttributes;
 import com.intellij.ui.TableCell;
@@ -106,7 +105,14 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
   }
 
   public int getTooltipXCoordinate(int row) {
-    return myComponent.getTooltipXCoordinate(getValue(myGraphTable.getModel().getValueAt(row, GraphTableModel.COMMIT_COLUMN)));
+    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());
+      TableColumn commitColumn = myGraphTable.getColumnModel().getColumn(GraphTableModel.COMMIT_COLUMN);
+      return commitColumn.getWidth() - (labelWidth - LabelPainter.GRADIENT_WIDTH) / 2;
+    }
+    return -1;
   }
 
   private static class MyComponent extends SimpleColoredRenderer {
@@ -213,16 +219,6 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
       int width = (int)(maxIndex * PaintParameters.getNodeWidth(myGraphTable.getRowHeight()));
       return new PaintInfo(image, width);
     }
-
-    public int getTooltipXCoordinate(@NotNull GraphCommitCell cell) {
-      Collection<VcsRef> refs = cell.getRefsToThisCommit();
-      if (!refs.isEmpty()) {
-        myReferencePainter.customizePainter(this, refs, getBackground(), getForeground());
-        TableColumn commitColumn = myGraphTable.getColumnModel().getColumn(GraphTableModel.COMMIT_COLUMN);
-        return commitColumn.getWidth() - (myReferencePainter.getSize().width - LabelPainter.GRADIENT_WIDTH) / 2;
-      }
-      return -1;
-    }
   }
 
   private static class PaintInfo {
@@ -250,7 +246,6 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
   }
 
   private class FadeOutPainter {
-    @NotNull private final LabelPainter myEmptyPainter = new LabelPainter(myLogData);
     private int myWidth = LabelPainter.GRADIENT_WIDTH;
 
     public void customize(@NotNull Collection<VcsRef> currentRefs, int row, int column, @NotNull JTable table) {
@@ -260,15 +255,13 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
         int prevWidth = 0;
         if (row > 0) {
           GraphCommitCell commitCell = getValue(table.getValueAt(row - 1, column));
-          myEmptyPainter.customizePainter(myComponent, commitCell.getRefsToThisCommit(), myComponent.getBackground(), JBColor.black);
-          prevWidth = myEmptyPainter.getSize().width;
+          prevWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight());
         }
 
         int nextWidth = 0;
         if (row < table.getRowCount() - 1) {
           GraphCommitCell commitCell = getValue(table.getValueAt(row + 1, column));
-          myEmptyPainter.customizePainter(myComponent, commitCell.getRefsToThisCommit(), myComponent.getBackground(), JBColor.black);
-          nextWidth = myEmptyPainter.getSize().width;
+          nextWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight());
         }
 
         myWidth = Math.max(Math.max(prevWidth, nextWidth), LabelPainter.GRADIENT_WIDTH);
index 49bd0e51995380408d1b410dd9e483377aa2adc9..365ce4d5e20356ae4a1be969567ac6164fde4b87 100644 (file)
@@ -33,6 +33,7 @@ package com.intellij.vcs.log.ui.render;
 import com.intellij.openapi.ui.GraphicsConfig;
 import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.ui.JBColor;
 import com.intellij.ui.SimpleColoredComponent;
 import com.intellij.util.ObjectUtils;
 import com.intellij.util.containers.ContainerUtil;
@@ -97,10 +98,10 @@ public class LabelPainter implements ReferencePainter {
   }
 
   @NotNull
-  public static Pair<List<Pair<String, LabelIcon>>, Integer> calculatePresentation(@NotNull List<RefGroup> refGroups,
-                                                                                   @NotNull FontMetrics fontMetrics,
-                                                                                   int height,
-                                                                                   @NotNull Color background) {
+  private static Pair<List<Pair<String, LabelIcon>>, Integer> calculatePresentation(@NotNull List<RefGroup> refGroups,
+                                                                                    @NotNull FontMetrics fontMetrics,
+                                                                                    int height,
+                                                                                    @NotNull Color background) {
     int width = GRADIENT_WIDTH + RIGHT_PADDING;
 
     List<Pair<String, LabelIcon>> labels = ContainerUtil.newArrayList();
@@ -128,6 +129,15 @@ public class LabelPainter implements ReferencePainter {
     return Pair.create(labels, width);
   }
 
+  public static int calculateWidth(@NotNull VcsLogData logData,
+                                   @NotNull Collection<VcsRef> references,
+                                   @NotNull JComponent component,
+                                   int height) {
+    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;
+  }
+
   @NotNull
   private static String shortenRefName(@NotNull String refName) {
     int textLength = refName.length();