Search in sources :

Example 1 with Mark

use of org.omegat.gui.editor.mark.Mark in project omegat by omegat-org.

the class TestCore method setUpCore.

@Before
public final void setUpCore() throws Exception {
    configDir = Files.createTempDirectory("omegat").toFile();
    TestPreferencesInitializer.init(configDir.getAbsolutePath());
    final IMainMenu mainMenu = new IMainMenu() {

        public JMenu getToolsMenu() {
            return new JMenu();
        }

        public JMenu getProjectMenu() {
            return new JMenu();
        }

        public JMenu getOptionsMenu() {
            return new JMenu();
        }

        public JMenu getMachineTranslationMenu() {
            return new JMenu();
        }

        public JMenu getGlossaryMenu() {
            return new JMenu();
        }

        public JMenuItem getProjectRecentMenuItem() {
            return new JMenu();
        }

        public JMenu getAutoCompletionMenu() {
            return new JMenu();
        }

        public void invokeAction(String action, int modifiers) {
        }
    };
    Core.setMainWindow(new IMainWindow() {

        public void addDockable(Dockable pane) {
        }

        public void displayErrorRB(Throwable ex, String errorKey, Object... params) {
        }

        public Font getApplicationFont() {
            return new Font("Dialog", Font.PLAIN, 12);
        }

        public JFrame getApplicationFrame() {
            return new JFrame();
        }

        public void lockUI() {
        }

        public void showLengthMessage(String messageText) {
        }

        public void showProgressMessage(String messageText) {
        }

        public void showStatusMessageRB(String messageKey, Object... params) {
        }

        public void showTimedStatusMessageRB(String messageKey, Object... params) {
        }

        public void displayWarningRB(String warningKey, Object... params) {
        }

        public void displayWarningRB(String warningKey, String supercedesKey, Object... params) {
        }

        public void showErrorDialogRB(String title, String message, Object... args) {
        }

        public void unlockUI() {
        }

        public IMainMenu getMainMenu() {
            return mainMenu;
        }

        public Cursor getCursor() {
            return null;
        }

        public void setCursor(Cursor cursor) {
        }

        public int showConfirmDialog(Object message, String title, int optionType, int messageType) throws HeadlessException {
            return 0;
        }

        public void showMessageDialog(String message) {
        }
    });
    Core.setCurrentProject(new NotLoadedProject());
    final IEditorSettings editorSettings = new IEditorSettings() {

        @Override
        public boolean isUseTabForAdvance() {
            return false;
        }

        @Override
        public void setUseTabForAdvance(boolean useTabForAdvance) {
        }

        @Override
        public boolean isMarkTranslated() {
            return false;
        }

        @Override
        public void setMarkTranslated(boolean markTranslated) {
        }

        @Override
        public boolean isMarkUntranslated() {
            return false;
        }

        @Override
        public void setMarkUntranslated(boolean markUntranslated) {
        }

        @Override
        public boolean isMarkAutoPopulated() {
            return false;
        }

        @Override
        public void setMarkAutoPopulated(boolean markAutoPopulated) {
        }

        @Override
        public boolean isDisplaySegmentSources() {
            return false;
        }

        @Override
        public void setDisplaySegmentSources(boolean displaySegmentSources) {
        }

        @Override
        public boolean isMarkNonUniqueSegments() {
            return false;
        }

        @Override
        public void setMarkNonUniqueSegments(boolean markNonUniqueSegments) {
        }

        @Override
        public boolean isMarkNotedSegments() {
            return false;
        }

        @Override
        public void setMarkNotedSegments(boolean markNotedSegments) {
        }

        @Override
        public boolean isMarkNBSP() {
            return false;
        }

        @Override
        public void setMarkNBSP(boolean markNBSP) {
        }

        @Override
        public boolean isMarkWhitespace() {
            return false;
        }

        @Override
        public void setMarkWhitespace(boolean markWhitespace) {
        }

        @Override
        public boolean isMarkBidi() {
            return false;
        }

        @Override
        public void setMarkBidi(boolean markBidi) {
        }

        @Override
        public boolean isAutoSpellChecking() {
            return false;
        }

        @Override
        public void setAutoSpellChecking(boolean isNeedToSpell) {
        }

        @Override
        public boolean isDoFontFallback() {
            return false;
        }

        @Override
        public void setDoFontFallback(boolean doFallback) {
        }

        @Override
        public String getDisplayModificationInfo() {
            return null;
        }

        @Override
        public void setDisplayModificationInfo(String displayModificationInfo) {
        }

        @Override
        public void updateTagValidationPreferences() {
        }

        @Override
        public void updateViewPreferences() {
        }

        @Override
        public boolean isMarkLanguageChecker() {
            return false;
        }

        @Override
        public void setMarkLanguageChecker(boolean markLanguageChecker) {
        }

        @Override
        public boolean isMarkGlossaryMatches() {
            return false;
        }

        @Override
        public void setMarkGlossaryMatches(boolean markGlossaryMatches) {
        }
    };
    TestCoreInitializer.initEditor(new IEditor() {

        @Override
        public void windowDeactivated() {
        }

        @Override
        public void undo() {
        }

        @Override
        public void setFilter(IEditorFilter filter) {
        }

        @Override
        public void setAlternateTranslationForCurrentEntry(boolean alternate) {
        }

        @Override
        public void requestFocus() {
        }

        @Override
        public void replaceEditTextAndMark(String text) {
        }

        @Override
        public void replaceEditText(String text) {
        }

        @Override
        public void removeFilter() {
        }

        @Override
        public void remarkOneMarker(String markerClassName) {
        }

        @Override
        public void registerUntranslated() {
        }

        @Override
        public void registerPopupMenuConstructors(int priority, IPopupMenuConstructor constructor) {
        }

        @Override
        public void registerIdenticalTranslation() {
        }

        @Override
        public void registerEmptyTranslation() {
        }

        @Override
        public void refreshViewAfterFix(List<Integer> fixedEntries) {
        }

        @Override
        public void refreshView(boolean doCommit) {
        }

        @Override
        public void redo() {
        }

        @Override
        public void prevEntryWithNote() {
        }

        @Override
        public void prevEntry() {
        }

        @Override
        public void nextUntranslatedEntry() {
        }

        @Override
        public void nextUniqueEntry() {
        }

        @Override
        public void nextTranslatedEntry() {
        }

        @Override
        public void nextEntryWithNote() {
        }

        @Override
        public void nextEntry() {
        }

        @Override
        public void markActiveEntrySource(SourceTextEntry requiredActiveEntry, List<Mark> marks, String markerClassName) {
        }

        @Override
        public void insertText(String text) {
        }

        @Override
        public void insertTextAndMark(String text) {
        }

        @Override
        public void insertTag(String tag) {
        }

        @Override
        public void gotoHistoryForward() {
        }

        @Override
        public void gotoHistoryBack() {
        }

        @Override
        public void gotoFile(int fileIndex) {
        }

        @Override
        public void gotoEntryAfterFix(int fixedEntry, String fixedSource) {
        }

        @Override
        public void gotoEntry(String srcString, EntryKey key) {
        }

        @Override
        public void gotoEntry(int entryNum) {
        }

        @Override
        public void gotoEntry(int entryNum, CaretPosition pos) {
        }

        @Override
        public IEditorSettings getSettings() {
            return editorSettings;
        }

        @Override
        public String getSelectedText() {
            return null;
        }

        @Override
        public IEditorFilter getFilter() {
            return null;
        }

        @Override
        public String getCurrentTranslation() {
            return null;
        }

        @Override
        public String getCurrentTargetFile() {
            return null;
        }

        @Override
        public String getCurrentFile() {
            return null;
        }

        @Override
        public int getCurrentEntryNumber() {
            return 0;
        }

        @Override
        public SourceTextEntry getCurrentEntry() {
            return null;
        }

        @Override
        public IAutoCompleter getAutoCompleter() {
            return null;
        }

        @Override
        public void commitAndLeave() {
        }

        @Override
        public void commitAndDeactivate() {
        }

        @Override
        public void changeCase(CHANGE_CASE_TO newCase) {
        }

        @Override
        public void activateEntry() {
        }
    });
}
Also used : IEditor(org.omegat.gui.editor.IEditor) HeadlessException(java.awt.HeadlessException) IMainWindow(org.omegat.gui.main.IMainWindow) Dockable(com.vlsolutions.swing.docking.Dockable) Mark(org.omegat.gui.editor.mark.Mark) Cursor(java.awt.Cursor) Font(java.awt.Font) JFrame(javax.swing.JFrame) SourceTextEntry(org.omegat.core.data.SourceTextEntry) IAutoCompleter(org.omegat.gui.editor.autocompleter.IAutoCompleter) IEditorFilter(org.omegat.gui.editor.IEditorFilter) EntryKey(org.omegat.core.data.EntryKey) IPopupMenuConstructor(org.omegat.gui.editor.IPopupMenuConstructor) IEditorSettings(org.omegat.gui.editor.IEditorSettings) NotLoadedProject(org.omegat.core.data.NotLoadedProject) IMainMenu(org.omegat.gui.main.IMainMenu) JMenu(javax.swing.JMenu) Before(org.junit.Before)

Example 2 with Mark

use of org.omegat.gui.editor.mark.Mark in project omegat by omegat-org.

the class EditorController method markActiveEntrySource.

/**
 * {@inheritDoc}
 */
public void markActiveEntrySource(final SourceTextEntry requiredActiveEntry, final List<Mark> marks, final String markerClassName) {
    UIThreadsUtil.mustBeSwingThread();
    for (Mark m : marks) {
        if (m.entryPart != Mark.ENTRY_PART.SOURCE) {
            throw new RuntimeException("Mark must be for source only");
        }
    }
    SourceTextEntry realActive = m_docSegList[displayedEntryIndex].ste;
    if (realActive != requiredActiveEntry) {
        return;
    }
    int mi = markerController.getMarkerIndex(markerClassName);
    EntryMarks ev = new EntryMarks(m_docSegList[displayedEntryIndex], m_docSegList[displayedEntryIndex].getDisplayVersion(), mi);
    ev.result = marks;
    markerController.queueMarksOutput(ev);
}
Also used : EntryMarks(org.omegat.gui.editor.mark.EntryMarks) SourceTextEntry(org.omegat.core.data.SourceTextEntry) Mark(org.omegat.gui.editor.mark.Mark) Point(java.awt.Point)

Example 3 with Mark

use of org.omegat.gui.editor.mark.Mark in project omegat by omegat-org.

the class TransTipsMarker method getMarksForTokens.

private static List<Mark> getMarksForTokens(List<Token[]> tokens, String srcText, String tooltip) {
    if (tokens.isEmpty() || srcText.isEmpty()) {
        return Collections.emptyList();
    }
    List<Mark> result = new ArrayList<>(tokens.size());
    tokens.sort(Comparator.comparing(toks -> toks[0].getOffset()));
    for (Token[] toks : tokens) {
        if (toks.length > 1) {
            Arrays.sort(toks, Comparator.comparingInt(Token::getOffset));
        }
        for (Token tok : toks) {
            Mark prev = result.isEmpty() ? null : result.get(result.size() - 1);
            int currStart = tok.getOffset();
            int currEnd = currStart + tok.getLength();
            Mark newMark;
            // combine them into a single mark
            if (prev != null && canCloseSpan(srcText, prev.endOffset, currStart)) {
                newMark = new Mark(Mark.ENTRY_PART.SOURCE, prev.startOffset, currEnd);
                result.set(result.size() - 1, newMark);
            } else {
                newMark = new Mark(Mark.ENTRY_PART.SOURCE, currStart, currEnd);
                result.add(newMark);
            }
            newMark.painter = TRANSTIPS_UNDERLINER;
            newMark.toolTipText = tooltip;
        }
    }
    return result;
}
Also used : UnderlineFactory(org.omegat.gui.editor.UnderlineFactory) Arrays(java.util.Arrays) SourceTextEntry(org.omegat.core.data.SourceTextEntry) Token(org.omegat.util.Token) Styles(org.omegat.util.gui.Styles) ArrayList(java.util.ArrayList) List(java.util.List) Mark(org.omegat.gui.editor.mark.Mark) Core(org.omegat.core.Core) IMarker(org.omegat.gui.editor.mark.IMarker) HighlightPainter(javax.swing.text.Highlighter.HighlightPainter) Comparator(java.util.Comparator) Collections(java.util.Collections) ArrayList(java.util.ArrayList) Mark(org.omegat.gui.editor.mark.Mark) Token(org.omegat.util.Token)

Example 4 with Mark

use of org.omegat.gui.editor.mark.Mark in project omegat by omegat-org.

the class FalseFriendsTest method testRemoveRules.

@Test
public void testRemoveRules() throws Exception {
    LanguageToolMarker marker = new LanguageToolMarker() {

        public boolean isEnabled() {
            return true;
        }
    };
    List<Mark> marks = marker.getMarksForEntry(null, "This is some long text without translation.", "", true);
    assertEquals(0, marks.size());
    marks = marker.getMarksForEntry(null, "This is text with the same translation.", "This is text with the same translation.", true);
    assertEquals(0, marks.size());
}
Also used : LanguageToolMarker(org.omegat.languagetools.LanguageToolWrapper.LanguageToolMarker) Mark(org.omegat.gui.editor.mark.Mark) Test(org.junit.Test)

Example 5 with Mark

use of org.omegat.gui.editor.mark.Mark in project omegat by omegat-org.

the class FalseFriendsTest method testExecute.

@Test
public void testExecute() throws Exception {
    LanguageToolMarker marker = new LanguageToolMarker() {

        public boolean isEnabled() {
            return true;
        }
    };
    List<Mark> marks = marker.getMarksForEntry(null, "This is abnegation.", "To jest abnegacja.", true);
    assertEquals(1, marks.size());
    assertTrue(marks.get(0).toolTipText.contains("slovenliness"));
}
Also used : LanguageToolMarker(org.omegat.languagetools.LanguageToolWrapper.LanguageToolMarker) Mark(org.omegat.gui.editor.mark.Mark) Test(org.junit.Test)

Aggregations

Mark (org.omegat.gui.editor.mark.Mark)6 SourceTextEntry (org.omegat.core.data.SourceTextEntry)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Before (org.junit.Before)2 Test (org.junit.Test)2 EntryKey (org.omegat.core.data.EntryKey)2 NotLoadedProject (org.omegat.core.data.NotLoadedProject)2 IEditor (org.omegat.gui.editor.IEditor)2 IEditorFilter (org.omegat.gui.editor.IEditorFilter)2 IEditorSettings (org.omegat.gui.editor.IEditorSettings)2 IPopupMenuConstructor (org.omegat.gui.editor.IPopupMenuConstructor)2 IAutoCompleter (org.omegat.gui.editor.autocompleter.IAutoCompleter)2 LanguageToolMarker (org.omegat.languagetools.LanguageToolWrapper.LanguageToolMarker)2 Dockable (com.vlsolutions.swing.docking.Dockable)1 Cursor (java.awt.Cursor)1 Font (java.awt.Font)1 Frame (java.awt.Frame)1 HeadlessException (java.awt.HeadlessException)1 Point (java.awt.Point)1