Search in sources :

Example 26 with SourceTextEntry

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();
        }
    }
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry) IProject(org.omegat.core.data.IProject) Point(java.awt.Point)

Example 27 with SourceTextEntry

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

Example 28 with SourceTextEntry

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);
    }
}
Also used : MainWindowUI(org.omegat.gui.main.MainWindowUI) StatisticsInfo(org.omegat.core.statistics.StatisticsInfo) SourceTextEntry(org.omegat.core.data.SourceTextEntry) FileInfo(org.omegat.core.data.IProject.FileInfo) IProject(org.omegat.core.data.IProject) Point(java.awt.Point)

Example 29 with SourceTextEntry

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);
    }
}
Also used : SourceTextEntry(org.omegat.core.data.SourceTextEntry)

Example 30 with SourceTextEntry

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;
}
Also used : ProtectedPart(org.omegat.core.data.ProtectedPart) SourceTextEntry(org.omegat.core.data.SourceTextEntry) Point(java.awt.Point)

Aggregations

SourceTextEntry (org.omegat.core.data.SourceTextEntry)32 Point (java.awt.Point)14 TMXEntry (org.omegat.core.data.TMXEntry)12 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)9 ArrayList (java.util.ArrayList)8 IProject (org.omegat.core.data.IProject)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 EntryKey (org.omegat.core.data.EntryKey)5 FileInfo (org.omegat.core.data.IProject.FileInfo)5 Language (org.omegat.util.Language)5 List (java.util.List)4 Before (org.junit.Before)4 ProtectedPart (org.omegat.core.data.ProtectedPart)4 NearString (org.omegat.core.matching.NearString)4 Cursor (java.awt.Cursor)3 File (java.io.File)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Locale (java.util.Locale)2