增加 ApplicationManager.java 的注释

This commit is contained in:
许轲 2023-10-11 02:07:45 +08:00
parent 7d4123ba50
commit b9fdb14bcd

View File

@ -37,10 +37,16 @@ import java.util.concurrent.ExecutorService;
import static org.jcnc.jnotepad.common.constants.AppConstants.DEFAULT_PROPERTY; import static org.jcnc.jnotepad.common.constants.AppConstants.DEFAULT_PROPERTY;
import static org.jcnc.jnotepad.common.constants.AppConstants.PROGRAM_FILE_DIRECTORY; import static org.jcnc.jnotepad.common.constants.AppConstants.PROGRAM_FILE_DIRECTORY;
/** /**
* 应用程序管理类<br/> * 应用程序管理类
* 此类负责管理应用程序的生命周期等操作 *
* <p>
* 此类负责管理应用程序的生命周期和操作它包括初始化应用程序执行默认操作加载缓存加载资源迁移程序根文件夹停止前操作等功能
* </p>
*
* <p>
* 该类是一个单例类通过getInstance方法获取实例
* </p>
* *
* @author gewuyou * @author gewuyou
*/ */
@ -55,22 +61,27 @@ public class ApplicationManager {
private Stage primaryStage; private Stage primaryStage;
private Application application; private Application application;
private ApplicationManager() { private ApplicationManager() {
} }
/**
* 获取ApplicationManager的单例实例
*
* @return ApplicationManager的单例实例
*/
public static ApplicationManager getInstance() { public static ApplicationManager getInstance() {
return INSTANCE; return INSTANCE;
} }
/** /**
* 初始化程序(Initializes the application) * 初始化应用程序
* *
* @apiNote * <p>
* @since 2023/9/20 17:26 * 此方法用于初始化应用程序的各个组件包括设置应用程序主题初始化UI组件初始化插件初始化顶部菜单栏初始化侧边工具栏初始化下方状态栏初始化标签页布局等
* </p>
*/ */
public void initializeApp() { public void initializeApp() {
// 设置应用程序主题 SetTheApplicationTheme // 设置应用程序主题
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet()); Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
// 初始化scene // 初始化scene
initScene(); initScene();
@ -92,6 +103,10 @@ public class ApplicationManager {
/** /**
* 执行默认操作 * 执行默认操作
*
* <p>
* 此方法用于执行应用程序的默认操作例如根据参数打开关联文件并创建文本区域加载已打开的文件夹等
* </p>
*/ */
public void executeDefaultAction() { public void executeDefaultAction() {
// 使用加载关联文件并创建文本区域 // 使用加载关联文件并创建文本区域
@ -124,6 +139,10 @@ public class ApplicationManager {
/** /**
* 加载缓存 * 加载缓存
*
* <p>
* 此方法用于加载应用程序的缓存
* </p>
*/ */
public void loadAppCache() { public void loadAppCache() {
// 加载缓存 // 加载缓存
@ -132,6 +151,10 @@ public class ApplicationManager {
/** /**
* 加载资源 * 加载资源
*
* <p>
* 此方法用于加载应用程序的资源包括加载资源文件和绑定快捷键
* </p>
*/ */
public void loadAppResources() { public void loadAppResources() {
// 加载资源 // 加载资源
@ -142,6 +165,10 @@ public class ApplicationManager {
/** /**
* 迁移程序根文件夹 * 迁移程序根文件夹
*
* <p>
* 此方法用于迁移应用程序的根文件夹将根文件夹从之前的位置迁移到新的位置
* </p>
*/ */
public void migrateFileRootFolder() { public void migrateFileRootFolder() {
AppConfig config = AppConfigController.getInstance().getConfig(); AppConfig config = AppConfigController.getInstance().getConfig();
@ -174,7 +201,9 @@ public class ApplicationManager {
/** /**
* 停止前操作 * 停止前操作
* *
* @apiNote 在停止程序之前会执行此操作 * <p>
* 在停止应用程序之前执行一系列操作包括刷新插件配置销毁插件保存已打开的文件标签页将缓存写入本地迁移程序根文件夹关闭线程池等
* </p>
*/ */
public void operationBeforeStopping() { public void operationBeforeStopping() {
PluginConfigController pluginConfigController = PluginConfigController.getInstance(); PluginConfigController pluginConfigController = PluginConfigController.getInstance();
@ -195,7 +224,7 @@ public class ApplicationManager {
} }
/** /**
* 获取当前窗口 * 获取当前窗口
* *
* @return 当前窗口 * @return 当前窗口
*/ */
@ -206,8 +235,7 @@ public class ApplicationManager {
/** /**
* 获取当前窗口的场景 * 获取当前窗口的场景
* *
* @return javafx.scene.Scene * @return 当前窗口的场景
* @since 2023/9/20 18:21
*/ */
public Scene getScene() { public Scene getScene() {
return scene; return scene;
@ -220,8 +248,9 @@ public class ApplicationManager {
/** /**
* 加载程序布局 * 加载程序布局
* *
* @apiNote * <p>
* @since 2023/9/20 17:25 * 此方法用于加载应用程序的布局包括根布局容器底部根侧边栏垂直布局主界面边界布局顶部边界面板右侧边栏垂直布局根布局等组件
* </p>
*/ */
public void initAppLayout() { public void initAppLayout() {
// 加载根布局容器 // 加载根布局容器
@ -237,9 +266,15 @@ public class ApplicationManager {
RootRightSideBarVerticalBoxManager.getInstance().initRootRightSideBarVerticalBox(); RootRightSideBarVerticalBoxManager.getInstance().initRootRightSideBarVerticalBox();
// 初始化根布局 // 初始化根布局
RootBorderPaneManager.getInstance().initRootBorderPane(); RootBorderPaneManager.getInstance().initRootBorderPane();
} }
/**
* 重启应用程序
*
* <p>
* 此方法用于重启当前的Java应用程序
* </p>
*/
public void restart() { public void restart() {
try { try {
// 获取当前Java应用程序的命令 // 获取当前Java应用程序的命令
@ -250,14 +285,12 @@ public class ApplicationManager {
ProcessBuilder builder = new ProcessBuilder(javaCommand, "-cp", System.getProperty("java.class.path"), mainClass); ProcessBuilder builder = new ProcessBuilder(javaCommand, "-cp", System.getProperty("java.class.path"), mainClass);
builder.start(); builder.start();
// 关闭当前应用程序 // 关闭当前应用程序
// fixme 使用这个System.exit(0);在开发环境点击重启程序停止前操作不生效
stop(); stop();
} catch (IOException e) { } catch (IOException e) {
LogUtil.getLogger("正在重启当前应用程序".getClass()); LogUtil.getLogger("正在重启当前应用程序".getClass());
} }
} }
public Pane getRoot() { public Pane getRoot() {
return root; return root;
} }
@ -282,6 +315,13 @@ public class ApplicationManager {
this.primaryStage = primaryStage; this.primaryStage = primaryStage;
} }
/**
* 停止应用程序
*
* <p>
* 此方法用于停止应用程序
* </p>
*/
public void stop() { public void stop() {
Platform.exit(); Platform.exit();
} }