diff --git a/platform/util/resources/misc/registry.properties b/platform/util/resources/misc/registry.properties index 827945914bfa..bab44c2d6d12 100644 --- a/platform/util/resources/misc/registry.properties +++ b/platform/util/resources/misc/registry.properties @@ -305,14 +305,14 @@ vcs.log.open.another.log.visible=false vcs.log.open.another.log.visible.description=An action that opens a new tab with log vcs.log.keep.up.to.date=true vcs.log.keep.up.to.date.description=Load log on start after heavy tasks are completed and keep it up to date even when not visible -vcs.log.labels.redesign=true -vcs.log.labels.redesign.description=Show branch labels on the right with combined tag icons, do not display tag names, combine tracked branches, display detached heads with an exclamation mark vcs.log.highlight.not.indexed=false vcs.log.highlight.not.indexed.description=Highlight commits that are not indexed vcs.log.index.git=true vcs.log.index.git.description=Index all commits in Git repository for fast filtering vcs.log.graph.history=false vcs.log.graph.history.description=Action in context menu that opens a new log tab filtered by file in context +vcs.log.labels.left.aligned=false +vcs.log.labels.left.aligned.description=Align labels in Log table to the left vcs.executable.validator.timeout.sec=60 vcs.unversioned.files.in.commit=true diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/ReferencesPanel.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/ReferencesPanel.java index 103e11251201..ab5575fc11c1 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/ReferencesPanel.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/ReferencesPanel.java @@ -15,25 +15,27 @@ */ package com.intellij.vcs.log.ui.frame; +import com.intellij.ui.ColorUtil; import com.intellij.ui.components.JBLabel; import com.intellij.ui.components.panels.Wrapper; import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; import com.intellij.util.ui.JBUI; +import com.intellij.util.ui.UIUtil; import com.intellij.vcs.log.VcsRef; import com.intellij.vcs.log.VcsRefType; -import com.intellij.vcs.log.ui.render.GraphCommitCellRenderer; import com.intellij.vcs.log.ui.render.LabelIcon; import com.intellij.vcs.log.ui.render.RectanglePainter; -import com.intellij.vcs.log.ui.render.RectangleReferencePainter; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; -import java.util.*; +import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.Map; import static com.intellij.openapi.vcs.history.VcsHistoryUtil.getCommitDetailsFont; import static com.intellij.vcs.log.ui.frame.CommitPanel.getCommitDetailsBackground; @@ -73,37 +75,28 @@ public class ReferencesPanel extends JPanel { int height = getIconHeight(); JBLabel firstLabel = null; - if (GraphCommitCellRenderer.isRedesignedLabels()) { - for (Map.Entry> typeAndRefs : myGroupedVisibleReferences.entrySet()) { - VcsRefType type = typeAndRefs.getKey(); - Collection refs = typeAndRefs.getValue(); - int refIndex = 0; - for (VcsRef reference : refs) { - Icon icon = createIcon(type, refs, refIndex, height); - String ending = (refIndex != refs.size() - 1) ? "," : ""; - String text = reference.getName() + ending; - JBLabel label = createLabel(text, icon); - if (firstLabel == null) { - firstLabel = label; - add(label); - } - else { - addWrapped(label, firstLabel); - } - refIndex++; + for (Map.Entry> typeAndRefs : myGroupedVisibleReferences.entrySet()) { + VcsRefType type = typeAndRefs.getKey(); + Collection refs = typeAndRefs.getValue(); + int refIndex = 0; + for (VcsRef reference : refs) { + Icon icon = createIcon(type, refs, refIndex, height); + String ending = (refIndex != refs.size() - 1) ? "," : ""; + String text = reference.getName() + ending; + JBLabel label = createLabel(text, icon); + if (firstLabel == null) { + firstLabel = label; + add(label); } - } - if (getHiddenReferencesSize() > 0) { - JBLabel label = createRestLabel(getHiddenReferencesSize()); - addWrapped(label, ObjectUtils.assertNotNull(firstLabel)); + else { + addWrapped(label, firstLabel); + } + refIndex++; } } - else { - for (Map.Entry> typeAndRefs : myGroupedVisibleReferences.entrySet()) { - for (VcsRef reference : typeAndRefs.getValue()) { - add(new ReferencePanel(reference)); - } - } + if (getHiddenReferencesSize() > 0) { + JBLabel label = createRestLabel(getHiddenReferencesSize()); + addWrapped(label, ObjectUtils.assertNotNull(firstLabel)); } setVisible(!myGroupedVisibleReferences.isEmpty()); revalidate(); @@ -165,6 +158,17 @@ public class ReferencesPanel extends JPanel { return getCommitDetailsBackground(); } + @NotNull + public static Color getLabelColor(@NotNull Color color) { + if (UIUtil.isUnderDarcula()) { + color = ColorUtil.darker(color, 6); + } + else { + color = ColorUtil.brighter(color, 6); + } + return ColorUtil.desaturate(color, 3); + } + private static class ReferencePanel extends JPanel { @NotNull private final RectanglePainter myLabelPainter; @NotNull private final VcsRef myReference; @@ -178,7 +182,7 @@ public class ReferencesPanel extends JPanel { @Override public void paint(Graphics g) { myLabelPainter.paint((Graphics2D)g, myReference.getName(), 0, 0, - RectangleReferencePainter.getLabelColor(myReference.getType().getBackgroundColor())); + getLabelColor(myReference.getType().getBackgroundColor())); } @Override diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java index 29d4577511f8..7e9d6232f324 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/render/GraphCommitCellRenderer.java @@ -1,6 +1,5 @@ package com.intellij.vcs.log.ui.render; -import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.changes.issueLinks.IssueLinkRenderer; import com.intellij.ui.SimpleColoredComponent; @@ -34,7 +33,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer refs = cell.getRefsToThisCommit(); if (!refs.isEmpty()) { 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 (myTooltipPainter.isLeftAligned()) { + double distance = point.getX() - myTemplateComponent.getGraphWidth(cell.getPrintElements()); + if (distance > 0 && distance <= getReferencesWidth(row, cell)) { + return new TooltipReferencesPanel(myLogData, myTooltipPainter, refs); + } + } + else { + if (getColumnWidth() - point.getX() <= getReferencesWidth(row, cell)) { + return new TooltipReferencesPanel(myLogData, myTooltipPainter, refs); + } } } return null; @@ -83,7 +84,10 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer refs = cell.getRefsToThisCommit(); if (!refs.isEmpty()) { myTemplateComponent.customize(cell, myGraphTable.isRowSelected(row), myGraphTable.hasFocus(), @@ -122,7 +126,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer printElements) { + double maxIndex = getMaxGraphElementIndex(printElements); + BufferedImage image = UIUtil.createImage((int)(PaintParameters.getNodeWidth(myGraphTable.getRowHeight()) * (maxIndex + 2)), + myGraphTable.getRowHeight(), + BufferedImage.TYPE_INT_ARGB); + Graphics2D g2 = image.createGraphics(); + myPainter.draw(g2, printElements); + + int width = (int)(maxIndex * PaintParameters.getNodeWidth(myGraphTable.getRowHeight())); + return new PaintInfo(image, width); + } + + private int getGraphWidth(@NotNull Collection printElements) { + double maxIndex = getMaxGraphElementIndex(printElements); + return (int)(maxIndex * PaintParameters.getNodeWidth(myGraphTable.getRowHeight())); + } + + private double getMaxGraphElementIndex(@NotNull Collection printElements) { double maxIndex = 0; for (PrintElement printElement : printElements) { maxIndex = Math.max(maxIndex, printElement.getPositionInCurrentRow()); @@ -219,14 +240,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer> myLabels = ContainerUtil.newArrayList(); - private int myHeight = JBUI.scale(22); - private int myWidth = 0; - - private final RectanglePainter myLabelPainter = new RectanglePainter(false) { - @Override - protected Font getLabelFont() { - return getReferenceFont(); - } - }; - - public RectangleReferencePainter(@NotNull VcsLogData data) { - myLogData = data; - } - - @Override - public void customizePainter(@NotNull JComponent component, - @NotNull Collection 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; - myWidth = 2 * PaintParameters.LABEL_PADDING; - - myLabels = ContainerUtil.newArrayList(); - VcsLogRefManager manager = ReferencePainter.getRefManager(myLogData, references); - if (manager == null) return; - - List sorted = ContainerUtil.sorted(references, manager.getLabelsOrderComparator()); - - for (Map.Entry> entry : ContainerUtil.groupBy(sorted, VcsRef::getType).entrySet()) { - VcsRef ref = ObjectUtils.assertNotNull(ContainerUtil.getFirstItem(entry.getValue())); - String text = ref.getName() + (entry.getValue().size() > 1 ? " +" : ""); - myLabels.add(Pair.create(text, entry.getKey().getBackgroundColor())); - - myWidth += myLabelPainter.calculateSize(text, metrics).getWidth() + PaintParameters.LABEL_PADDING; - } - } - - public void paint(@NotNull Graphics2D g2, int x, int y, int height) { - if (myLabels.isEmpty()) return; - - GraphicsConfig config = GraphicsUtil.setupAAPainting(g2); - g2.setFont(getReferenceFont()); - g2.setStroke(new BasicStroke(1.5f)); - - FontMetrics fontMetrics = g2.getFontMetrics(); - - x += PaintParameters.LABEL_PADDING; - for (Pair label : myLabels) { - Dimension size = myLabelPainter.calculateSize(label.first, fontMetrics); - int paddingY = y + (height - size.height) / 2; - myLabelPainter.paint(g2, label.first, x, paddingY, getLabelColor(label.second)); - x += size.width + PaintParameters.LABEL_PADDING; - } - - config.restore(); - } - - @NotNull - public static Color getLabelColor(@NotNull Color color) { - if (UIUtil.isUnderDarcula()) { - color = ColorUtil.darker(color, 6); - } - else { - color = ColorUtil.brighter(color, 6); - } - return ColorUtil.desaturate(color, 3); - } - - public Dimension getSize() { - if (myLabels.isEmpty()) return new Dimension(); - return new Dimension(myWidth, myHeight); - } - - @Override - public boolean isLeftAligned() { - return true; - } -}