⚰️ 删除无用代码 🐛 修复 BUG 当无打开文件时打开文件程序抛空指针异常问题

This commit is contained in:
gewuyou 2023-08-26 13:49:35 +08:00
parent 5ad48be1cd
commit 7ab6793179
8 changed files with 20 additions and 149 deletions

View File

@ -1,5 +1,6 @@
package org.jcnc.jnotepad;
import atlantafx.base.theme.PrimerLight;
import javafx.application.Application;
import javafx.application.Platform;
@ -55,7 +56,6 @@ public class LunchApp extends Application {
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());

View File

@ -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;
}
}

View File

@ -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 {

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -74,7 +74,7 @@ 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);

View File

@ -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/";
}

View File

@ -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() {