protected void paintHighlight(Graphics gfx, int line, int y) { if (line >= textArea.getSelectionStartLine() && line <= textArea.getSelectionEndLine()) paintLineHighlight(gfx, line, y); if (highlights != null) highlights.paintHighlight(gfx, line, y); if (bracketHighlight && line == textArea.getBracketLine()) paintBracketHighlight(gfx, line, y); if (line == textArea.getCaretLine()) paintCaret(gfx, line, y); }
protected void paintLineHighlight(Graphics gfx, int line, int y) { int height = fm.getHeight(); y += fm.getLeading() + fm.getMaxDescent(); int selectionStart = textArea.getSelectionStart(); int selectionEnd = textArea.getSelectionEnd(); if (selectionStart == selectionEnd) { if (lineHighlight) { gfx.setColor(lineHighlightColor); gfx.fillRect(0, y, getWidth(), height); } } else { gfx.setColor(selectionColor); int selectionStartLine = textArea.getSelectionStartLine(); int selectionEndLine = textArea.getSelectionEndLine(); int lineStart = textArea.getLineStartOffset(line); int x1, x2; if (textArea.isSelectionRectangular()) { int lineLen = textArea.getLineLength(line); x1 = textArea._offsetToX( line, Math.min( lineLen, selectionStart - textArea.getLineStartOffset(selectionStartLine))); x2 = textArea._offsetToX( line, Math.min(lineLen, selectionEnd - textArea.getLineStartOffset(selectionEndLine))); if (x1 == x2) x2++; } else if (selectionStartLine == selectionEndLine) { x1 = textArea._offsetToX(line, selectionStart - lineStart); x2 = textArea._offsetToX(line, selectionEnd - lineStart); } else if (line == selectionStartLine) { x1 = textArea._offsetToX(line, selectionStart - lineStart); x2 = getWidth(); } else if (line == selectionEndLine) { x1 = 0; x2 = textArea._offsetToX(line, selectionEnd - lineStart); } else { x1 = 0; x2 = getWidth(); } // "inlined" min/max() gfx.fillRect(x1 > x2 ? x2 : x1, y, x1 > x2 ? (x1 - x2) : (x2 - x1), height); } }