!119 ♻️ 重构代码 创建单例组件管理类,将单例组件初始化与单例组件分离
Merge pull request !119 from 格物方能致知/refactor-I84M61
This commit is contained in:
commit
c5d8e80e19
@ -15,10 +15,8 @@ import org.jcnc.jnotepad.controller.ResourceController;
|
||||
import org.jcnc.jnotepad.controller.config.PluginConfigController;
|
||||
import org.jcnc.jnotepad.controller.manager.Controller;
|
||||
import org.jcnc.jnotepad.plugin.manager.PluginManager;
|
||||
import org.jcnc.jnotepad.util.LogUtil;
|
||||
import org.jcnc.jnotepad.util.UiUtil;
|
||||
import org.jcnc.jnotepad.views.manager.*;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@ -32,7 +30,6 @@ import java.util.concurrent.ExecutorService;
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class ApplicationManager {
|
||||
Logger logger = LogUtil.getLogger(this.getClass());
|
||||
private static final ApplicationManager INSTANCE = new ApplicationManager();
|
||||
/**
|
||||
* 线程池
|
||||
@ -72,8 +69,8 @@ public class ApplicationManager {
|
||||
BottomStatusBoxManager.getInstance().initStatusBox();
|
||||
// 初始标签页布局组件
|
||||
CenterTabPaneManager.getInstance().initCenterTabPane();
|
||||
// 初始化ui组件
|
||||
initUiComponents();
|
||||
// 初始化应用布局
|
||||
initAppLayout();
|
||||
// 初始化primaryStage
|
||||
initPrimaryStage();
|
||||
}
|
||||
@ -152,17 +149,25 @@ public class ApplicationManager {
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载ui组件
|
||||
* 加载程序布局
|
||||
*
|
||||
* @apiNote
|
||||
* @since 2023/9/20 17:25
|
||||
*/
|
||||
public void initUiComponents() {
|
||||
// 加载组件
|
||||
public void initAppLayout() {
|
||||
// 加载根布局容器
|
||||
RootManager rootManager = RootManager.getInstance(scene);
|
||||
rootManager.initScreen(scene);
|
||||
// 初始化底部根侧边栏垂直布局
|
||||
RootBottomSideBarVerticalBoxManager.getInstance().initSidebarVerticalBox();
|
||||
// 初始化主界面边界布局
|
||||
MainBorderPaneManager.getInstance().initMainBorderPane();
|
||||
// 初始化右侧边栏垂直布局
|
||||
RootRightSideBarVerticalBoxManager.getInstance().initRootRightSideBarVerticalBox();
|
||||
// 初始化顶部菜单栏
|
||||
TopMenuBarManager.getInstance().initTopMenuBar();
|
||||
// 初始化根布局
|
||||
RootBorderPaneManager.getInstance().initRootBorderPane();
|
||||
}
|
||||
|
||||
public Pane getRoot() {
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package org.jcnc.jnotepad.views.manager;
|
||||
|
||||
import org.jcnc.jnotepad.views.root.center.main.MainBorderPane;
|
||||
import org.jcnc.jnotepad.views.root.center.main.center.tab.CenterTabPane;
|
||||
|
||||
/**
|
||||
* 主界面边界布局
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class MainBorderPaneManager {
|
||||
private static final MainBorderPaneManager INSTANCE = new MainBorderPaneManager();
|
||||
|
||||
private static final MainBorderPane MAIN_BORDER_PANE = MainBorderPane.getInstance();
|
||||
|
||||
private MainBorderPaneManager() {
|
||||
|
||||
}
|
||||
|
||||
public static MainBorderPaneManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void initMainBorderPane() {
|
||||
// 文本框
|
||||
MAIN_BORDER_PANE.setCenterComponent(CenterTabPane.getInstance());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
package org.jcnc.jnotepad.views.manager;
|
||||
|
||||
import org.jcnc.jnotepad.views.root.RootBorderPane;
|
||||
import org.jcnc.jnotepad.views.root.bottom.RootBottomSideBarVerticalBox;
|
||||
import org.jcnc.jnotepad.views.root.center.main.MainBorderPane;
|
||||
import org.jcnc.jnotepad.views.root.left.sidebar.tools.ToolHorizontalBox;
|
||||
import org.jcnc.jnotepad.views.root.right.RootRightSideBarVerticalBox;
|
||||
import org.jcnc.jnotepad.views.root.top.RootTopBorderPane;
|
||||
|
||||
/**
|
||||
* 应用程序的根布局管理类
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class RootBorderPaneManager {
|
||||
|
||||
private static final RootBorderPaneManager INSTANCE = new RootBorderPaneManager();
|
||||
|
||||
private final RootBorderPane rootBorderPane = RootBorderPane.getInstance();
|
||||
|
||||
private RootBorderPaneManager() {
|
||||
|
||||
}
|
||||
|
||||
public static RootBorderPaneManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 RootBorderPane。
|
||||
*
|
||||
* <p>设置主界面(MainBorderPane)、工具栏(ToolHBox)、侧边栏(RootRightSideBarVBox)、
|
||||
* 菜单栏(RootTopBorderPane)以及底部边栏(RootBottomSideBarVBox)等主要组件。</p>
|
||||
*/
|
||||
public void initRootBorderPane() {
|
||||
// 中间,用于显示主界面
|
||||
rootBorderPane.setCenterComponent(MainBorderPane.getInstance());
|
||||
// 主界面的左边,工具栏
|
||||
rootBorderPane.setLeftComponent(ToolHorizontalBox.getInstance());
|
||||
// 主界面的右边,侧边栏
|
||||
rootBorderPane.setRightComponent(RootRightSideBarVerticalBox.getInstance());
|
||||
// 主界面的上面,菜单栏
|
||||
rootBorderPane.setTopComponent(RootTopBorderPane.getInstance());
|
||||
// 主界面的下面,底部边栏
|
||||
rootBorderPane.setBottomComponent(RootBottomSideBarVerticalBox.getInstance());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package org.jcnc.jnotepad.views.manager;
|
||||
|
||||
import org.jcnc.jnotepad.views.root.right.RootRightSideBarVerticalBox;
|
||||
|
||||
/**
|
||||
* 右侧边栏的垂直布局容器管理类
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class RootRightSideBarVerticalBoxManager {
|
||||
private static final RootRightSideBarVerticalBoxManager INSTANCE = new RootRightSideBarVerticalBoxManager();
|
||||
|
||||
private final RootRightSideBarVerticalBox rootRightSideBarVerticalBox = RootRightSideBarVerticalBox.getInstance();
|
||||
|
||||
private RootRightSideBarVerticalBoxManager() {
|
||||
}
|
||||
|
||||
public static RootRightSideBarVerticalBoxManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化右侧边栏的垂直布局。
|
||||
*/
|
||||
public void initRootRightSideBarVerticalBox() {
|
||||
// 在此添加右侧边栏布局和内容的初始化代码
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package org.jcnc.jnotepad.views.manager;
|
||||
|
||||
import org.jcnc.jnotepad.views.root.top.RootTopBorderPane;
|
||||
import org.jcnc.jnotepad.views.root.top.menu.TopMenuBar;
|
||||
|
||||
/**
|
||||
* 顶部边界面板管理类
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class RootTopBorderPaneManager {
|
||||
private static final RootTopBorderPaneManager INSTANCE = new RootTopBorderPaneManager();
|
||||
|
||||
private final RootTopBorderPane rootTopBorderPane = RootTopBorderPane.getInstance();
|
||||
|
||||
private RootTopBorderPaneManager() {
|
||||
|
||||
}
|
||||
|
||||
public static RootTopBorderPaneManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 RootTopBorderPane。
|
||||
*
|
||||
* <p>在顶部区域添加了 TopMenuBar 的单例实例。</p>
|
||||
*/
|
||||
public void initRootBorderPane() {
|
||||
// 在顶部区域添加菜单栏
|
||||
rootTopBorderPane.setTopComponent(TopMenuBar.getInstance());
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,6 @@
|
||||
package org.jcnc.jnotepad.views.root;
|
||||
|
||||
import org.jcnc.jnotepad.ui.module.AbstractBorderPane;
|
||||
import org.jcnc.jnotepad.views.root.bottom.RootBottomSideBarVerticalBox;
|
||||
import org.jcnc.jnotepad.views.root.center.main.MainBorderPane;
|
||||
import org.jcnc.jnotepad.views.root.left.sidebar.tools.ToolHorizontalBox;
|
||||
import org.jcnc.jnotepad.views.root.right.RootRightSideBarVerticalBox;
|
||||
import org.jcnc.jnotepad.views.root.top.RootTopBorderPane;
|
||||
|
||||
/**
|
||||
* RootBorderPane 表示 JNotepad 应用程序的根布局。
|
||||
@ -21,7 +16,7 @@ public class RootBorderPane extends AbstractBorderPane {
|
||||
private static final RootBorderPane INSTANCE = new RootBorderPane();
|
||||
|
||||
private RootBorderPane() {
|
||||
initRootBorderPane();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,25 +27,4 @@ public class RootBorderPane extends AbstractBorderPane {
|
||||
public static RootBorderPane getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 RootBorderPane。
|
||||
*
|
||||
* <p>设置主界面(MainBorderPane)、工具栏(ToolHBox)、侧边栏(RootRightSideBarVBox)、
|
||||
* 菜单栏(RootTopBorderPane)以及底部边栏(RootBottomSideBarVBox)等主要组件。</p>
|
||||
*/
|
||||
private void initRootBorderPane() {
|
||||
// 中间,用于显示主界面
|
||||
setCenterComponent(MainBorderPane.getInstance());
|
||||
// 主界面的左边,工具栏
|
||||
setLeftComponent(ToolHorizontalBox.getInstance());
|
||||
// 主界面的右边,侧边栏
|
||||
setRightComponent(RootRightSideBarVerticalBox.getInstance());
|
||||
// 主界面的上面,菜单栏
|
||||
setTopComponent(RootTopBorderPane.getInstance());
|
||||
// 主界面的下面,底部边栏
|
||||
setBottomComponent(RootBottomSideBarVerticalBox.getInstance());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package org.jcnc.jnotepad.views.root.center.main;
|
||||
|
||||
import org.jcnc.jnotepad.ui.module.AbstractBorderPane;
|
||||
import org.jcnc.jnotepad.views.root.center.main.center.tab.CenterTabPane;
|
||||
|
||||
/**
|
||||
* 主界面边界布局
|
||||
@ -15,7 +14,7 @@ public class MainBorderPane extends AbstractBorderPane {
|
||||
private static final MainBorderPane INSTANCE = new MainBorderPane();
|
||||
|
||||
private MainBorderPane() {
|
||||
initRootBorderPane();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -27,9 +26,4 @@ public class MainBorderPane extends AbstractBorderPane {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private void initRootBorderPane() {
|
||||
// 文本框
|
||||
setCenterComponent(CenterTabPane.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -12,27 +12,21 @@ import org.jcnc.jnotepad.ui.module.AbstractVerticalBox;
|
||||
public class RootRightSideBarVerticalBox extends AbstractVerticalBox {
|
||||
|
||||
/**
|
||||
* 唯一的 RootRightSideBarVerticalBox 实例,使用单例模式
|
||||
* 唯一的 RootRightSideBarVerticalBoxManager 实例,使用单例模式
|
||||
*/
|
||||
private static final RootRightSideBarVerticalBox INSTANCE = new RootRightSideBarVerticalBox();
|
||||
|
||||
private RootRightSideBarVerticalBox() {
|
||||
initSidebarVerticalBox();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 RootRightSideBarVerticalBox 的唯一实例。
|
||||
* 获取 RootRightSideBarVerticalBoxManager 的唯一实例。
|
||||
*
|
||||
* @return RootRightSideBarVerticalBox 的实例
|
||||
* @return RootRightSideBarVerticalBoxManager 的实例
|
||||
*/
|
||||
public static RootRightSideBarVerticalBox getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化右侧边栏的垂直布局。
|
||||
*/
|
||||
private void initSidebarVerticalBox() {
|
||||
// 在此添加右侧边栏布局和内容的初始化代码
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package org.jcnc.jnotepad.views.root.top;
|
||||
|
||||
import org.jcnc.jnotepad.ui.module.AbstractBorderPane;
|
||||
import org.jcnc.jnotepad.views.root.top.menu.TopMenuBar;
|
||||
|
||||
/**
|
||||
* RootTopBorderPane 类表示 JNotepad 应用程序的顶部边界面板。
|
||||
@ -17,7 +16,7 @@ public class RootTopBorderPane extends AbstractBorderPane {
|
||||
private static final RootTopBorderPane INSTANCE = new RootTopBorderPane();
|
||||
|
||||
private RootTopBorderPane() {
|
||||
initRootBorderPane();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -29,13 +28,5 @@ public class RootTopBorderPane extends AbstractBorderPane {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化 RootTopBorderPane。
|
||||
*
|
||||
* <p>在顶部区域添加了 TopMenuBar 的单例实例。</p>
|
||||
*/
|
||||
private void initRootBorderPane() {
|
||||
// 在顶部区域添加菜单栏
|
||||
setTopComponent(TopMenuBar.getInstance());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user