mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs-log] remove RectangleReferencePainter and corresponding registry option
Introduce vcs.log.labels.left.aligned. It keeps labels design, but shifts them to the left.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<VcsRefType, Collection<VcsRef>> typeAndRefs : myGroupedVisibleReferences.entrySet()) {
|
||||
VcsRefType type = typeAndRefs.getKey();
|
||||
Collection<VcsRef> 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<VcsRefType, Collection<VcsRef>> typeAndRefs : myGroupedVisibleReferences.entrySet()) {
|
||||
VcsRefType type = typeAndRefs.getKey();
|
||||
Collection<VcsRef> 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<VcsRefType, Collection<VcsRef>> 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
|
||||
|
||||
+36
-22
@@ -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<GraphComm
|
||||
|
||||
@NotNull private final MyComponent myComponent;
|
||||
@NotNull private final MyComponent myTemplateComponent;
|
||||
@Nullable private final ReferencePainter myTooltipPainter;
|
||||
@NotNull private final ReferencePainter myTooltipPainter;
|
||||
|
||||
public GraphCommitCellRenderer(@NotNull VcsLogData logData,
|
||||
@NotNull GraphCellPainter painter,
|
||||
@@ -42,7 +41,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
|
||||
myLogData = logData;
|
||||
myGraphTable = table;
|
||||
|
||||
myTooltipPainter = isRedesignedLabels() ? new LabelPainter(myLogData) : null;
|
||||
myTooltipPainter = new LabelPainter(myLogData);
|
||||
myComponent = new MyComponent(logData, painter, table);
|
||||
myTemplateComponent = new MyComponent(logData, painter, table);
|
||||
}
|
||||
@@ -58,21 +57,23 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
|
||||
return myComponent;
|
||||
}
|
||||
|
||||
public static boolean isRedesignedLabels() {
|
||||
return Registry.is("vcs.log.labels.redesign");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JComponent getTooltip(@NotNull Object value, @NotNull Point point, int row) {
|
||||
if (myTooltipPainter == null) return null;
|
||||
|
||||
GraphCommitCell cell = getValue(value);
|
||||
Collection<VcsRef> 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<GraphComm
|
||||
}
|
||||
|
||||
private int getReferencesWidth(int row) {
|
||||
GraphCommitCell cell = getValue(myGraphTable.getModel().getValueAt(row, GraphTableModel.COMMIT_COLUMN));
|
||||
return getReferencesWidth(row, getValue(myGraphTable.getModel().getValueAt(row, GraphTableModel.COMMIT_COLUMN)));
|
||||
}
|
||||
|
||||
private int getReferencesWidth(int row, @NotNull GraphCommitCell cell) {
|
||||
Collection<VcsRef> refs = cell.getRefsToThisCommit();
|
||||
if (!refs.isEmpty()) {
|
||||
myTemplateComponent.customize(cell, myGraphTable.isRowSelected(row), myGraphTable.hasFocus(),
|
||||
@@ -122,7 +126,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
|
||||
myPainter = painter;
|
||||
myGraphTable = table;
|
||||
|
||||
myReferencePainter = isRedesignedLabels() ? new LabelPainter(myLogData) : new RectangleReferencePainter(myLogData);
|
||||
myReferencePainter = new LabelPainter(myLogData);
|
||||
|
||||
myIssueLinkRenderer = new IssueLinkRenderer(myLogData.getProject(), this);
|
||||
myFont = RectanglePainter.getFont();
|
||||
@@ -173,7 +177,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
|
||||
myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground, isSelected,
|
||||
0 /*left aligned painter does not use available width*/);
|
||||
|
||||
appendTextPadding(myGraphImage.getWidth() + myReferencePainter.getSize().width);
|
||||
appendTextPadding(myGraphImage.getWidth() + myReferencePainter.getSize().width + LabelPainter.RIGHT_PADDING);
|
||||
appendText(cell, style);
|
||||
}
|
||||
else {
|
||||
@@ -208,6 +212,23 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
|
||||
|
||||
@NotNull
|
||||
private PaintInfo getGraphImage(@NotNull Collection<? extends PrintElement> 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<? extends PrintElement> printElements) {
|
||||
double maxIndex = getMaxGraphElementIndex(printElements);
|
||||
return (int)(maxIndex * PaintParameters.getNodeWidth(myGraphTable.getRowHeight()));
|
||||
}
|
||||
|
||||
private double getMaxGraphElementIndex(@NotNull Collection<? extends PrintElement> printElements) {
|
||||
double maxIndex = 0;
|
||||
for (PrintElement printElement : printElements) {
|
||||
maxIndex = Math.max(maxIndex, printElement.getPositionInCurrentRow());
|
||||
@@ -219,14 +240,7 @@ public class GraphCommitCellRenderer extends TypeSafeTableCellRenderer<GraphComm
|
||||
maxIndex++;
|
||||
|
||||
maxIndex = Math.max(maxIndex, Math.min(MAX_GRAPH_WIDTH, myGraphTable.getVisibleGraph().getRecommendedWidth()));
|
||||
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);
|
||||
return maxIndex;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -32,6 +32,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.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
import com.intellij.ui.JBColor;
|
||||
@@ -253,7 +254,7 @@ public class LabelPainter implements ReferencePainter {
|
||||
|
||||
@Override
|
||||
public boolean isLeftAligned() {
|
||||
return false;
|
||||
return Registry.is("vcs.log.labels.left.aligned");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.vcs.log.ui.render;
|
||||
|
||||
import com.intellij.openapi.ui.GraphicsConfig;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.ui.ColorUtil;
|
||||
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;
|
||||
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 javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class RectangleReferencePainter implements ReferencePainter {
|
||||
@NotNull private final VcsLogData myLogData;
|
||||
@NotNull private List<Pair<String, Color>> 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<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;
|
||||
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());
|
||||
|
||||
for (Map.Entry<VcsRefType, Collection<VcsRef>> 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<String, Color> 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user