♻️ 重构代码 移除Ui单例于Ui工具类
This commit is contained in:
parent
2ffefb6c7b
commit
29c3a59b34
@ -23,11 +23,6 @@ module org.jcnc.jnotepad {
|
|||||||
exports org.jcnc.jnotepad.controller.event.handler.menuBar;
|
exports org.jcnc.jnotepad.controller.event.handler.menuBar;
|
||||||
exports org.jcnc.jnotepad.tool;
|
exports org.jcnc.jnotepad.tool;
|
||||||
exports org.jcnc.jnotepad.Interface;
|
exports org.jcnc.jnotepad.Interface;
|
||||||
exports org.jcnc.jnotepad.ui.module;
|
|
||||||
exports org.jcnc.jnotepad.ui.setStage;
|
|
||||||
exports org.jcnc.jnotepad.root.center.main.center.tab;
|
|
||||||
exports org.jcnc.jnotepad.root.top.menu;
|
|
||||||
exports org.jcnc.jnotepad.view.manager;
|
|
||||||
opens org.jcnc.jnotepad.app.config;
|
opens org.jcnc.jnotepad.app.config;
|
||||||
exports org.jcnc.jnotepad.root.center.main.bottom.status;
|
exports org.jcnc.jnotepad.root.center.main.bottom.status;
|
||||||
|
|
||||||
|
|||||||
@ -27,10 +27,6 @@ import java.util.concurrent.ExecutorService;
|
|||||||
* @author 许轲
|
* @author 许轲
|
||||||
*/
|
*/
|
||||||
public class LunchApp extends Application {
|
public class LunchApp extends Application {
|
||||||
/**
|
|
||||||
* 线程池
|
|
||||||
*/
|
|
||||||
private final ExecutorService threadPool = ThreadPoolManager.getThreadPool();
|
|
||||||
private static final Pane ROOT = new Pane();
|
private static final Pane ROOT = new Pane();
|
||||||
private static final Scene SCENE;
|
private static final Scene SCENE;
|
||||||
|
|
||||||
@ -40,6 +36,10 @@ public class LunchApp extends Application {
|
|||||||
SCENE = new Scene(ROOT, width, length);
|
SCENE = new Scene(ROOT, width, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程池
|
||||||
|
*/
|
||||||
|
private final ExecutorService threadPool = ThreadPoolManager.getThreadPool();
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
launch(args);
|
launch(args);
|
||||||
@ -48,6 +48,7 @@ public class LunchApp extends Application {
|
|||||||
public static Window getWindow() {
|
public static Window getWindow() {
|
||||||
return SCENE.getWindow();
|
return SCENE.getWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Stage primaryStage) {
|
public void start(Stage primaryStage) {
|
||||||
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
|
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
|
||||||
|
|||||||
@ -30,6 +30,7 @@ public class AppConfigController {
|
|||||||
private static final AppConfigController INSTANCE = new AppConfigController();
|
private static final AppConfigController INSTANCE = new AppConfigController();
|
||||||
private AppConfig appConfig;
|
private AppConfig appConfig;
|
||||||
private String dir;
|
private String dir;
|
||||||
|
|
||||||
private AppConfigController() {
|
private AppConfigController() {
|
||||||
setDir(Paths.get(System.getProperty("user.home"), ".jnotepad").toString());
|
setDir(Paths.get(System.getProperty("user.home"), ".jnotepad").toString());
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
|||||||
@ -4,8 +4,9 @@ import javafx.event.ActionEvent;
|
|||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
||||||
import org.jcnc.jnotepad.constants.TextConstants;
|
import org.jcnc.jnotepad.constants.TextConstants;
|
||||||
|
import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
|
||||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||||
import org.jcnc.jnotepad.tool.UiUtil;
|
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||||
import org.jcnc.jnotepad.ui.module.LineNumberTextArea;
|
import org.jcnc.jnotepad.ui.module.LineNumberTextArea;
|
||||||
import org.jcnc.jnotepad.view.manager.ViewManager;
|
import org.jcnc.jnotepad.view.manager.ViewManager;
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ public class NewFile implements EventHandler<ActionEvent> {
|
|||||||
// 创建一个新的文本编辑区
|
// 创建一个新的文本编辑区
|
||||||
LineNumberTextArea textArea = new LineNumberTextArea();
|
LineNumberTextArea textArea = new LineNumberTextArea();
|
||||||
// TODO: refactor:统一TextArea新建、绑定监听器入口
|
// TODO: refactor:统一TextArea新建、绑定监听器入口
|
||||||
ViewManager viewManager = UiUtil.getViewManager();
|
ViewManager viewManager = ViewManager.getInstance();
|
||||||
// 创建标签页
|
// 创建标签页
|
||||||
JNotepadTab jNotepadTab = new JNotepadTab(
|
JNotepadTab jNotepadTab = new JNotepadTab(
|
||||||
UiResourceBundle.getContent(TextConstants.NEW_FILE)
|
UiResourceBundle.getContent(TextConstants.NEW_FILE)
|
||||||
@ -42,8 +43,8 @@ public class NewFile implements EventHandler<ActionEvent> {
|
|||||||
// 设置当前标签页与本地文件无关联
|
// 设置当前标签页与本地文件无关联
|
||||||
jNotepadTab.setRelevance(false);
|
jNotepadTab.setRelevance(false);
|
||||||
// 将Tab页添加到TabPane中
|
// 将Tab页添加到TabPane中
|
||||||
UiUtil.getJnotepadTabPane().addNewTab(jNotepadTab);
|
JNotepadTabPane.getInstance().addNewTab(jNotepadTab);
|
||||||
// 更新编码信息
|
// 更新编码信息
|
||||||
UiUtil.getStatusBox().updateEncodingLabel();
|
JNotepadStatusBox.getInstance().updateEncodingLabel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ public class OpenFile implements EventHandler<ActionEvent> {
|
|||||||
*/
|
*/
|
||||||
public void openFile(File file) {
|
public void openFile(File file) {
|
||||||
// 获取标签页集合
|
// 获取标签页集合
|
||||||
JNotepadTabPane jnotepadTabPane = UiUtil.getJnotepadTabPane();
|
JNotepadTabPane jnotepadTabPane = JNotepadTabPane.getInstance();
|
||||||
// 遍历标签页,查找匹配的标签页
|
// 遍历标签页,查找匹配的标签页
|
||||||
for (Tab tab : jnotepadTabPane.getTabs()) {
|
for (Tab tab : jnotepadTabPane.getTabs()) {
|
||||||
// 获取绑定的文件
|
// 获取绑定的文件
|
||||||
@ -124,7 +124,7 @@ public class OpenFile implements EventHandler<ActionEvent> {
|
|||||||
// 设置当前标签页关联本地文件
|
// 设置当前标签页关联本地文件
|
||||||
tab.setRelevance(true);
|
tab.setRelevance(true);
|
||||||
tab.setUserData(file);
|
tab.setUserData(file);
|
||||||
UiUtil.getJnotepadTabPane().addNewTab(tab);
|
JNotepadTabPane.getInstance().addNewTab(tab);
|
||||||
});
|
});
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
LogUtil.getLogger(this.getClass()).info("已忽视IO异常!");
|
LogUtil.getLogger(this.getClass()).info("已忽视IO异常!");
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import javafx.stage.FileChooser;
|
|||||||
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
||||||
import org.jcnc.jnotepad.constants.TextConstants;
|
import org.jcnc.jnotepad.constants.TextConstants;
|
||||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||||
|
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||||
import org.jcnc.jnotepad.tool.LogUtil;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
import org.jcnc.jnotepad.tool.UiUtil;
|
import org.jcnc.jnotepad.tool.UiUtil;
|
||||||
import org.jcnc.jnotepad.ui.dialog.factory.impl.TextFileChooserFactory;
|
import org.jcnc.jnotepad.ui.dialog.factory.impl.TextFileChooserFactory;
|
||||||
@ -26,7 +27,7 @@ public class RenameFile implements EventHandler<ActionEvent> {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent actionEvent) {
|
public void handle(ActionEvent actionEvent) {
|
||||||
// 获取当前标签页
|
// 获取当前标签页
|
||||||
JNotepadTab jnotepadtab = UiUtil.getJnotepadtab();
|
JNotepadTab jnotepadtab = JNotepadTabPane.getInstance().getSelected();
|
||||||
if (jnotepadtab == null || jnotepadtab.getText().isEmpty()) {
|
if (jnotepadtab == null || jnotepadtab.getText().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -90,7 +91,7 @@ public class RenameFile implements EventHandler<ActionEvent> {
|
|||||||
// 获取原始文件对象
|
// 获取原始文件对象
|
||||||
File file = (File) jnotepadtab.getUserData();
|
File file = (File) jnotepadtab.getUserData();
|
||||||
// 获取应用窗口并绑定
|
// 获取应用窗口并绑定
|
||||||
File newFile = TextFileChooserFactory.getInstance()
|
File newFile = TextFileChooserFactory.getInstance()
|
||||||
.createFileChooser(
|
.createFileChooser(
|
||||||
UiResourceBundle.getContent(TextConstants.RENAME),
|
UiResourceBundle.getContent(TextConstants.RENAME),
|
||||||
jnotepadtab.getText(),
|
jnotepadtab.getText(),
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import org.jcnc.jnotepad.app.i18n.UiResourceBundle;
|
|||||||
import org.jcnc.jnotepad.constants.TextConstants;
|
import org.jcnc.jnotepad.constants.TextConstants;
|
||||||
import org.jcnc.jnotepad.controller.i18n.LocalizationController;
|
import org.jcnc.jnotepad.controller.i18n.LocalizationController;
|
||||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||||
|
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||||
|
import org.jcnc.jnotepad.root.top.menu.JNotepadMenuBar;
|
||||||
import org.jcnc.jnotepad.tool.LogUtil;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
import org.jcnc.jnotepad.tool.SingletonUtil;
|
import org.jcnc.jnotepad.tool.SingletonUtil;
|
||||||
import org.jcnc.jnotepad.tool.UiUtil;
|
import org.jcnc.jnotepad.tool.UiUtil;
|
||||||
@ -34,7 +36,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent actionEvent) {
|
public void handle(ActionEvent actionEvent) {
|
||||||
// 获取当前tab页
|
// 获取当前tab页
|
||||||
JNotepadTab selectedTab = UiUtil.getJnotepadtab();
|
JNotepadTab selectedTab = JNotepadTabPane.getInstance().getSelected();
|
||||||
if (selectedTab == null) {
|
if (selectedTab == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -50,7 +52,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
|
|||||||
if (CONFIG_NAME.equals(selectedTab.getText())) {
|
if (CONFIG_NAME.equals(selectedTab.getText())) {
|
||||||
// 重新加载语言包和快捷键
|
// 重新加载语言包和快捷键
|
||||||
SingletonUtil.getAppConfigController().loadConfig();
|
SingletonUtil.getAppConfigController().loadConfig();
|
||||||
UiUtil.getMenuBar().initShortcutKeys();
|
JNotepadMenuBar.getInstance().initShortcutKeys();
|
||||||
LocalizationController.initLocal();
|
LocalizationController.initLocal();
|
||||||
logger.info("已刷新语言包!");
|
logger.info("已刷新语言包!");
|
||||||
logger.info("已刷新快捷键!");
|
logger.info("已刷新快捷键!");
|
||||||
@ -66,7 +68,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
|
|||||||
* @see LogUtil
|
* @see LogUtil
|
||||||
*/
|
*/
|
||||||
protected void saveTab(Class<?> currentClass) {
|
protected void saveTab(Class<?> currentClass) {
|
||||||
JNotepadTab selectedTab = UiUtil.getJnotepadtab();
|
JNotepadTab selectedTab = JNotepadTabPane.getInstance().getSelected();
|
||||||
if (selectedTab == null) {
|
if (selectedTab == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@ package org.jcnc.jnotepad.controller.event.handler.tool;
|
|||||||
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import org.jcnc.jnotepad.tool.UiUtil;
|
import org.jcnc.jnotepad.ui.setStage.SetStage;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,7 +21,7 @@ public class SetBtn implements EventHandler<ActionEvent> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
UiUtil.getSetStage().openSetStage();
|
SetStage.getInstance().openSetStage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -9,6 +9,7 @@ import org.jcnc.jnotepad.ui.module.AbstractBorderPane;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根舞台下的Root主布局
|
* 根舞台下的Root主布局
|
||||||
|
*
|
||||||
* @author 许轲
|
* @author 许轲
|
||||||
*/
|
*/
|
||||||
public class RootBorderPane extends AbstractBorderPane {
|
public class RootBorderPane extends AbstractBorderPane {
|
||||||
@ -19,6 +20,10 @@ public class RootBorderPane extends AbstractBorderPane {
|
|||||||
initRootBorderPane();
|
initRootBorderPane();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RootBorderPane getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
private void initRootBorderPane() {
|
private void initRootBorderPane() {
|
||||||
//中间,用于显示Main主布局
|
//中间,用于显示Main主布局
|
||||||
setCenterComponent(MainBorderPane.getInstance());
|
setCenterComponent(MainBorderPane.getInstance());
|
||||||
@ -31,10 +36,6 @@ public class RootBorderPane extends AbstractBorderPane {
|
|||||||
//主布局的下面
|
//主布局的下面
|
||||||
setBottomComponent(RootBottomSideBarVBox.getInstance());
|
setBottomComponent(RootBottomSideBarVBox.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RootBorderPane getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -11,11 +11,11 @@ public class RootBottomSideBarVBox extends AbstractVBox {
|
|||||||
initSidebarVBox();
|
initSidebarVBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSidebarVBox() {
|
|
||||||
getChildren().addAll(JNotepadStatusBox.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RootBottomSideBarVBox getInstance() {
|
public static RootBottomSideBarVBox getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initSidebarVBox() {
|
||||||
|
getChildren().addAll(JNotepadStatusBox.getInstance());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,15 +16,15 @@ public class MainBorderPane extends AbstractBorderPane {
|
|||||||
initRootBorderPane();
|
initRootBorderPane();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MainBorderPane getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
private void initRootBorderPane() {
|
private void initRootBorderPane() {
|
||||||
//文本框
|
//文本框
|
||||||
setCenterComponent(JNotepadTabPane.getInstance());
|
setCenterComponent(JNotepadTabPane.getInstance());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MainBorderPane getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -80,6 +80,7 @@ public class JNotepadTab extends Tab {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存为指定文件
|
* 保存为指定文件
|
||||||
|
*
|
||||||
* @param file 新文件
|
* @param file 新文件
|
||||||
*/
|
*/
|
||||||
public void save(File file) {
|
public void save(File file) {
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
package org.jcnc.jnotepad.root.center.main.center.tab;
|
package org.jcnc.jnotepad.root.center.main.center.tab;
|
||||||
|
|
||||||
import javafx.scene.control.TabPane;
|
import javafx.scene.control.TabPane;
|
||||||
|
import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
|
||||||
|
import org.jcnc.jnotepad.root.top.menu.JNotepadMenuBar;
|
||||||
import org.jcnc.jnotepad.tool.SingletonUtil;
|
import org.jcnc.jnotepad.tool.SingletonUtil;
|
||||||
import org.jcnc.jnotepad.tool.UiUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标签页布局组件封装。
|
* 标签页布局组件封装。
|
||||||
@ -30,10 +31,10 @@ public class JNotepadTabPane extends TabPane {
|
|||||||
(ov, from, to) -> {
|
(ov, from, to) -> {
|
||||||
if (to != null) {
|
if (to != null) {
|
||||||
// 更新菜单栏中与tab相关设置
|
// 更新菜单栏中与tab相关设置
|
||||||
UiUtil.getMenuBar().updateMenuStatusBySelectedTab();
|
JNotepadMenuBar.getInstance().updateMenuStatusBySelectedTab();
|
||||||
}
|
}
|
||||||
// 更新状态标签
|
// 更新状态标签
|
||||||
UiUtil.getStatusBox().updateWhenTabSelected();
|
JNotepadStatusBox.getInstance().updateWhenTabSelected();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -71,6 +72,6 @@ public class JNotepadTabPane extends TabPane {
|
|||||||
public void fireTabSelected() {
|
public void fireTabSelected() {
|
||||||
JNotepadTab selectedTab = getSelected();
|
JNotepadTab selectedTab = getSelected();
|
||||||
selectedTab.setAutoLine(SingletonUtil.getAppConfigController().getAutoLineConfig());
|
selectedTab.setAutoLine(SingletonUtil.getAppConfigController().getAutoLineConfig());
|
||||||
UiUtil.getStatusBox().updateWhenTabSelected();
|
JNotepadStatusBox.getInstance().updateWhenTabSelected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,11 +10,11 @@ public class RootRightSideBarVBox extends AbstractVBox {
|
|||||||
initSidebarVBox();
|
initSidebarVBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSidebarVBox() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RootRightSideBarVBox getInstance() {
|
public static RootRightSideBarVBox getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initSidebarVBox() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,14 +17,14 @@ public class RootTopBorderPane extends AbstractBorderPane {
|
|||||||
initRootBorderPane();
|
initRootBorderPane();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RootTopBorderPane getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
private void initRootBorderPane() {
|
private void initRootBorderPane() {
|
||||||
//文本框上面
|
//文本框上面
|
||||||
setTopComponent(JNotepadMenuBar.getInstance());
|
setTopComponent(JNotepadMenuBar.getInstance());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RootTopBorderPane getInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@ public class SingletonUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取UI资源绑定组件I
|
* 获取UI资源绑定组件
|
||||||
*
|
*
|
||||||
* @return org.jcnc.jnotepad.app.i18n.UiResourceBundle
|
* @return org.jcnc.jnotepad.app.i18n.UiResourceBundle
|
||||||
* @since 2023/8/30 12:45
|
* @since 2023/8/30 12:45
|
||||||
|
|||||||
@ -2,61 +2,25 @@ package org.jcnc.jnotepad.tool;
|
|||||||
|
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.stage.Window;
|
import javafx.stage.Window;
|
||||||
|
import org.jcnc.jnotepad.LunchApp;
|
||||||
import org.jcnc.jnotepad.constants.AppConstants;
|
import org.jcnc.jnotepad.constants.AppConstants;
|
||||||
import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
|
|
||||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
|
||||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
|
||||||
import org.jcnc.jnotepad.root.top.menu.JNotepadMenuBar;
|
|
||||||
import org.jcnc.jnotepad.ui.setStage.SetStage;
|
|
||||||
import org.jcnc.jnotepad.view.manager.ViewManager;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UI工具<br>
|
* UI工具
|
||||||
* 封装了项目所有的UI组件,以减少组件单例模式造成代码的复杂性
|
|
||||||
*
|
*
|
||||||
* @author gewuyou
|
* @author gewuyou
|
||||||
*/
|
*/
|
||||||
public class UiUtil {
|
public class UiUtil {
|
||||||
/**
|
|
||||||
* 标签页布局组件
|
|
||||||
*/
|
|
||||||
private static final JNotepadTabPane TAB_PANE = JNotepadTabPane.getInstance();
|
|
||||||
/**
|
|
||||||
* 视图管理组件
|
|
||||||
*/
|
|
||||||
private static final ViewManager VIEW_MANAGER = ViewManager.getInstance();
|
|
||||||
/**
|
|
||||||
* 状态栏组件
|
|
||||||
*/
|
|
||||||
private static final JNotepadStatusBox STATUS_BOX = JNotepadStatusBox.getInstance();
|
|
||||||
/**
|
|
||||||
* 菜单栏组件
|
|
||||||
*/
|
|
||||||
private static final JNotepadMenuBar MENU_BAR = JNotepadMenuBar.getInstance();
|
|
||||||
/**
|
/**
|
||||||
* 应用程序图标
|
* 应用程序图标
|
||||||
*/
|
*/
|
||||||
private static final Image ICON = new Image(Objects.requireNonNull(UiUtil.class.getResource(AppConstants.APP_ICON)).toString());
|
private static final Image ICON = new Image(Objects.requireNonNull(UiUtil.class.getResource(AppConstants.APP_ICON)).toString());
|
||||||
/**
|
|
||||||
* 设置窗口
|
|
||||||
*/
|
|
||||||
private static final SetStage SET_STAGE = SetStage.getInstance();
|
|
||||||
|
|
||||||
private UiUtil() {
|
private UiUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取设置窗口
|
|
||||||
*
|
|
||||||
* @return org.jcnc.jnotepad.ui.setStage.SetStage
|
|
||||||
* @since 2023/8/30 12:39
|
|
||||||
*/
|
|
||||||
public static SetStage getSetStage() {
|
|
||||||
return SET_STAGE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取应用程序图标
|
* 获取应用程序图标
|
||||||
*
|
*
|
||||||
@ -67,30 +31,6 @@ public class UiUtil {
|
|||||||
return ICON;
|
return ICON;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取标签页布局组件
|
|
||||||
*
|
|
||||||
* @return org.jcnc.jnotepad.ui.root.center.tab.JNotepadTabPane
|
|
||||||
* @apiNote JNotepadTabPane.getInstance()
|
|
||||||
* @see JNotepadTabPane
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static JNotepadTabPane getJnotepadTabPane() {
|
|
||||||
return TAB_PANE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取标签页组件
|
|
||||||
*
|
|
||||||
* @return org.jcnc.jnotepad.ui.root.center.tab.JNotepadTab
|
|
||||||
* @apiNote JNotepadTabPane.getInstance().getSelected()<br>获取当前选中的标签页
|
|
||||||
* @see JNotepadTabPane
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static JNotepadTab getJnotepadtab() {
|
|
||||||
return TAB_PANE.getSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取应用窗口
|
* 获取应用窗口
|
||||||
*
|
*
|
||||||
@ -99,37 +39,6 @@ public class UiUtil {
|
|||||||
* @since 2023/8/29 14:12
|
* @since 2023/8/29 14:12
|
||||||
*/
|
*/
|
||||||
public static Window getAppWindow() {
|
public static Window getAppWindow() {
|
||||||
return TAB_PANE.getSelected().getTabPane().getScene().getWindow();
|
return LunchApp.getWindow();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取视图管理组件
|
|
||||||
*
|
|
||||||
* @return org.jcnc.jnotepad.view.manager.ViewManager
|
|
||||||
* @apiNote ViewManager.getInstance()
|
|
||||||
* @since 2023/8/29 14:13
|
|
||||||
*/
|
|
||||||
public static ViewManager getViewManager() {
|
|
||||||
return VIEW_MANAGER;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取状态栏组件
|
|
||||||
*
|
|
||||||
* @return org.jcnc.jnotepad.ui.root.bottom.status.JNotepadStatusBox
|
|
||||||
* @since 2023/8/29 14:14
|
|
||||||
*/
|
|
||||||
public static JNotepadStatusBox getStatusBox() {
|
|
||||||
return STATUS_BOX;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取菜单栏组件
|
|
||||||
*
|
|
||||||
* @return org.jcnc.jnotepad.ui.root.top.menu.JNotepadMenuBar
|
|
||||||
* @since 2023/8/29 14:15
|
|
||||||
*/
|
|
||||||
public static JNotepadMenuBar getMenuBar() {
|
|
||||||
return MENU_BAR;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,12 +13,12 @@ import java.io.File;
|
|||||||
*/
|
*/
|
||||||
public class TextFileChooserFactory implements FileChooserFactory {
|
public class TextFileChooserFactory implements FileChooserFactory {
|
||||||
|
|
||||||
|
private static final TextFileChooserFactory INSTANCE = new TextFileChooserFactory();
|
||||||
|
|
||||||
private TextFileChooserFactory() {
|
private TextFileChooserFactory() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final TextFileChooserFactory INSTANCE = new TextFileChooserFactory();
|
|
||||||
|
|
||||||
public static TextFileChooserFactory getInstance() {
|
public static TextFileChooserFactory getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,11 @@ package org.jcnc.jnotepad.ui.module;
|
|||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
|
import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
|
||||||
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
|
||||||
|
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
|
||||||
import org.jcnc.jnotepad.tool.LogUtil;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
import org.jcnc.jnotepad.tool.SingletonUtil;
|
import org.jcnc.jnotepad.tool.SingletonUtil;
|
||||||
import org.jcnc.jnotepad.tool.UiUtil;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
@ -19,9 +20,9 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class LineNumberTextArea extends BorderPane {
|
public class LineNumberTextArea extends BorderPane {
|
||||||
|
|
||||||
private static final Logger logger=LogUtil.getLogger(LineNumberTextArea.class);
|
|
||||||
static final int[] SIZE_TABLE = {9, 99, 999, 9999, 99999, 999999, 9999999,
|
static final int[] SIZE_TABLE = {9, 99, 999, 9999, 99999, 999999, 9999999,
|
||||||
99999999, 999999999, Integer.MAX_VALUE};
|
99999999, 999999999, Integer.MAX_VALUE};
|
||||||
|
private static final Logger logger = LogUtil.getLogger(LineNumberTextArea.class);
|
||||||
private static final int MIN_LINE_NUMBER_WIDTH = 30;
|
private static final int MIN_LINE_NUMBER_WIDTH = 30;
|
||||||
private final TextArea mainTextArea;
|
private final TextArea mainTextArea;
|
||||||
private final TextArea lineNumberArea;
|
private final TextArea lineNumberArea;
|
||||||
@ -59,12 +60,12 @@ public class LineNumberTextArea extends BorderPane {
|
|||||||
|
|
||||||
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
|
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
|
||||||
|
|
||||||
this.mainTextArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> UiUtil.getStatusBox().updateWordCountStatusLabel());
|
this.mainTextArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> JNotepadStatusBox.getInstance().updateWordCountStatusLabel());
|
||||||
this.textProperty().addListener((observable, oldValue, newValue) -> {
|
this.textProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
// 更新行号
|
// 更新行号
|
||||||
updateLineNumberArea();
|
updateLineNumberArea();
|
||||||
// 更新状态栏
|
// 更新状态栏
|
||||||
UiUtil.getStatusBox().updateWordCountStatusLabel();
|
JNotepadStatusBox.getInstance().updateWordCountStatusLabel();
|
||||||
// 自动保存
|
// 自动保存
|
||||||
save();
|
save();
|
||||||
});
|
});
|
||||||
@ -74,7 +75,7 @@ public class LineNumberTextArea extends BorderPane {
|
|||||||
* 以原文件编码格式写回文件
|
* 以原文件编码格式写回文件
|
||||||
*/
|
*/
|
||||||
public void save() {
|
public void save() {
|
||||||
JNotepadTab tab = UiUtil.getJnotepadtab();
|
JNotepadTab tab = JNotepadTabPane.getInstance().getSelected();
|
||||||
if (tab == null) {
|
if (tab == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user