Search in sources :

Example 11 with Segmenter

use of org.omegat.core.segmentation.Segmenter in project omegat by omegat-org.

the class Core method initializeGUI.

/**
 * Initialize application components.
 */
public static void initializeGUI(final Map<String, String> params) throws Exception {
    cmdLineParams = params;
    // 1. Initialize project
    currentProject = new NotLoadedProject();
    // 2. Initialize application frame
    MainWindow me = new MainWindow();
    mainWindow = me;
    // Load recent used projects
    RecentProjects.updateMenu();
    Core.registerMarker(new ProtectedPartsMarker());
    Core.registerMarker(new RemoveTagMarker());
    Core.registerMarker(new NBSPMarker());
    Core.registerMarker(new TransTipsMarker());
    Core.registerMarker(new WhitespaceMarkerFactory.SpaceMarker());
    Core.registerMarker(new WhitespaceMarkerFactory.TabMarker());
    Core.registerMarker(new WhitespaceMarkerFactory.LFMarker());
    Core.registerMarker(new BidiMarkerFactory.RLMMarker());
    Core.registerMarker(new BidiMarkerFactory.LRMMarker());
    Core.registerMarker(new BidiMarkerFactory.PDFMarker());
    Core.registerMarker(new BidiMarkerFactory.LROMarker());
    Core.registerMarker(new BidiMarkerFactory.RLOMarker());
    Core.registerMarker(new ReplaceMarker());
    Core.registerMarker(new ComesFromAutoTMMarker());
    Core.registerMarker(new FontFallbackMarker());
    LanguageToolWrapper.init();
    segmenter = new Segmenter(Preferences.getSRX());
    filterMaster = new FilterMaster(Preferences.getFilters());
    // 3. Initialize other components. They add themselves to the main window.
    editor = new EditorController(me);
    tagValidation = new TagValidationTool();
    issuesWindow = new IssuesPanelController(me);
    matcher = new MatchesTextArea(me);
    GlossaryTextArea glossaryArea = new GlossaryTextArea(me);
    glossary = glossaryArea;
    glossaryManager = new GlossaryManager(glossaryArea);
    notes = new NotesTextArea(me);
    comments = new CommentsTextArea(me);
    machineTranslatePane = new MachineTranslateTextArea(me);
    dictionaries = new DictionariesTextArea(me);
    spellChecker = new SpellChecker();
    multiple = new MultipleTransPane(me);
    new SegmentPropertiesArea(me);
    SaveThread th = new SaveThread();
    saveThread = th;
    th.start();
}
Also used : NBSPMarker(org.omegat.gui.editor.mark.NBSPMarker) MachineTranslateTextArea(org.omegat.gui.exttrans.MachineTranslateTextArea) EditorController(org.omegat.gui.editor.EditorController) MultipleTransPane(org.omegat.gui.multtrans.MultipleTransPane) DictionariesTextArea(org.omegat.gui.dictionaries.DictionariesTextArea) WhitespaceMarkerFactory(org.omegat.gui.editor.mark.WhitespaceMarkerFactory) GlossaryManager(org.omegat.gui.glossary.GlossaryManager) ReplaceMarker(org.omegat.gui.editor.mark.ReplaceMarker) NotesTextArea(org.omegat.gui.notes.NotesTextArea) IMainWindow(org.omegat.gui.main.IMainWindow) MainWindow(org.omegat.gui.main.MainWindow) IssuesPanelController(org.omegat.gui.issues.IssuesPanelController) BidiMarkerFactory(org.omegat.gui.editor.mark.BidiMarkerFactory) ProtectedPartsMarker(org.omegat.gui.editor.mark.ProtectedPartsMarker) FontFallbackMarker(org.omegat.gui.editor.mark.FontFallbackMarker) SaveThread(org.omegat.core.threads.SaveThread) RemoveTagMarker(org.omegat.gui.editor.mark.RemoveTagMarker) CommentsTextArea(org.omegat.gui.comments.CommentsTextArea) ComesFromAutoTMMarker(org.omegat.gui.editor.mark.ComesFromAutoTMMarker) Segmenter(org.omegat.core.segmentation.Segmenter) TagValidationTool(org.omegat.core.tagvalidation.TagValidationTool) MatchesTextArea(org.omegat.gui.matches.MatchesTextArea) GlossaryTextArea(org.omegat.gui.glossary.GlossaryTextArea) NotLoadedProject(org.omegat.core.data.NotLoadedProject) FilterMaster(org.omegat.filters2.master.FilterMaster) ISpellChecker(org.omegat.core.spellchecker.ISpellChecker) SpellChecker(org.omegat.core.spellchecker.SpellChecker) SegmentPropertiesArea(org.omegat.gui.properties.SegmentPropertiesArea) TransTipsMarker(org.omegat.gui.glossary.TransTipsMarker)

Example 12 with Segmenter

use of org.omegat.core.segmentation.Segmenter in project omegat by omegat-org.

the class RealProject method loadProject.

/**
 * Load exist project in a "big" sense -- loads project's properties, glossaries, tms, source files etc.
 */
public synchronized void loadProject(boolean onlineMode) {
    Log.logInfoRB("LOG_DATAENGINE_LOAD_START");
    UIThreadsUtil.mustNotBeSwingThread();
    // load new project
    try {
        if (!lockProject()) {
            throw new KnownException("PROJECT_LOCKED");
        }
        isOnlineMode = onlineMode;
        if (RuntimePreferences.isLocationSaveEnabled()) {
            Preferences.setPreference(Preferences.CURRENT_FOLDER, new File(config.getProjectRoot()).getAbsoluteFile().getParent());
            Preferences.save();
        }
        Core.getMainWindow().showStatusMessageRB("CT_LOADING_PROJECT");
        if (remoteRepositoryProvider != null) {
            tmxPrepared = null;
            glossaryPrepared = null;
            remoteRepositoryProvider.switchAllToLatest();
            // Add filters.xml and segmentation.conf
            for (String file : new String[] { '/' + config.getProjectInternalRelative() + FilterMaster.FILE_FILTERS, '/' + config.getProjectInternalRelative() + SRX.CONF_SENTSEG }) {
                remoteRepositoryProvider.copyFilesFromRepoToProject(file);
            }
            // After adding filters.xml and segmentation.conf, we must reload them again
            config.loadProjectFilters();
            config.loadProjectSRX();
            loadFilterSettings();
            loadTranslations();
            Core.getMainWindow().showStatusMessageRB("TEAM_REBASE_AND_COMMIT");
            rebaseAndCommitProject(true);
            // retrieve other directories
            remoteRepositoryProvider.switchAllToLatest();
            for (String dir : new String[] { config.getSourceDir().getUnderRoot(), config.getGlossaryDir().getUnderRoot(), config.getTmDir().getUnderRoot(), config.getDictDir().getUnderRoot() }) {
                if (dir == null || dir.contains("..")) {
                    continue;
                }
                // copy but skip project_save.tmx and glossary.txt
                remoteRepositoryProvider.copyFilesFromRepoToProject(dir, '/' + config.getProjectInternalRelative() + OConsts.STATUS_EXTENSION, '/' + config.getWritableGlossaryFile().getUnderRoot());
            }
        } else {
            loadFilterSettings();
            loadTranslations();
        }
        // Set project specific segmentation rules if they exist, or defaults otherwise.
        // This can be done after loadTranslations(), as segmentation is not used for this
        SRX srx = Optional.ofNullable(config.getProjectSRX()).orElse(Preferences.getSRX());
        Core.setSegmenter(new Segmenter(srx));
        loadSourceFiles();
        allProjectEntries = Collections.unmodifiableList(allProjectEntries);
        importHandler = new ImportFromAutoTMX(this, allProjectEntries);
        importTranslationsFromSources();
        loadTM();
        loadOtherLanguages();
        // build word count
        String stat = CalcStandardStatistics.buildProjectStats(this, hotStat);
        String fn = config.getProjectInternal() + OConsts.STATS_FILENAME;
        Statistics.writeStat(fn, stat);
        loaded = true;
        // Project Loaded...
        Core.getMainWindow().showStatusMessageRB(null);
        setProjectModified(false);
    } catch (Exception e) {
        Log.logErrorRB(e, "TF_LOAD_ERROR");
        Core.getMainWindow().displayErrorRB(e, "TF_LOAD_ERROR");
        if (!loaded) {
            unlockProject();
        }
    } catch (OutOfMemoryError oome) {
        // Fix for bug 1571944 @author Henry Pijffers
        // (henry.pijffers@saxnot.com)
        // Oh shit, we're all out of storage space!
        // Of course we should've cleaned up after ourselves earlier,
        // but since we didn't, do a bit of cleaning up now, otherwise
        // we can't even inform the user about our slacking off.
        allProjectEntries.clear();
        projectFilesList.clear();
        transMemories.clear();
        projectTMX = null;
        // There, that should do it, now inform the user
        long memory = Runtime.getRuntime().maxMemory() / 1024 / 1024;
        Log.logErrorRB("OUT_OF_MEMORY", memory);
        Log.log(oome);
        Core.getMainWindow().showErrorDialogRB("TF_ERROR", "OUT_OF_MEMORY", memory);
        // Just quit, we can't help it anyway
        System.exit(0);
    }
    Log.logInfoRB("LOG_DATAENGINE_LOAD_END");
}
Also used : KnownException(org.omegat.core.KnownException) SRX(org.omegat.core.segmentation.SRX) Segmenter(org.omegat.core.segmentation.Segmenter) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) KnownException(org.omegat.core.KnownException) IOException(java.io.IOException) SAXParseException(org.xml.sax.SAXParseException)

Aggregations

Segmenter (org.omegat.core.segmentation.Segmenter)12 FilterMaster (org.omegat.filters2.master.FilterMaster)6 File (java.io.File)5 Before (org.junit.Before)5 IOException (java.io.IOException)4 SRX (org.omegat.core.segmentation.SRX)3 Language (org.omegat.util.Language)3 Filters (gen.core.filters.Filters)1 Color (java.awt.Color)1 Component (java.awt.Component)1 Cursor (java.awt.Cursor)1 Font (java.awt.Font)1 Rectangle (java.awt.Rectangle)1 Toolkit (java.awt.Toolkit)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 Transferable (java.awt.datatransfer.Transferable)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ComponentAdapter (java.awt.event.ComponentAdapter)1