Package editor.util
Class TextComponentUtil
java.lang.Object
editor.util.TextComponentUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classprivate static classprivate static classstatic enumprivate static classprivate static classprivate static classprivate static classprivate static classprivate static class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intadjustForLineComment(JTextComponent editor, int iStart) static voiddeleteWordAtCaret(JTextComponent editor) static voidstatic intfindCharacterPositionOnLine(int startPosition, String string, char charToFind, TextComponentUtil.Direction d) static intfindNonWhitespacePositionAfter(String script, int position) static intfindNonWhitespacePositionBefore(String script, int position) protected static StringfindPreviousTextChunk(int startPosition, String text) static voidfixTextComponentKeyMap(JTextComponent editor) private static intgetCharClass(char c) static intgetColumnAtPosition(JTextComponent editor, int caretPosition) static intgetDeepestWhiteSpaceLineStartAfter(String script, int offset) Eats whitespace lines after the given offset until it finds a non-whitespace line and returns the start of the last whitespace line found, or the initial value if none was.static Stringstatic intgetLineAtPosition(JTextComponent editor, int position) Gets the line at a given position in the editorstatic intgetLineEnd(String text, int initialCaretPosition) static intgetLineStart(String text, int initialCaretPosition) static int[]getLineStartAndEndPositions(String text, int initialCaretPosition) This will return a two element array, start line pos and end line pos.static StringgetMemberAtCaret(JTextComponent editor) static Dimensionstatic intgetNextWordPostition(int pos, String source, boolean consumeWhitespaceFirst) static Stringstatic StringgetPartialWordBeforePos(JTextComponent editor, int iPos) private static intgetPreviousWord(JTextComponent editor, int iOffset) static intgetWhiteSpaceLineStartAfter(String script, int end) Returns the start of the next line if that line is only whitespace.static intgetWhiteSpaceLineStartBefore(String script, int start) Returns the start of the previous line if that line is only whitespace.static intgetWhiteSpaceOrCommentLineStartAfter(String script, int end) Returns the start of the next line if that line is only whitespace.static intgetWhiteSpaceOrCommentLineStartBefore(String script, int start) Returns the start of the previous line if that line is only whitespace.static StringgetWordAtCaret(JTextComponent editor) static Dimensionstatic Dimensionstatic intgetWordEnd(JTextComponent editor, int iOffset) static intgetWordStart(JTextComponent editor, int iOffset) static voidhandleHomeKey(JTextComponent editor) private static booleanisAdditionalSymbol(String currWord, String strPossibleAdditionalSymbol, String symbol) static booleanisNonWhitespaceBetween(JTextComponent editor, int iStart, int iEnd) static booleanisValidIdentifier(CharSequence seqId, boolean acceptDot) static voidjumpLeft(JTextComponent editor) static voidjumpRight(JTextComponent editor) static StringmakeValidIdentifier(String str, boolean acceptDot, boolean bAcceptUnderscore) private static intmaybeAdjustOffsetToNextWord(String text, int iOffset) private static voidperformCompoundUndableEdit(JTextComponent editor, Runnable edit) static intreplaceWordAtCaret(JTextComponent editor, String strText) static voidreplaceWordAtCaretDynamic(JTextComponent editor, String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord) static voidreplaceWordAtCaretDynamicAndRemoveEmptyParens(JTextComponent editor, String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord) static voidreplaceWordAtCaretNice(JTextComponent editor, String strText) static voidreplaceWordAtClosestDot(JTextComponent editor, String strText) static intreplaceWordBeforeCaret(JTextComponent editor, String strText) private static voidselectFirstArg(String strText, int initialSelectionStart, JTextComponent editor) static voidselectLeft(JTextComponent editor) static voidselectLineAtCaret(JTextComponent editor) static voidselectRight(JTextComponent editor) static voidselectWordAtCaret(JTextComponent editor) static voidshowPasteBufferDialogForComponent(JTextComponent component) static voidunindentLineAtCaret(JTextComponent editor)
-
Field Details
-
SIGNIFICANT_CHARS
-
SHOW_PASTE_BUFFER
- See Also:
-
-
Constructor Details
-
TextComponentUtil
public TextComponentUtil()
-
-
Method Details
-
findCharacterPositionOnLine
public static int findCharacterPositionOnLine(int startPosition, String string, char charToFind, TextComponentUtil.Direction d) -
getWordAtCaret
-
getPartialWordBeforeCaret
-
getPartialWordBeforePos
-
getWordDimensionAtCaret
-
getWordDimensionBeforeCaret
-
getMemberDimensionAtCaret
-
getMemberAtCaret
-
selectWordAtCaret
-
replaceWordAtClosestDot
-
selectFirstArg
private static void selectFirstArg(String strText, int initialSelectionStart, JTextComponent editor) throws BadLocationException - Throws:
BadLocationException
-
replaceWordAtCaret
- Returns:
- offset of replaced word
-
replaceWordBeforeCaret
- Returns:
- offset of replaced word
-
replaceWordAtCaretNice
-
replaceWordAtCaretDynamic
public static void replaceWordAtCaretDynamic(JTextComponent editor, String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord) -
replaceWordAtCaretDynamicAndRemoveEmptyParens
public static void replaceWordAtCaretDynamicAndRemoveEmptyParens(JTextComponent editor, String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord) -
performCompoundUndableEdit
-
getWordStart
- Throws:
BadLocationException
-
getWordEnd
- Throws:
BadLocationException
-
maybeAdjustOffsetToNextWord
private static int maybeAdjustOffsetToNextWord(String text, int iOffset) throws BadLocationException - Throws:
BadLocationException
-
getPreviousWord
- Throws:
BadLocationException
-
adjustForLineComment
public static int adjustForLineComment(JTextComponent editor, int iStart) throws BadLocationException - Throws:
BadLocationException
-
isNonWhitespaceBetween
-
isAdditionalSymbol
-
getLineStartAndEndPositions
This will return a two element array, start line pos and end line pos. The character from the document for the startPos will be the first character of the line The character from the document for the endPos will be the last character of the line, i.e. the char before the new line if one is present.- Returns:
- a two element array with the start and end positions of the given line
-
getLineStart
-
getLineEnd
-
deleteWordAtCaret
- Throws:
BadLocationException
-
findPreviousTextChunk
-
getLineAtPosition
Gets the line at a given position in the editor -
getColumnAtPosition
-
getWhiteSpaceLineStartBefore
Returns the start of the previous line if that line is only whitespace. Returns -1 otherwise. -
getWhiteSpaceLineStartAfter
Returns the start of the next line if that line is only whitespace. Returns -1 otherwise. -
getWhiteSpaceOrCommentLineStartBefore
Returns the start of the previous line if that line is only whitespace. Returns -1 otherwise. -
getWhiteSpaceOrCommentLineStartAfter
Returns the start of the next line if that line is only whitespace. Returns -1 otherwise. -
getDeepestWhiteSpaceLineStartAfter
Eats whitespace lines after the given offset until it finds a non-whitespace line and returns the start of the last whitespace line found, or the initial value if none was. -
findNonWhitespacePositionAfter
- Returns:
- the next non-whitespace position in the given script
-
findNonWhitespacePositionBefore
- Returns:
- the first non-whitespace position in the given script before the given position
-
getNextWordPostition
-
getCharClass
private static int getCharClass(char c) -
fixTextComponentKeyMap
-
expandSelectionIfNeeded
-
selectLineAtCaret
-
selectRight
-
jumpRight
-
jumpLeft
-
selectLeft
-
handleHomeKey
-
showPasteBufferDialogForComponent
-
unindentLineAtCaret
- Throws:
BadLocationException
-
getIdentifierAtCaret
-
isValidIdentifier
-
makeValidIdentifier
-