解决冲突

This commit is contained in:
许轲 2023-09-02 13:25:17 +08:00
parent 71dfbb76d4
commit 3e04aa09da
18 changed files with 123 additions and 183 deletions

View File

@ -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.interfaces; exports org.jcnc.jnotepad.interfaces;
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;

View File

@ -27,10 +27,7 @@ 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 +37,11 @@ public class LunchApp extends Application {
SCENE = new Scene(ROOT, width, length); SCENE = new Scene(ROOT, width, length);
} }
/**
* 线程池
*/
private final ExecutorService threadPool = ThreadPoolManager.getThreadPool();
/** /**
* 应用程序的入口点启动 JavaFX 应用程序 * 应用程序的入口点启动 JavaFX 应用程序
* *

View File

@ -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.center.tab.MainTab; import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
import org.jcnc.jnotepad.tool.UiUtil; import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
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;
@ -35,17 +36,17 @@ 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();
// 创建标签页 // 创建标签页
MainTab mainTab = new MainTab( JNotepadTab JNotepadTab = new JNotepadTab(
UiResourceBundle.getContent(TextConstants.NEW_FILE) UiResourceBundle.getContent(TextConstants.NEW_FILE)
+ viewManager.selfIncreaseAndGetTabIndex(), + viewManager.selfIncreaseAndGetTabIndex(),
textArea); textArea);
// 设置当前标签页与本地文件无关联 // 设置当前标签页与本地文件无关联
mainTab.setRelevance(false); JNotepadTab.setRelevance(false);
// 将Tab页添加到TabPane中 // 将Tab页添加到TabPane中
UiUtil.getJnotepadTabPane().addNewTab(mainTab); JNotepadTabPane.getInstance().addNewTab(JNotepadTab);
// 更新编码信息 // 更新编码信息
UiUtil.getStatusBox().updateEncodingLabel(); JNotepadStatusBox.getInstance().updateEncodingLabel();
} }
} }

View File

@ -9,8 +9,8 @@ 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.manager.ThreadPoolManager; import org.jcnc.jnotepad.manager.ThreadPoolManager;
import org.jcnc.jnotepad.root.center.main.center.tab.MainTab; import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
import org.jcnc.jnotepad.root.center.main.center.tab.MainTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
import org.jcnc.jnotepad.tool.EncodingDetector; import org.jcnc.jnotepad.tool.EncodingDetector;
import org.jcnc.jnotepad.tool.LogUtil; import org.jcnc.jnotepad.tool.LogUtil;
import org.jcnc.jnotepad.tool.UiUtil; import org.jcnc.jnotepad.tool.UiUtil;
@ -83,9 +83,9 @@ public class OpenFile implements EventHandler<ActionEvent> {
*/ */
public void openFile(File file) { public void openFile(File file) {
// 获取标签页集合 // 获取标签页集合
MainTabPane jnotepadMainTabPane = UiUtil.getJnotepadTabPane(); JNotepadTabPane jnotepadTabPane = JNotepadTabPane.getInstance();
// 遍历标签页查找匹配的标签页 // 遍历标签页查找匹配的标签页
for (Tab tab : jnotepadMainTabPane.getTabs()) { for (Tab tab : jnotepadTabPane.getTabs()) {
// 获取绑定的文件 // 获取绑定的文件
File tabFile = (File) tab.getUserData(); File tabFile = (File) tab.getUserData();
if (tabFile == null) { if (tabFile == null) {
@ -93,7 +93,7 @@ public class OpenFile implements EventHandler<ActionEvent> {
} }
if (file.getPath().equals((tabFile).getPath())) { if (file.getPath().equals((tabFile).getPath())) {
// 找到匹配的标签页设置为选中状态并跳转 // 找到匹配的标签页设置为选中状态并跳转
jnotepadMainTabPane.getSelectionModel().select(tab); jnotepadTabPane.getSelectionModel().select(tab);
return; return;
} }
} }
@ -119,11 +119,11 @@ public class OpenFile implements EventHandler<ActionEvent> {
LogUtil.getLogger(this.getClass()).info("已调用读取文件功能"); LogUtil.getLogger(this.getClass()).info("已调用读取文件功能");
Platform.runLater(() -> { Platform.runLater(() -> {
textArea.getMainTextArea().setText(text); textArea.getMainTextArea().setText(text);
MainTab tab = createNewTab(file.getName(), textArea, encoding); JNotepadTab tab = createNewTab(file.getName(), textArea, encoding);
// 设置当前标签页关联本地文件 // 设置当前标签页关联本地文件
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异常!");
@ -146,7 +146,7 @@ public class OpenFile implements EventHandler<ActionEvent> {
* @param textArea 文本区域 * @param textArea 文本区域
* @return 新的标签页 * @return 新的标签页
*/ */
private MainTab createNewTab(String tabName, LineNumberTextArea textArea, Charset charset) { private JNotepadTab createNewTab(String tabName, LineNumberTextArea textArea, Charset charset) {
return new MainTab(tabName, textArea, charset); return new JNotepadTab(tabName, textArea, charset);
} }
} }

View File

@ -7,7 +7,8 @@ import javafx.scene.input.KeyCode;
import javafx.stage.FileChooser; 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.MainTab; 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;
@ -29,7 +30,7 @@ public class RenameFile implements EventHandler<ActionEvent> {
@Override @Override
public void handle(ActionEvent actionEvent) { public void handle(ActionEvent actionEvent) {
// 获取当前标签页 // 获取当前标签页
MainTab jnotepadtab = UiUtil.getJnotepadtab(); JNotepadTab jnotepadtab = JNotepadTabPane.getInstance().getSelected();
if (jnotepadtab == null || jnotepadtab.getText().isEmpty()) { if (jnotepadtab == null || jnotepadtab.getText().isEmpty()) {
return; return;
} }
@ -49,7 +50,7 @@ public class RenameFile implements EventHandler<ActionEvent> {
* *
* @param jnotepadtab 标签页组件 * @param jnotepadtab 标签页组件
*/ */
private void handleRenameTab(MainTab jnotepadtab) { private void handleRenameTab(JNotepadTab jnotepadtab) {
TextField textField = new TextField(jnotepadtab.getText()); TextField textField = new TextField(jnotepadtab.getText());
textField.getStyleClass().add("tab-title-editable"); textField.getStyleClass().add("tab-title-editable");
// 清空标签页名称 // 清空标签页名称
@ -87,7 +88,7 @@ public class RenameFile implements EventHandler<ActionEvent> {
* *
* @param jnotepadtab 标签页组件 * @param jnotepadtab 标签页组件
*/ */
private void handleRenameRelevanceFile(MainTab jnotepadtab) { private void handleRenameRelevanceFile(JNotepadTab jnotepadtab) {
// 获取原始文件对象 // 获取原始文件对象
File file = (File) jnotepadtab.getUserData(); File file = (File) jnotepadtab.getUserData();
// 获取应用窗口并绑定 // 获取应用窗口并绑定

View File

@ -6,7 +6,9 @@ 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.controller.i18n.LocalizationController; import org.jcnc.jnotepad.controller.i18n.LocalizationController;
import org.jcnc.jnotepad.root.center.main.center.tab.MainTab; 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;
@ -38,7 +40,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
@Override @Override
public void handle(ActionEvent actionEvent) { public void handle(ActionEvent actionEvent) {
// 获取当前tab页 // 获取当前tab页
MainTab selectedTab = UiUtil.getJnotepadtab(); JNotepadTab selectedTab = JNotepadTabPane.getInstance().getSelected();
if (selectedTab == null) { if (selectedTab == null) {
return; return;
} }
@ -54,7 +56,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("已刷新快捷键!");
@ -70,7 +72,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
* @see LogUtil * @see LogUtil
*/ */
protected void saveTab(Class<?> currentClass) { protected void saveTab(Class<?> currentClass) {
MainTab selectedTab = UiUtil.getJnotepadtab(); JNotepadTab selectedTab = JNotepadTabPane.getInstance().getSelected();
if (selectedTab == null) { if (selectedTab == null) {
return; return;
} }

View File

@ -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.ui.setStage.SetStage; import org.jcnc.jnotepad.ui.setstage.SetStage;
/** /**
* 设置按钮事件的事件处理程序 * 设置按钮事件的事件处理程序

View File

@ -24,6 +24,15 @@ public class RootBorderPane extends AbstractBorderPane {
initRootBorderPane(); initRootBorderPane();
} }
/**
* 获取 RootBorderPane 的单例实例
*
* @return RootBorderPane 的单例实例
*/
public static RootBorderPane getInstance() {
return INSTANCE;
}
/** /**
* 初始化 RootBorderPane * 初始化 RootBorderPane
* *
@ -43,12 +52,5 @@ public class RootBorderPane extends AbstractBorderPane {
setBottomComponent(RootBottomSideBarVerticalBox.getInstance()); setBottomComponent(RootBottomSideBarVerticalBox.getInstance());
} }
/**
* 获取 RootBorderPane 的单例实例
*
* @return RootBorderPane 的单例实例
*/
public static RootBorderPane getInstance() {
return INSTANCE;
}
} }

View File

@ -1,6 +1,6 @@
package org.jcnc.jnotepad.root.bottom; package org.jcnc.jnotepad.root.bottom;
import org.jcnc.jnotepad.root.center.main.bottom.status.StatusHorizontalBox; import org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox;
import org.jcnc.jnotepad.ui.module.AbstractVerticalBox; import org.jcnc.jnotepad.ui.module.AbstractVerticalBox;
/** /**
@ -18,10 +18,6 @@ public class RootBottomSideBarVerticalBox extends AbstractVerticalBox {
initSidebarVerticalBox(); initSidebarVerticalBox();
} }
private void initSidebarVerticalBox() {
getChildren().addAll(StatusHorizontalBox.getInstance());
}
/** /**
* 获取 RootBottomSideBarVerticalBox 的唯一实例 * 获取 RootBottomSideBarVerticalBox 的唯一实例
* *
@ -30,4 +26,8 @@ public class RootBottomSideBarVerticalBox extends AbstractVerticalBox {
public static RootBottomSideBarVerticalBox getInstance() { public static RootBottomSideBarVerticalBox getInstance() {
return INSTANCE; return INSTANCE;
} }
private void initSidebarVerticalBox() {
getChildren().addAll(JNotepadStatusBox.getInstance());
}
} }

View File

@ -1,6 +1,6 @@
package org.jcnc.jnotepad.root.center.main; package org.jcnc.jnotepad.root.center.main;
import org.jcnc.jnotepad.root.center.main.center.tab.MainTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
import org.jcnc.jnotepad.ui.module.AbstractBorderPane; import org.jcnc.jnotepad.ui.module.AbstractBorderPane;
/** /**
@ -18,11 +18,6 @@ public class MainBorderPane extends AbstractBorderPane {
initRootBorderPane(); initRootBorderPane();
} }
private void initRootBorderPane() {
// 文本框
setCenterComponent(MainTabPane.getInstance());
}
/** /**
* 获取 MainBorderPane 的唯一实例 * 获取 MainBorderPane 的唯一实例
* *
@ -31,4 +26,10 @@ public class MainBorderPane extends AbstractBorderPane {
public static MainBorderPane getInstance() { public static MainBorderPane getInstance() {
return INSTANCE; return INSTANCE;
} }
private void initRootBorderPane() {
// 文本框
setCenterComponent(JNotepadTabPane.getInstance());
}
} }

View File

@ -6,8 +6,8 @@ import javafx.scene.control.Label;
import javafx.scene.control.TextArea; import javafx.scene.control.TextArea;
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.MainTab; import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
import org.jcnc.jnotepad.root.center.main.center.tab.MainTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
import org.jcnc.jnotepad.ui.module.AbstractHorizontalBox; import org.jcnc.jnotepad.ui.module.AbstractHorizontalBox;
import java.nio.charset.Charset; import java.nio.charset.Charset;
@ -19,9 +19,9 @@ import java.nio.charset.Charset;
* *
* @author songdragon * @author songdragon
*/ */
public class StatusHorizontalBox extends AbstractHorizontalBox { public class JNotepadStatusBox extends AbstractHorizontalBox {
private static final StatusHorizontalBox STATUS_BOX = new StatusHorizontalBox(); private static final JNotepadStatusBox STATUS_BOX = new JNotepadStatusBox();
private static final String STATUS_LABEL_FORMAT = "%s : %d \t%s: %d \t%s: %d \t"; private static final String STATUS_LABEL_FORMAT = "%s : %d \t%s: %d \t%s: %d \t";
/** /**
* 字数统计及光标 * 字数统计及光标
@ -33,11 +33,11 @@ public class StatusHorizontalBox extends AbstractHorizontalBox {
private Label encodingLabel; private Label encodingLabel;
private StatusHorizontalBox() { private JNotepadStatusBox() {
initStatusBox(); initStatusBox();
} }
public static StatusHorizontalBox getInstance() { public static JNotepadStatusBox getInstance() {
return STATUS_BOX; return STATUS_BOX;
} }
@ -89,7 +89,7 @@ public class StatusHorizontalBox extends AbstractHorizontalBox {
* 更新字数统计 * 更新字数统计
*/ */
public void updateWordCountStatusLabel() { public void updateWordCountStatusLabel() {
MainTabPane instance = MainTabPane.getInstance(); JNotepadTabPane instance = JNotepadTabPane.getInstance();
if (instance.getSelected() == null) { if (instance.getSelected() == null) {
return; return;
} }
@ -107,12 +107,12 @@ public class StatusHorizontalBox extends AbstractHorizontalBox {
* <br>2. 状态栏更新当前选中tab的字符编码 * <br>2. 状态栏更新当前选中tab的字符编码
*/ */
public void updateWhenTabSelected() { public void updateWhenTabSelected() {
MainTabPane instance = MainTabPane.getInstance(); JNotepadTabPane instance = JNotepadTabPane.getInstance();
if (instance.getSelected() != null) { if (instance.getSelected() != null) {
updateWordCountStatusLabel(); updateWordCountStatusLabel();
MainTab mainTab = instance.getSelected(); JNotepadTab JNotepadTab = instance.getSelected();
if (mainTab != null) { if (JNotepadTab != null) {
updateEncodingLabel(mainTab.getCharset().name()); updateEncodingLabel(JNotepadTab.getCharset().name());
} }
} }
} }

View File

@ -13,7 +13,7 @@ import java.nio.charset.Charset;
* *
* @author songdragon * @author songdragon
*/ */
public class MainTab extends Tab { public class JNotepadTab extends Tab {
private final LineNumberTextArea lineNumberTextArea; private final LineNumberTextArea lineNumberTextArea;
/** /**
@ -26,15 +26,15 @@ public class MainTab extends Tab {
private boolean isRelevance = false; private boolean isRelevance = false;
private Charset charset = Charset.defaultCharset(); private Charset charset = Charset.defaultCharset();
public MainTab(String tabTitle) { public JNotepadTab(String tabTitle) {
this(tabTitle, new LineNumberTextArea()); this(tabTitle, new LineNumberTextArea());
} }
public MainTab(String tabTitle, LineNumberTextArea textArea) { public JNotepadTab(String tabTitle, LineNumberTextArea textArea) {
this(tabTitle, textArea, Charset.defaultCharset()); this(tabTitle, textArea, Charset.defaultCharset());
} }
public MainTab(String tabTitle, LineNumberTextArea textArea, Charset charset) { public JNotepadTab(String tabTitle, LineNumberTextArea textArea, Charset charset) {
super(tabTitle); super(tabTitle);
lineNumberTextArea = textArea; lineNumberTextArea = textArea;
this.setContent(lineNumberTextArea); this.setContent(lineNumberTextArea);

View File

@ -10,15 +10,15 @@ import org.jcnc.jnotepad.tool.SingletonUtil;
* *
* @author songdragon * @author songdragon
*/ */
public class MainTabPane extends TabPane { public class JNotepadTabPane extends TabPane {
private static final MainTabPane TAB_PANE = new MainTabPane(); private static final JNotepadTabPane TAB_PANE = new JNotepadTabPane();
private MainTabPane() { private JNotepadTabPane() {
initListeners(); initListeners();
} }
public static MainTabPane getInstance() { public static JNotepadTabPane getInstance() {
return TAB_PANE; return TAB_PANE;
} }
@ -44,7 +44,7 @@ public class MainTabPane extends TabPane {
* *
* @param tab 新标签页 * @param tab 新标签页
*/ */
public void addNewTab(MainTab tab) { public void addNewTab(JNotepadTab tab) {
if (tab == null) { if (tab == null) {
return; return;
} }
@ -61,8 +61,8 @@ public class MainTabPane extends TabPane {
* *
* @return 当前选中的标签页 * @return 当前选中的标签页
*/ */
public MainTab getSelected() { public JNotepadTab getSelected() {
return (MainTab) this.getSelectionModel().getSelectedItem(); return (JNotepadTab) this.getSelectionModel().getSelectedItem();
} }
/** /**
@ -70,7 +70,7 @@ public class MainTabPane extends TabPane {
* 应用当前菜单上选中的自动换行设置 * 应用当前菜单上选中的自动换行设置
*/ */
public void fireTabSelected() { public void fireTabSelected() {
MainTab selectedTab = getSelected(); JNotepadTab selectedTab = getSelected();
selectedTab.setAutoLine(SingletonUtil.getAppConfigController().getAutoLineConfig()); selectedTab.setAutoLine(SingletonUtil.getAppConfigController().getAutoLineConfig());
JNotepadStatusBox.getInstance().updateWhenTabSelected(); JNotepadStatusBox.getInstance().updateWhenTabSelected();
} }

View File

@ -3,21 +3,36 @@ package org.jcnc.jnotepad.root.right;
import org.jcnc.jnotepad.ui.module.AbstractVerticalBox; import org.jcnc.jnotepad.ui.module.AbstractVerticalBox;
/** /**
* @author 许轲 * 右侧边栏的垂直布局容器类
*
* <p>该类用于管理右侧边栏的布局和内容</p>
*
* @Author 许轲
*/ */
public class RootRightSideBarVerticalBox extends AbstractVerticalBox { public class RootRightSideBarVerticalBox extends AbstractVerticalBox {
/**
* 唯一的 RootRightSideBarVerticalBox 实例使用单例模式
*/
private static final RootRightSideBarVerticalBox INSTANCE = new RootRightSideBarVerticalBox(); private static final RootRightSideBarVerticalBox INSTANCE = new RootRightSideBarVerticalBox();
private RootRightSideBarVerticalBox() { private RootRightSideBarVerticalBox() {
initSidebarVerticalBox(); initSidebarVerticalBox();
} }
private void initSidebarVerticalBox() { /**
* 获取 RootRightSideBarVerticalBox 的唯一实例
} *
* @return RootRightSideBarVerticalBox 的实例
*/
public static RootRightSideBarVerticalBox getInstance() { public static RootRightSideBarVerticalBox getInstance() {
return INSTANCE; return INSTANCE;
} }
/**
* 初始化右侧边栏的垂直布局
*/
private void initSidebarVerticalBox() {
// 在此添加右侧边栏布局和内容的初始化代码
}
} }

View File

@ -20,6 +20,15 @@ public class RootTopBorderPane extends AbstractBorderPane {
initRootBorderPane(); initRootBorderPane();
} }
/**
* 获取 RootTopBorderPane 的单例实例
*
* @return RootTopBorderPane 的单例实例
*/
public static RootTopBorderPane getInstance() {
return INSTANCE;
}
/** /**
* 初始化 RootTopBorderPane * 初始化 RootTopBorderPane
* *
@ -29,13 +38,4 @@ public class RootTopBorderPane extends AbstractBorderPane {
// 在顶部区域添加菜单栏 // 在顶部区域添加菜单栏
setTopComponent(JNotepadMenuBar.getInstance()); setTopComponent(JNotepadMenuBar.getInstance());
} }
/**
* 获取 RootTopBorderPane 的单例实例
*
* @return RootTopBorderPane 的单例实例
*/
public static RootTopBorderPane getInstance() {
return INSTANCE;
}
} }

View File

@ -10,8 +10,8 @@ import org.jcnc.jnotepad.controller.config.AppConfigController;
import org.jcnc.jnotepad.controller.event.handler.menubar.*; import org.jcnc.jnotepad.controller.event.handler.menubar.*;
import org.jcnc.jnotepad.controller.event.handler.tool.SetBtn; import org.jcnc.jnotepad.controller.event.handler.tool.SetBtn;
import org.jcnc.jnotepad.controller.i18n.LocalizationController; import org.jcnc.jnotepad.controller.i18n.LocalizationController;
import org.jcnc.jnotepad.root.center.main.center.tab.MainTab; import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab;
import org.jcnc.jnotepad.root.center.main.center.tab.MainTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane;
import org.jcnc.jnotepad.root.left.sidebar.tools.ToolBar; import org.jcnc.jnotepad.root.left.sidebar.tools.ToolBar;
import org.jcnc.jnotepad.tool.LogUtil; import org.jcnc.jnotepad.tool.LogUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -35,7 +35,7 @@ public class JNotepadMenuBar extends MenuBar {
/** /**
* 标签页布局组件封装 * 标签页布局组件封装
*/ */
MainTabPane mainTabPane = MainTabPane.getInstance(); JNotepadTabPane JNotepadTabPane = org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane.getInstance();
AppConfigController appConfigController = AppConfigController.getInstance(); AppConfigController appConfigController = AppConfigController.getInstance();
Logger logger = LogUtil.getLogger(this.getClass()); Logger logger = LogUtil.getLogger(this.getClass());
/** /**
@ -289,7 +289,7 @@ public class JNotepadMenuBar extends MenuBar {
// 1. 更新全局配置 // 1. 更新全局配置
AppConfigController.getInstance().setAutoLineConfig(after); AppConfigController.getInstance().setAutoLineConfig(after);
// 2. 对当前tab生效配置 // 2. 对当前tab生效配置
mainTabPane.fireTabSelected(); JNotepadTabPane.fireTabSelected();
}); });
topItem.selectedProperty().addListener((observableValue, before, after) -> { topItem.selectedProperty().addListener((observableValue, before, after) -> {
// 获取窗口容器 // 获取窗口容器
@ -322,7 +322,7 @@ public class JNotepadMenuBar extends MenuBar {
* 根据当前选中tab更新菜单选项 * 根据当前选中tab更新菜单选项
*/ */
public void updateMenuStatusBySelectedTab() { public void updateMenuStatusBySelectedTab() {
MainTab selectedTab = mainTabPane.getSelected(); JNotepadTab selectedTab = JNotepadTabPane.getSelected();
lineFeedItem.selectedProperty().setValue(selectedTab.isAutoLine()); lineFeedItem.selectedProperty().setValue(selectedTab.isAutoLine());
} }
} }

View File

@ -2,13 +2,8 @@ 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.StatusHorizontalBox;
import org.jcnc.jnotepad.root.center.main.center.tab.MainTab;
import org.jcnc.jnotepad.root.center.main.center.tab.MainTabPane;
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;
@ -20,42 +15,14 @@ import java.util.Objects;
* @author gewuyou * @author gewuyou
*/ */
public class UiUtil { public class UiUtil {
/**
* 标签页布局组件
*/
private static final MainTabPane TAB_PANE = MainTabPane.getInstance();
/**
* 视图管理组件
*/
private static final ViewManager VIEW_MANAGER = ViewManager.getInstance();
/**
* 状态栏组件
*/
private static final StatusHorizontalBox STATUS_BOX = StatusHorizontalBox.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 设置窗口对象
*/
public static SetStage getSetStage() {
return SET_STAGE;
}
/** /**
* 获取应用程序图标 * 获取应用程序图标
@ -66,28 +33,6 @@ public class UiUtil {
return ICON; return ICON;
} }
/**
* 获取标签页布局组件
*
* @return org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane 标签页布局组件对象
* @apiNote JNotepadTabPane.getInstance()
* @see MainTabPane
*/
public static MainTabPane getJnotepadTabPane() {
return TAB_PANE;
}
/**
* 获取标签页组件
*
* @return org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab 标签页组件对象
* @apiNote JNotepadTabPane.getInstance().getSelected()<br>获取当前选中的标签页
* @see MainTabPane
*/
public static MainTab getJnotepadtab() {
return TAB_PANE.getSelected();
}
/** /**
* 获取应用窗口 * 获取应用窗口
* *
@ -95,34 +40,8 @@ public class UiUtil {
* @apiNote JNotepadTabPane.getInstance().getSelected().getTabPane().getScene().getWindow() * @apiNote JNotepadTabPane.getInstance().getSelected().getTabPane().getScene().getWindow()
*/ */
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()
*/
public static ViewManager getViewManager() {
return VIEW_MANAGER;
}
/**
* 获取状态栏组件
*
* @return org.jcnc.jnotepad.root.center.main.bottom.status.JNotepadStatusBox 状态栏组件对象
*/
public static StatusHorizontalBox getStatusBox() {
return STATUS_BOX;
}
/**
* 获取菜单栏组件
*
* @return org.jcnc.jnotepad.root.top.menu.JNotepadMenuBar 菜单栏组件对象
*/
public static JNotepadMenuBar getMenuBar() {
return MENU_BAR;
}
} }

View File

@ -3,7 +3,9 @@ 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.center.tab.MainTab; 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.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;
@ -23,9 +25,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;
@ -61,12 +63,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();
}); });
@ -76,7 +78,7 @@ public class LineNumberTextArea extends BorderPane {
* 以原文件编码格式写回文件 * 以原文件编码格式写回文件
*/ */
public void save() { public void save() {
MainTab tab = UiUtil.getJnotepadtab(); JNotepadTab tab = JNotepadTabPane.getInstance().getSelected();
if (tab == null) { if (tab == null) {
return; return;
} }