Element root = doc.getDefaultRootElement();
int lineCount = root.getElementCount();
int topPosition = textArea.viewToModel(
new Point(visibleRect.x,visibleRect.y));
int topLine = root.getElementIndex(topPosition);
FoldManager fm = null;
if (textArea instanceof RSyntaxTextArea) {
fm = ((RSyntaxTextArea)textArea).getFoldManager();
}
// Compute the y at which to begin painting text, taking into account
// that 1 logical line => at least 1 physical line, so it may be that
// y<0. The computed y-value is the y-value of the top of the first
// (possibly) partially-visible view.
Rectangle visibleEditorRect = ui.getVisibleEditorRect();
Rectangle r = LineNumberList.getChildViewBounds(v, topLine,
visibleEditorRect);
int y = r.y;
final int RHS_BORDER_WIDTH = getRhsBorderWidth();
int rhs;
boolean ltr = getComponentOrientation().isLeftToRight();
if (ltr) {
rhs = width - RHS_BORDER_WIDTH;
}
else { // rtl
rhs = RHS_BORDER_WIDTH;
}
int visibleBottom = visibleRect.y + visibleRect.height;
FontMetrics metrics = g.getFontMetrics();
// Keep painting lines until our y-coordinate is past the visible
// end of the text area.
g.setColor(getForeground());
while (y < visibleBottom) {
r = LineNumberList.getChildViewBounds(v, topLine, visibleEditorRect);
/*
// Highlight the current line's line number, if desired.
if (currentLineHighlighted && topLine==currentLine) {
g.setColor(textArea.getCurrentLineHighlightColor());
g.fillRect(0,y, width,(r.y+r.height)-y);
g.setColor(getForeground());
}
*/
// Paint the line number.
int index = (topLine+1) + getLineNumberingStartIndex() - 1;
String number = Integer.toString(index);
if (ltr) {
int strWidth = metrics.stringWidth(number);
g.drawString(number, rhs-strWidth,y+ascent);
}
else {
int x = RHS_BORDER_WIDTH;
g.drawString(number, x, y+ascent);
}
// The next possible y-coordinate is just after the last line
// painted.
y += r.height;
// Update topLine (we're actually using it for our "current line"
// variable now).
if (fm!=null) {
Fold fold = fm.getFoldForLine(topLine);
if (fold!=null && fold.isCollapsed()) {
topLine += fold.getCollapsedLineCount();
}
}
topLine++;