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));
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;
@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,
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
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;
}
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);
}
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;
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());
}
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);
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);
}
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());
- }
- }
- }
- }
}
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;
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.*;
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;
@NotNull Collection<VcsRef> references,
@NotNull Color background,
@NotNull Color foreground,
+ boolean isSelected,
int availableWidth) {
myBackground = background;
myForeground = foreground;
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;
}
@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);
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
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;
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);
public boolean isLeftAligned() {
return false;
}
+
+ @Override
+ public Font getReferenceFont() {
+ Font font = RectanglePainter.getFont();
+ return font.deriveFont(font.getSize() - 1f);
+ }
}
@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;
@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);