use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.
the class EditorController method setFilter.
/**
* {@inheritDoc} Document is reloaded to immediately have the filter being
* effective.
*/
public void setFilter(IEditorFilter filter) {
UIThreadsUtil.mustBeSwingThread();
if (entriesFilterControlComponent != null) {
pane.remove(entriesFilterControlComponent);
}
entriesFilter = filter;
entriesFilterControlComponent = filter.getControlComponent();
pane.add(entriesFilterControlComponent, BorderLayout.NORTH);
pane.revalidate();
SourceTextEntry curEntry = getCurrentEntry();
Document3 doc = editor.getOmDocument();
IProject project = Core.getProject();
// Prevent NullPointerErrors in loadDocument. Only load if there is a document.
if (doc != null && project != null && project.getProjectFiles() != null && curEntry != null) {
int curEntryNum = curEntry.entryNum();
// rebuild entrylist
loadDocument();
if (entriesFilter == null || entriesFilter.allowed(curEntry)) {
gotoEntry(curEntry.entryNum());
} else {
// filtered entry could have been if it was not filtered.
for (int j = 0; j < m_docSegList.length; j++) {
if (m_docSegList[j].segmentNumberInProject >= curEntryNum) {
//
displayedEntryIndex = j - 1;
break;
}
}
nextEntry();
}
}
}
use of org.omegat.core.data.SourceTextEntry 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();
}
use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.
the class EditorController method showStat.
/**
* Calculate statistic for file, request statistic for project and display in status bar.
*/
public void showStat() {
IProject project = Core.getProject();
IProject.FileInfo fi = project.getProjectFiles().get(displayedFileIndex);
int translatedInFile = 0;
int translatedUniqueInFile = 0;
int uniqueInFile = 0;
boolean isUnique;
for (SourceTextEntry ste : fi.entries) {
isUnique = ste.getDuplicate() != SourceTextEntry.DUPLICATE.NEXT;
if (isUnique) {
uniqueInFile++;
}
if (project.getTranslationInfo(ste).isTranslated()) {
translatedInFile++;
if (isUnique) {
translatedUniqueInFile++;
}
}
}
StatisticsInfo stat = project.getStatistics();
final MainWindowUI.StatusBarMode progressMode = Preferences.getPreferenceEnumDefault(Preferences.SB_PROGRESS_MODE, MainWindowUI.StatusBarMode.DEFAULT);
if (progressMode == MainWindowUI.StatusBarMode.DEFAULT) {
StringBuilder pMsg = new StringBuilder(1024).append(" ");
pMsg.append(translatedInFile).append("/").append(fi.entries.size()).append(" (").append(stat.numberofTranslatedSegments).append("/").append(stat.numberOfUniqueSegments).append(", ").append(stat.numberOfSegmentsTotal).append(") ");
mw.showProgressMessage(pMsg.toString());
} else {
/*
* Percentage mode based on idea by Yu Tang
* http://dirtysexyquery.blogspot.tw/2013/03/omegat-custom-progress-format.html
*/
java.text.NumberFormat nfPer = java.text.NumberFormat.getPercentInstance();
nfPer.setRoundingMode(java.math.RoundingMode.DOWN);
nfPer.setMaximumFractionDigits(1);
String message = StringUtil.format(OStrings.getString("MW_PROGRESS_DEFAULT_PERCENTAGE"), (translatedUniqueInFile == 0) ? "0%" : nfPer.format((double) translatedUniqueInFile / uniqueInFile), uniqueInFile - translatedUniqueInFile, (stat.numberofTranslatedSegments == 0) ? "0%" : nfPer.format((double) stat.numberofTranslatedSegments / stat.numberOfUniqueSegments), stat.numberOfUniqueSegments - stat.numberofTranslatedSegments, stat.numberOfSegmentsTotal);
mw.showProgressMessage(message);
}
}
use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.
the class EditorController method showLengthMessage.
/**
* Display length of source and translation parts in the status bar.
*/
void showLengthMessage() {
Document3 doc = editor.getOmDocument();
String trans = doc.extractTranslation();
if (trans != null) {
SourceTextEntry ste = m_docSegList[displayedEntryIndex].ste;
String lMsg = " " + ste.getSrcText().length() + "/" + trans.length() + " ";
mw.showLengthMessage(lMsg);
}
}
use of org.omegat.core.data.SourceTextEntry in project omegat by omegat-org.
the class EditorTextArea3 method moveCursorOverTag.
/**
* Move cursor over tag(possible, with selection)
*
* @param withShift
* true if selection need
* @param checkTagStart
* true if check tag start, false if check tag end
* @return true if tag processed
*/
boolean moveCursorOverTag(boolean withShift, boolean checkTagStart) {
Document3 doc = getOmDocument();
int caret = getCaretPosition();
int start = doc.getTranslationStart();
int end = doc.getTranslationEnd();
if (caret < start || caret > end) {
// Don't try to jump over tags.
return false;
}
if ((caret == start && !checkTagStart) || (caret == end && checkTagStart)) {
// Don't try to jump over tags.
return false;
}
SourceTextEntry ste = doc.controller.getCurrentEntry();
String text = doc.extractTranslation();
int off = caret - start;
// iterate by 'protected parts'
if (ste != null) {
for (ProtectedPart pp : ste.getProtectedParts()) {
if (checkTagStart) {
if (StringUtil.isSubstringAfter(text, off, pp.getTextInSourceSegment())) {
int pos = off + start + pp.getTextInSourceSegment().length();
if (withShift) {
getCaret().moveDot(pos);
} else {
getCaret().setDot(pos);
}
return true;
}
} else {
if (StringUtil.isSubstringBefore(text, off, pp.getTextInSourceSegment())) {
int pos = off + start - pp.getTextInSourceSegment().length();
if (withShift) {
getCaret().moveDot(pos);
} else {
getCaret().setDot(pos);
}
return true;
}
}
}
}
return false;
}
Aggregations