Package editor.util

Class TextComponentUtil


  • public class TextComponentUtil
    extends Object
    • Constructor Detail

      • TextComponentUtil

        public TextComponentUtil()
    • Method Detail

      • findCharacterPositionOnLine

        public static int findCharacterPositionOnLine​(int startPosition,
                                                      String string,
                                                      char charToFind,
                                                      TextComponentUtil.Direction d)
      • getPartialWordBeforeCaret

        public static String getPartialWordBeforeCaret​(JTextComponent editor)
      • getPartialWordBeforePos

        public static String getPartialWordBeforePos​(JTextComponent editor,
                                                     int iPos)
      • 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)
      • 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)
      • 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)
      • selectLeft

        public static void selectLeft​(JTextComponent editor)
      • handleHomeKey

        public static void handleHomeKey​(JTextComponent editor)
      • showPasteBufferDialogForComponent

        public static void showPasteBufferDialogForComponent​(JTextComponent component)
      • isValidIdentifier

        public static boolean isValidIdentifier​(CharSequence seqId,
                                                boolean acceptDot)
      • makeValidIdentifier

        public static String makeValidIdentifier​(String str,
                                                 boolean acceptDot,
                                                 boolean bAcceptUnderscore)