Package editor.util
Class TextComponentUtil
- java.lang.Object
-
- editor.util.TextComponentUtil
-
public class TextComponentUtil extends Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTextComponentUtil.Direction
-
Constructor Summary
Constructors Constructor Description TextComponentUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intadjustForLineComment(JTextComponent editor, int iStart)static voiddeleteWordAtCaret(JTextComponent editor)static voidexpandSelectionIfNeeded(JTextComponent editor)static 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)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 StringgetIdentifierAtCaret(EditorHostTextPane editor)static 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 DimensiongetMemberDimensionAtCaret(JTextComponent editor)static intgetNextWordPostition(int pos, String source, boolean consumeWhitespaceFirst)static StringgetPartialWordBeforeCaret(JTextComponent editor)static StringgetPartialWordBeforePos(JTextComponent editor, int iPos)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 DimensiongetWordDimensionAtCaret(JTextComponent editor)static DimensiongetWordDimensionBeforeCaret(JTextComponent editor)static intgetWordEnd(JTextComponent editor, int iOffset)static intgetWordStart(JTextComponent editor, int iOffset)static voidhandleHomeKey(JTextComponent editor)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)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)static voidselectLeft(JTextComponent editor)static voidselectLineAtCaret(JTextComponent editor)static voidselectRight(JTextComponent editor)static voidselectWordAtCaret(JTextComponent editor)static voidshowPasteBufferDialogForComponent(JTextComponent component)static voidunindentLineAtCaret(JTextComponent editor)
-
-
-
Method Detail
-
findCharacterPositionOnLine
public static int findCharacterPositionOnLine(int startPosition, String string, char charToFind, TextComponentUtil.Direction d)
-
getWordAtCaret
public static String getWordAtCaret(JTextComponent editor)
-
getPartialWordBeforeCaret
public static String getPartialWordBeforeCaret(JTextComponent editor)
-
getPartialWordBeforePos
public static String getPartialWordBeforePos(JTextComponent editor, int iPos)
-
getWordDimensionAtCaret
public static Dimension getWordDimensionAtCaret(JTextComponent editor)
-
getWordDimensionBeforeCaret
public static Dimension getWordDimensionBeforeCaret(JTextComponent editor)
-
getMemberDimensionAtCaret
public static Dimension getMemberDimensionAtCaret(JTextComponent editor)
-
getMemberAtCaret
public static String getMemberAtCaret(JTextComponent editor)
-
selectWordAtCaret
public static void selectWordAtCaret(JTextComponent editor)
-
replaceWordAtClosestDot
public static void replaceWordAtClosestDot(JTextComponent editor, String strText)
-
replaceWordAtCaret
public static int replaceWordAtCaret(JTextComponent editor, String strText)
- Returns:
- offset of replaced word
-
replaceWordBeforeCaret
public static int replaceWordBeforeCaret(JTextComponent editor, String strText)
- Returns:
- offset of replaced word
-
replaceWordAtCaretNice
public static void replaceWordAtCaretNice(JTextComponent editor, String strText)
-
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)
-
getWordStart
public static int getWordStart(JTextComponent editor, int iOffset) throws BadLocationException
- Throws:
BadLocationException
-
getWordEnd
public static int getWordEnd(JTextComponent editor, int iOffset) throws BadLocationException
- Throws:
BadLocationException
-
adjustForLineComment
public static int adjustForLineComment(JTextComponent editor, int iStart) throws BadLocationException
- Throws:
BadLocationException
-
isNonWhitespaceBetween
public static boolean isNonWhitespaceBetween(JTextComponent editor, int iStart, int iEnd)
-
getLineStartAndEndPositions
public static int[] getLineStartAndEndPositions(String text, int initialCaretPosition)
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
public static int getLineStart(String text, int initialCaretPosition)
-
getLineEnd
public static int getLineEnd(String text, int initialCaretPosition)
-
deleteWordAtCaret
public static void deleteWordAtCaret(JTextComponent editor) throws BadLocationException
- Throws:
BadLocationException
-
findPreviousTextChunk
protected static String findPreviousTextChunk(int startPosition, String text)
-
getLineAtPosition
public static int getLineAtPosition(JTextComponent editor, int position)
Gets the line at a given position in the editor
-
getColumnAtPosition
public static int getColumnAtPosition(JTextComponent editor, int caretPosition)
-
getWhiteSpaceLineStartBefore
public static int getWhiteSpaceLineStartBefore(String script, int start)
Returns the start of the previous line if that line is only whitespace. Returns -1 otherwise.
-
getWhiteSpaceLineStartAfter
public static int getWhiteSpaceLineStartAfter(String script, int end)
Returns the start of the next line if that line is only whitespace. Returns -1 otherwise.
-
getWhiteSpaceOrCommentLineStartBefore
public static int getWhiteSpaceOrCommentLineStartBefore(String script, int start)
Returns the start of the previous line if that line is only whitespace. Returns -1 otherwise.
-
getWhiteSpaceOrCommentLineStartAfter
public static int getWhiteSpaceOrCommentLineStartAfter(String script, int end)
Returns the start of the next line if that line is only whitespace. Returns -1 otherwise.
-
getDeepestWhiteSpaceLineStartAfter
public 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.
-
findNonWhitespacePositionAfter
public static int findNonWhitespacePositionAfter(String script, int position)
- Returns:
- the next non-whitespace position in the given script
-
findNonWhitespacePositionBefore
public static int findNonWhitespacePositionBefore(String script, int position)
- Returns:
- the first non-whitespace position in the given script before the given position
-
getNextWordPostition
public static int getNextWordPostition(int pos, String source, boolean consumeWhitespaceFirst)
-
fixTextComponentKeyMap
public static void fixTextComponentKeyMap(JTextComponent editor)
-
expandSelectionIfNeeded
public static void expandSelectionIfNeeded(JTextComponent editor)
-
selectLineAtCaret
public static void selectLineAtCaret(JTextComponent editor)
-
selectRight
public static void selectRight(JTextComponent editor)
-
jumpRight
public static void jumpRight(JTextComponent editor)
-
jumpLeft
public static void jumpLeft(JTextComponent editor)
-
selectLeft
public static void selectLeft(JTextComponent editor)
-
handleHomeKey
public static void handleHomeKey(JTextComponent editor)
-
showPasteBufferDialogForComponent
public static void showPasteBufferDialogForComponent(JTextComponent component)
-
unindentLineAtCaret
public static void unindentLineAtCaret(JTextComponent editor) throws BadLocationException
- Throws:
BadLocationException
-
getIdentifierAtCaret
public static String getIdentifierAtCaret(EditorHostTextPane editor)
-
isValidIdentifier
public static boolean isValidIdentifier(CharSequence seqId, boolean acceptDot)
-
-