[vcs-log] remove fade-out, add grey background for the labels instead
authorJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Wed, 26 Oct 2016 19:19:26 +0000 (22:19 +0300)
committerJulia Beliaeva <Julia.Beliaeva@jetbrains.com>
Mon, 31 Oct 2016 21:31:26 +0000 (00:31 +0300)
platform/vcs-log/impl/src/com/intellij/vcs/log/VcsLogStandardColors.java
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 976eccb2b727845bde3b20fc5e4d2ecb3b1a628d..55f823989132d20766f5262c8ed00b5f47e3a7f3 100644 (file)
@@ -21,7 +21,7 @@ import java.awt.*;
 
 public class VcsLogStandardColors {
   public static class Refs {
-    public static final Color TIP = new JBColor(new Color(0xffe137), new Color(0xe1c731));
+    public static final Color TIP = new JBColor(new Color(0xffd100), new Color(0xe1c731));
     public static final Color LEAF = new JBColor(new Color(0x8a2d6b), new Color(0xc31e8c));
     public static final Color BRANCH = new JBColor(new Color(0x3cb45c), new Color(0x3cb45c));
     public static final Color BRANCH_REF = new JBColor(new Color(0x9f79b5), new Color(0x9f79b5));
index a7ca1d6c1cc6413065c9a982d60564a8fdaaac3a..daa74873ddac584c1d0d1dac27ba391ad36a462f 100644 (file)
@@ -1,13 +1,10 @@
 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.SimpleColoredRenderer;
 import com.intellij.ui.SimpleTextAttributes;
-import com.intellij.ui.TableCell;
 import com.intellij.util.ObjectUtils;
-import com.intellij.util.ui.GraphicsUtil;
 import com.intellij.util.ui.JBUI;
 import com.intellij.util.ui.UIUtil;
 import com.intellij.vcs.log.VcsRef;
@@ -33,13 +30,9 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
   @NotNull private final VcsLogData myLogData;
   @NotNull private final VcsLogGraphTable myGraphTable;
 
-  @Nullable private final FadeOutPainter myFadeOutPainter;
-  @Nullable private final ReferencePainter myTooltipPainter;
-
   @NotNull private final MyComponent myComponent;
-  @NotNull private final MyComponentWithFadeOut myTemplateComponent;
-
-  private boolean myExpanded;
+  @NotNull private final MyComponent myTemplateComponent;
+  @Nullable private final ReferencePainter myTooltipPainter;
 
   public GraphCommitCellRenderer(@NotNull VcsLogData logData,
                                  @NotNull GraphCellPainter painter,
@@ -47,11 +40,9 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
     myLogData = logData;
     myGraphTable = table;
 
-    myFadeOutPainter = isRedesignedLabels() ? new FadeOutPainter(painter) : null;
     myTooltipPainter = isRedesignedLabels() ? new LabelPainter(myLogData) : null;
-
-    myComponent = new MyComponentWithFadeOut(logData, painter, table);
-    myTemplateComponent = new MyComponentWithFadeOut(logData, painter, table);
+    myComponent = new MyComponent(logData, painter, table);
+    myTemplateComponent = new MyComponent(logData, painter, table);
   }
 
   @Override
@@ -62,11 +53,6 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
                                                         int row,
                                                         int column) {
     myComponent.customize(value, isSelected, hasFocus, row, column);
-
-    myExpanded = myGraphTable.getExpandableItemsHandler().getExpandedItems().contains(new TableCell(row, column));
-    if (myFadeOutPainter != null) {
-      myFadeOutPainter.customize(value.getRefsToThisCommit(), row, column, table  /*any color fits here*/);
-    }
     return myComponent;
   }
 
@@ -81,7 +67,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(), getColumnWidth());
+      myTooltipPainter.customizePainter(myComponent, refs, myComponent.getBackground(), myComponent.getForeground(),
+                                        true/*counterintuitive, but true*/, getColumnWidth());
       if (getReferencesWidth(row) >= getColumnWidth() - point.getX()) {
         return new TooltipReferencesPanel(myLogData, myTooltipPainter, refs);
       }
@@ -99,7 +86,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
     if (!refs.isEmpty()) {
       myTemplateComponent.customize(cell, myGraphTable.isRowSelected(row), myGraphTable.hasFocus(),
                                     row, GraphTableModel.COMMIT_COLUMN);
-      return myTemplateComponent.getReferencePainter().getSize().width - LabelPainter.GRADIENT_WIDTH;
+      return myTemplateComponent.getReferencePainter().getSize().width;
     }
 
     return 0;
@@ -145,7 +132,6 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
     public Dimension getPreferredSize() {
       Dimension preferredSize = super.getPreferredSize();
       int referencesSize = myReferencePainter.isLeftAligned() ? 0 : myReferencePainter.getSize().width;
-      if (referencesSize > 0) referencesSize -= LabelPainter.GRADIENT_WIDTH;
       return new Dimension(preferredSize.width + referencesSize, getPreferredHeight());
     }
 
@@ -182,7 +168,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
 
       append(""); // appendTextPadding wont work without this
       if (myReferencePainter.isLeftAligned()) {
-        myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground,
+        myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground, isSelected,
                                             0 /*left aligned painter does not use available width*/);
 
         appendTextPadding(myGraphImage.getWidth() + myReferencePainter.getSize().width);
@@ -191,12 +177,12 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
       else {
         appendTextPadding(myGraphImage.getWidth());
         myIssueLinkRenderer.appendTextWithLinks(cell.getText(), style);
-        myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground,
-                                            getAvailableWidth(row, column));
+        myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground, isSelected,
+                                            getAvailableWidth(column));
       }
     }
 
-    protected int getAvailableWidth(int row, int column) {
+    private int getAvailableWidth(int column) {
       int columnWidth = myGraphTable.getColumnModel().getColumn(column).getWidth();
       return Math.min(columnWidth - super.getPreferredSize().width, columnWidth / 3);
     }
@@ -266,90 +252,4 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
       return myWidth;
     }
   }
-
-  private class FadeOutPainter {
-    @NotNull private final MyComponent myTemplateComponent;
-    private int myWidth = LabelPainter.GRADIENT_WIDTH;
-
-    private FadeOutPainter(@NotNull GraphCellPainter painter) {
-      myTemplateComponent = new MyComponentWithFadeOut(myLogData, painter, myGraphTable);
-    }
-
-    public void customize(@NotNull Collection<VcsRef> currentRefs, int row, int column, @NotNull JTable table) {
-      myWidth = 0;
-
-      if (currentRefs.isEmpty()) {
-        int prevWidth = 0;
-        if (row > 0) {
-          GraphCommitCell commitCell = getValue(table.getValueAt(row - 1, column));
-          if (!commitCell.getRefsToThisCommit().isEmpty()) {
-            myTemplateComponent.customize(commitCell, table.isRowSelected(row - 1), table.hasFocus(), row - 1, column);
-            prevWidth = myTemplateComponent.myReferencePainter.getSize().width;
-          }
-        }
-
-        int nextWidth = 0;
-        if (row < table.getRowCount() - 1) {
-          GraphCommitCell commitCell = getValue(table.getValueAt(row + 1, column));
-          if (!commitCell.getRefsToThisCommit().isEmpty()) {
-            myTemplateComponent.customize(commitCell, table.isRowSelected(row + 1), table.hasFocus(), row + 1, column);
-            nextWidth = myTemplateComponent.myReferencePainter.getSize().width;
-          }
-        }
-
-        myWidth = Math.max(Math.max(prevWidth, nextWidth), LabelPainter.GRADIENT_WIDTH);
-      }
-    }
-
-    public void paint(@NotNull Graphics2D g2, int x, int y, int height) {
-      GraphicsConfig config = GraphicsUtil.setupAAPainting(g2);
-      LabelPainter.paintFadeOut(g2, x, y, myWidth, height, myComponent.getBackground());
-      config.restore();
-    }
-
-    public int getWidth() {
-      return myWidth;
-    }
-  }
-
-  private class MyComponentWithFadeOut extends MyComponent {
-    private final MyComponent myTemplateComponent;
-
-    public MyComponentWithFadeOut(@NotNull VcsLogData logData, @NotNull GraphCellPainter painter, @NotNull VcsLogGraphTable table) {
-      super(logData, painter, table);
-      myTemplateComponent = new MyComponent(logData, painter, table);
-    }
-
-    @Override
-    protected int getAvailableWidth(int row, int column) {
-      int currentAvailableWidth = super.getAvailableWidth(row, column);
-      if (row > 0) {
-        GraphCommitCell cell = getValue(myGraphTable.getValueAt(row - 1, column));
-        if (cell.getRefsToThisCommit().isEmpty()) {
-          myTemplateComponent.customize(cell, myGraphTable.isRowSelected(row - 1), myGraphTable.hasFocus(), row - 1, column);
-          currentAvailableWidth = Math.min(currentAvailableWidth, myTemplateComponent.getAvailableWidth(row - 1, column));
-        }
-      }
-      if (row < myGraphTable.getRowCount() - 1) {
-        GraphCommitCell cell = getValue(myGraphTable.getValueAt(row + 1, column));
-        if (cell.getRefsToThisCommit().isEmpty()) {
-          myTemplateComponent.customize(cell, myGraphTable.isRowSelected(row + 1), myGraphTable.hasFocus(), row + 1, column);
-          currentAvailableWidth = Math.min(currentAvailableWidth, myTemplateComponent.getAvailableWidth(row + 1, column));
-        }
-      }
-      return currentAvailableWidth;
-    }
-
-    @Override
-    public void paintComponent(Graphics g) {
-      super.paintComponent(g);
-
-      if (myFadeOutPainter != null) {
-        if (!myExpanded) {
-          int start = Math.max(myGraphImage.getWidth(), getWidth() - myFadeOutPainter.getWidth());
-          myFadeOutPainter.paint((Graphics2D)g, start, 0, getHeight());
-        }
-      }
-    }
-  }
 }
index 719649a7381a385edaac80d51139d358523bbf83..965a344932c9d966a09f1edb0035eeb191889d2c 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.ColorUtil;
 import com.intellij.ui.JBColor;
 import com.intellij.ui.SimpleColoredComponent;
 import com.intellij.util.ObjectUtils;
@@ -47,6 +48,7 @@ import com.intellij.vcs.log.VcsRef;
 import com.intellij.vcs.log.VcsRefType;
 import com.intellij.vcs.log.data.VcsLogData;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
 import java.awt.*;
@@ -55,25 +57,26 @@ import java.util.List;
 import java.util.Map;
 
 public class LabelPainter implements ReferencePainter {
-  public static final int TOP_TEXT_PADDING = JBUI.scale(2);
-  public static final int BOTTOM_TEXT_PADDING = JBUI.scale(1);
-  public static final int GRADIENT_WIDTH = JBUI.scale(50);
-  public static final int RIGHT_PADDING = JBUI.scale(5);
-  public static final int MIDDLE_PADDING = JBUI.scale(5);
+  public static final int TOP_TEXT_PADDING = JBUI.scale(1);
+  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);
   private static final int MAX_LENGTH = 22;
   private static final String THREE_DOTS = "...";
   private static final String TWO_DOTS = "..";
   private static final String SEPARATOR = "/";
+  @SuppressWarnings("UseJBColor") private static final JBColor BACKGROUND = new JBColor(Color.BLACK, Color.WHITE);
+  private static final float BALANCE = 0.08f;
 
   @NotNull private final VcsLogData myLogData;
 
   @NotNull private List<Pair<String, LabelIcon>> myLabels = ContainerUtil.newArrayList();
   private int myHeight = JBUI.scale(22);
   private int myWidth = 0;
-  @NotNull
-  private Color myBackground = UIUtil.getTableBackground();
-  @NotNull
-  private Color myForeground = UIUtil.getTableForeground();
+  @NotNull private Color myBackground = UIUtil.getTableBackground();
+  @Nullable private Color myGreyBackground = null;
+  @NotNull private Color myForeground = UIUtil.getTableForeground();
 
   public LabelPainter(@NotNull VcsLogData data) {
     myLogData = data;
@@ -83,6 +86,7 @@ public class LabelPainter implements ReferencePainter {
                                @NotNull Collection<VcsRef> references,
                                @NotNull Color background,
                                @NotNull Color foreground,
+                               boolean isSelected,
                                int availableWidth) {
     myBackground = background;
     myForeground = foreground;
@@ -92,9 +96,12 @@ 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, false);
-    if (presentation.second - GRADIENT_WIDTH > availableWidth) {
-      presentation = calculatePresentation(refGroups, metrics, myHeight, myBackground, true);
+
+    myGreyBackground = calculateGreyBackground(refGroups, background, isSelected);
+    Pair<List<Pair<String, LabelIcon>>, Integer> presentation =
+      calculatePresentation(refGroups, metrics, myHeight, myGreyBackground != null ? myGreyBackground : myBackground, false);
+    if (presentation.second > availableWidth) {
+      presentation = calculatePresentation(refGroups, metrics, myHeight, myGreyBackground != null ? myGreyBackground : myBackground, true);
     }
 
     myLabels = presentation.first;
@@ -102,12 +109,12 @@ 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,
-                                                                                   boolean shorten) {
-    int width = GRADIENT_WIDTH + RIGHT_PADDING;
+  private static Pair<List<Pair<String, LabelIcon>>, Integer> calculatePresentation(@NotNull List<RefGroup> refGroups,
+                                                                                    @NotNull FontMetrics fontMetrics,
+                                                                                    int height,
+                                                                                    @NotNull Color background,
+                                                                                    boolean shorten) {
+    int width = LEFT_PADDING + RIGHT_PADDING;
 
     List<Pair<String, LabelIcon>> labels = ContainerUtil.newArrayList();
     if (refGroups.isEmpty()) return Pair.create(labels, width);
@@ -134,14 +141,23 @@ 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, 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*/,
-                                 shorten).second;
+  @Nullable
+  private static Color calculateGreyBackground(@NotNull List<RefGroup> refGroups, @NotNull Color background, boolean isSelected) {
+    if (isSelected) return null;
+
+    boolean paintGreyBackground;
+    for (RefGroup group : refGroups) {
+      if (group.isExpanded()) {
+        paintGreyBackground = ContainerUtil.find(group.getRefs(), ref -> !ref.getName().isEmpty()) != null;
+      }
+      else {
+        paintGreyBackground = !group.getName().isEmpty();
+      }
+
+      if (paintGreyBackground) return ColorUtil.mix(background, BACKGROUND, BALANCE);
+    }
+
+    return null;
   }
 
   @NotNull
@@ -188,9 +204,21 @@ public class LabelPainter implements ReferencePainter {
     g2.setFont(getReferenceFont());
     g2.setStroke(new BasicStroke(1.5f));
 
-    x = paintFadeOut(g2, x, y, myWidth, height, myBackground);
-
     FontMetrics fontMetrics = g2.getFontMetrics();
+    int baseLine = SimpleColoredComponent.getTextBaseLine(fontMetrics, height);
+
+    g2.setColor(myBackground);
+    g2.fillRect(x, y, myWidth, height);
+
+    if (myGreyBackground != null) {
+      g2.setColor(myGreyBackground);
+      g2.fillRect(x, y + baseLine - fontMetrics.getAscent() - TOP_TEXT_PADDING,
+                  myWidth - RIGHT_PADDING + LEFT_PADDING,
+                  fontMetrics.getHeight() + TOP_TEXT_PADDING + BOTTOM_TEXT_PADDING);
+    }
+
+    x += LEFT_PADDING;
+
     for (Pair<String, LabelIcon> label : myLabels) {
       LabelIcon icon = label.second;
       String text = label.first;
@@ -199,27 +227,13 @@ public class LabelPainter implements ReferencePainter {
       x += icon.getIconWidth();
 
       g2.setColor(myForeground);
-      g2.drawString(text, x, y + SimpleColoredComponent.getTextBaseLine(fontMetrics, height));
+      g2.drawString(text, x, y + baseLine);
       x += fontMetrics.stringWidth(text) + MIDDLE_PADDING;
     }
 
     config.restore();
   }
 
-  public static int paintFadeOut(@NotNull Graphics2D g2, int x, int y, int width, int height, @NotNull Color background) {
-    //noinspection UseJBColor
-    g2.setPaint(new GradientPaint(x, y,
-                                  new Color(background.getRed(), background.getGreen(), background.getBlue(), 0),
-                                  x + GRADIENT_WIDTH, y,
-                                  background));
-    g2.fill(new Rectangle(x, y, GRADIENT_WIDTH, height));
-    x += GRADIENT_WIDTH;
-
-    g2.setColor(background);
-    g2.fillRect(x, y, width - GRADIENT_WIDTH, height);
-    return x;
-  }
-
   public Dimension getSize() {
     if (myLabels.isEmpty()) return new Dimension();
     return new Dimension(myWidth, myHeight);
@@ -229,5 +243,11 @@ public class LabelPainter implements ReferencePainter {
   public boolean isLeftAligned() {
     return false;
   }
+
+  @Override
+  public Font getReferenceFont() {
+    Font font = RectanglePainter.getFont();
+    return font.deriveFont(font.getSize() - 1f);
+  }
 }
 
index 16a31f613c9da156df880a13ac5957f991277cfe..2ee86d5846c89f37a949a67284658a80051ad030 100644 (file)
@@ -58,6 +58,7 @@ public class RectangleReferencePainter implements ReferencePainter {
                                @NotNull Collection<VcsRef> references,
                                @NotNull Color background,
                                @NotNull Color foreground,
+                               boolean isSelected,
                                int availableWidth) {
     FontMetrics metrics = component.getFontMetrics(getReferenceFont());
     myHeight = metrics.getHeight() + RectanglePainter.TOP_TEXT_PADDING + RectanglePainter.BOTTOM_TEXT_PADDING;
index b5452f8085b1d32bf6694941f87acda517fcb039..d057ff60c1be13090130f61b8e026c0b8b6b331c 100644 (file)
@@ -33,6 +33,7 @@ public interface ReferencePainter {
                         @NotNull Collection<VcsRef> references,
                         @NotNull Color background,
                         @NotNull Color foreground,
+                        boolean isSelected,
                         int availableWidth);
 
   void paint(@NotNull Graphics2D g2, int x, int y, int height);