GraphCommitCell cell = getValue(value);
Collection<VcsRef> refs = cell.getRefsToThisCommit();
if (!refs.isEmpty()) {
- myTooltipPainter.customizePainter(myComponent, refs, myComponent.getBackground(), myComponent.getForeground());
+ myTooltipPainter
+ .customizePainter(myComponent, refs, myComponent.getBackground(), myComponent.getForeground(), myComponent.getWidth());
if (myTooltipPainter.getSize().getWidth() - LabelPainter.GRADIENT_WIDTH >= width - point.getX()) {
return new TooltipReferencesPanel(myLogData, myTooltipPainter, refs);
}
GraphCommitCell cell = getValue(myGraphTable.getModel().getValueAt(row, GraphTableModel.COMMIT_COLUMN));
Collection<VcsRef> refs = cell.getRefsToThisCommit();
if (!refs.isEmpty()) {
- int labelWidth = LabelPainter.calculateWidth(myLogData, refs, myComponent, getPreferredHeight());
+ int labelWidth = LabelPainter.calculateWidth(myLogData, refs, myComponent, getPreferredHeight(), true);
TableColumn commitColumn = myGraphTable.getColumnModel().getColumn(GraphTableModel.COMMIT_COLUMN);
return commitColumn.getWidth() - (labelWidth - LabelPainter.GRADIENT_WIDTH) / 2;
}
Collection<VcsRef> refs = cell.getRefsToThisCommit();
Color baseForeground = ObjectUtils.assertNotNull(myGraphTable.getBaseStyle(row, column, hasFocus, isSelected).getForeground());
- myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground);
- setBorder(null);
- append("");
- appendTextPadding(myGraphImage.getWidth() + (myReferencePainter.isLeftAligned() ? myReferencePainter.getSize().width : 0));
- myIssueLinkRenderer.appendTextWithLinks(cell.getText(), style);
+ append(""); // appendTextPadding wont work without this
+ int columnWidth = myGraphTable.getColumnModel().getColumn(column).getWidth();
+ if (myReferencePainter.isLeftAligned()) {
+ myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground,
+ 0 /*left aligned painter does not use available width*/);
+
+ appendTextPadding(myGraphImage.getWidth() + myReferencePainter.getSize().width);
+ myIssueLinkRenderer.appendTextWithLinks(cell.getText(), style);
+ }
+ else {
+ appendTextPadding(myGraphImage.getWidth());
+ myIssueLinkRenderer.appendTextWithLinks(cell.getText(), style);
+ myReferencePainter.customizePainter(this, refs, getBackground(), baseForeground,
+ Math.min(columnWidth - super.getPreferredSize().width, columnWidth / 3));
+ }
}
private int calculateHeight() {
int prevWidth = 0;
if (row > 0) {
GraphCommitCell commitCell = getValue(table.getValueAt(row - 1, column));
- prevWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight());
+ prevWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight(), true);
}
int nextWidth = 0;
if (row < table.getRowCount() - 1) {
GraphCommitCell commitCell = getValue(table.getValueAt(row + 1, column));
- nextWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight());
+ nextWidth = LabelPainter.calculateWidth(myLogData, commitCell.getRefsToThisCommit(), myComponent, getPreferredHeight(), true);
}
myWidth = Math.max(Math.max(prevWidth, nextWidth), LabelPainter.GRADIENT_WIDTH);
public void customizePainter(@NotNull JComponent component,
@NotNull Collection<VcsRef> references,
@NotNull Color background,
- @NotNull Color foreground) {
+ @NotNull Color foreground,
+ 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);
+ 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);
+ }
myLabels = presentation.first;
myWidth = presentation.second;
}
@NotNull
- private static Pair<List<Pair<String, LabelIcon>>, Integer> calculatePresentation(@NotNull List<RefGroup> refGroups,
- @NotNull FontMetrics fontMetrics,
- int height,
- @NotNull Color background) {
+ 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;
List<Pair<String, LabelIcon>> labels = ContainerUtil.newArrayList();
if (group.isExpanded()) {
for (VcsRef ref : group.getRefs()) {
LabelIcon labelIcon = new LabelIcon(height, background, ref.getType().getBackgroundColor());
- String text = shortenRefName(ref.getName());
+ String text = shorten ? shortenRefName(ref.getName()) : ref.getName();
labels.add(Pair.create(text, labelIcon));
width += labelIcon.getIconWidth() + fontMetrics.stringWidth(text) + MIDDLE_PADDING;
}
else {
LabelIcon labelIcon = new LabelIcon(height, background, getGroupColors(group));
- String text = shortenRefName(group.getName());
+ String text = shorten ? shortenRefName(group.getName()) : group.getName();
labels.add(Pair.create(text, labelIcon));
width += labelIcon.getIconWidth() + fontMetrics.stringWidth(text) + MIDDLE_PADDING;
public static int calculateWidth(@NotNull VcsLogData logData,
@NotNull Collection<VcsRef> references,
@NotNull JComponent component,
- int height) {
+ 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*/).second;
+ return calculatePresentation(refGroups, component.getFontMetrics(RectanglePainter.getFont()), height, JBColor.white/*bg color does not affect width*/,
+ shorten).second;
}
@NotNull
public void customizePainter(@NotNull JComponent component,
@NotNull Collection<VcsRef> references,
@NotNull Color background,
- @NotNull Color foreground) {
+ @NotNull Color foreground,
+ int availableWidth) {
FontMetrics metrics = component.getFontMetrics(getReferenceFont());
myHeight = metrics.getHeight() + RectanglePainter.TOP_TEXT_PADDING + RectanglePainter.BOTTOM_TEXT_PADDING;
myWidth = 2 * PaintParameters.LABEL_PADDING;
void customizePainter(@NotNull JComponent component,
@NotNull Collection<VcsRef> references,
@NotNull Color background,
- @NotNull Color foreground);
+ @NotNull Color foreground,
+ int availableWidth);
void paint(@NotNull Graphics2D g2, int x, int y, int height);