if (isSingleLine()) { lineCount = 1; if (startLine > 1) { startLine = 1; } } font = event.gc.getFont(); fontData = font.getFontData()[0]; lineBuffer = new Image(getDisplay(), clientArea.width, renderHeight); lineGC = new GC(lineBuffer); lineGC.setFont(font); lineGC.setForeground(foreground); lineGC.setBackground(background); for (int i = startLine; paintY < renderHeight && i < lineCount; i++, paintY += lineHeight) { String line = content.getLine(i); renderer.drawLine(line, i, paintY, lineGC, background, foreground, fontData, true); } if (paintY < renderHeight) { lineGC.setBackground(background); lineGC.setForeground(background); lineGC.fillRectangle(0, paintY, clientArea.width, renderHeight - paintY); } event.gc.drawImage(lineBuffer, 0, startY); lineGC.dispose(); lineBuffer.dispose();  event.gc.setBackground(background); event.gc.fillRectangle(0, 0, clientArea.width, topMargin); event.gc.fillRectangle(0, 0, leftMargin, renderHeight); event.gc.fillRectangle( 0, clientArea.height - bottomMargin, clientArea.width, bottomMargin); event.gc.fillRectangle( clientArea.width - rightMargin, 0, rightMargin, renderHeight);
performPaint(event.gc, startLine, startY, renderHeight);
void handlePaint(Event event) {	int startLine = Math.max(0, (event.y - topMargin + verticalScrollOffset) / lineHeight);	int paintYFromTopLine = (startLine - topIndex) * lineHeight;	int topLineOffset = topIndex * lineHeight - verticalScrollOffset;	int startY = paintYFromTopLine + topLineOffset;	// adjust y position for pixel based scrolling	int renderHeight = event.y + event.height - startY;	int paintY = topMargin;	int lineCount = content.getLineCount();	Rectangle clientArea = getClientArea();	Color background = getBackground();	Color foreground = getForeground();	Image lineBuffer;	GC lineGC;	Font font;	FontData fontData;		// Check if there is work to do. clientArea.width should never be 0	// if we receive a paint event but we never want to try and create 	// an Image with 0 width.	if (clientArea.width == 0 || event.height == 0) {				return;	}	if (isSingleLine()) {		lineCount = 1;		if (startLine > 1) {			startLine = 1;		}	}	font = event.gc.getFont();	fontData = font.getFontData()[0];	lineBuffer = new Image(getDisplay(), clientArea.width, renderHeight);	lineGC = new GC(lineBuffer);		lineGC.setFont(font);	lineGC.setForeground(foreground);	lineGC.setBackground(background);	for (int i = startLine; paintY < renderHeight && i < lineCount; i++, paintY += lineHeight) {		String line = content.getLine(i);		renderer.drawLine(line, i, paintY, lineGC, background, foreground, fontData, true);	}	if (paintY < renderHeight) {		lineGC.setBackground(background);		lineGC.setForeground(background);		lineGC.fillRectangle(0, paintY, clientArea.width, renderHeight - paintY);	}	event.gc.drawImage(lineBuffer, 0, startY);	lineGC.dispose();	lineBuffer.dispose();	// clear the margin background	event.gc.setBackground(background);	event.gc.fillRectangle(0, 0, clientArea.width, topMargin);	event.gc.fillRectangle(0, 0, leftMargin, renderHeight);		event.gc.fillRectangle(		0, clientArea.height - bottomMargin, 		clientArea.width, bottomMargin);	event.gc.fillRectangle(		clientArea.width - rightMargin, 0, 		rightMargin, renderHeight);}