!69 ♻️ 重构代码

Merge pull request !69 from 格物方能致知/develop
This commit is contained in:
格物方能致知 2023-09-02 06:00:12 +00:00 committed by Gitee
commit f1b8187edd
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
12 changed files with 85 additions and 85 deletions

View File

@ -4,9 +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.bottom.status.BottomStatusBox;
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
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;
@ -38,15 +38,15 @@ public class NewFile implements EventHandler<ActionEvent> {
// TODO: refactor统一TextArea新建绑定监听器入口 // TODO: refactor统一TextArea新建绑定监听器入口
ViewManager viewManager = ViewManager.getInstance(); ViewManager viewManager = ViewManager.getInstance();
// 创建标签页 // 创建标签页
JNotepadTab JNotepadTab = new JNotepadTab( CenterTab centerTab = new CenterTab(
UiResourceBundle.getContent(TextConstants.NEW_FILE) UiResourceBundle.getContent(TextConstants.NEW_FILE)
+ viewManager.selfIncreaseAndGetTabIndex(), + viewManager.selfIncreaseAndGetTabIndex(),
textArea); textArea);
// 设置当前标签页与本地文件无关联 // 设置当前标签页与本地文件无关联
JNotepadTab.setRelevance(false); centerTab.setRelevance(false);
// 将Tab页添加到TabPane中 // 将Tab页添加到TabPane中
JNotepadTabPane.getInstance().addNewTab(JNotepadTab); CenterTabPane.getInstance().addNewTab(centerTab);
// 更新编码信息 // 更新编码信息
JNotepadStatusBox.getInstance().updateEncodingLabel(); BottomStatusBox.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.JNotepadTab; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
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,7 +83,7 @@ public class OpenFile implements EventHandler<ActionEvent> {
*/ */
public void openFile(File file) { public void openFile(File file) {
// 获取标签页集合 // 获取标签页集合
JNotepadTabPane jnotepadTabPane = JNotepadTabPane.getInstance(); CenterTabPane jnotepadTabPane = CenterTabPane.getInstance();
// 遍历标签页查找匹配的标签页 // 遍历标签页查找匹配的标签页
for (Tab tab : jnotepadTabPane.getTabs()) { for (Tab tab : jnotepadTabPane.getTabs()) {
// 获取绑定的文件 // 获取绑定的文件
@ -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);
JNotepadTab tab = createNewTab(file.getName(), textArea, encoding); CenterTab tab = createNewTab(file.getName(), textArea, encoding);
// 设置当前标签页关联本地文件 // 设置当前标签页关联本地文件
tab.setRelevance(true); tab.setRelevance(true);
tab.setUserData(file); tab.setUserData(file);
JNotepadTabPane.getInstance().addNewTab(tab); CenterTabPane.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 JNotepadTab createNewTab(String tabName, LineNumberTextArea textArea, Charset charset) { private CenterTab createNewTab(String tabName, LineNumberTextArea textArea, Charset charset) {
return new JNotepadTab(tabName, textArea, charset); return new CenterTab(tabName, textArea, charset);
} }
} }

View File

@ -7,8 +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.JNotepadTab; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
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;
@ -30,54 +30,54 @@ public class RenameFile implements EventHandler<ActionEvent> {
@Override @Override
public void handle(ActionEvent actionEvent) { public void handle(ActionEvent actionEvent) {
// 获取当前标签页 // 获取当前标签页
JNotepadTab jnotepadtab = JNotepadTabPane.getInstance().getSelected(); CenterTab centerTab = CenterTabPane.getInstance().getSelected();
if (jnotepadtab == null || jnotepadtab.getText().isEmpty()) { if (centerTab == null || centerTab.getText().isEmpty()) {
return; return;
} }
// 判断当前是否为关联文件 // 判断当前是否为关联文件
if (jnotepadtab.isRelevance()) { if (centerTab.isRelevance()) {
// 重命名关联文件 // 重命名关联文件
handleRenameRelevanceFile(jnotepadtab); handleRenameRelevanceFile(centerTab);
} }
// 如果当前不是关联文件则重命名标签页 // 如果当前不是关联文件则重命名标签页
else { else {
handleRenameTab(jnotepadtab); handleRenameTab(centerTab);
} }
} }
/** /**
* 重命名标签页 * 重命名标签页
* *
* @param jnotepadtab 标签页组件 * @param centerTab 标签页组件
*/ */
private void handleRenameTab(JNotepadTab jnotepadtab) { private void handleRenameTab(CenterTab centerTab) {
TextField textField = new TextField(jnotepadtab.getText()); TextField textField = new TextField(centerTab.getText());
textField.getStyleClass().add("tab-title-editable"); textField.getStyleClass().add("tab-title-editable");
// 清空标签页名称 // 清空标签页名称
jnotepadtab.setText(""); centerTab.setText("");
// 监听 Enter 完成编辑 // 监听 Enter 完成编辑
textField.setOnKeyPressed(event -> { textField.setOnKeyPressed(event -> {
if (event.getCode() == KeyCode.ENTER) { if (event.getCode() == KeyCode.ENTER) {
jnotepadtab.setText(textField.getText()); centerTab.setText(textField.getText());
// 可选移除 TextField 的图形 // 可选移除 TextField 的图形
jnotepadtab.setGraphic(null); centerTab.setGraphic(null);
// 可选恢复标签页的关闭按钮 // 可选恢复标签页的关闭按钮
jnotepadtab.setClosable(true); centerTab.setClosable(true);
} }
}); });
// 监听失去焦点事件完成编辑 // 监听失去焦点事件完成编辑
textField.focusedProperty().addListener((observable, oldValue, newValue) -> { textField.focusedProperty().addListener((observable, oldValue, newValue) -> {
if (Boolean.FALSE.equals(newValue)) { if (Boolean.FALSE.equals(newValue)) {
jnotepadtab.setText(textField.getText()); centerTab.setText(textField.getText());
// 可选移除 TextField 的图形 // 可选移除 TextField 的图形
jnotepadtab.setGraphic(null); centerTab.setGraphic(null);
// 可选恢复标签页的关闭按钮 // 可选恢复标签页的关闭按钮
jnotepadtab.setClosable(true); centerTab.setClosable(true);
} }
}); });
jnotepadtab.setClosable(false); centerTab.setClosable(false);
// 设置 TextField 作为标签页的图形 // 设置 TextField 作为标签页的图形
jnotepadtab.setGraphic(textField); centerTab.setGraphic(textField);
// 默认获取焦点并选中所有文字 // 默认获取焦点并选中所有文字
textField.requestFocus(); textField.requestFocus();
textField.selectAll(); textField.selectAll();
@ -86,25 +86,25 @@ public class RenameFile implements EventHandler<ActionEvent> {
/** /**
* 重命名关联文件 * 重命名关联文件
* *
* @param jnotepadtab 标签页组件 * @param centerTab 标签页组件
*/ */
private void handleRenameRelevanceFile(JNotepadTab jnotepadtab) { private void handleRenameRelevanceFile(CenterTab centerTab) {
// 获取原始文件对象 // 获取原始文件对象
File file = (File) jnotepadtab.getUserData(); File file = (File) centerTab.getUserData();
// 获取应用窗口并绑定 // 获取应用窗口并绑定
File newFile = TextFileChooserFactory.getInstance() File newFile = TextFileChooserFactory.getInstance()
.createFileChooser( .createFileChooser(
UiResourceBundle.getContent(TextConstants.RENAME), UiResourceBundle.getContent(TextConstants.RENAME),
jnotepadtab.getText(), centerTab.getText(),
new File(file.getParent()), new File(file.getParent()),
new FileChooser.ExtensionFilter("All types", "*.*")) new FileChooser.ExtensionFilter("All types", "*.*"))
.showSaveDialog(UiUtil.getAppWindow()); .showSaveDialog(UiUtil.getAppWindow());
if (newFile != null) { if (newFile != null) {
boolean rename = file.renameTo(newFile); boolean rename = file.renameTo(newFile);
// 设置文件数据 // 设置文件数据
jnotepadtab.setUserData(newFile); centerTab.setUserData(newFile);
if (rename) { if (rename) {
jnotepadtab.setText(newFile.getName()); centerTab.setText(newFile.getName());
logger.info("文件重命名成功"); logger.info("文件重命名成功");
} else { } else {
logger.debug("文件重命名失败"); logger.debug("文件重命名失败");

View File

@ -6,8 +6,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.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.CenterTab;
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
import org.jcnc.jnotepad.root.top.menu.TopMenuBar; import org.jcnc.jnotepad.root.top.menu.TopMenuBar;
import org.jcnc.jnotepad.tool.LogUtil; import org.jcnc.jnotepad.tool.LogUtil;
import org.jcnc.jnotepad.tool.SingletonUtil; import org.jcnc.jnotepad.tool.SingletonUtil;
@ -40,7 +40,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
@Override @Override
public void handle(ActionEvent actionEvent) { public void handle(ActionEvent actionEvent) {
// 获取当前tab页 // 获取当前tab页
JNotepadTab selectedTab = JNotepadTabPane.getInstance().getSelected(); CenterTab selectedTab = CenterTabPane.getInstance().getSelected();
if (selectedTab == null) { if (selectedTab == null) {
return; return;
} }
@ -72,7 +72,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
* @see LogUtil * @see LogUtil
*/ */
protected void saveTab(Class<?> currentClass) { protected void saveTab(Class<?> currentClass) {
JNotepadTab selectedTab = JNotepadTabPane.getInstance().getSelected(); CenterTab selectedTab = CenterTabPane.getInstance().getSelected();
if (selectedTab == null) { if (selectedTab == null) {
return; return;
} }

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.JNotepadStatusBox; import org.jcnc.jnotepad.root.center.main.bottom.status.BottomStatusBox;
import org.jcnc.jnotepad.ui.module.AbstractVerticalBox; import org.jcnc.jnotepad.ui.module.AbstractVerticalBox;
/** /**
@ -28,6 +28,6 @@ public class RootBottomSideBarVerticalBox extends AbstractVerticalBox {
} }
private void initSidebarVerticalBox() { private void initSidebarVerticalBox() {
getChildren().addAll(JNotepadStatusBox.getInstance()); getChildren().addAll(BottomStatusBox.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.JNotepadTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
import org.jcnc.jnotepad.ui.module.AbstractBorderPane; import org.jcnc.jnotepad.ui.module.AbstractBorderPane;
/** /**
@ -29,7 +29,7 @@ public class MainBorderPane extends AbstractBorderPane {
private void initRootBorderPane() { private void initRootBorderPane() {
// 文本框 // 文本框
setCenterComponent(JNotepadTabPane.getInstance()); setCenterComponent(CenterTabPane.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.JNotepadTab; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
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 JNotepadStatusBox extends AbstractHorizontalBox { public class BottomStatusBox extends AbstractHorizontalBox {
private static final JNotepadStatusBox STATUS_BOX = new JNotepadStatusBox(); private static final BottomStatusBox STATUS_BOX = new BottomStatusBox();
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 JNotepadStatusBox extends AbstractHorizontalBox {
private Label encodingLabel; private Label encodingLabel;
private JNotepadStatusBox() { private BottomStatusBox() {
initStatusBox(); initStatusBox();
} }
public static JNotepadStatusBox getInstance() { public static BottomStatusBox getInstance() {
return STATUS_BOX; return STATUS_BOX;
} }
@ -89,7 +89,7 @@ public class JNotepadStatusBox extends AbstractHorizontalBox {
* 更新字数统计 * 更新字数统计
*/ */
public void updateWordCountStatusLabel() { public void updateWordCountStatusLabel() {
JNotepadTabPane instance = JNotepadTabPane.getInstance(); CenterTabPane instance = CenterTabPane.getInstance();
if (instance.getSelected() == null) { if (instance.getSelected() == null) {
return; return;
} }
@ -107,12 +107,12 @@ public class JNotepadStatusBox extends AbstractHorizontalBox {
* <br>2. 状态栏更新当前选中tab的字符编码 * <br>2. 状态栏更新当前选中tab的字符编码
*/ */
public void updateWhenTabSelected() { public void updateWhenTabSelected() {
JNotepadTabPane instance = JNotepadTabPane.getInstance(); CenterTabPane instance = CenterTabPane.getInstance();
if (instance.getSelected() != null) { if (instance.getSelected() != null) {
updateWordCountStatusLabel(); updateWordCountStatusLabel();
JNotepadTab JNotepadTab = instance.getSelected(); CenterTab CenterTab = instance.getSelected();
if (JNotepadTab != null) { if (CenterTab != null) {
updateEncodingLabel(JNotepadTab.getCharset().name()); updateEncodingLabel(CenterTab.getCharset().name());
} }
} }
} }

View File

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

View File

@ -1,7 +1,7 @@
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.center.main.bottom.status.BottomStatusBox;
import org.jcnc.jnotepad.root.top.menu.TopMenuBar; import org.jcnc.jnotepad.root.top.menu.TopMenuBar;
import org.jcnc.jnotepad.tool.SingletonUtil; import org.jcnc.jnotepad.tool.SingletonUtil;
@ -10,15 +10,15 @@ import org.jcnc.jnotepad.tool.SingletonUtil;
* *
* @author songdragon * @author songdragon
*/ */
public class JNotepadTabPane extends TabPane { public class CenterTabPane extends TabPane {
private static final JNotepadTabPane TAB_PANE = new JNotepadTabPane(); private static final CenterTabPane TAB_PANE = new CenterTabPane();
private JNotepadTabPane() { private CenterTabPane() {
initListeners(); initListeners();
} }
public static JNotepadTabPane getInstance() { public static CenterTabPane getInstance() {
return TAB_PANE; return TAB_PANE;
} }
@ -34,7 +34,7 @@ public class JNotepadTabPane extends TabPane {
TopMenuBar.getInstance().updateMenuStatusBySelectedTab(); TopMenuBar.getInstance().updateMenuStatusBySelectedTab();
} }
// 更新状态标签 // 更新状态标签
JNotepadStatusBox.getInstance().updateWhenTabSelected(); BottomStatusBox.getInstance().updateWhenTabSelected();
} }
); );
} }
@ -44,7 +44,7 @@ public class JNotepadTabPane extends TabPane {
* *
* @param tab 新标签页 * @param tab 新标签页
*/ */
public void addNewTab(JNotepadTab tab) { public void addNewTab(CenterTab tab) {
if (tab == null) { if (tab == null) {
return; return;
} }
@ -61,8 +61,8 @@ public class JNotepadTabPane extends TabPane {
* *
* @return 当前选中的标签页 * @return 当前选中的标签页
*/ */
public JNotepadTab getSelected() { public CenterTab getSelected() {
return (JNotepadTab) this.getSelectionModel().getSelectedItem(); return (CenterTab) this.getSelectionModel().getSelectedItem();
} }
/** /**
@ -70,8 +70,8 @@ public class JNotepadTabPane extends TabPane {
* 应用当前菜单上选中的自动换行设置 * 应用当前菜单上选中的自动换行设置
*/ */
public void fireTabSelected() { public void fireTabSelected() {
JNotepadTab selectedTab = getSelected(); CenterTab selectedTab = getSelected();
selectedTab.setAutoLine(SingletonUtil.getAppConfigController().getAutoLineConfig()); selectedTab.setAutoLine(SingletonUtil.getAppConfigController().getAutoLineConfig());
JNotepadStatusBox.getInstance().updateWhenTabSelected(); BottomStatusBox.getInstance().updateWhenTabSelected();
} }
} }

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.JNotepadTab; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
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 TopMenuBar extends MenuBar {
/** /**
* 标签页布局组件封装 * 标签页布局组件封装
*/ */
JNotepadTabPane JNotepadTabPane = org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane.getInstance(); CenterTabPane centerTabPane = CenterTabPane.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 TopMenuBar extends MenuBar {
// 1. 更新全局配置 // 1. 更新全局配置
AppConfigController.getInstance().setAutoLineConfig(after); AppConfigController.getInstance().setAutoLineConfig(after);
// 2. 对当前tab生效配置 // 2. 对当前tab生效配置
JNotepadTabPane.fireTabSelected(); centerTabPane.fireTabSelected();
}); });
topItem.selectedProperty().addListener((observableValue, before, after) -> { topItem.selectedProperty().addListener((observableValue, before, after) -> {
// 获取窗口容器 // 获取窗口容器
@ -322,7 +322,7 @@ public class TopMenuBar extends MenuBar {
* 根据当前选中tab更新菜单选项 * 根据当前选中tab更新菜单选项
*/ */
public void updateMenuStatusBySelectedTab() { public void updateMenuStatusBySelectedTab() {
JNotepadTab selectedTab = JNotepadTabPane.getSelected(); CenterTab selectedTab = centerTabPane.getSelected();
lineFeedItem.selectedProperty().setValue(selectedTab.isAutoLine()); lineFeedItem.selectedProperty().setValue(selectedTab.isAutoLine());
} }
} }

View File

@ -37,7 +37,7 @@ public class UiUtil {
* 获取应用窗口 * 获取应用窗口
* *
* @return javafx.stage.Window 应用窗口对象 * @return javafx.stage.Window 应用窗口对象
* @apiNote JNotepadTabPane.getInstance().getSelected().getTabPane().getScene().getWindow() * @apiNote LunchApp.getWindow()
*/ */
public static Window getAppWindow() { public static Window getAppWindow() {
return LunchApp.getWindow(); return LunchApp.getWindow();

View File

@ -3,9 +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.bottom.status.JNotepadStatusBox; import org.jcnc.jnotepad.root.center.main.bottom.status.BottomStatusBox;
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTab; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTab;
import org.jcnc.jnotepad.root.center.main.center.tab.JNotepadTabPane; import org.jcnc.jnotepad.root.center.main.center.tab.CenterTabPane;
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.slf4j.Logger; import org.slf4j.Logger;
@ -62,12 +62,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) -> JNotepadStatusBox.getInstance().updateWordCountStatusLabel()); this.mainTextArea.caretPositionProperty().addListener((caretObservable, oldPosition, newPosition) -> BottomStatusBox.getInstance().updateWordCountStatusLabel());
this.textProperty().addListener((observable, oldValue, newValue) -> { this.textProperty().addListener((observable, oldValue, newValue) -> {
// 更新行号 // 更新行号
updateLineNumberArea(); updateLineNumberArea();
// 更新状态栏 // 更新状态栏
JNotepadStatusBox.getInstance().updateWordCountStatusLabel(); BottomStatusBox.getInstance().updateWordCountStatusLabel();
// 自动保存 // 自动保存
save(); save();
}); });
@ -77,7 +77,7 @@ public class LineNumberTextArea extends BorderPane {
* 以原文件编码格式写回文件 * 以原文件编码格式写回文件
*/ */
public void save() { public void save() {
JNotepadTab tab = JNotepadTabPane.getInstance().getSelected(); CenterTab tab = CenterTabPane.getInstance().getSelected();
if (tab == null) { if (tab == null) {
return; return;
} }