Package editor.util
Class TextComponentUtil
- java.lang.Object
-
- editor.util.TextComponentUtil
-
public class TextComponentUtil extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTextComponentUtil.CustomCopyActionprivate static classTextComponentUtil.CustomCutActionprivate static classTextComponentUtil.CustomHomeActionstatic classTextComponentUtil.Directionprivate static classTextComponentUtil.JumpLeftActionprivate static classTextComponentUtil.JumpRightActionprivate static classTextComponentUtil.KeyMapControllerprivate static classTextComponentUtil.SelectLeftActionprivate static classTextComponentUtil.SelectRightActionprivate static classTextComponentUtil.ShowPasteBufferAction
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringSHOW_PASTE_BUFFERprivate static java.util.Set<java.lang.String>SIGNIFICANT_CHARS
-
Constructor Summary
Constructors Constructor Description TextComponentUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static intadjustForLineComment(javax.swing.text.JTextComponent editor, int iStart)static voiddeleteWordAtCaret(javax.swing.text.JTextComponent editor)static voidexpandSelectionIfNeeded(javax.swing.text.JTextComponent editor)static intfindCharacterPositionOnLine(int startPosition, java.lang.String string, char charToFind, TextComponentUtil.Direction d)static intfindNonWhitespacePositionAfter(java.lang.String script, int position)static intfindNonWhitespacePositionBefore(java.lang.String script, int position)protected static java.lang.StringfindPreviousTextChunk(int startPosition, java.lang.String text)static voidfixTextComponentKeyMap(javax.swing.text.JTextComponent editor)private static intgetCharClass(char c)static intgetColumnAtPosition(javax.swing.text.JTextComponent editor, int caretPosition)static intgetDeepestWhiteSpaceLineStartAfter(java.lang.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 java.lang.StringgetIdentifierAtCaret(EditorHostTextPane editor)static intgetLineAtPosition(javax.swing.text.JTextComponent editor, int position)Gets the line at a given position in the editorstatic intgetLineEnd(java.lang.String text, int initialCaretPosition)static intgetLineStart(java.lang.String text, int initialCaretPosition)static int[]getLineStartAndEndPositions(java.lang.String text, int initialCaretPosition)This will return a two element array, start line pos and end line pos.static java.lang.StringgetMemberAtCaret(javax.swing.text.JTextComponent editor)static java.awt.DimensiongetMemberDimensionAtCaret(javax.swing.text.JTextComponent editor)static intgetNextWordPostition(int pos, java.lang.String source, boolean consumeWhitespaceFirst)static java.lang.StringgetPartialWordBeforeCaret(javax.swing.text.JTextComponent editor)static java.lang.StringgetPartialWordBeforePos(javax.swing.text.JTextComponent editor, int iPos)private static intgetPreviousWord(javax.swing.text.JTextComponent editor, int iOffset)static intgetWhiteSpaceLineStartAfter(java.lang.String script, int end)Returns the start of the next line if that line is only whitespace.static intgetWhiteSpaceLineStartBefore(java.lang.String script, int start)Returns the start of the previous line if that line is only whitespace.static intgetWhiteSpaceOrCommentLineStartAfter(java.lang.String script, int end)Returns the start of the next line if that line is only whitespace.static intgetWhiteSpaceOrCommentLineStartBefore(java.lang.String script, int start)Returns the start of the previous line if that line is only whitespace.static java.lang.StringgetWordAtCaret(javax.swing.text.JTextComponent editor)static java.awt.DimensiongetWordDimensionAtCaret(javax.swing.text.JTextComponent editor)static java.awt.DimensiongetWordDimensionBeforeCaret(javax.swing.text.JTextComponent editor)static intgetWordEnd(javax.swing.text.JTextComponent editor, int iOffset)static intgetWordStart(javax.swing.text.JTextComponent editor, int iOffset)static voidhandleHomeKey(javax.swing.text.JTextComponent editor)private static booleanisAdditionalSymbol(java.lang.String currWord, java.lang.String strPossibleAdditionalSymbol, java.lang.String symbol)static booleanisNonWhitespaceBetween(javax.swing.text.JTextComponent editor, int iStart, int iEnd)static booleanisValidIdentifier(java.lang.CharSequence seqId, boolean acceptDot)static voidjumpLeft(javax.swing.text.JTextComponent editor)static voidjumpRight(javax.swing.text.JTextComponent editor)static java.lang.StringmakeValidIdentifier(java.lang.String str, boolean acceptDot, boolean bAcceptUnderscore)private static intmaybeAdjustOffsetToNextWord(java.lang.String text, int iOffset)private static voidperformCompoundUndableEdit(javax.swing.text.JTextComponent editor, java.lang.Runnable edit)static intreplaceWordAtCaret(javax.swing.text.JTextComponent editor, java.lang.String strText)static voidreplaceWordAtCaretDynamic(javax.swing.text.JTextComponent editor, java.lang.String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord)static voidreplaceWordAtCaretDynamicAndRemoveEmptyParens(javax.swing.text.JTextComponent editor, java.lang.String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord)static voidreplaceWordAtCaretNice(javax.swing.text.JTextComponent editor, java.lang.String strText)static voidreplaceWordAtClosestDot(javax.swing.text.JTextComponent editor, java.lang.String strText)static intreplaceWordBeforeCaret(javax.swing.text.JTextComponent editor, java.lang.String strText)private static voidselectFirstArg(java.lang.String strText, int initialSelectionStart, javax.swing.text.JTextComponent editor)static voidselectLeft(javax.swing.text.JTextComponent editor)static voidselectLineAtCaret(javax.swing.text.JTextComponent editor)static voidselectRight(javax.swing.text.JTextComponent editor)static voidselectWordAtCaret(javax.swing.text.JTextComponent editor)static voidshowPasteBufferDialogForComponent(javax.swing.text.JTextComponent component)static voidunindentLineAtCaret(javax.swing.text.JTextComponent editor)
-
-
-
Field Detail
-
SIGNIFICANT_CHARS
private static final java.util.Set<java.lang.String> SIGNIFICANT_CHARS
-
SHOW_PASTE_BUFFER
private static final java.lang.String SHOW_PASTE_BUFFER
- See Also:
- Constant Field Values
-
-
Method Detail
-
findCharacterPositionOnLine
public static int findCharacterPositionOnLine(int startPosition, java.lang.String string, char charToFind, TextComponentUtil.Direction d)
-
getWordAtCaret
public static java.lang.String getWordAtCaret(javax.swing.text.JTextComponent editor)
-
getPartialWordBeforeCaret
public static java.lang.String getPartialWordBeforeCaret(javax.swing.text.JTextComponent editor)
-
getPartialWordBeforePos
public static java.lang.String getPartialWordBeforePos(javax.swing.text.JTextComponent editor, int iPos)
-
getWordDimensionAtCaret
public static java.awt.Dimension getWordDimensionAtCaret(javax.swing.text.JTextComponent editor)
-
getWordDimensionBeforeCaret
public static java.awt.Dimension getWordDimensionBeforeCaret(javax.swing.text.JTextComponent editor)
-
getMemberDimensionAtCaret
public static java.awt.Dimension getMemberDimensionAtCaret(javax.swing.text.JTextComponent editor)
-
getMemberAtCaret
public static java.lang.String getMemberAtCaret(javax.swing.text.JTextComponent editor)
-
selectWordAtCaret
public static void selectWordAtCaret(javax.swing.text.JTextComponent editor)
-
replaceWordAtClosestDot
public static void replaceWordAtClosestDot(javax.swing.text.JTextComponent editor, java.lang.String strText)
-
selectFirstArg
private static void selectFirstArg(java.lang.String strText, int initialSelectionStart, javax.swing.text.JTextComponent editor) throws javax.swing.text.BadLocationException- Throws:
javax.swing.text.BadLocationException
-
replaceWordAtCaret
public static int replaceWordAtCaret(javax.swing.text.JTextComponent editor, java.lang.String strText)- Returns:
- offset of replaced word
-
replaceWordBeforeCaret
public static int replaceWordBeforeCaret(javax.swing.text.JTextComponent editor, java.lang.String strText)- Returns:
- offset of replaced word
-
replaceWordAtCaretNice
public static void replaceWordAtCaretNice(javax.swing.text.JTextComponent editor, java.lang.String strText)
-
replaceWordAtCaretDynamic
public static void replaceWordAtCaretDynamic(javax.swing.text.JTextComponent editor, java.lang.String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord)
-
replaceWordAtCaretDynamicAndRemoveEmptyParens
public static void replaceWordAtCaretDynamicAndRemoveEmptyParens(javax.swing.text.JTextComponent editor, java.lang.String strText, IReplaceWordCallback replaceWordCallback, boolean selectFirstArg, boolean replaceWholeWord)
-
performCompoundUndableEdit
private static void performCompoundUndableEdit(javax.swing.text.JTextComponent editor, java.lang.Runnable edit)
-
getWordStart
public static int getWordStart(javax.swing.text.JTextComponent editor, int iOffset) throws javax.swing.text.BadLocationException- Throws:
javax.swing.text.BadLocationException
-
getWordEnd
public static int getWordEnd(javax.swing.text.JTextComponent editor, int iOffset) throws javax.swing.text.BadLocationException- Throws:
javax.swing.text.BadLocationException
-
maybeAdjustOffsetToNextWord
private static int maybeAdjustOffsetToNextWord(java.lang.String text, int iOffset) throws javax.swing.text.BadLocationException- Throws:
javax.swing.text.BadLocationException
-
getPreviousWord
private static int getPreviousWord(javax.swing.text.JTextComponent editor, int iOffset) throws javax.swing.text.BadLocationException- Throws:
javax.swing.text.BadLocationException
-
adjustForLineComment
public static int adjustForLineComment(javax.swing.text.JTextComponent editor, int iStart) throws javax.swing.text.BadLocationException- Throws:
javax.swing.text.BadLocationException
-
isNonWhitespaceBetween
public static boolean isNonWhitespaceBetween(javax.swing.text.JTextComponent editor, int iStart, int iEnd)
-
isAdditionalSymbol
private static boolean isAdditionalSymbol(java.lang.String currWord, java.lang.String strPossibleAdditionalSymbol, java.lang.String symbol)
-
getLineStartAndEndPositions
public static int[] getLineStartAndEndPositions(java.lang.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(java.lang.String text, int initialCaretPosition)
-
getLineEnd
public static int getLineEnd(java.lang.String text, int initialCaretPosition)
-
deleteWordAtCaret
public static void deleteWordAtCaret(javax.swing.text.JTextComponent editor) throws javax.swing.text.BadLocationException- Throws:
javax.swing.text.BadLocationException
-
findPreviousTextChunk
protected static java.lang.String findPreviousTextChunk(int startPosition, java.lang.String text)
-
getLineAtPosition
public static int getLineAtPosition(javax.swing.text.JTextComponent editor, int position)Gets the line at a given position in the editor
-
getColumnAtPosition
public static int getColumnAtPosition(javax.swing.text.JTextComponent editor, int caretPosition)
-
getWhiteSpaceLineStartBefore
public static int getWhiteSpaceLineStartBefore(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.String script, int position)- Returns:
- the next non-whitespace position in the given script
-
findNonWhitespacePositionBefore
public static int findNonWhitespacePositionBefore(java.lang.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, java.lang.String source, boolean consumeWhitespaceFirst)
-
getCharClass
private static int getCharClass(char c)
-
fixTextComponentKeyMap
public static void fixTextComponentKeyMap(javax.swing.text.JTextComponent editor)
-
expandSelectionIfNeeded
public static void expandSelectionIfNeeded(javax.swing.text.JTextComponent editor)
-
selectLineAtCaret
public static void selectLineAtCaret(javax.swing.text.JTextComponent editor)
-
selectRight
public static void selectRight(javax.swing.text.JTextComponent editor)
-
jumpRight
public static void jumpRight(javax.swing.text.JTextComponent editor)
-
jumpLeft
public static void jumpLeft(javax.swing.text.JTextComponent editor)
-
selectLeft
public static void selectLeft(javax.swing.text.JTextComponent editor)
-
handleHomeKey
public static void handleHomeKey(javax.swing.text.JTextComponent editor)
-
showPasteBufferDialogForComponent
public static void showPasteBufferDialogForComponent(javax.swing.text.JTextComponent component)
-
unindentLineAtCaret
public static void unindentLineAtCaret(javax.swing.text.JTextComponent editor) throws javax.swing.text.BadLocationException- Throws:
javax.swing.text.BadLocationException
-
getIdentifierAtCaret
public static java.lang.String getIdentifierAtCaret(EditorHostTextPane editor)
-
isValidIdentifier
public static boolean isValidIdentifier(java.lang.CharSequence seqId, boolean acceptDot)
-
makeValidIdentifier
public static java.lang.String makeValidIdentifier(java.lang.String str, boolean acceptDot, boolean bAcceptUnderscore)
-
-