import com.intellij.openapi.ui.GraphicsConfig;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkRenderer;
-import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.JBColor;
import com.intellij.ui.SimpleColoredRenderer;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.ui.TableCell;
import com.intellij.util.ObjectUtils;
-import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.GraphicsUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
@NotNull private final VcsLogData myLogData;
@NotNull private final VcsLogGraphTable myGraphTable;
- @Nullable private final FadeOutPainter myFadeOutPainter = isRedesignedLabels() ? new FadeOutPainter() : null;
- @Nullable private final ReferencePainter myTooltipPainter = isRedesignedLabels() ? new LabelPainter() : null;
+ @Nullable private final FadeOutPainter myFadeOutPainter;
+ @Nullable private final ReferencePainter myTooltipPainter;
@NotNull private final MyComponent myComponent;
myLogData = logData;
myGraphTable = table;
+ myFadeOutPainter = isRedesignedLabels() ? new FadeOutPainter() : null;
+ myTooltipPainter = isRedesignedLabels() ? new LabelPainter(myLogData) : null;
+
myComponent = new MyComponent(logData, painter, table) {
@Override
public void paintComponent(Graphics g) {
myExpanded = myGraphTable.getExpandableItemsHandler().getExpandedItems().contains(new TableCell(row, column));
if (myFadeOutPainter != null) {
- myFadeOutPainter.customize(value.getRefsToThisCommit(), row, column, table, JBColor.black /*any color fits here*/);
+ 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()) {
- customizeRefsPainter(myTooltipPainter, refs, myComponent.getForeground(), myLogData, myComponent);
+ myTooltipPainter.customizePainter(myComponent, refs, myComponent.getBackground(), myComponent.getForeground());
if (myTooltipPainter.getSize().getWidth() - LabelPainter.GRADIENT_WIDTH >= width - point.getX()) {
return new TooltipReferencesPanel(myLogData, myTooltipPainter, refs);
}
return null;
}
- private static void customizeRefsPainter(@NotNull ReferencePainter painter,
- @NotNull Collection<VcsRef> refs,
- @NotNull Color foreground,
- @NotNull VcsLogData logData,
- @NotNull JComponent component) {
- if (!refs.isEmpty()) {
- VirtualFile root = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(refs)).getRoot();
- painter.customizePainter(component, refs, logData.getLogProvider(root).getReferenceManager(),
- component.getBackground(), foreground);
- }
- else {
- painter.customizePainter(component, refs, null, component.getBackground(), foreground);
- }
- }
-
public int getPreferredHeight() {
return myComponent.getPreferredHeight();
}
@NotNull private final VcsLogGraphTable myGraphTable;
@NotNull private final GraphCellPainter myPainter;
@NotNull private final IssueLinkRenderer myIssueLinkRenderer;
- @NotNull private final ReferencePainter myReferencePainter =
- isRedesignedLabels() ? new LabelPainter() : new RectangleReferencePainter();
+ @NotNull private final ReferencePainter myReferencePainter;
@NotNull protected PaintInfo myGraphImage = new PaintInfo(UIUtil.createImage(1, 1, BufferedImage.TYPE_INT_ARGB), 0);
@NotNull private Font myFont;
myPainter = painter;
myGraphTable = table;
+ myReferencePainter = isRedesignedLabels() ? new LabelPainter(myLogData) : new RectangleReferencePainter(myLogData);
+
myIssueLinkRenderer = new IssueLinkRenderer(myLogData.getProject(), this);
myFont = RectanglePainter.getFont();
myHeight = calculateHeight();
SimpleTextAttributes style = myGraphTable.applyHighlighters(this, row, column, hasFocus, isSelected);
Collection<VcsRef> refs = cell.getRefsToThisCommit();
- Color foreground = ObjectUtils.assertNotNull(myGraphTable.getBaseStyle(row, column, hasFocus, isSelected).getForeground());
- customizeRefsPainter(myReferencePainter, refs, foreground, myLogData, this);
+ Color baseForeground = ObjectUtils.assertNotNull(myGraphTable.getBaseStyle(row, column, hasFocus, isSelected).getForeground());
+ myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground);
setBorder(null);
append("");
public int getTooltipXCoordinate(@NotNull GraphCommitCell cell) {
Collection<VcsRef> refs = cell.getRefsToThisCommit();
if (!refs.isEmpty()) {
- customizeRefsPainter(myReferencePainter, refs, getForeground(), myLogData, this);
+ myReferencePainter.customizePainter(this, refs, getBackground(), getForeground());
TableColumn commitColumn = myGraphTable.getColumnModel().getColumn(GraphTableModel.COMMIT_COLUMN);
return commitColumn.getWidth() - (myReferencePainter.getSize().width - LabelPainter.GRADIENT_WIDTH) / 2;
}
}
private class FadeOutPainter {
- @NotNull private final LabelPainter myEmptyPainter = new LabelPainter();
+ @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, @NotNull Color foreground) {
+ 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));
- customizeRefsPainter(myEmptyPainter, commitCell.getRefsToThisCommit(), foreground, myLogData, myComponent);
+ myEmptyPainter.customizePainter(myComponent, commitCell.getRefsToThisCommit(), myComponent.getBackground(), JBColor.black);
prevWidth = myEmptyPainter.getSize().width;
}
int nextWidth = 0;
if (row < table.getRowCount() - 1) {
GraphCommitCell commitCell = getValue(table.getValueAt(row + 1, column));
- customizeRefsPainter(myEmptyPainter, commitCell.getRefsToThisCommit(), foreground, myLogData, myComponent);
+ myEmptyPainter.customizePainter(myComponent, commitCell.getRefsToThisCommit(), myComponent.getBackground(), JBColor.black);
nextWidth = myEmptyPainter.getSize().width;
}
import com.intellij.vcs.log.VcsLogRefManager;
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.*;
private static final String TWO_DOTS = "..";
private static final String SEPARATOR = "/";
- @NotNull
- private List<Pair<String, LabelIcon>> myLabels = ContainerUtil.newArrayList();
+ @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
@NotNull
private Color myForeground = UIUtil.getTableForeground();
+ public LabelPainter(@NotNull VcsLogData data) {
+ myLogData = data;
+ }
+
public void customizePainter(@NotNull JComponent component,
@NotNull Collection<VcsRef> references,
- @Nullable VcsLogRefManager manager,
@NotNull Color background,
@NotNull Color foreground) {
myBackground = background;
FontMetrics metrics = component.getFontMetrics(getReferenceFont());
myHeight = metrics.getHeight() + TOP_TEXT_PADDING + BOTTOM_TEXT_PADDING;
- myWidth = GRADIENT_WIDTH + RIGHT_PADDING;
- myLabels = ContainerUtil.newArrayList();
- if (manager == null) return;
+ 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);
+
+ myLabels = presentation.first;
+ myWidth = presentation.second;
+ }
- for (RefGroup group : manager.groupForTable(references)) {
+ @NotNull
+ public 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();
+ if (refGroups.isEmpty()) return Pair.create(labels, width);
+
+ for (RefGroup group : refGroups) {
if (group.isExpanded()) {
for (VcsRef ref : group.getRefs()) {
- LabelIcon labelIcon = new LabelIcon(myHeight, myBackground, ref.getType().getBackgroundColor());
+ LabelIcon labelIcon = new LabelIcon(height, background, ref.getType().getBackgroundColor());
String text = shortenRefName(ref.getName());
- myLabels.add(Pair.create(text, labelIcon));
- myWidth += labelIcon.getIconWidth() + metrics.stringWidth(text) + MIDDLE_PADDING;
+ labels.add(Pair.create(text, labelIcon));
+ width += labelIcon.getIconWidth() + fontMetrics.stringWidth(text) + MIDDLE_PADDING;
}
}
else {
-
- LabelIcon labelIcon = new LabelIcon(myHeight, myBackground, getGroupColors(group));
+ LabelIcon labelIcon = new LabelIcon(height, background, getGroupColors(group));
String text = shortenRefName(group.getName());
- myLabels.add(Pair.create(text, labelIcon));
- myWidth += labelIcon.getIconWidth() + metrics.stringWidth(text) + MIDDLE_PADDING;
+ labels.add(Pair.create(text, labelIcon));
+ width += labelIcon.getIconWidth() + fontMetrics.stringWidth(text) + MIDDLE_PADDING;
}
}
+
+ return Pair.create(labels, width);
}
@NotNull
}
@NotNull
- public Color[] getGroupColors(@NotNull RefGroup group) {
+ public static Color[] getGroupColors(@NotNull RefGroup group) {
MultiMap<VcsRefType, VcsRef> referencesByType = ContainerUtil.groupBy(group.getRefs(), VcsRef::getType);
Color[] colors;
if (referencesByType.size() == 1) {
import com.intellij.vcs.log.VcsLogRefManager;
import com.intellij.vcs.log.VcsRef;
import com.intellij.vcs.log.VcsRefType;
+import com.intellij.vcs.log.data.VcsLogData;
import com.intellij.vcs.log.paint.PaintParameters;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
import java.util.Map;
public class RectangleReferencePainter implements ReferencePainter {
- @NotNull
- private List<Pair<String, Color>> myLabels = ContainerUtil.newArrayList();
+ @NotNull private final VcsLogData myLogData;
+ @NotNull private List<Pair<String, Color>> myLabels = ContainerUtil.newArrayList();
private int myHeight = JBUI.scale(22);
private int myWidth = 0;
}
};
+ public RectangleReferencePainter(@NotNull VcsLogData data) {
+ myLogData = data;
+ }
+
@Override
public void customizePainter(@NotNull JComponent component,
@NotNull Collection<VcsRef> references,
- @Nullable VcsLogRefManager manager,
@NotNull Color background,
@NotNull Color foreground) {
FontMetrics metrics = component.getFontMetrics(getReferenceFont());
myWidth = 2 * PaintParameters.LABEL_PADDING;
myLabels = ContainerUtil.newArrayList();
+ VcsLogRefManager manager = ReferencePainter.getRefManager(myLogData, references);
if (manager == null) return;
List<VcsRef> sorted = ContainerUtil.sorted(references, manager.getLabelsOrderComparator());