textAreaInsets = textArea.getInsets(textAreaInsets);
actualTopY += textAreaInsets.top;
int y = actualTopY + ascent;
// Get the actual first line to paint, taking into account folding.
FoldManager fm = null;
if (textArea instanceof RSyntaxTextArea) {
fm = ((RSyntaxTextArea)textArea).getFoldManager();
topLine += fm.getHiddenLineCountAbove(topLine, true);
}
final int RHS_BORDER_WIDTH = getRhsBorderWidth();
/*
// Highlight the current line's line number, if desired.
if (textArea.getHighlightCurrentLine() && currentLine>=topLine &&
currentLine<=bottomLine) {
g.setColor(textArea.getCurrentLineHighlightColor());
g.fillRect(0,actualTopY+(currentLine-topLine)*cellHeight,
cellWidth,cellHeight);
}
*/
// Paint line numbers
g.setColor(getForeground());
boolean ltr = getComponentOrientation().isLeftToRight();
if (ltr) {
FontMetrics metrics = g.getFontMetrics();
int rhs = getWidth() - RHS_BORDER_WIDTH;
int line = topLine + 1;
while (y<visibleRect.y+visibleRect.height+ascent && line<=textArea.getLineCount()) {
String number = Integer.toString(line + getLineNumberingStartIndex() - 1);
int width = metrics.stringWidth(number);
g.drawString(number, rhs-width,y);
y += cellHeight;
Fold fold = fm.getFoldForLine(line-1);
// Skip to next line to paint, taking extra care for lines with
// block ends and begins together, e.g. "} else {"
while (fold!=null && fold.isCollapsed()) {
int hiddenLineCount = fold.getLineCount();
if (hiddenLineCount==0) {
// Fold parser identified a 0-line fold region... This
// is really a bug, but we'll handle it gracefully.
break;
}
line += hiddenLineCount;
fold = fm.getFoldForLine(line-1);
}
line++;
}
}
else { // rtl
int line = topLine + 1;
while (y<visibleRect.y+visibleRect.height && line<textArea.getLineCount()) {
String number = Integer.toString(line + getLineNumberingStartIndex() - 1);
g.drawString(number, RHS_BORDER_WIDTH, y);
y += cellHeight;
Fold fold = fm.getFoldForLine(line-1);
// Skip to next line to paint, taking extra care for lines with
// block ends and begins together, e.g. "} else {"
while (fold!=null && fold.isCollapsed()) {
line += fold.getLineCount();
fold = fm.getFoldForLine(line);
}
line++;
}
}