Graphics2D g2d = (Graphics2D)g;
host = (RSyntaxTextArea)getContainer();
int ascent = host.getMaxAscent();
int fontHeight = host.getLineHeight();
FoldManager fm = host.getFoldManager();
TokenPainter painter = host.getTokenPainter();
Element root = getElement();
// Whether token styles should always be painted, even in selections
int selStart = host.getSelectionStart();
int selEnd = host.getSelectionEnd();
boolean useSelectedTextColor = host.getUseSelectedTextColor();
int n = getViewCount(); // Number of lines.
int x = alloc.x + getLeftInset();
tempRect.y = alloc.y + getTopInset();
Rectangle clip = g.getClipBounds();
for (int i = 0; i < n; i++) {
tempRect.x = x + getOffset(X_AXIS, i);
//tempRect.y = y + getOffset(Y_AXIS, i);
tempRect.width = getSpan(X_AXIS, i);
tempRect.height = getSpan(Y_AXIS, i);
//System.err.println("For line " + i + ": tempRect==" + tempRect);
if (tempRect.intersects(clip)) {
Element lineElement = root.getElement(i);
int startOffset = lineElement.getStartOffset();
int endOffset = lineElement.getEndOffset()-1; // Why always "-1"?
View view = getView(i);
if (!useSelectedTextColor || selStart==selEnd ||
(startOffset>=selEnd || endOffset<selStart)) {
drawView(painter, g2d, alloc, view, fontHeight,
tempRect.y+ascent);
}
else {
//System.out.println("Drawing line with selection: " + i);
drawViewWithSelection(painter, g2d, alloc, view, fontHeight,
tempRect.y+ascent, selStart, selEnd);
}
}
tempRect.y += tempRect.height;
Fold possibleFold = fm.getFoldForLine(i);
if (possibleFold!=null && possibleFold.isCollapsed()) {
i += possibleFold.getCollapsedLineCount();
// Visible indicator of collapsed lines
Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
if (c!=null) {