List of utility methods to do JTextComponent Word
int | getNextWord(JTextComponent c, int offs) Determines the start of the next word for the given location. int nextWord; Element line = getParagraphElement(c, offs); for (nextWord = getNextWordInParagraph(c, line, offs, false); nextWord == BreakIterator.DONE; nextWord = getNextWordInParagraph(c, line, offs, true)) { offs = line.getEndOffset(); line = getParagraphElement(c, offs); return nextWord; ... |
int | getNextWordInParagraph(JTextComponent c, Element line, int offs, boolean first) Finds the next word in the given elements text. if (line == null) { throw new BadLocationException("No more words", offs); Document doc = line.getDocument(); int lineStart = line.getStartOffset(); int lineEnd = Math.min(line.getEndOffset(), doc.getLength()); if ((offs >= lineEnd) || (offs < lineStart)) { throw new BadLocationException("No more words", offs); ... |
String | getPartialWordBeforePos(JTextComponent editor, int iPos) get Partial Word Before Pos try { int iNonWhitespace = findNonWhitespacePositionBefore(editor.getText(), iPos - 1); int iStart = getWordStart(editor, iNonWhitespace); return editor.getText(iStart, iPos - iStart).trim(); } catch (BadLocationException e) { return ""; |
int | getPreviousWord(JTextComponent editor, int iOffset) get Previous Word String text = editor.getText(); int iStart = getWordStart(editor, iOffset); for (iOffset = iStart - 1; iOffset >= 0 && Character.isWhitespace(text.charAt(iOffset)); iOffset--) ; if (iOffset < 0) { return iStart; return getWordStart(editor, iOffset); ... |
String | getWordAtCaret(JTextComponent editor) get Word At Caret try { int iCaretPos = editor.getCaretPosition(); int iStart = getWordStart(editor, iCaretPos); int iEnd = getWordEnd(editor, iCaretPos); return editor.getText(iStart, iEnd - iStart); } catch (BadLocationException e) { return getPartialWordBeforeCaret(editor); |
Dimension | getWordDimensionAtCaret(JTextComponent editor) get Word Dimension At Caret try { int iCaretPos = editor.getCaretPosition(); int iStart = getWordStart(editor, iCaretPos); int iEnd = getWordEnd(editor, iCaretPos); editor.getText(iStart, iEnd - iStart); return new Dimension(iStart, iEnd); } catch (BadLocationException e) { return getWordDimensionBeforeCaret(editor); ... |
Dimension | getWordDimensionBeforeCaret(JTextComponent editor) get Word Dimension Before Caret try { int iEnd = editor.getCaretPosition(); int iStart = getPreviousWord(editor, iEnd); editor.getText(iStart, iEnd - iStart); return new Dimension(iStart, iEnd); } catch (BadLocationException e) { return null; |
int | getWordEnd(JTextComponent c, int offs) Determines the end of a word for the given model location. int result = Utilities.getWordEnd(c, offs); if (result > 0) { char ch = c.getDocument().getText(result - 1, 1).charAt(0); if (isDirectionChar(ch)) { result--; return result; ... |
int | getWordEnd(JTextComponent editor, int iOffset) get Word End String text = editor.getText(); iOffset = maybeAdjustOffsetToNextWord(text, iOffset); int iEnd = iOffset; for (; iEnd < text.length() && Character.isJavaIdentifierPart(text.charAt(iEnd)); iEnd++) ; if (iEnd == iOffset && !Character.isWhitespace(text.charAt(iEnd))) { iEnd++; return iEnd; |
int | getWordStart(JTextComponent c, int offs) Determines the start of a word for the given model location. Document doc = c.getDocument(); Element line = getParagraphElement(c, offs); if (line == null) { throw new BadLocationException("No word at " + offs, offs); int lineStart = line.getStartOffset(); int lineEnd = Math.min(line.getEndOffset(), doc.getLength()); String s = doc.getText(lineStart, lineEnd - lineStart); ... |