Package editor.util

Class TextComponentUtil


  • public class TextComponentUtil
    extends java.lang.Object
    • 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
    • Constructor Detail

      • TextComponentUtil

        public TextComponentUtil()
    • 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)