Skip to content

Commit

Permalink
'#1866: Minor enhancements in bookmark cell renderer.
Browse files Browse the repository at this point in the history
  • Loading branch information
wladimirleite committed Sep 14, 2023
1 parent 626040e commit a99f23c
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class BookmarkCellRenderer {
private static final RenderingHints renderingHints;

private String[] names;
private Color[] colors;
private Color[] colors, foregrounds;
private final Map<Integer, ClippedString[]> clippedNamesMemo = new HashMap<Integer, ClippedString[]>();
private int maxSpacing;
private String lastStr;
Expand Down Expand Up @@ -51,8 +51,10 @@ void setBookmark(String str, Color color) {
}
if (colors == null || colors.length < names.length) {
colors = new Color[1];
foregrounds = new Color[1];
}
colors[0] = color;
foregrounds[0] = BookmarkColorsUtil.getForeground(color);
if (strChanged) {
maxSpacing = Integer.MAX_VALUE;
clippedNamesMemo.clear();
Expand All @@ -76,10 +78,12 @@ public void setBookmarks(IMultiBookmarks bookmarks, String str) {
}
if (colors == null || colors.length < names.length) {
colors = new Color[names.length];
foregrounds = new Color[names.length];
}
for (int i = 0; i < names.length; i++) {
Color c = bookmarks.getBookmarkColor(names[i]);
colors[i] = c == null ? BookmarkStandardColors.defaultColor : c;
c = colors[i] = c == null ? BookmarkStandardColors.defaultColor : c;
foregrounds[i] = BookmarkColorsUtil.getForeground(c);
}
if (strChanged) {
maxSpacing = Integer.MAX_VALUE;
Expand Down Expand Up @@ -158,14 +162,13 @@ public void paint(Graphics2D g, int w, int h) {
g.setRenderingHints(renderingHints);
FontMetrics fm = g.getFontMetrics();
ClippedString[] cn = getClippedNames(fm, g, w);
int y = (int) Math.round((h - 1 - fm.getHeight()) / 2.0 + fm.getAscent());
int y = (h - fm.getHeight()) / 2 + fm.getAscent();
int x = 0;
for (int i = 0; i < cn.length; i++) {
ClippedString cs = cn[i];
Color c = colors[i];
g.setColor(c);
g.fillRoundRect(x, 0, cs.w, h - 1, h / 2, h / 2);
g.setColor(BookmarkColorsUtil.getForeground(c));
g.setColor(colors[i]);
g.fillRoundRect(x, 1, cs.w, h - 2, h / 2, h / 2);
g.setColor(foregrounds[i]);
g.drawString(cs.str, x + 3, y);
x += cs.w + 1;
}
Expand Down

0 comments on commit a99f23c

Please sign in to comment.