void (Graphics g, Rectangle clip) { int lineHeight = getLineHeight(); int visibleLineNumber = clip.y / lineHeight; int startLineNumber = xyToLogicalPosition(new Point(0, clip.y)).line; if (startLineNumber >= myDocument.getLineCount() || startLineNumber < 0) { return; } int start = myDocument.getLineStartOffset(startLineNumber); IterationState iterationState = new IterationState(this, start, true); LineIterator lIterator = createLineIterator(); lIterator.start(start); if (lIterator.atEnd()) { return; } TextAttributes attributes = iterationState.getMergedAttributes(); Color backColor = attributes.getBackgroundColor(); Point position = new Point(0, visibleLineNumber * lineHeight); int fontType = attributes.getFontType(); CharSequence text = myDocument.getCharsNoThreadCheck(); int lastLineIndex = Math.max(0, myDocument.getLineCount() - 1); while (!iterationState.atEnd() && !lIterator.atEnd()) { int hEnd = iterationState.getEndOffset(); int lEnd = lIterator.getEnd(); if (hEnd >= lEnd) { FoldRegion collapsedFolderAt = myFoldingModel.getCollapsedRegionAtOffset(start); if (collapsedFolderAt == null) { position.x = drawBackground(g, backColor, text.subSequence(start, lEnd - lIterator.getSeparatorLength()), position, fontType); if (lIterator.getLineNumber() < lastLineIndex) { if (backColor != null) { Color saved = g.getColor(); g.setColor(backColor); g.fillRect(position.x, position.y, clip.x + clip.width - position.x, lineHeight); g.setColor(saved); } } else { paintAfterFileEndBackground(iterationState, g, position, clip, lineHeight); break; } position.x = 0; if (position.y > clip.y + clip.height) break; position.y += lineHeight; start = lEnd; } lIterator.advance(); } else { FoldRegion collapsedFolderAt = iterationState.getCurrentFold(); if (collapsedFolderAt != null) { position.x = drawBackground(g, backColor, collapsedFolderAt.getPlaceholderText(), position, fontType); } else { if (hEnd > lEnd - lIterator.getSeparatorLength()) { position.x = drawBackground(g, backColor, text.subSequence(start, lEnd - lIterator.getSeparatorLength()), position, fontType); } else { position.x = drawBackground(g, backColor, text.subSequence(start, hEnd), position, fontType); } } iterationState.advance(); attributes = iterationState.getMergedAttributes(); backColor = attributes.getBackgroundColor(); fontType = attributes.getFontType(); start = iterationState.getStartOffset(); } } if (lIterator.getLineNumber() >= lastLineIndex && position.y <= clip.y + clip.height) { paintAfterFileEndBackground(iterationState, g, position, clip, lineHeight); } }