!33 修改项目文件结构 ⚰️ 删除无用代码 修复 BUG 当无打开文件时打开文件程序抛空指针异常问题
Merge pull request !33 from 格物方能致知/master
This commit is contained in:
commit
0a4fb7150d
1
pom.xml
1
pom.xml
@ -56,6 +56,7 @@
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.4.11</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.ibm.icu</groupId>
|
||||
<artifactId>icu4j</artifactId>
|
||||
|
||||
@ -22,4 +22,5 @@ module org.jcnc.jnotepad {
|
||||
exports org.jcnc.jnotepad.view.manager;
|
||||
exports org.jcnc.jnotepad.constants;
|
||||
exports org.jcnc.jnotepad.ui;
|
||||
exports org.jcnc.jnotepad.app.init;
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package org.jcnc.jnotepad;
|
||||
|
||||
|
||||
import atlantafx.base.theme.PrimerLight;
|
||||
import javafx.application.Application;
|
||||
import javafx.application.Platform;
|
||||
@ -7,10 +8,10 @@ import javafx.scene.Scene;
|
||||
import javafx.scene.image.Image;
|
||||
import javafx.scene.layout.Pane;
|
||||
import javafx.stage.Stage;
|
||||
import org.jcnc.jnotepad.app.config.LoadJnotepadConfig;
|
||||
import org.jcnc.jnotepad.app.config.LoadLanguageConfig;
|
||||
import org.jcnc.jnotepad.app.config.LoadShortcutKeyConfig;
|
||||
import org.jcnc.jnotepad.app.config.LocalizationConfig;
|
||||
import org.jcnc.jnotepad.app.init.LoadJnotepadConfig;
|
||||
import org.jcnc.jnotepad.app.init.LoadLanguageConfig;
|
||||
import org.jcnc.jnotepad.app.init.LoadShortcutKeyConfig;
|
||||
import org.jcnc.jnotepad.constants.AppConstants;
|
||||
import org.jcnc.jnotepad.controller.manager.Controller;
|
||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
||||
@ -24,7 +25,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 启动程序
|
||||
*
|
||||
@ -53,11 +53,9 @@ public class LunchApp extends Application {
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
Pane root = new Pane();
|
||||
|
||||
double width = AppConstants.SCREEN_WIDTH;
|
||||
double length = AppConstants.SCREEN_LENGTH;
|
||||
String icon = AppConstants.APP_ICON;
|
||||
|
||||
scene = new Scene(root, width, length);
|
||||
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
|
||||
scene.getStylesheets().add(Objects.requireNonNull(getClass().getResource("/css/styles.css")).toExternalForm());
|
||||
|
||||
@ -1,53 +0,0 @@
|
||||
package org.jcnc.jnotepad.app.config;
|
||||
|
||||
|
||||
import org.jcnc.jnotepad.app.entity.ShortcutKey;
|
||||
import org.jcnc.jnotepad.app.entity.Style;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 应用程序配置类
|
||||
*
|
||||
* @author gewuyou 一个大转盘
|
||||
* @see [相关类/方法]
|
||||
*/
|
||||
public class JnotepadConfig {
|
||||
/**
|
||||
* 快捷键列表
|
||||
*/
|
||||
private List<ShortcutKey> shortcutKeyList;
|
||||
|
||||
/**
|
||||
* 样式列表 TODO
|
||||
*/
|
||||
private List<Style> styleList;
|
||||
|
||||
/**
|
||||
* 单例模式
|
||||
*/
|
||||
private JnotepadConfig() {
|
||||
}
|
||||
|
||||
private static final JnotepadConfig INSTANCE = new JnotepadConfig();
|
||||
|
||||
public static JnotepadConfig getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public List<ShortcutKey> getShortcutKeyList() {
|
||||
return shortcutKeyList;
|
||||
}
|
||||
|
||||
public void setShortcutKeyList(List<ShortcutKey> shortcutKeyList) {
|
||||
this.shortcutKeyList = shortcutKeyList;
|
||||
}
|
||||
|
||||
public List<Style> getStyleList() {
|
||||
return styleList;
|
||||
}
|
||||
|
||||
public void setStyleList(List<Style> styleList) {
|
||||
this.styleList = styleList;
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,6 @@
|
||||
package org.jcnc.jnotepad.app.config;
|
||||
|
||||
import org.jcnc.jnotepad.LunchApp;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@ -11,8 +12,9 @@ import static org.jcnc.jnotepad.constants.AppConstants.APP_NAME;
|
||||
import static org.jcnc.jnotepad.constants.TextConstants.*;
|
||||
|
||||
/**
|
||||
* 本地化配置文件
|
||||
*
|
||||
* 本地化配置文件<br>
|
||||
* 注意:该配置文件必须先于快捷键配置文件加载
|
||||
* @see LunchApp
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class LocalizationConfig {
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
package org.jcnc.jnotepad.app.entity;
|
||||
|
||||
/**
|
||||
* 快捷键
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class ShortcutKey {
|
||||
private String buttonName;
|
||||
private String shortcutKeyValue;
|
||||
|
||||
public ShortcutKey() {
|
||||
}
|
||||
|
||||
public ShortcutKey(String buttonName, String shortcutKeyValue) {
|
||||
this.buttonName = buttonName;
|
||||
this.shortcutKeyValue = shortcutKeyValue;
|
||||
}
|
||||
|
||||
public String getButtonName() {
|
||||
return buttonName;
|
||||
}
|
||||
|
||||
public void setButtonName(String buttonName) {
|
||||
this.buttonName = buttonName;
|
||||
}
|
||||
|
||||
public String getShortcutKeyValue() {
|
||||
return shortcutKeyValue;
|
||||
}
|
||||
|
||||
public void setShortcutKeyValue(String shortcutKeyValue) {
|
||||
this.shortcutKeyValue = shortcutKeyValue;
|
||||
}
|
||||
}
|
||||
@ -1,35 +0,0 @@
|
||||
package org.jcnc.jnotepad.app.entity;
|
||||
|
||||
/**
|
||||
* 样式
|
||||
*
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class Style {
|
||||
private String styleName;
|
||||
private String styleValue;
|
||||
|
||||
public Style() {
|
||||
}
|
||||
|
||||
public Style(String styleName, String styleValue) {
|
||||
this.styleName = styleName;
|
||||
this.styleValue = styleValue;
|
||||
}
|
||||
|
||||
public String getStyleName() {
|
||||
return styleName;
|
||||
}
|
||||
|
||||
public void setStyleName(String styleName) {
|
||||
this.styleName = styleName;
|
||||
}
|
||||
|
||||
public String getStyleValue() {
|
||||
return styleValue;
|
||||
}
|
||||
|
||||
public void setStyleValue(String styleValue) {
|
||||
this.styleValue = styleValue;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,9 @@
|
||||
package org.jcnc.jnotepad.app.config;
|
||||
package org.jcnc.jnotepad.app.init;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.jcnc.jnotepad.app.config.LocalizationConfig;
|
||||
import org.jcnc.jnotepad.exception.AppException;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.jcnc.jnotepad.tool.PopUpUtil;
|
||||
@ -61,6 +62,7 @@ public abstract class LoadJnotepadConfig<T> {
|
||||
// 不存在则创建
|
||||
createConfig();
|
||||
try {
|
||||
// 创建后重新加载
|
||||
loadConfig(new FileInputStream(CONFIG_NAME));
|
||||
} catch (FileNotFoundException ex) {
|
||||
throw new AppException(ex.getMessage());
|
||||
@ -72,24 +74,12 @@ public abstract class LoadJnotepadConfig<T> {
|
||||
* 解析配置文件
|
||||
*
|
||||
* @param inputStream 输入流
|
||||
* @return java.util.List<java.util.LinkedHashMap < java.lang.String, java.lang.String>>
|
||||
* @return T
|
||||
* @since 2023/8/25 15:18
|
||||
*/
|
||||
protected abstract T parseConfig(InputStream inputStream);
|
||||
|
||||
private void createConfig() {
|
||||
// List<ShortcutKey> shortcutKeyList = getShortcutKeys();
|
||||
// JnotepadConfig.getInstance().setShortcutKeyList(shortcutKeyList);
|
||||
// for (ShortcutKey shortcutKey : shortcutKeyList) {
|
||||
// // 保证json的key必须和变量名一致
|
||||
// MenuItem menuItem = JNotepadMenuBar.getMenuBar().getItemMap().get(shortcutKey.getButtonName());
|
||||
// String shortKeyValue = shortcutKey.getShortcutKeyValue();
|
||||
// if ("".equals(shortKeyValue) || Objects.isNull(menuItem)) {
|
||||
// continue;
|
||||
// }
|
||||
// // 动态添加快捷键
|
||||
// menuItem.setAccelerator(KeyCombination.keyCombination(shortKeyValue));
|
||||
// }
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(CONFIG_NAME))) {
|
||||
writer.write(JNOTEPAD_CONFIG);
|
||||
} catch (IOException e) {
|
||||
@ -98,36 +88,6 @@ public abstract class LoadJnotepadConfig<T> {
|
||||
LocalizationConfig.getLocalizationConfig().initLocalizationConfig();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 获取快捷键集合
|
||||
// *
|
||||
// * @return java.util.List<org.jcnc.jnotepad.app.entity.ShortcutKey> 快捷键集合
|
||||
// * @since 2023/8/24 14:19
|
||||
// */
|
||||
// private static List<ShortcutKey> getShortcutKeys() {
|
||||
// List<ShortcutKey> shortcutKeyList = new ArrayList<>();
|
||||
// // 打开文件
|
||||
// ShortcutKey shortcutKeyOfOpen = new ShortcutKey("openItem", "ctrl+o");
|
||||
//
|
||||
// // 新建
|
||||
// ShortcutKey shortcutKeyOfNew = new ShortcutKey("newItem", "ctrl+n");
|
||||
//
|
||||
// // 保存
|
||||
// ShortcutKey shortcutKeyOfSave = new ShortcutKey("saveItem", "ctrl+s");
|
||||
//
|
||||
// // 保存作为
|
||||
// ShortcutKey shortcutKeyOfSaveAs = new ShortcutKey("saveAsItem", "ctrl+shift+s");
|
||||
//
|
||||
// // 打开配置文件
|
||||
// ShortcutKey shortcutKeyOfOpenConfig = new ShortcutKey("openConfigItem", "alt+s");
|
||||
//
|
||||
// shortcutKeyList.add(shortcutKeyOfOpen);
|
||||
// shortcutKeyList.add(shortcutKeyOfNew);
|
||||
// shortcutKeyList.add(shortcutKeyOfSave);
|
||||
// shortcutKeyList.add(shortcutKeyOfSaveAs);
|
||||
// shortcutKeyList.add(shortcutKeyOfOpenConfig);
|
||||
// return shortcutKeyList;
|
||||
// }
|
||||
|
||||
/**
|
||||
* 加载配置文件
|
||||
@ -1,5 +1,6 @@
|
||||
package org.jcnc.jnotepad.app.config;
|
||||
package org.jcnc.jnotepad.app.init;
|
||||
|
||||
import org.jcnc.jnotepad.app.config.LocalizationConfig;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
||||
import org.slf4j.Logger;
|
||||
@ -1,4 +1,4 @@
|
||||
package org.jcnc.jnotepad.app.config;
|
||||
package org.jcnc.jnotepad.app.init;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import javafx.scene.control.MenuItem;
|
||||
@ -1,16 +1,10 @@
|
||||
package org.jcnc.jnotepad.constants;
|
||||
|
||||
/**
|
||||
* 路径常量
|
||||
*
|
||||
* 路径常量<br>
|
||||
* @author gewuyou
|
||||
*/
|
||||
public class PathConstants {
|
||||
private PathConstants() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置文件路径
|
||||
*/
|
||||
public static final String CONFIGURATION_FILE_PATH = "../config/";
|
||||
}
|
||||
|
||||
@ -2,8 +2,8 @@ package org.jcnc.jnotepad.controller.event.handler;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.EventHandler;
|
||||
import org.jcnc.jnotepad.app.config.LoadLanguageConfig;
|
||||
import org.jcnc.jnotepad.app.config.LoadShortcutKeyConfig;
|
||||
import org.jcnc.jnotepad.app.init.LoadLanguageConfig;
|
||||
import org.jcnc.jnotepad.app.init.LoadShortcutKeyConfig;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
||||
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
||||
|
||||
@ -52,14 +52,10 @@ public class LineNumberTextArea extends BorderPane {
|
||||
|
||||
private void initListeners() {
|
||||
// 当主要文本区域的垂直滚动位置发生变化时,使行号文本区域的滚动位置保持一致
|
||||
mainTextArea.scrollTopProperty().addListener((observable, oldValue, newValue) -> {
|
||||
lineNumberArea.setScrollTop(mainTextArea.getScrollTop());
|
||||
});
|
||||
mainTextArea.scrollTopProperty().addListener((observable, oldValue, newValue) -> lineNumberArea.setScrollTop(mainTextArea.getScrollTop()));
|
||||
|
||||
// 当行号文本区域的垂直滚动位置发生变化时,使主要文本区域的滚动位置保持一致
|
||||
lineNumberArea.scrollTopProperty().addListener((observable, oldValue, newValue) -> {
|
||||
mainTextArea.setScrollTop(lineNumberArea.getScrollTop());
|
||||
});
|
||||
lineNumberArea.scrollTopProperty().addListener((observable, oldValue, newValue) -> mainTextArea.setScrollTop(lineNumberArea.getScrollTop()));
|
||||
|
||||
lineNumberArea.textProperty().addListener((observable, oldValue, newValue) -> updateLineNumberWidth());
|
||||
|
||||
@ -79,14 +75,16 @@ public class LineNumberTextArea extends BorderPane {
|
||||
*/
|
||||
public void save() {
|
||||
JNotepadTab tab = JNotepadTabPane.getInstance().getSelected();
|
||||
File file = (File) tab.getUserData();
|
||||
String newValue = this.mainTextArea.getText();
|
||||
if (file != null) {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file, tab.getCharset()))) {
|
||||
writer.write(newValue);
|
||||
LogUtil.getLogger(this.getClass()).info("正在自动保存---");
|
||||
} catch (IOException ignored) {
|
||||
LogUtil.getLogger(this.getClass()).info("已忽视IO异常!");
|
||||
if (tab != null) {
|
||||
File file = (File) tab.getUserData();
|
||||
String newValue = this.mainTextArea.getText();
|
||||
if (file != null) {
|
||||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(file, tab.getCharset()))) {
|
||||
writer.write(newValue);
|
||||
LogUtil.getLogger(this.getClass()).info("正在自动保存---");
|
||||
} catch (IOException ignored) {
|
||||
LogUtil.getLogger(this.getClass()).info("已忽视IO异常!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -137,7 +135,7 @@ public class LineNumberTextArea extends BorderPane {
|
||||
|
||||
// 恢复之前的滚动位置
|
||||
mainTextArea.setScrollTop(mainTextAreaScrollTop);
|
||||
lineNumberArea.setScrollTop(lineNumberAreaScrollTop-8);
|
||||
lineNumberArea.setScrollTop(lineNumberAreaScrollTop - 8);
|
||||
}
|
||||
|
||||
public TextArea getMainTextArea() {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package org.jcnc.jnotepad.view.init;
|
||||
|
||||
import org.jcnc.jnotepad.app.config.LoadJnotepadConfig;
|
||||
import org.jcnc.jnotepad.app.init.LoadJnotepadConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user