Class EditorController

java.lang.Object
org.omegat.gui.editor.EditorController
All Implemented Interfaces:
IEditor

public class EditorController extends Object implements IEditor
Class for control all editor operations.

You can find good description of java text editor working at Using the Swing Text Package * that was originally found at http://java.sun.com/products/jfc/tsc/articles/text/overview/

  • Constructor Details

    • EditorController

      public EditorController(IMainWindow mainWindow)
  • Method Details

    • isOrientationAllLtr

      public boolean isOrientationAllLtr()
      The orientation of the document is all LtR.
      Specified by:
      isOrientationAllLtr in interface IEditor
      Returns:
      true when the orientation is all RtL. otherwise false.
    • requestFocus

      public void requestFocus()
      Description copied from interface: IEditor
      Set current focus to editor.
      Specified by:
      requestFocus in interface IEditor
    • getCurrentEntry

      public @Nullable SourceTextEntry getCurrentEntry()
      Description copied from interface: IEditor
      Get current active entry. Can be called from any thread.
      Specified by:
      getCurrentEntry in interface IEditor
    • getCurrentSegmentBuilder

      public @Nullable SegmentBuilder getCurrentSegmentBuilder()
    • getCurrentFile

      public @Nullable String getCurrentFile()
      Description copied from interface: IEditor
      Get relative path (under source) of the source file currently open in the editor.

      Can be called from any thread.

      Specified by:
      getCurrentFile in interface IEditor
    • getCurrentTargetFile

      public @Nullable String getCurrentTargetFile()
      Description copied from interface: IEditor
      Get the relative path (under target) of the target file corresponding to the current source file (per IEditor.getCurrentFile()). This file is what is created upon doing Create Target Documents, but it may not exist yet.

      Can be called from any thread.

      Specified by:
      getCurrentTargetFile in interface IEditor
    • activateEntry

      public void activateEntry()
      Description copied from interface: IEditor
      Activate entry for edit. Must be called only from UI thread. Will position cursor at the start of segment
      Specified by:
      activateEntry in interface IEditor
    • activateEntryAndGotoOffset

      public void activateEntryAndGotoOffset(int offset)
    • activateEntry

      public void activateEntry(IEditor.CaretPosition pos)
      Activates the current entry (if available) by displaying source text and embedding displayed text in markers.

      Also moves document focus to the current entry and makes sure fuzzy info displayed if available.

    • showStat

      public void showStat()
      Calculate statistic for file, request statistic for project and display in status bar.
    • refreshEntries

      public void refreshEntries(Set<Integer> entryNumbers)
      Refresh some entries. Usually after external translation changes replacement.
    • commitAndDeactivate

      public void commitAndDeactivate()
      Commits the translation. Reads current entry text and commit it to memory if it's changed. Also clears out segment markers while we're at it.

      Since 1.6: Translation equal to source may be validated as OK translation if appropriate option is set in Workflow options dialog.

      All displayed segments with the same source text updated also.

      Specified by:
      commitAndDeactivate in interface IEditor
    • commitAndLeave

      public void commitAndLeave()
      Description copied from interface: IEditor
      Commits the translation and leave entry activated. Translation will be saved. Must be called only from UI thread.
      Specified by:
      commitAndLeave in interface IEditor
    • nextEntry

      public void nextEntry()
      Description copied from interface: IEditor
      Move to next entry. Must be called only from UI thread.
      Specified by:
      nextEntry in interface IEditor
    • prevEntry

      public void prevEntry()
      Description copied from interface: IEditor
      Move to previous entry. Must be called only from UI thread.
      Specified by:
      prevEntry in interface IEditor
    • nextUntranslatedEntry

      public void nextUntranslatedEntry()
      Finds the next untranslated entry in the document.
      Specified by:
      nextUntranslatedEntry in interface IEditor
    • nextTranslatedEntry

      public void nextTranslatedEntry()
      Finds the next translated entry in the document.
      Specified by:
      nextTranslatedEntry in interface IEditor
    • nextXAutoEntry

      public void nextXAutoEntry()
      Finds the next/previous x-auto translated entry
      Specified by:
      nextXAutoEntry in interface IEditor
    • prevXAutoEntry

      public void prevXAutoEntry()
      Description copied from interface: IEditor
      Move to previous x-auto translated entry. Must be called only from UI thread.
      Specified by:
      prevXAutoEntry in interface IEditor
    • nextXEnforcedEntry

      public void nextXEnforcedEntry()
      Finds the next/previous x-enforced translated entry
      Specified by:
      nextXEnforcedEntry in interface IEditor
    • prevXEnforcedEntry

      public void prevXEnforcedEntry()
      Description copied from interface: IEditor
      Move to previous x-enforced translated entry. Must be called only from UI thread.
      Specified by:
      prevXEnforcedEntry in interface IEditor
    • nextEntryWithNote

      public void nextEntryWithNote()
      Finds the next entry with a non-empty note.
      Specified by:
      nextEntryWithNote in interface IEditor
    • prevEntryWithNote

      public void prevEntryWithNote()
      Finds the previous entry with a non-empty note.
      Specified by:
      prevEntryWithNote in interface IEditor
    • nextUniqueEntry

      public void nextUniqueEntry()
      Find the next unique entry.
      Specified by:
      nextUniqueEntry in interface IEditor
    • getCurrentEntryNumber

      public int getCurrentEntryNumber()
      Description copied from interface: IEditor
      Get current active entry number. Can be called from any thread.
      Specified by:
      getCurrentEntryNumber in interface IEditor
    • gotoFile

      public void gotoFile(int fileIndex)
      Description copied from interface: IEditor
      Goto first entry in specified file.
      Specified by:
      gotoFile in interface IEditor
      Parameters:
      fileIndex - file index in project
    • gotoEntry

      public void gotoEntry(int entryNum)
      Description copied from interface: IEditor
      Goto entry with specified number. Convenience method for IEditor.gotoEntry(int, CaretPosition) where the caret position will be the start of the entry.
      Specified by:
      gotoEntry in interface IEditor
      Parameters:
      entryNum - entry number, starts from 1 Must be called only from UI thread.
    • gotoEntry

      public void gotoEntry(int entryNum, IEditor.CaretPosition pos)
      Description copied from interface: IEditor
      Goto entry with specified number, and restore caret to specified position.
      Specified by:
      gotoEntry in interface IEditor
      Parameters:
      entryNum - entry number, starts from 1 Must be called only from UI thread.
    • gotoEntry

      public void gotoEntry(@Nullable String srcString, @Nullable EntryKey key)
      Description copied from interface: IEditor
      Goto entry based on a string and entry key.
      Specified by:
      gotoEntry in interface IEditor
      Parameters:
      srcString - entry source string
      key - entry key (can be null) Must be called only from UI thread.
    • gotoEntryAfterFix

      public void gotoEntryAfterFix(int entryNum, String fixedSource)
      Description copied from interface: IEditor
      Goto entry with specified number while avoiding clobbering the tag fixes.
      Specified by:
      gotoEntryAfterFix in interface IEditor
      Parameters:
      entryNum - entry number, starts from 1
      fixedSource - The source of the entry that was fixed Must be called only from UI thread.
    • refreshViewAfterFix

      public void refreshViewAfterFix(@Nullable List<Integer> fixedEntries)
      Description copied from interface: IEditor
      Refresh the current editor view while avoiding clobbering any tag fixes.
      Specified by:
      refreshViewAfterFix in interface IEditor
      Parameters:
      fixedEntries - A list of all entries that were altered Must be called only from UI thread.
    • refreshView

      public void refreshView(boolean doCommit)
      Specified by:
      refreshView in interface IEditor
    • changeCase

      public void changeCase(IEditor.CHANGE_CASE_TO toWhat)
      Change case of the selected text or if none is selected, of the current word.
      Specified by:
      changeCase in interface IEditor
      Parameters:
      toWhat - : lower, title, upper, or cycle
    • replaceEditText

      public void replaceEditText(String text)
      Description copied from interface: IEditor
      Replaces the entire edit area with a given text. Must be called only from UI thread.
      Specified by:
      replaceEditText in interface IEditor
    • replaceEditText

      public void replaceEditText(String text, String origin)
      Description copied from interface: IEditor
      Replaces the entire edit area with a given text which origin is origin.

      when manual edit and origin is unknown, origin will be null. Must be called only from UI thread.

      Specified by:
      replaceEditText in interface IEditor
    • replacePartOfText

      public void replacePartOfText(String text, int start, int end)
    • replaceEditTextAndMark

      public void replaceEditTextAndMark(String text, String origin)
      Description copied from interface: IEditor
      Replace text and mark as to be changed by the translator from origin, i.e, background of segment should be marked Must be called only from UI thread.
      Specified by:
      replaceEditTextAndMark in interface IEditor
    • replaceEditTextAndMark

      public void replaceEditTextAndMark(String text)
      Description copied from interface: IEditor
      Inserts text at the cursor position and mark as to be changed by the translator, i.e, background of segment should be marked Must be called only from UI thread.
      Specified by:
      replaceEditTextAndMark in interface IEditor
    • getCurrentTranslation

      public String getCurrentTranslation()
      Description copied from interface: IEditor
      Returns current translation or null.
      Specified by:
      getCurrentTranslation in interface IEditor
    • getCurrentPositionInEntryTranslation

      public int getCurrentPositionInEntryTranslation()
      Returns current caret position in the editable translation.
    • getPositionInEntryTranslation

      public int getPositionInEntryTranslation(int pos)
      Returns the relative caret position in the editable translation for a given absolute index into the overall editor document.
    • setCaretPosition

      public void setCaretPosition(IEditor.CaretPosition pos)
    • insertText

      public void insertText(String text)
      Description copied from interface: IEditor
      Inserts text at the cursor position. Must be called only from UI thread.
      Specified by:
      insertText in interface IEditor
    • insertTextAndMark

      public void insertTextAndMark(String text)
      Description copied from interface: IEditor
      Inserts text at the cursor position and mark as to be changed by the translator, i.e, background of segment should be marked Must be called only from UI thread.
      Specified by:
      insertTextAndMark in interface IEditor
      Parameters:
      text - The text to insert
    • insertTag

      public void insertTag(String tag)
      Description copied from interface: IEditor
      Inserts tag at the cursor position, probably with adding bidi control chars. Must be called only from UI thread.
      Specified by:
      insertTag in interface IEditor
    • selectSourceText

      public void selectSourceText()
      Description copied from interface: IEditor
      Select the source text of the current segment.
      Specified by:
      selectSourceText in interface IEditor
    • gotoHistoryBack

      public void gotoHistoryBack()
      Description copied from interface: IEditor
      Go to previous segment from history. Must be called only from UI thread.
      Specified by:
      gotoHistoryBack in interface IEditor
    • gotoHistoryForward

      public void gotoHistoryForward()
      Description copied from interface: IEditor
      Go to next segment from history. Must be called only from UI thread.
      Specified by:
      gotoHistoryForward in interface IEditor
    • getSettings

      public EditorSettings getSettings()
      Description copied from interface: IEditor
      Get settings instance.
      Specified by:
      getSettings in interface IEditor
      Returns:
      interface for read and change editor settings Can be called from any thread.
    • undo

      public void undo()
      Description copied from interface: IEditor
      Undo editing. Must be called only from UI thread.
      Specified by:
      undo in interface IEditor
    • redo

      public void redo()
      Description copied from interface: IEditor
      Redo editing. Must be called only from UI thread.
      Specified by:
      redo in interface IEditor
    • getSelectedText

      public String getSelectedText()
      Description copied from interface: IEditor
      Get currently selected text.
      Specified by:
      getSelectedText in interface IEditor
      Returns:
      selected text Must be called only from UI thread.
    • remarkOneMarker

      public void remarkOneMarker(String markerClassName)
      Description copied from interface: IEditor
      Calls specified marker for reprocess all entries.
      Specified by:
      remarkOneMarker in interface IEditor
    • markActiveEntrySource

      public void markActiveEntrySource(SourceTextEntry requiredActiveEntry, List<Mark> marks, String markerClassName)
      Description copied from interface: IEditor
      All plugins can call this method for mark something in active entry.
      Specified by:
      markActiveEntrySource in interface IEditor
      Parameters:
      requiredActiveEntry - entry which should be active. If user moved to other entry, then marks will be skipped
      marks - list of marks
      markerClassName - marker's class name
    • registerPopupMenuConstructors

      public void registerPopupMenuConstructors(int priority, IPopupMenuConstructor constructor)
      Description copied from interface: IEditor
      Register constructor of popup menu.
      Specified by:
      registerPopupMenuConstructors in interface IEditor
      Parameters:
      priority - priority of process order
      constructor - constructor instance
    • getFilter

      public IEditorFilter getFilter()
      Description copied from interface: IEditor
      Gets a filter for this editor, or null if filter doesn't applied.
      Specified by:
      getFilter in interface IEditor
    • setFilter

      public void setFilter(IEditorFilter filter)
      Sets a filter to this editor. The filter causes only the selected entries to be shown in the editor. Document is reloaded to immediately have the filter being effective.
      Specified by:
      setFilter in interface IEditor
      Parameters:
      filter - Filter instance
    • removeFilter

      public void removeFilter()
      Removes the current filter. Document is reloaded if appropriate to immediately remove the filter;
      Specified by:
      removeFilter in interface IEditor
    • setAlternateTranslationForCurrentEntry

      public void setAlternateTranslationForCurrentEntry(boolean alternate)
      Description copied from interface: IEditor
      Set default/alternate translation for current entry.
      Specified by:
      setAlternateTranslationForCurrentEntry in interface IEditor
    • registerUntranslated

      public void registerUntranslated()
      Description copied from interface: IEditor
      Register untranslated.
      Specified by:
      registerUntranslated in interface IEditor
    • registerEmptyTranslation

      public void registerEmptyTranslation()
      Description copied from interface: IEditor
      Register as empty.
      Specified by:
      registerEmptyTranslation in interface IEditor
    • registerIdenticalTranslation

      public void registerIdenticalTranslation()
      Description copied from interface: IEditor
      Register translation to be identical to source.
      Specified by:
      registerIdenticalTranslation in interface IEditor
    • windowDeactivated

      public void windowDeactivated()
      Description copied from interface: IEditor
      Perform any necessary actions for window deactivation.
      Specified by:
      windowDeactivated in interface IEditor
    • getCurrentPositionInEntryTranslationInEditor

      public IEditor.CaretPosition getCurrentPositionInEntryTranslationInEditor()
      Description copied from interface: IEditor
      Get the current position in the entity translation in the editor
      Specified by:
      getCurrentPositionInEntryTranslationInEditor in interface IEditor
      Returns:
      caret position.
    • getAlphabeticalMarkers

      public AlphabeticalMarkers getAlphabeticalMarkers()
    • getAutoCompleter

      public IAutoCompleter getAutoCompleter()
      Description copied from interface: IEditor
      Access the AutoCompleter
      Specified by:
      getAutoCompleter in interface IEditor