Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ public class LineNumberList extends AbstractGutterComponent
*/
private Color currentLineNumberColor;

/**
* The Increase Required from the base font size of the current line number.
*/
private float currentLineNumberFontIncreaseSize = 2f;

public static final Color DEFAULT_LINE_NUMBER_COLOR = Color.GRAY;


Expand Down Expand Up @@ -387,6 +392,8 @@ protected void paintComponent(Graphics g) {

// Paint line numbers
boolean ltr = getComponentOrientation().isLeftToRight();
Font baseFont = g.getFont();
Font currentLineNumberFont = baseFont.deriveFont(Font.BOLD).deriveFont(baseFont.getSize() + currentLineNumberFontIncreaseSize); // Forcing Bold Style on the current line number
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the new field is its own font then we don't have to derive the new font on each call to paintComponent().

if (ltr) {
FontMetrics metrics = g.getFontMetrics();
int rhs = getWidth() - rhsBorderWidth;
Expand All @@ -397,12 +404,16 @@ protected void paintComponent(Graphics g) {
if (currentLine + 1 == line + getLineNumberingStartIndex() - 1) {
Color color = currentLineNumberColor != null ? currentLineNumberColor :
getForeground();
g.setFont(currentLineNumberFont);
g.setColor(color);
// Calculating the shift width required in Left to Right View Mode since the current line number font will have a greater size than the base font.
g.drawString(number, rhs - width - (g.getFontMetrics().stringWidth(number) - g.getFontMetrics(baseFont).stringWidth(number)), y);
}
else {
g.setFont(baseFont);
g.setColor(getForeground());
g.drawString(number, rhs-width, y);
}
g.drawString(number, rhs-width,y);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The g.drawString() call could still be here instead of in the if- and else blocks if we create a new x variable and assign it a vale in the if/else blocks. I'd kind-of prefer a single g.drawString() here.

y += cellHeight;
if (fm!=null) {
Fold fold = fm.getFoldForLine(line-1);
Expand Down Expand Up @@ -430,11 +441,13 @@ protected void paintComponent(Graphics g) {
Color color = currentLineNumberColor != null ? currentLineNumberColor :
getForeground();
g.setColor(color);
// Calculating the shift width required in Right to Left View Mode since the current line number font will have a greater size than the base font.
g.drawString(number, rhsBorderWidth + (g.getFontMetrics().stringWidth(number) - g.getFontMetrics(baseFont).stringWidth(number)), y);
}
else {
g.setColor(getForeground());
g.drawString(number, rhsBorderWidth, y);
}
g.drawString(number, rhsBorderWidth, y);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same changes here as in the LTR case

y += cellHeight;
if (fm!=null) {
Fold fold = fm.getFoldForLine(line-1);
Expand Down Expand Up @@ -726,7 +739,10 @@ void updateCellWidths() {
lineCount = lineCount/10;
count++;
} while (lineCount >= 10);
cellWidth += fontMetrics.charWidth('9')*(count+1) + 3;
// This was required since the current line number has a higher font size so the previous method can cause the first digit of the
// number to go out of bounds of the line number list.
// Maybe there is some better solution to this situation.
cellWidth += fontMetrics.charWidth('9')*(count+1) + (fontMetrics.charWidth('9') * (int)currentLineNumberFontIncreaseSize);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming we just move to a currentLineNumberFont variable, we can just pick the larger of the two FontMetrics values here to simplify things a bit:

Font font = getFont();
FontMetrics fontMetrics = font.getFontMetrics();
int charWidth = fontMetrics.charWidth('9');
if (currentLineNumberFont != null) {
  int charWidth2 = currentLineNumberFont.getFontMetrics().charWidth('9');
  charWidth = Math.max(charWidth, charWidth2);
}
...
cellWidth += charWidth * (count + 1) + 3;

Might even move that charWidth calculation logic into a private helper method just to make the code more readable,.

}
}

Expand Down