🚩 添加使用系统文件选择器时显示应用图标
This commit is contained in:
parent
8f4448bac2
commit
5cda1ddf87
2
pom.xml
2
pom.xml
@ -13,8 +13,6 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<junit.version>5.9.2</junit.version>
|
<junit.version>5.9.2</junit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.mkpaz</groupId>
|
<groupId>io.github.mkpaz</groupId>
|
||||||
|
|||||||
@ -22,5 +22,8 @@ module org.jcnc.jnotepad {
|
|||||||
exports org.jcnc.jnotepad.constants;
|
exports org.jcnc.jnotepad.constants;
|
||||||
exports org.jcnc.jnotepad.ui;
|
exports org.jcnc.jnotepad.ui;
|
||||||
exports org.jcnc.jnotepad.controller.i18n;
|
exports org.jcnc.jnotepad.controller.i18n;
|
||||||
|
exports org.jcnc.jnotepad.ui.tab;
|
||||||
|
exports org.jcnc.jnotepad.ui.status;
|
||||||
|
exports org.jcnc.jnotepad.ui.menu;
|
||||||
opens org.jcnc.jnotepad.app.config;
|
opens org.jcnc.jnotepad.app.config;
|
||||||
}
|
}
|
||||||
@ -1,8 +1,5 @@
|
|||||||
package org.jcnc.jnotepad.Interface;
|
package org.jcnc.jnotepad.Interface;
|
||||||
|
|
||||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -43,8 +43,6 @@ public class LunchApp extends Application {
|
|||||||
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
|
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
|
||||||
scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/styles.css")).toExternalForm());
|
scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/styles.css")).toExternalForm());
|
||||||
initUiComponents();
|
initUiComponents();
|
||||||
|
|
||||||
|
|
||||||
UIResourceBundle.bindStringProperty(primaryStage.titleProperty(), TextConstants.TITLE);
|
UIResourceBundle.bindStringProperty(primaryStage.titleProperty(), TextConstants.TITLE);
|
||||||
primaryStage.setWidth(width);
|
primaryStage.setWidth(width);
|
||||||
primaryStage.setHeight(length);
|
primaryStage.setHeight(length);
|
||||||
|
|||||||
@ -15,6 +15,11 @@ import java.nio.file.Path;
|
|||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 应用程序配置控制器
|
||||||
|
*
|
||||||
|
* @author songdragon
|
||||||
|
*/
|
||||||
public class AppConfigController {
|
public class AppConfigController {
|
||||||
|
|
||||||
private static final Logger logger = LogUtil.getLogger(AppConfigController.class);
|
private static final Logger logger = LogUtil.getLogger(AppConfigController.class);
|
||||||
@ -104,7 +109,7 @@ public class AppConfigController {
|
|||||||
/**
|
/**
|
||||||
* 获取当前配置文件所在目录
|
* 获取当前配置文件所在目录
|
||||||
*
|
*
|
||||||
* @return
|
* @return 所在目录
|
||||||
*/
|
*/
|
||||||
public String getDir() {
|
public String getDir() {
|
||||||
return dir;
|
return dir;
|
||||||
|
|||||||
@ -4,8 +4,8 @@ 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.tool.UiUtil;
|
||||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
||||||
import org.jcnc.jnotepad.ui.status.JNotepadStatusBox;
|
|
||||||
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
||||||
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
||||||
import org.jcnc.jnotepad.view.manager.ViewManager;
|
import org.jcnc.jnotepad.view.manager.ViewManager;
|
||||||
@ -37,13 +37,13 @@ public class NewFile implements EventHandler<ActionEvent> {
|
|||||||
// 设置当前标签页与本地文件无关联
|
// 设置当前标签页与本地文件无关联
|
||||||
textArea.setRelevance(false);
|
textArea.setRelevance(false);
|
||||||
// TODO: refactor:统一TextArea新建、绑定监听器入口
|
// TODO: refactor:统一TextArea新建、绑定监听器入口
|
||||||
ViewManager viewManager = ViewManager.getInstance();
|
ViewManager viewManager = UiUtil.getViewManager();
|
||||||
// 将Tab页添加到TabPane中
|
// 将Tab页添加到TabPane中
|
||||||
JNotepadTabPane.getInstance().addNewTab(new JNotepadTab(UIResourceBundle.getContent(TextConstants.NEW_FILE)
|
JNotepadTabPane.getInstance().addNewTab(new JNotepadTab(UIResourceBundle.getContent(TextConstants.NEW_FILE)
|
||||||
+ viewManager.selfIncreaseAndGetTabIndex(),
|
+ viewManager.selfIncreaseAndGetTabIndex(),
|
||||||
textArea));
|
textArea));
|
||||||
|
|
||||||
// 更新编码信息
|
// 更新编码信息
|
||||||
JNotepadStatusBox.getInstance().updateEncodingLabel();
|
UiUtil.getStatusBox().updateEncodingLabel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -8,6 +8,7 @@ import javafx.stage.FileChooser;
|
|||||||
import org.jcnc.jnotepad.manager.ThreadPoolManager;
|
import org.jcnc.jnotepad.manager.ThreadPoolManager;
|
||||||
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.ui.LineNumberTextArea;
|
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
||||||
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
||||||
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
||||||
@ -39,7 +40,7 @@ public class OpenFile implements EventHandler<ActionEvent> {
|
|||||||
// 创建文件选择器
|
// 创建文件选择器
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
// 显示文件选择对话框,并获取选中的文件
|
// 显示文件选择对话框,并获取选中的文件
|
||||||
File file = fileChooser.showOpenDialog(null);
|
File file = fileChooser.showOpenDialog(UiUtil.getAppWindow());
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
openFile(file);
|
openFile(file);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,9 @@ import javafx.stage.FileChooser;
|
|||||||
import org.jcnc.jnotepad.controller.config.AppConfigController;
|
import org.jcnc.jnotepad.controller.config.AppConfigController;
|
||||||
import org.jcnc.jnotepad.controller.i18n.LocalizationController;
|
import org.jcnc.jnotepad.controller.i18n.LocalizationController;
|
||||||
import org.jcnc.jnotepad.tool.LogUtil;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
|
import org.jcnc.jnotepad.tool.UiUtil;
|
||||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
||||||
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
|
||||||
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
||||||
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -33,7 +32,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();
|
JNotepadTab selectedTab = UiUtil.getJnotepadtab();
|
||||||
if (selectedTab == null) {
|
if (selectedTab == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -51,7 +50,7 @@ public class SaveFile implements EventHandler<ActionEvent> {
|
|||||||
if (CONFIG_NAME.equals(selectedTab.getText())) {
|
if (CONFIG_NAME.equals(selectedTab.getText())) {
|
||||||
// 重新加载语言包和快捷键
|
// 重新加载语言包和快捷键
|
||||||
AppConfigController.getInstance().loadConfig();
|
AppConfigController.getInstance().loadConfig();
|
||||||
JNotepadMenuBar.getMenuBar().initShortcutKeys();
|
UiUtil.getMenuBar().initShortcutKeys();
|
||||||
LocalizationController.initLocal();
|
LocalizationController.initLocal();
|
||||||
logger.info("已刷新语言包!");
|
logger.info("已刷新语言包!");
|
||||||
logger.info("已刷新快捷键!");
|
logger.info("已刷新快捷键!");
|
||||||
@ -67,7 +66,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();
|
JNotepadTab selectedTab = UiUtil.getJnotepadtab();
|
||||||
if (selectedTab != null) {
|
if (selectedTab != null) {
|
||||||
// 创建一个文件窗口
|
// 创建一个文件窗口
|
||||||
FileChooser fileChooser = new FileChooser();
|
FileChooser fileChooser = new FileChooser();
|
||||||
@ -75,7 +74,8 @@ public class SaveFile implements EventHandler<ActionEvent> {
|
|||||||
fileChooser.setInitialFileName(selectedTab.getText());
|
fileChooser.setInitialFileName(selectedTab.getText());
|
||||||
// 设置保存文件类型
|
// 设置保存文件类型
|
||||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("文本文档", "*.txt"));
|
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("文本文档", "*.txt"));
|
||||||
File file = fileChooser.showSaveDialog(null);
|
// 获取应用窗口并绑定
|
||||||
|
File file = fileChooser.showSaveDialog(UiUtil.getAppWindow());
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
LogUtil.getLogger(currentClass).info("正在保存文件:{}", file.getName());
|
LogUtil.getLogger(currentClass).info("正在保存文件:{}", file.getName());
|
||||||
selectedTab.save();
|
selectedTab.save();
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package org.jcnc.jnotepad.tool;
|
package org.jcnc.jnotepad.tool;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.PrettyPrinter;
|
|
||||||
import com.fasterxml.jackson.core.util.DefaultIndenter;
|
import com.fasterxml.jackson.core.util.DefaultIndenter;
|
||||||
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
|
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|||||||
102
src/main/java/org/jcnc/jnotepad/tool/UiUtil.java
Normal file
102
src/main/java/org/jcnc/jnotepad/tool/UiUtil.java
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
package org.jcnc.jnotepad.tool;
|
||||||
|
|
||||||
|
import javafx.stage.Window;
|
||||||
|
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
||||||
|
import org.jcnc.jnotepad.ui.status.JNotepadStatusBox;
|
||||||
|
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
||||||
|
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
||||||
|
import org.jcnc.jnotepad.view.manager.ViewManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UI工具<br>
|
||||||
|
* 封装了项目所有的UI组件,以减少组件单例模式造成代码的复杂性
|
||||||
|
*
|
||||||
|
* @author gewuyou
|
||||||
|
*/
|
||||||
|
public class UiUtil {
|
||||||
|
private 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.getMenuBar();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取标签页布局组件
|
||||||
|
*
|
||||||
|
* @return org.jcnc.jnotepad.ui.tab.JNotepadTabPane
|
||||||
|
* @apiNote JNotepadTabPane.getInstance()
|
||||||
|
* @see JNotepadTabPane
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static JNotepadTabPane getJnotepadTabPane() {
|
||||||
|
return TAB_PANE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取标签页组件
|
||||||
|
*
|
||||||
|
* @return org.jcnc.jnotepad.ui.tab.JNotepadTab
|
||||||
|
* @apiNote JNotepadTabPane.getInstance().getSelected()<br>获取当前选中的标签页
|
||||||
|
* @see JNotepadTabPane
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static JNotepadTab getJnotepadtab() {
|
||||||
|
return TAB_PANE.getSelected();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取应用窗口
|
||||||
|
*
|
||||||
|
* @return javafx.stage.Window
|
||||||
|
* @apiNote JNotepadTabPane.getInstance().getSelected().getTabPane().getScene().getWindow()
|
||||||
|
* @since 2023/8/29 14:12
|
||||||
|
*/
|
||||||
|
public static Window getAppWindow() {
|
||||||
|
return TAB_PANE.getSelected().getTabPane().getScene().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.status.JNotepadStatusBox
|
||||||
|
* @since 2023/8/29 14:14
|
||||||
|
*/
|
||||||
|
public static JNotepadStatusBox getStatusBox() {
|
||||||
|
return STATUS_BOX;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取菜单栏组件
|
||||||
|
*
|
||||||
|
* @return org.jcnc.jnotepad.ui.menu.JNotepadMenuBar
|
||||||
|
* @since 2023/8/29 14:15
|
||||||
|
*/
|
||||||
|
public static JNotepadMenuBar getMenuBar() {
|
||||||
|
return MENU_BAR;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,8 +2,7 @@ package org.jcnc.jnotepad.ui.tab;
|
|||||||
|
|
||||||
import javafx.scene.control.TabPane;
|
import javafx.scene.control.TabPane;
|
||||||
import org.jcnc.jnotepad.controller.config.AppConfigController;
|
import org.jcnc.jnotepad.controller.config.AppConfigController;
|
||||||
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
import org.jcnc.jnotepad.tool.UiUtil;
|
||||||
import org.jcnc.jnotepad.ui.status.JNotepadStatusBox;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标签页布局组件封装。
|
* 标签页布局组件封装。
|
||||||
@ -27,10 +26,10 @@ public class JNotepadTabPane extends TabPane {
|
|||||||
(ov, from, to) -> {
|
(ov, from, to) -> {
|
||||||
if (to != null) {
|
if (to != null) {
|
||||||
// 更新菜单栏中与tab相关设置
|
// 更新菜单栏中与tab相关设置
|
||||||
JNotepadMenuBar.getMenuBar().updateMenuStatusBySelectedTab();
|
UiUtil.getMenuBar().updateMenuStatusBySelectedTab();
|
||||||
}
|
}
|
||||||
// 更新状态标签
|
// 更新状态标签
|
||||||
JNotepadStatusBox.getInstance().updateWhenTabSelected();
|
UiUtil.getStatusBox().updateWhenTabSelected();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -69,6 +68,6 @@ public class JNotepadTabPane extends TabPane {
|
|||||||
public void fireTabSelected() {
|
public void fireTabSelected() {
|
||||||
JNotepadTab selectedTab = getSelected();
|
JNotepadTab selectedTab = getSelected();
|
||||||
selectedTab.setAutoLine(AppConfigController.getInstance().getAutoLineConfig());
|
selectedTab.setAutoLine(AppConfigController.getInstance().getAutoLineConfig());
|
||||||
JNotepadStatusBox.getInstance().updateWhenTabSelected();
|
UiUtil.getStatusBox().updateWhenTabSelected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user