Search in sources :

Example 11 with IProject

use of org.omegat.core.data.IProject in project omegat by omegat-org.

the class ExternalFinder method getProjectConfig.

/**
 * Get the project-specific configuration.
 *
 * @return The configuration, or null if no project is loaded or the project
 *         has no config file
 */
public static ExternalFinderConfiguration getProjectConfig() {
    IProject currentProject = Core.getProject();
    if (!currentProject.isProjectLoaded()) {
        return null;
    }
    if (projectConfig == null) {
        // load project's xml file
        File projectFile = getProjectFile(currentProject);
        IExternalFinderItemLoader projectItemLoader = new ExternalFinderXMLLoader(projectFile, SCOPE.PROJECT);
        try {
            projectConfig = projectItemLoader.load();
        } catch (FileNotFoundException e) {
        // Ignore
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, e.getMessage(), e);
        }
    }
    return projectConfig;
}
Also used : IExternalFinderItemLoader(org.omegat.externalfinder.item.IExternalFinderItemLoader) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File) IProject(org.omegat.core.data.IProject) ExternalFinderXMLLoader(org.omegat.externalfinder.item.ExternalFinderXMLLoader) FileNotFoundException(java.io.FileNotFoundException)

Example 12 with IProject

use of org.omegat.core.data.IProject in project omegat by omegat-org.

the class DictionariesTextArea method onProjectOpen.

@Override
protected void onProjectOpen() {
    clear();
    IProject project = Core.getProject();
    tokenizer = project.getSourceTokenizer();
    manager.setIndexLanguage(project.getProjectProperties().getSourceLanguage());
    manager.setTokenizer(tokenizer);
    manager.start(new File(project.getProjectProperties().getDictRoot()));
}
Also used : File(java.io.File) IProject(org.omegat.core.data.IProject)

Example 13 with IProject

use of org.omegat.core.data.IProject 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 14 with IProject

use of org.omegat.core.data.IProject 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 15 with IProject

use of org.omegat.core.data.IProject in project omegat by omegat-org.

the class HistoryCompleter method train.

synchronized void train() {
    IProject project = Core.getProject();
    if (!project.isProjectLoaded()) {
        return;
    }
    long start = System.currentTimeMillis();
    wordCompleter.reset();
    project.iterateByDefaultTranslations((source, trans) -> trainString(trans.translation));
    project.iterateByMultipleTranslations((source, trans) -> trainString(trans.translation));
    long time = System.currentTimeMillis() - start;
    LOGGER.finer(() -> String.format("Time to train History Completer: %d ms", time));
}
Also used : IProject(org.omegat.core.data.IProject)

Aggregations

IProject (org.omegat.core.data.IProject)15 SourceTextEntry (org.omegat.core.data.SourceTextEntry)5 Point (java.awt.Point)4 File (java.io.File)4 FileInfo (org.omegat.core.data.IProject.FileInfo)3 TMXEntry (org.omegat.core.data.TMXEntry)3 Map (java.util.Map)2 EntryKey (org.omegat.core.data.EntryKey)2 PrepareTMXEntry (org.omegat.core.data.PrepareTMXEntry)2 StatisticsInfo (org.omegat.core.statistics.StatisticsInfo)2 Language (org.omegat.util.Language)2 Cursor (java.awt.Cursor)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 TimeoutException (java.util.concurrent.TimeoutException)1 Before (org.junit.Before)1 KnownException (org.omegat.core.KnownException)1