Class EditorUtils

java.lang.Object
org.omegat.gui.editor.EditorUtils

public final class EditorUtils extends Object
Some utilities methods.
  • Method Details

    • getWordStart

      @Deprecated public static int getWordStart(JTextComponent c, int offs) throws BadLocationException
      Deprecated.
      Determines the start of a word for the given model location. This method skips direction char.
      Parameters:
      c - TextComponent of the editor area.
      offs - offset of the text.
      Returns:
      position of word start on the text component.
      Throws:
      BadLocationException - when there is no line found in the text component.
    • getWordStart

      public static int getWordStart(JTextComponent c, int offs, Locale locale) throws BadLocationException
      Determines the start of a word for the given model location. This method skips direction char.
      Parameters:
      c - TextComponent of the editor area.
      offs - offset of the text.
      locale - locale of the text.
      Returns:
      position of word start on the text component.
      Throws:
      BadLocationException - when there is no line found in the text component.
    • getWordEnd

      @Deprecated public static int getWordEnd(JTextComponent c, int offs) throws BadLocationException
      Deprecated.
      Determines the end of a word for the given model location. This method skips direction char.
      Parameters:
      c - TextComponent of the editor area.
      offs - offset of the text.
      Returns:
      position of the word end on the text component.
      Throws:
      BadLocationException - when there is no line found in the text component.
    • getWordEnd

      public static int getWordEnd(JTextComponent c, int offs, Locale locale) throws BadLocationException
      Determines the end of a word for the given model location. This method skips direction char.
      Parameters:
      c - TextComponent of the editor area.
      offs - offset of the text.
      locale - locale of the text.
      Returns:
      position of the word end on the text component.
      Throws:
      BadLocationException - when there is no line found in the text component.
    • removeDirectionChars

      public static String removeDirectionChars(String text)
      Remove invisible direction chars from string.
      Parameters:
      text - string with direction chars
      Returns:
      string without direction chars
    • removeDirectionCharsAroundTags

      public static String removeDirectionCharsAroundTags(String text, SourceTextEntry ste)
      Remove bidi chars around tags only.
      Parameters:
      text - string with direction chars
      Returns:
      string without direction chars
    • doChangeCase

      public static String doChangeCase(String input, IEditor.CHANGE_CASE_TO toWhat)
      Change the case of the input string to the indicated case. When toWhat is IEditor.CHANGE_CASE_TO.CYCLE the result will be UPPER > LOWER > SENTENCE > TITLE > UPPER.

      This is a convenience method for doChangeCase(String, CHANGE_CASE_TO, Locale, ITokenizer). The locale and tokenizer will be taken from the current project's target language values.

      Parameters:
      input - The string to change
      toWhat - The case to change to, or IEditor.CHANGE_CASE_TO.CYCLE
      Returns:
      The modified string
    • doChangeCase

      public static String doChangeCase(String input, IEditor.CHANGE_CASE_TO toWhat, Locale locale, ITokenizer tokenizer)
      Change the case of the input string to the indicated case. When toWhat is IEditor.CHANGE_CASE_TO.CYCLE the result will be UPPER > LOWER > SENTENCE > TITLE > UPPER.
      Parameters:
      input - The string to change
      toWhat - The case to change to, or IEditor.CHANGE_CASE_TO.CYCLE
      locale - The locale of the input string
      tokenizer - A tokenizer for the input string language
      Returns:
      The modified string
    • replaceGlossaryEntries

      public static String replaceGlossaryEntries(String text)
      Convenience method for replaceGlossaryEntries(String, List, Locale, ITokenizer). Glossary entries are retrieved from GlossaryManager; the locale and tokenizer are taken from the project's current values for the source language.
      Parameters:
      text - Text in which to replace glossary hits. Assumed to be in the project's source language.
      Returns:
      Text with source glossary terms replaced with target terms
    • replaceGlossaryEntries

      public static String replaceGlossaryEntries(String text, List<GlossaryEntry> entries, Locale locale, ITokenizer tokenizer)
      Given a list of glossary entries, replace any instances of the source term appearing in the given text with the target term. When there are multiple target terms, the first one is used.
      Parameters:
      text - Text in which to replace glossary hits (assumed to be in the project's source language)
      entries - List of glossary entries
      locale - Locale with which to perform capitalization matching (assumed to be source locale)
      tokenizer - Tokenizer with which to a split text (assumed to be project's source tokenizer)
      Returns:
      Text with source glossary terms replaced with target terms
    • addBidiAroundTags

      public static String addBidiAroundTags(String text, SourceTextEntry ste)
      Add RTL+LTR around tags. Used for display tags better in RTL text.
    • hasBidiAroundTag

      public static boolean hasBidiAroundTag(String text, String tag, int pos)