protected void paintLineNumbers(Graphics gfx) {
		FontMetrics pfm = textArea.getPainter().getFontMetrics();
		int lineHeight = pfm.getHeight();
		int baseline = (int) Math.round((this.baseline + lineHeight - pfm
				.getMaxDescent()) / 2.0);

		int firstLine = textArea.getFirstLine() + 1;
		int lastLine = firstLine + (getHeight() / lineHeight);

		int firstValidLine = (int) Math.max(1, firstLine);
		int lastValidLine = (int) Math.min(textArea.getLineCount(), lastLine);

		gfx.setFont(getFont());

		gfx.setColor(getForeground());

		String number;

		for (int line = firstLine; line <= lastLine; line++, baseline += lineHeight) {
			// only print numbers for valid lines
			if (line < firstValidLine || line > lastValidLine)
				continue;

			number = Integer.toString(line);

			int offset;

			switch (alignment) {
			case RIGHT:
				offset = gutterSize.width - collapsedSize.width
						- (fm.stringWidth(number) + 1);
				break;
			case CENTER:
				offset = ((gutterSize.width - collapsedSize.width) - fm
						.stringWidth(number)) / 2;
				break;
			case LEFT:
			default:
				offset = 1;
			}

			if (interval > 1 && line % interval == 0) {
				gfx.setColor(getHighlightedForeground());
				gfx.drawString(number, ileft + offset, baseline);
				gfx.setColor(getForeground());
			} else {
				gfx.drawString(number, ileft + offset, baseline);
			}
		}
	}