Package editor.util
Class TextComponentUtil
java.lang.Object
editor.util.TextComponentUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
private static class
private static class
static enum
private static class
private static class
private static class
private static class
private static class
private static class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
adjustForLineComment
(JTextComponent editor, int iStart) static void
deleteWordAtCaret
(JTextComponent editor) static void
static int
findCharacterPositionOnLine
(int startPosition, String string, char charToFind, TextComponentUtil.Direction d) static int
findNonWhitespacePositionAfter
(String script, int position) static int
findNonWhitespacePositionBefore
(String script, int position) protected static String
findPreviousTextChunk
(int startPosition, String text) static void
fixTextComponentKeyMap
(JTextComponent editor) private static int
getCharClass
(char c) static int
getColumnAtPosition
(JTextComponent editor, int caretPosition) static int
getDeepestWhiteSpaceLineStartAfter
(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 String
static int
getLineAtPosition
(JTextComponent editor, int position) Gets the line at a given position in the editorstatic int
getLineEnd
(String text, int initialCaretPosition) static int
getLineStart
(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 String
getMemberAtCaret
(JTextComponent editor) static Dimension
static int
getNextWordPostition
(int pos, String source, boolean consumeWhitespaceFirst) static String
static String
getPartialWordBeforePos
(JTextComponent editor, int iPos) private static int
getPreviousWord
(JTextComponent editor, int iOffset) static int
getWhiteSpaceLineStartAfter
(String script, int end) Returns the start of the next line if that line is only whitespace.static int
getWhiteSpaceLineStartBefore
(String script, int start) Returns the start of the previous line if that line is only whitespace.static int
getWhiteSpaceOrCommentLineStartAfter
(String script, int end) Returns the start of the next line if that line is only whitespace.static int
getWhiteSpaceOrCommentLineStartBefore
(String script, int start) Returns the start of the previous line if that line is only whitespace.static String
getWordAtCaret
(JTextComponent editor) static Dimension
static Dimension
static int
getWordEnd
(JTextComponent editor, int iOffset) static int
getWordStart
(JTextComponent editor, int iOffset) static void
handleHomeKey
(JTextComponent editor) private static boolean
isAdditionalSymbol
(String currWord, String strPossibleAdditionalSymbol, String symbol) static boolean
isNonWhitespaceBetween
(JTextComponent editor, int iStart, int iEnd) static boolean
isValidIdentifier
(CharSequence seqId, boolean acceptDot) static void
jumpLeft
(JTextComponent editor) static void
jumpRight
(JTextComponent editor) static String
makeValidIdentifier
(String str, boolean acceptDot, boolean bAcceptUnderscore) private static int
maybeAdjustOffsetToNextWord
(String text, int iOffset) private static void
performCompoundUndableEdit
(JTextComponent editor, Runnable edit) static int
replaceWordAtCaret
(JTextComponent editor, String strText) static void
replaceWordAtCaretDynamic
(JTextComponent editor, String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord) static void
replaceWordAtCaretDynamicAndRemoveEmptyParens
(JTextComponent editor, String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord) static void
replaceWordAtCaretNice
(JTextComponent editor, String strText) static void
replaceWordAtClosestDot
(JTextComponent editor, String strText) static int
replaceWordBeforeCaret
(JTextComponent editor, String strText) private static void
selectFirstArg
(String strText, int initialSelectionStart, JTextComponent editor) static void
selectLeft
(JTextComponent editor) static void
selectLineAtCaret
(JTextComponent editor) static void
selectRight
(JTextComponent editor) static void
selectWordAtCaret
(JTextComponent editor) static void
showPasteBufferDialogForComponent
(JTextComponent component) static void
unindentLineAtCaret
(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
-