Java tutorial
/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.ocsoft.olivia.core; import java.io.IOException; import org.frows.genericfile.v0_3_2.GenericFile; import org.ocsoft.olivia.DefaultValues; import org.ocsoft.olivia.commands.ProjectCommands; import org.ocsoft.olivia.contexts.TimerContext; import org.ocsoft.olivia.logger.OliviaLogger; import org.ocsoft.olivia.models.contents.config.OliviaConfig; import org.ocsoft.olivia.models.contents.config.def.BasicDebugInfoConfigDef; import org.ocsoft.olivia.models.contents.config.def.BasicUserConfigDef; import org.ocsoft.olivia.models.contents.documents.EncodingDetector; import org.ocsoft.olivia.models.contents.documents.TextEncoding; import org.ocsoft.olivia.models.tab.TabModel; import org.ocsoft.olivia.observers.OliviaObservatories; import org.ocsoft.olivia.utils.LoadPluginUtils; import com.fasterxml.jackson.databind.JsonNode; /** * Olivia?????????. * @author tohhy */ public class OliviaInitializer { private OliviaInitializer() { } static void doInitialize() { //??? OliviaObservatories.getSystem().onInitialize(); //?? initializeSystem(); //?? initializeScenes(); //??? initializeAssociations(); //?? initializeProjects(); //?? initializeTabs(); //?? initializeMenus(); //???? initializeComponents(); //?? initializeTimerTasks(); //??? OliviaObservatories.getSystem().afterInitialize(); } private static void initializeSystem() { //??? InitializeUtils.createSystemFiles(); //? GenericFile pluginsDir = DefaultValues.USER_PLUGINS_DIR; LoadPluginUtils.loadPlugins(pluginsDir); // EncodingDetector.getInstance().setDefaultEncoding(TextEncoding.get("UTF-8")); //?? int launchTime = Olivia.getConfig().getDebugInfo().getAsInt(BasicDebugInfoConfigDef.DebugLaunchCount); Olivia.getConfig().getDebugInfo().set(BasicDebugInfoConfigDef.DebugLaunchCount, launchTime + 1); } private static void initializeScenes() { //scenes???json? //??. GenericFile systemScenesDir = DefaultValues.SYS_SCENES_DIR; GenericFile userScenesDir = DefaultValues.USER_SCENES_DIR; InitializeUtils.registerScenes(systemScenesDir, userScenesDir); } private static void initializeAssociations() { //????? String defaultAssociations = InitializeUtils.readDefaultAssociations(); //?? OliviaConfig userConfig = Olivia.getConfig().getUser(); try { //??? if (defaultAssociations != null) Olivia.getAssociation().loadStateFromJson(defaultAssociations); //????? JsonNode userAssociations = userConfig.get(BasicUserConfigDef.ASSOCITAITONS.getConfigKey()); if (userAssociations != null && userAssociations.size() != 0) { Olivia.getAssociation().putAllFromJson(userAssociations.toString()); } } catch (IOException e) { OliviaLogger.catchException(e); } } private static void initializeProjects() { //?? OliviaConfig userConfig = Olivia.getConfig().getUser(); //?? JsonNode json = userConfig.get("projects"); if (json != null) Olivia.getProjects().loadStateFromNode(json); } private static void initializeTabs() { //?? OliviaConfig userConfig = Olivia.getConfig().getUser(); //? JsonNode json = userConfig.get("tabs"); if (json != null) Olivia.getTabs().loadStateFromNode(json); //??? TabModel current = Olivia.getTabs().getCurrentTab(); if (current != null && current.getTreeNode() != null) { Olivia.getProjects().setCurrentProject(current.getTreeNode().getProject()); Olivia.getProjects().getCurrentProject().setCurrentNode(current.getTreeNode()); Olivia.getScene().setCurrentScene(current.getOpennedSceneID()); } } private static void initializeMenus() { new MenuInitializer().initialize(); } private static void initializeTimerTasks() { TimerContext timer = Olivia.getTimer(); //?? timer.addTaskWithStartDelay("autoSave", ProjectCommands.SAVE_ALL, 0, //1 = 60 = 60*60 = 60*60*1000Ms 1 * 60 * 60 * 1000); } private static void initializeComponents() { InitializeUtils.restoreState("components-window", Olivia.getView().getComponents().getWindow()); } }