/** * Converts an offset in a line into an x co-ordinate. This is a * slow version that can be used any time. * @param line The line * @param offset The offset, from the start of the line */ public final int offsetToX(int line, int offset) { // don't use cached tokens painter.currentLineTokens = null; return _offsetToX(line,offset); }
protected void paintBracketHighlight(Graphics gfx, int line, int y) { int position = textArea.getBracketPosition(); if(position == -1) return; y += fm.getLeading() + fm.getMaxDescent(); int x = textArea._offsetToX(line,position); gfx.setColor(bracketHighlightColor); // Hack!!! Since there is no fast way to get the character // from the bracket matching routine, we use ( since all // brackets probably have the same width anyway gfx.drawRect(x,y,fm.charWidth('(') - 1, fm.getHeight() - 1); }
protected void paintCaret(Graphics gfx, int line, int y) { if(textArea.isCaretVisible()) { int offset = textArea.getCaretPosition() - textArea.getLineStartOffset(line); int caretX = textArea._offsetToX(line,offset); int caretWidth = ((blockCaret || textArea.isOverwriteEnabled()) ? fm.charWidth('w') : 1); y += fm.getLeading() + fm.getMaxDescent(); int height = fm.getHeight(); gfx.setColor(caretColor); if(textArea.isOverwriteEnabled()) { gfx.fillRect(caretX,y + height - 1, caretWidth,1); } else { gfx.drawRect(caretX,y,caretWidth - 1,height - 1); } } } }
x1 = textArea._offsetToX(line,Math.min(lineLen, selectionStart - textArea.getLineStartOffset( selectionStartLine))); x2 = textArea._offsetToX(line,Math.min(lineLen, selectionEnd - textArea.getLineStartOffset( selectionEndLine))); x1 = textArea._offsetToX(line, selectionStart - lineStart); x2 = textArea._offsetToX(line, selectionEnd - lineStart); x1 = textArea._offsetToX(line, selectionStart - lineStart); x2 = getWidth(); x2 = textArea._offsetToX(line, selectionEnd - lineStart);
int x = _offsetToX(line,offset); int width = painter.getFontMetrics().charWidth('w');