Search in sources :

Example 1 with ScoresComparator

use of org.omegat.core.matching.NearString.ScoresComparator 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

Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1 MouseListener (java.awt.event.MouseListener)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)1