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 class
TextComponentUtil.Direction
-
Constructor Summary
Constructors Constructor Description TextComponentUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
adjustForLineComment(JTextComponent editor, int iStart)
static void
deleteWordAtCaret(JTextComponent editor)
static void
expandSelectionIfNeeded(JTextComponent editor)
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)
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
getIdentifierAtCaret(EditorHostTextPane editor)
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
getMemberDimensionAtCaret(JTextComponent editor)
static int
getNextWordPostition(int pos, String source, boolean consumeWhitespaceFirst)
static String
getPartialWordBeforeCaret(JTextComponent editor)
static String
getPartialWordBeforePos(JTextComponent editor, int iPos)
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
getWordDimensionAtCaret(JTextComponent editor)
static Dimension
getWordDimensionBeforeCaret(JTextComponent editor)
static int
getWordEnd(JTextComponent editor, int iOffset)
static int
getWordStart(JTextComponent editor, int iOffset)
static void
handleHomeKey(JTextComponent editor)
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)
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)
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)
-
-
-
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)
-
-