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();
}
Aggregations