Package editor.util

Class TextComponentUtil

java.lang.Object
editor.util.TextComponentUtil

public class TextComponentUtil extends Object
  • Field Details

  • Constructor Details

    • TextComponentUtil

      public TextComponentUtil()
  • Method Details

    • 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)
    • selectFirstArg

      private static void selectFirstArg(String strText, int initialSelectionStart, JTextComponent editor) throws BadLocationException
      Throws:
      BadLocationException
    • 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)
    • performCompoundUndableEdit

      private static void performCompoundUndableEdit(JTextComponent editor, Runnable edit)
    • 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
    • maybeAdjustOffsetToNextWord

      private static int maybeAdjustOffsetToNextWord(String text, int iOffset) throws BadLocationException
      Throws:
      BadLocationException
    • getPreviousWord

      private static int getPreviousWord(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)
    • isAdditionalSymbol

      private static boolean isAdditionalSymbol(String currWord, String strPossibleAdditionalSymbol, String symbol)
    • 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)
    • getCharClass

      private static int getCharClass(char c)
    • 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)
    • makeValidIdentifier

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