Search in sources :

Example 11 with NearString

use of org.omegat.core.matching.NearString in project omegat by omegat-org.

the class MainWindow method doInsertTrans.

/**
 * insert current fuzzy match or selection at cursor position
 */
public void doInsertTrans() {
    if (!Core.getProject().isProjectLoaded()) {
        return;
    }
    String text = getSelectedTextInMatcher();
    boolean fromMT = false;
    if (StringUtil.isEmpty(text)) {
        NearString near = Core.getMatcher().getActiveMatch();
        if (near != null) {
            text = near.translation;
            if (near.comesFrom == NearString.MATCH_SOURCE.TM && FileUtil.isInPath(new File(Core.getProject().getProjectProperties().getTMRoot(), "mt"), new File(near.projs[0]))) {
                fromMT = true;
            }
        }
    }
    if (!StringUtil.isEmpty(text)) {
        if (fromMT) {
            Core.getEditor().insertTextAndMark(text);
        } else {
            Core.getEditor().insertText(text);
        }
        Core.getEditor().requestFocus();
    }
}
Also used : NearString(org.omegat.core.matching.NearString) NearString(org.omegat.core.matching.NearString) File(java.io.File)

Example 12 with NearString

use of org.omegat.core.matching.NearString in project omegat by omegat-org.

the class MatchesTextArea method setFoundResult.

/**
 * Sets the list of fuzzy matches to show in the pane. Each element of the
 * list should be an instance of {@link NearString}.
 */
@Override
protected void setFoundResult(final SourceTextEntry se, List<NearString> newMatches) {
    UIThreadsUtil.mustBeSwingThread();
    clear();
    if (newMatches == null) {
        return;
    }
    if (!newMatches.isEmpty() && Preferences.isPreference(Preferences.NOTIFY_FUZZY_MATCHES)) {
        scrollPane.notify(true);
    }
    NearString.SORT_KEY key = Preferences.getPreferenceEnumDefault(Preferences.EXT_TMX_SORT_KEY, SORT_KEY.SCORE);
    newMatches.sort(Comparator.comparing(ns -> ns.scores[0], new ScoresComparator(key).reversed()));
    matches.addAll(newMatches);
    delimiters.add(0);
    StringBuilder displayBuffer = new StringBuilder();
    MatchesVarExpansion template = new MatchesVarExpansion(Preferences.getPreferenceDefault(Preferences.EXT_TMX_MATCH_TEMPLATE, MatchesVarExpansion.DEFAULT_TEMPLATE));
    for (int i = 0; i < newMatches.size(); i++) {
        NearString match = newMatches.get(i);
        MatchesVarExpansion.Result result = template.apply(match, i + 1);
        displayBuffer.append(result.text);
        sourcePos.add(result.sourcePos);
        diffInfos.add(result.diffInfo);
        if (i < (newMatches.size() - 1)) {
            displayBuffer.append("\n\n");
        }
        delimiters.add(displayBuffer.length());
    }
    setText(displayBuffer.toString());
    setActiveMatch(0);
    checkForReplaceTranslation();
}
Also used : OConsts(org.omegat.util.OConsts) SourceTextEntry(org.omegat.core.data.SourceTextEntry) FileDropInfo(org.omegat.util.gui.DragTargetOverlay.FileDropInfo) Styles(org.omegat.util.gui.Styles) Point(java.awt.Point) StaticUIUtils(org.omegat.util.gui.StaticUIUtils) StyledDocument(javax.swing.text.StyledDocument) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) StringUtil(org.omegat.util.StringUtil) Locale(java.util.Locale) Core(org.omegat.core.Core) Map(java.util.Map) MouseAdapter(java.awt.event.MouseAdapter) TextRun(org.omegat.core.matching.DiffDriver.TextRun) IPaneMenu(org.omegat.util.gui.IPaneMenu) AttributeSet(javax.swing.text.AttributeSet) MouseListener(java.awt.event.MouseListener) IMainWindow(org.omegat.gui.main.IMainWindow) PreferencesWindowController(org.omegat.gui.preferences.PreferencesWindowController) Token(org.omegat.util.Token) Component(java.awt.Component) Collectors(java.util.stream.Collectors) DragTargetOverlay(org.omegat.util.gui.DragTargetOverlay) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) StringData(org.omegat.core.data.StringData) SORT_KEY(org.omegat.core.matching.NearString.SORT_KEY) TMXEntry(org.omegat.core.data.TMXEntry) Preferences(org.omegat.util.Preferences) ITokenizer(org.omegat.tokenizer.ITokenizer) ActionListener(java.awt.event.ActionListener) DockableScrollPane(org.omegat.gui.main.DockableScrollPane) HashMap(java.util.HashMap) NearString(org.omegat.core.matching.NearString) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SwingUtilities(javax.swing.SwingUtilities) JMenuItem(javax.swing.JMenuItem) OStrings(org.omegat.util.OStrings) EntryInfoThreadPane(org.omegat.gui.common.EntryInfoThreadPane) TMMatchesPreferencesController(org.omegat.gui.preferences.view.TMMatchesPreferencesController) UIThreadsUtil(org.omegat.util.gui.UIThreadsUtil) JPopupMenu(javax.swing.JPopupMenu) ActionEvent(java.awt.event.ActionEvent) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) ScoresComparator(org.omegat.core.matching.NearString.ScoresComparator) Comparator(java.util.Comparator) ScoresComparator(org.omegat.core.matching.NearString.ScoresComparator) SORT_KEY(org.omegat.core.matching.NearString.SORT_KEY) NearString(org.omegat.core.matching.NearString) Point(java.awt.Point)

Aggregations

NearString (org.omegat.core.matching.NearString)12 Point (java.awt.Point)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 SourceTextEntry (org.omegat.core.data.SourceTextEntry)3 TMXEntry (org.omegat.core.data.TMXEntry)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 JMenuItem (javax.swing.JMenuItem)2 StyledDocument (javax.swing.text.StyledDocument)2 TextRun (org.omegat.core.matching.DiffDriver.TextRun)2 Token (org.omegat.util.Token)2 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1