From 2f8337d6c096f02fd42572d5e47d957d5f024cc0 Mon Sep 17 00:00:00 2001 From: irengrig Date: Mon, 21 Mar 2011 19:20:07 +0300 Subject: [PATCH] git log: show current user name in bold --- .../com/intellij/ui/SimpleTextAttributes.java | 31 +++++++++ .../git4idea/history/wholeTree/GitLogUI.java | 64 +++++++++++++++++-- 2 files changed, 91 insertions(+), 4 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/SimpleTextAttributes.java b/platform/platform-api/src/com/intellij/ui/SimpleTextAttributes.java index a7d90c4922f0..31d1a3628b9c 100644 --- a/platform/platform-api/src/com/intellij/ui/SimpleTextAttributes.java +++ b/platform/platform-api/src/com/intellij/ui/SimpleTextAttributes.java @@ -17,6 +17,7 @@ package com.intellij.ui; import com.intellij.openapi.editor.markup.EffectType; import com.intellij.openapi.editor.markup.TextAttributes; +import com.intellij.openapi.util.Comparing; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.Nullable; @@ -215,4 +216,34 @@ public final class SimpleTextAttributes { return new SimpleTextAttributes(bg != null ? bg : getBgColor(), fg != null ? fg : getFgColor(), wave != null ? wave : getWaveColor(), style == -1 ? getStyle() : style); } + + // take what differs from REGULAR + public static SimpleTextAttributes merge(final SimpleTextAttributes weak, final SimpleTextAttributes strong) { + final int style; + final Color wave; + final Color fg; + final Color bg; + if (strong.getStyle() != REGULAR_ATTRIBUTES.getStyle()) { + style = strong.getStyle(); + } else { + style = weak.getStyle(); + } + if (! Comparing.equal(strong.getWaveColor(), REGULAR_ATTRIBUTES.getWaveColor())) { + wave = strong.getWaveColor(); + } else { + wave = weak.getWaveColor(); + } + if (! Comparing.equal(strong.getFgColor(), REGULAR_ATTRIBUTES.getFgColor())) { + fg = strong.getFgColor(); + } else { + fg = weak.getFgColor(); + } + if (! Comparing.equal(strong.getBgColor(), REGULAR_ATTRIBUTES.getBgColor())) { + bg = strong.getBgColor(); + } else { + bg = weak.getBgColor(); + } + + return new SimpleTextAttributes(bg, fg, wave, style); + } } diff --git a/plugins/git4idea/src/git4idea/history/wholeTree/GitLogUI.java b/plugins/git4idea/src/git4idea/history/wholeTree/GitLogUI.java index f8158855b7ce..a06b11471e44 100644 --- a/plugins/git4idea/src/git4idea/history/wholeTree/GitLogUI.java +++ b/plugins/git4idea/src/git4idea/history/wholeTree/GitLogUI.java @@ -776,17 +776,21 @@ public class GitLogUI implements Disposable { } } - private class HighLightingRenderer extends ColoredTableCellRenderer { + private class AuthorRenderer extends ColoredTableCellRenderer { + private final SimpleTextAttributes myCurrentUserAttributes; private final SimpleTextAttributes myHighlightAttributes; private final List mySearchContext; private final SimpleTextAttributes myUsualAttributes; protected final HighlightingRendererBase myWorker; - public HighLightingRenderer(SimpleTextAttributes highlightAttributes, SimpleTextAttributes usualAttributes, - final List searchContext) { + private AuthorRenderer(SimpleTextAttributes currentUserAttributes, + SimpleTextAttributes highlightAttributes, + List searchContext, + SimpleTextAttributes usualAttributes) { + myCurrentUserAttributes = currentUserAttributes; myHighlightAttributes = highlightAttributes; mySearchContext = searchContext; - myUsualAttributes = usualAttributes == null ? SimpleTextAttributes.REGULAR_ATTRIBUTES : usualAttributes; + myUsualAttributes = usualAttributes; myWorker = new HighlightingRendererBase(searchContext) { @Override protected void usual(String s) { @@ -807,6 +811,7 @@ public class GitLogUI implements Disposable { return; } final String text = value.toString(); + if (mySearchContext.isEmpty()) { append(text, myUsualAttributes); return; @@ -815,6 +820,57 @@ public class GitLogUI implements Disposable { } } + private class HighLightingRenderer extends ColoredTableCellRenderer { + private final SimpleTextAttributes myHighlightAttributes; + private final List mySearchContext; + private final SimpleTextAttributes myUsualAttributes; + private SimpleTextAttributes myUsualAttributesForRun; + protected final HighlightingRendererBase myWorker; + + public HighLightingRenderer(SimpleTextAttributes highlightAttributes, SimpleTextAttributes usualAttributes, + final List searchContext) { + myHighlightAttributes = highlightAttributes; + mySearchContext = searchContext; + myUsualAttributes = usualAttributes == null ? SimpleTextAttributes.REGULAR_ATTRIBUTES : usualAttributes; + myUsualAttributesForRun = myUsualAttributes; + myWorker = new HighlightingRendererBase(searchContext) { + @Override + protected void usual(String s) { + append(s, myUsualAttributesForRun); + } + + @Override + protected void highlight(String s) { + append(s, SimpleTextAttributes.merge(myUsualAttributesForRun, myHighlightAttributes)); + } + }; + } + + @Override + protected void customizeCellRenderer(JTable table, Object value, boolean selected, boolean hasFocus, int row, int column) { + setBackground(getLogicBackground(selected, row)); + if (BigTableTableModel.LOADING == value) { + return; + } + final String text = value.toString(); + myUsualAttributesForRun = isCurrentUser(row, text) ? + SimpleTextAttributes.merge(myUsualAttributes, SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES) : myUsualAttributes; + if (mySearchContext.isEmpty()) { + append(text, myUsualAttributesForRun); + return; + } + myWorker.tryHighlight(text); + } + + private boolean isCurrentUser(final int row, final String text) { + final CommitI commitAt = myTableModel.getCommitAt(row); + if (commitAt == null) return false; + final SymbolicRefs symbolicRefs = myRefs.get(commitAt.selectRepository(myRootsUnderVcs)); + if (symbolicRefs == null) return false; + return Comparing.equal(symbolicRefs.getUsername(), text); + } + } + private class SimpleRenderer extends ColoredTableCellRenderer { private final SimpleTextAttributes myAtt; private final boolean myShowLoading;