commit
810ba4c447
@ -31,7 +31,7 @@ public interface ControllerInterface {
|
|||||||
*
|
*
|
||||||
* @param file 文件
|
* @param file 文件
|
||||||
*/
|
*/
|
||||||
LineNumberTextArea getText(File file);
|
void getText(File file);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新UI和标签页
|
* 更新UI和标签页
|
||||||
|
|||||||
@ -4,6 +4,8 @@ import org.jcnc.jnotepad.init.Config;
|
|||||||
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static org.jcnc.jnotepad.constants.TextConstants.TEXT_WRAP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内存中,运行过程中的全局配置项
|
* 内存中,运行过程中的全局配置项
|
||||||
*
|
*
|
||||||
@ -11,10 +13,6 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
public class GlobalConfig {
|
public class GlobalConfig {
|
||||||
|
|
||||||
/**
|
|
||||||
* 自动换行配置key
|
|
||||||
*/
|
|
||||||
public static final String TEXT_WRAP = "text.wrap";
|
|
||||||
private static final GlobalConfig APP_GLOBAL_CONFIG = new GlobalConfig();
|
private static final GlobalConfig APP_GLOBAL_CONFIG = new GlobalConfig();
|
||||||
private final Properties properties;
|
private final Properties properties;
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ public class PathConstants {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 快捷键配置文件路径
|
* 快捷键配置文件路径
|
||||||
* todo:这里这个配置可以通过配置文件读取
|
* todo:这里这个配置应当可以通过配置文件读取
|
||||||
*/
|
*/
|
||||||
public static final String SHORTCUT_KEY_CONFIGURATION_FILE_PATH = "/config/shortcutKey.json";
|
public static final String SHORTCUT_KEY_CONFIGURATION_FILE_PATH = "/config/shortcutKey.json";
|
||||||
}
|
}
|
||||||
|
|||||||
67
src/main/java/org/jcnc/jnotepad/constants/TextConstants.java
Normal file
67
src/main/java/org/jcnc/jnotepad/constants/TextConstants.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package org.jcnc.jnotepad.constants;
|
||||||
|
|
||||||
|
import org.jcnc.jnotepad.init.Config;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 文本常量
|
||||||
|
*
|
||||||
|
* @author gewuyou
|
||||||
|
*/
|
||||||
|
public class TextConstants {
|
||||||
|
private TextConstants() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Config CONFIG = new Config();
|
||||||
|
private static final Properties PROPERTIES = CONFIG.readPropertiesFromFile();
|
||||||
|
|
||||||
|
///菜单栏文本常量
|
||||||
|
|
||||||
|
public static final String SAVA = PROPERTIES.getProperty("SAVA");
|
||||||
|
|
||||||
|
public static final String FILE = PROPERTIES.getProperty("FILE");
|
||||||
|
|
||||||
|
public static final String NEW = PROPERTIES.getProperty("NEW");
|
||||||
|
|
||||||
|
public static final String OPEN = PROPERTIES.getProperty("OPEN");
|
||||||
|
|
||||||
|
public static final String SAVA_AS = PROPERTIES.getProperty("SAVA_AS");
|
||||||
|
|
||||||
|
public static final String SET = PROPERTIES.getProperty("SET");
|
||||||
|
|
||||||
|
public static final String WORD_WRAP = PROPERTIES.getProperty("WORD_WRAP");
|
||||||
|
|
||||||
|
public static final String PLUGIN = PROPERTIES.getProperty("PLUGIN");
|
||||||
|
|
||||||
|
public static final String ADD_PLUGIN = PROPERTIES.getProperty("ADD_PLUGIN");
|
||||||
|
|
||||||
|
public static final String STATISTICS = PROPERTIES.getProperty("STATISTICS");
|
||||||
|
|
||||||
|
/// GlobalConfig文本常量
|
||||||
|
/**
|
||||||
|
* 自动换行配置key
|
||||||
|
*/
|
||||||
|
public static final String TEXT_WRAP = "text.wrap";
|
||||||
|
|
||||||
|
/// NewFile 文本常量
|
||||||
|
|
||||||
|
public static final String NEW_FILE = PROPERTIES.getProperty("NEW_FILE");
|
||||||
|
|
||||||
|
/// Config 文本常量
|
||||||
|
|
||||||
|
public static final String JNOTEPAD_CH_LANGUAGE_PACK_NAME = PROPERTIES.getProperty("JNotepad ch_language_pack");
|
||||||
|
public static final String JNOTEPAD_EN_LANGUAGE_PACK_NAME = PROPERTIES.getProperty("JNotepad en_language_pack");
|
||||||
|
|
||||||
|
/// EncodingDetector 文本常量
|
||||||
|
public static final String UNKNOWN = "UNKNOWN";
|
||||||
|
|
||||||
|
/// JNotepadStatusBox
|
||||||
|
public static final String ROW = PROPERTIES.getProperty("ROW");
|
||||||
|
|
||||||
|
public static final String COLUMN = PROPERTIES.getProperty("COLUMN");
|
||||||
|
|
||||||
|
public static final String WORD_COUNT = PROPERTIES.getProperty("WORD_COUNT");
|
||||||
|
|
||||||
|
public static final String ENCODE = PROPERTIES.getProperty("ENCODE");
|
||||||
|
}
|
||||||
@ -2,14 +2,14 @@ package org.jcnc.jnotepad.controller.event.handler;
|
|||||||
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
import org.jcnc.jnotepad.init.Config;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
||||||
import org.jcnc.jnotepad.ui.status.JNotepadStatusBox;
|
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;
|
||||||
|
|
||||||
import java.util.Properties;
|
import static org.jcnc.jnotepad.constants.TextConstants.NEW_FILE;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,9 +21,6 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
public class NewFile implements EventHandler<ActionEvent> {
|
public class NewFile implements EventHandler<ActionEvent> {
|
||||||
|
|
||||||
Config config = new Config();
|
|
||||||
Properties properties = config.readPropertiesFromFile();
|
|
||||||
String NEW_FILE = properties.getProperty("NEW_FILE");
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 处理新建文件事件。
|
* 处理新建文件事件。
|
||||||
@ -38,6 +35,7 @@ public class NewFile implements EventHandler<ActionEvent> {
|
|||||||
|
|
||||||
// TODO: refactor:统一TextArea新建、绑定监听器入口
|
// TODO: refactor:统一TextArea新建、绑定监听器入口
|
||||||
ViewManager viewManager = ViewManager.getInstance();
|
ViewManager viewManager = ViewManager.getInstance();
|
||||||
|
LogUtil.getLogger(NewFile.class).info("{}", NEW_FILE);
|
||||||
// 将Tab页添加到TabPane中
|
// 将Tab页添加到TabPane中
|
||||||
JNotepadTabPane.getInstance().addNewTab(new JNotepadTab(NEW_FILE
|
JNotepadTabPane.getInstance().addNewTab(new JNotepadTab(NEW_FILE
|
||||||
+ viewManager.selfIncreaseAndGetTabIndex(),
|
+ viewManager.selfIncreaseAndGetTabIndex(),
|
||||||
|
|||||||
@ -32,28 +32,40 @@ public class OpenFile implements EventHandler<ActionEvent> {
|
|||||||
File file = fileChooser.showOpenDialog(null);
|
File file = fileChooser.showOpenDialog(null);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
// 创建打开文件的任务
|
// 创建打开文件的任务
|
||||||
Task<Void> openFileTask = new Task<>() {
|
Task<Void> openFileTask = getVoidTask(controller, file);
|
||||||
@Override
|
|
||||||
protected Void call() {
|
|
||||||
// 调用控制器的getText方法,读取文件内容
|
|
||||||
controller.getText(file);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 设置任务成功完成时的处理逻辑
|
|
||||||
openFileTask.setOnSucceeded(e -> {
|
|
||||||
// 处理成功的逻辑
|
|
||||||
});
|
|
||||||
|
|
||||||
// 设置任务失败时的处理逻辑
|
|
||||||
openFileTask.setOnFailed(e -> {
|
|
||||||
// 处理失败的逻辑
|
|
||||||
});
|
|
||||||
|
|
||||||
// 创建并启动线程执行任务
|
// 创建并启动线程执行任务
|
||||||
Thread thread = new Thread(openFileTask);
|
Thread thread = new Thread(openFileTask);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取空返回值任务
|
||||||
|
*
|
||||||
|
* @param controller 控制器
|
||||||
|
* @param file 文件
|
||||||
|
* @return javafx.concurrent.Task<java.lang.Void>
|
||||||
|
* @apiNote
|
||||||
|
*/
|
||||||
|
private static Task<Void> getVoidTask(Controller controller, File file) {
|
||||||
|
Task<Void> openFileTask = new Task<>() {
|
||||||
|
@Override
|
||||||
|
protected Void call() {
|
||||||
|
// 调用控制器的getText方法,读取文件内容
|
||||||
|
controller.getText(file);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 设置任务成功完成时的处理逻辑
|
||||||
|
openFileTask.setOnSucceeded(e -> {
|
||||||
|
// 处理成功的逻辑
|
||||||
|
});
|
||||||
|
|
||||||
|
// 设置任务失败时的处理逻辑
|
||||||
|
openFileTask.setOnFailed(e -> {
|
||||||
|
// 处理失败的逻辑
|
||||||
|
});
|
||||||
|
return openFileTask;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@ package org.jcnc.jnotepad.controller.event.handler;
|
|||||||
|
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.tool.FileUtil.saveTab;
|
import static org.jcnc.jnotepad.tool.FileUtil.saveTab;
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ public class SaveAsFile implements EventHandler<ActionEvent> {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
|
LogUtil.getLogger(SaveAsFile.class).info("已调用另存为功能");
|
||||||
saveTab(this.getClass());
|
saveTab(this.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package org.jcnc.jnotepad.controller.manager;
|
|||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.concurrent.Task;
|
import javafx.concurrent.Task;
|
||||||
import org.jcnc.jnotepad.Interface.ControllerInterface;
|
import org.jcnc.jnotepad.Interface.ControllerInterface;
|
||||||
import org.jcnc.jnotepad.init.Config;
|
|
||||||
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.ui.LineNumberTextArea;
|
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
||||||
@ -17,7 +16,8 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
|
||||||
|
import static org.jcnc.jnotepad.constants.TextConstants.NEW_FILE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 控制器类,实现ControllerInterface接口,用于管理文本编辑器的各种操作和事件处理。
|
* 控制器类,实现ControllerInterface接口,用于管理文本编辑器的各种操作和事件处理。
|
||||||
@ -27,10 +27,6 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
public class Controller implements ControllerInterface {
|
public class Controller implements ControllerInterface {
|
||||||
|
|
||||||
Config config = new Config();
|
|
||||||
Properties properties = config.readPropertiesFromFile();
|
|
||||||
|
|
||||||
String NEW_FILE = properties.getProperty("NEW_FILE");
|
|
||||||
private static final Controller INSTANCE = new Controller();
|
private static final Controller INSTANCE = new Controller();
|
||||||
|
|
||||||
private Controller() {
|
private Controller() {
|
||||||
@ -80,7 +76,7 @@ public class Controller implements ControllerInterface {
|
|||||||
* @param file 文件对象
|
* @param file 文件对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public LineNumberTextArea getText(File file) {
|
public void getText(File file) {
|
||||||
LineNumberTextArea textArea = createNewTextArea();
|
LineNumberTextArea textArea = createNewTextArea();
|
||||||
// 设置当前标签页关联本地文件
|
// 设置当前标签页关联本地文件
|
||||||
textArea.setRelevance(true);
|
textArea.setRelevance(true);
|
||||||
@ -104,7 +100,6 @@ public class Controller implements ControllerInterface {
|
|||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
LogUtil.getLogger(this.getClass()).info("已忽视IO异常!");
|
LogUtil.getLogger(this.getClass()).info("已忽视IO异常!");
|
||||||
}
|
}
|
||||||
return textArea;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import javafx.scene.input.KeyCombination;
|
|||||||
import org.jcnc.jnotepad.Interface.ShortcutKeyInterface;
|
import org.jcnc.jnotepad.Interface.ShortcutKeyInterface;
|
||||||
import org.jcnc.jnotepad.tool.LogUtil;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -19,39 +20,22 @@ import static org.jcnc.jnotepad.constants.PathConstants.SHORTCUT_KEY_CONFIGURATI
|
|||||||
* @author 一个大转盘<br>
|
* @author 一个大转盘<br>
|
||||||
*/
|
*/
|
||||||
public class ShortcutKey implements ShortcutKeyInterface {
|
public class ShortcutKey implements ShortcutKeyInterface {
|
||||||
|
Logger logger = LogUtil.getLogger(this.getClass());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按配置创建快捷键
|
||||||
|
*
|
||||||
|
* @apiNote 此方法通过配置json文件初始化快捷键
|
||||||
|
* @since 2023/8/23 21:56
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createShortcutKeyByConfig() {
|
public void createShortcutKeyByConfig() {
|
||||||
String rootPath = System.getProperty("user.dir");
|
String jsonData = getJsonPathDataBasedOnJson();
|
||||||
// 构建JSON文件路径
|
|
||||||
String jsonFilePath = rootPath + SHORTCUT_KEY_CONFIGURATION_FILE_PATH;
|
|
||||||
InputStream inputStream = getClass().getResourceAsStream(SHORTCUT_KEY_CONFIGURATION_FILE_PATH);
|
|
||||||
StringBuffer jsonData = new StringBuffer();
|
|
||||||
File file = new File(jsonFilePath);
|
|
||||||
if (file.exists()) {
|
|
||||||
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
jsonData.append(line);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtil.getLogger(this.getClass()).error("读取配置失败!", e);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// todo new InputStreamReader(inputStream) 实参 'inputStream' 可能为null
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
jsonData.append(line);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
LogUtil.getLogger(this.getClass()).error("读取配置失败!", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 转json对象
|
// 转json对象
|
||||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||||
Gson gson = gsonBuilder.create();
|
Gson gson = gsonBuilder.create();
|
||||||
Map<String, String> shortcutKeyConfig = gson.fromJson(jsonData.toString(), new TypeToken<Map<String, String>>() {
|
Map<String, String> shortcutKeyConfig = gson.fromJson(jsonData, new TypeToken<Map<String, String>>() {
|
||||||
}.getType());
|
}.getType());
|
||||||
for (Map.Entry<String, String> stringObjectEntry : shortcutKeyConfig.entrySet()) {
|
for (Map.Entry<String, String> stringObjectEntry : shortcutKeyConfig.entrySet()) {
|
||||||
// 保证json的key必须和变量名一致
|
// 保证json的key必须和变量名一致
|
||||||
@ -60,8 +44,45 @@ public class ShortcutKey implements ShortcutKeyInterface {
|
|||||||
if ("".equals(shortKeyValue) || Objects.isNull(menuItem)) {
|
if ("".equals(shortKeyValue) || Objects.isNull(menuItem)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
logger.info("快捷键对象:{}->已分配快捷键:{}", menuItem.getText(), shortKeyValue);
|
||||||
// 动态添加快捷键
|
// 动态添加快捷键
|
||||||
menuItem.setAccelerator(KeyCombination.keyCombination(shortKeyValue));
|
menuItem.setAccelerator(KeyCombination.keyCombination(shortKeyValue));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据json路径返回解析的Json数据
|
||||||
|
*
|
||||||
|
* @return java.lang.String Json数据
|
||||||
|
*/
|
||||||
|
private String getJsonPathDataBasedOnJson() {
|
||||||
|
String rootPath = System.getProperty("user.dir");
|
||||||
|
// 构建JSON文件路径
|
||||||
|
String jsonFilePath = rootPath + SHORTCUT_KEY_CONFIGURATION_FILE_PATH;
|
||||||
|
StringBuilder jsonData = new StringBuilder();
|
||||||
|
InputStream inputStream = getClass().getResourceAsStream(SHORTCUT_KEY_CONFIGURATION_FILE_PATH);
|
||||||
|
File file = new File(jsonFilePath);
|
||||||
|
if (file.exists()) {
|
||||||
|
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
jsonData.append(line);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("读取配置失败!", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (inputStream != null) {
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
jsonData.append(line);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("读取配置失败!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return jsonData.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,16 @@
|
|||||||
package org.jcnc.jnotepad.init;
|
package org.jcnc.jnotepad.init;
|
||||||
|
|
||||||
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.constants.AppConstants.CH_LANGUAGE_PACK_NAME;
|
import static org.jcnc.jnotepad.constants.AppConstants.CH_LANGUAGE_PACK_NAME;
|
||||||
import static org.jcnc.jnotepad.constants.AppConstants.EN_LANGUAGE_PACK_NAME;
|
import static org.jcnc.jnotepad.constants.AppConstants.EN_LANGUAGE_PACK_NAME;
|
||||||
|
import static org.jcnc.jnotepad.constants.TextConstants.JNOTEPAD_CH_LANGUAGE_PACK_NAME;
|
||||||
|
import static org.jcnc.jnotepad.constants.TextConstants.JNOTEPAD_EN_LANGUAGE_PACK_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author 许轲
|
* @author 许轲
|
||||||
@ -13,7 +18,9 @@ import static org.jcnc.jnotepad.constants.AppConstants.EN_LANGUAGE_PACK_NAME;
|
|||||||
*/
|
*/
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
String LANGUAGE_PACK_NAME;
|
private String languagePackName;
|
||||||
|
|
||||||
|
Logger logger = LogUtil.getLogger(this.getClass());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 从文件中读取属性配置。
|
* 从文件中读取属性配置。
|
||||||
@ -24,8 +31,8 @@ public class Config {
|
|||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
|
||||||
//设置语言包
|
//设置语言包
|
||||||
LANGUAGE_PACK_NAME = EN_LANGUAGE_PACK_NAME;
|
languagePackName = EN_LANGUAGE_PACK_NAME;
|
||||||
try (InputStream inputStream = new FileInputStream(LANGUAGE_PACK_NAME)) {
|
try (InputStream inputStream = new FileInputStream(languagePackName)) {
|
||||||
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
||||||
properties.load(reader);
|
properties.load(reader);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -40,26 +47,28 @@ public class Config {
|
|||||||
* 如果属性文件不存在,将创建一个新的属性文件并设置默认属性。
|
* 如果属性文件不存在,将创建一个新的属性文件并设置默认属性。
|
||||||
*/
|
*/
|
||||||
public void initializePropertiesFile() {
|
public void initializePropertiesFile() {
|
||||||
Properties chLanguagePack = getCHLanguagePack();
|
Properties chLanguagePack = getChineseLanguagePack();
|
||||||
|
|
||||||
Properties enLanguagePack = getENLanguagePack();
|
Properties enLanguagePack = getEnglishLanguagePack();
|
||||||
|
|
||||||
try (OutputStream outputStream = new FileOutputStream(CH_LANGUAGE_PACK_NAME)) {
|
try (OutputStream outputStream = new FileOutputStream(CH_LANGUAGE_PACK_NAME)) {
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
||||||
chLanguagePack.store(writer, "JNotepad ch_language_pack");
|
chLanguagePack.store(writer, JNOTEPAD_CH_LANGUAGE_PACK_NAME);
|
||||||
|
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
|
logger.info("未检测到中文语言包!");
|
||||||
}
|
}
|
||||||
|
|
||||||
try (OutputStream outputStream = new FileOutputStream(EN_LANGUAGE_PACK_NAME)) {
|
try (OutputStream outputStream = new FileOutputStream(EN_LANGUAGE_PACK_NAME)) {
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8); // 使用 UTF-8 编码
|
||||||
enLanguagePack.store(writer, "JNotepad en_language_pack");
|
enLanguagePack.store(writer, JNOTEPAD_EN_LANGUAGE_PACK_NAME);
|
||||||
|
|
||||||
} catch (IOException ignored) {
|
} catch (IOException ignored) {
|
||||||
|
logger.info("未检测到英文语言包!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Properties getCHLanguagePack() {
|
private static Properties getChineseLanguagePack() {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
|
||||||
properties.setProperty("TITLE", "JNotepad"); // 设置默认属性
|
properties.setProperty("TITLE", "JNotepad"); // 设置默认属性
|
||||||
@ -81,7 +90,7 @@ public class Config {
|
|||||||
return properties;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Properties getENLanguagePack() {
|
private static Properties getEnglishLanguagePack() {
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
|
||||||
properties.setProperty("TITLE", "JNotepad");
|
properties.setProperty("TITLE", "JNotepad");
|
||||||
|
|||||||
@ -3,19 +3,15 @@ package org.jcnc.jnotepad.tool;
|
|||||||
|
|
||||||
import com.ibm.icu.text.CharsetDetector;
|
import com.ibm.icu.text.CharsetDetector;
|
||||||
import com.ibm.icu.text.CharsetMatch;
|
import com.ibm.icu.text.CharsetMatch;
|
||||||
import javafx.application.Platform;
|
|
||||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
import static org.jcnc.jnotepad.constants.TextConstants.UNKNOWN;
|
||||||
import java.nio.file.Paths;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编码检测工具类
|
* 编码检测工具类
|
||||||
@ -24,8 +20,8 @@ import java.nio.file.Paths;
|
|||||||
*/
|
*/
|
||||||
public class EncodingDetector {
|
public class EncodingDetector {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(EncodingDetector.class);
|
private static final Logger LOG = LogUtil.getLogger(EncodingDetector.class);
|
||||||
public static final String UNKNOWN = "UNKNOWN";
|
|
||||||
|
|
||||||
private EncodingDetector() {
|
private EncodingDetector() {
|
||||||
}
|
}
|
||||||
@ -41,14 +37,13 @@ public class EncodingDetector {
|
|||||||
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file.getPath()))) {
|
try (BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file.getPath()))) {
|
||||||
charsetDetector.setText(inputStream);
|
charsetDetector.setText(inputStream);
|
||||||
CharsetMatch match = charsetDetector.detect();
|
CharsetMatch match = charsetDetector.detect();
|
||||||
LOG.debug(match.getName() + " " + match.getConfidence());
|
LOG.debug("{} : {}", match.getName(), match.getConfidence());
|
||||||
if (match.getConfidence() > 50) {
|
if (match.getConfidence() > 50) {
|
||||||
return match.getName();
|
return match.getName();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("", e);
|
LOG.error("", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return UNKNOWN;
|
return UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
package org.jcnc.jnotepad.tool;
|
package org.jcnc.jnotepad.tool;
|
||||||
|
|
||||||
import javafx.scene.control.Tab;
|
|
||||||
import javafx.stage.FileChooser;
|
import javafx.stage.FileChooser;
|
||||||
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;
|
||||||
|
|
||||||
@ -13,11 +11,12 @@ import java.nio.charset.StandardCharsets;
|
|||||||
* @author 一个大转盘
|
* @author 一个大转盘
|
||||||
*/
|
*/
|
||||||
public class FileUtil {
|
public class FileUtil {
|
||||||
|
|
||||||
private FileUtil() {
|
private FileUtil() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 把一个文件中的内容读取成一个String字符串
|
* 把一个文件中的内容读取成一个String字符串<br>
|
||||||
*
|
*
|
||||||
* @param jsonFile json文件
|
* @param jsonFile json文件
|
||||||
* @return String
|
* @return String
|
||||||
@ -59,6 +58,7 @@ public class FileUtil {
|
|||||||
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("文本文档", "*.txt"));
|
fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("文本文档", "*.txt"));
|
||||||
File file = fileChooser.showSaveDialog(null);
|
File file = fileChooser.showSaveDialog(null);
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
LogUtil.getLogger(currentClass).info("正在保存文件:{}", file.getName());
|
||||||
selectedTab.save();
|
selectedTab.save();
|
||||||
// 将保存后的文件设置为已关联
|
// 将保存后的文件设置为已关联
|
||||||
selectedTab.getLineNumberTextArea().setRelevance(true);
|
selectedTab.getLineNumberTextArea().setRelevance(true);
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package org.jcnc.jnotepad.ui;
|
package org.jcnc.jnotepad.ui;
|
||||||
|
|
||||||
import javafx.beans.property.StringProperty;
|
import javafx.beans.property.StringProperty;
|
||||||
import javafx.scene.control.Tab;
|
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import org.jcnc.jnotepad.tool.LogUtil;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
|
|||||||
@ -5,14 +5,17 @@ import javafx.scene.control.Menu;
|
|||||||
import javafx.scene.control.MenuBar;
|
import javafx.scene.control.MenuBar;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
import org.jcnc.jnotepad.app.config.GlobalConfig;
|
import org.jcnc.jnotepad.app.config.GlobalConfig;
|
||||||
import org.jcnc.jnotepad.controller.event.handler.*;
|
import org.jcnc.jnotepad.controller.event.handler.NewFile;
|
||||||
import org.jcnc.jnotepad.init.Config;
|
import org.jcnc.jnotepad.controller.event.handler.OpenFile;
|
||||||
|
import org.jcnc.jnotepad.controller.event.handler.SaveAsFile;
|
||||||
|
import org.jcnc.jnotepad.controller.event.handler.SaveFile;
|
||||||
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 java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
|
import static org.jcnc.jnotepad.constants.TextConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 封装菜单栏组件。
|
* 封装菜单栏组件。
|
||||||
@ -21,23 +24,11 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
public class JNotepadMenuBar extends MenuBar {
|
public class JNotepadMenuBar extends MenuBar {
|
||||||
|
|
||||||
Config config = new Config();
|
|
||||||
Properties properties = config.readPropertiesFromFile();
|
|
||||||
String SAVA = properties.getProperty("SAVA");
|
|
||||||
String FILE = properties.getProperty("FILE");
|
|
||||||
String NEW = properties.getProperty("NEW");
|
|
||||||
String OPEN = properties.getProperty("OPEN");
|
|
||||||
String SAVA_AS = properties.getProperty("SAVA_AS");
|
|
||||||
|
|
||||||
String SET = properties.getProperty("SET");
|
/**
|
||||||
|
* 标签页布局组件封装。
|
||||||
String WORD_WRAP = properties.getProperty("WORD_WRAP");
|
*/
|
||||||
|
JNotepadTabPane jNotepadTabPane = JNotepadTabPane.getInstance();
|
||||||
String PLUGIN = properties.getProperty("PLUGIN");
|
|
||||||
|
|
||||||
String ADD_PLUGIN = properties.getProperty("ADD_PLUGIN");
|
|
||||||
|
|
||||||
String STATISTICS = properties.getProperty("STATISTICS");
|
|
||||||
|
|
||||||
private static final JNotepadMenuBar MENU_BAR = new JNotepadMenuBar();
|
private static final JNotepadMenuBar MENU_BAR = new JNotepadMenuBar();
|
||||||
|
|
||||||
@ -172,7 +163,7 @@ public class JNotepadMenuBar extends MenuBar {
|
|||||||
// 1. 更新全局配置
|
// 1. 更新全局配置
|
||||||
GlobalConfig.getConfig().setAutoLineConfig(after);
|
GlobalConfig.getConfig().setAutoLineConfig(after);
|
||||||
// 2. 对当前tab生效配置
|
// 2. 对当前tab生效配置
|
||||||
JNotepadTabPane.getInstance().fireTabSelected();
|
jNotepadTabPane.fireTabSelected();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,7 +175,7 @@ public class JNotepadMenuBar extends MenuBar {
|
|||||||
* 根据当前选中tab,更新菜单选项
|
* 根据当前选中tab,更新菜单选项
|
||||||
*/
|
*/
|
||||||
public void updateMenuStatusBySelectedTab() {
|
public void updateMenuStatusBySelectedTab() {
|
||||||
JNotepadTab selectedTab = JNotepadTabPane.getInstance().getSelected();
|
JNotepadTab selectedTab = jNotepadTabPane.getSelected();
|
||||||
lineFeedItem.selectedProperty().setValue(selectedTab.isAutoLine());
|
lineFeedItem.selectedProperty().setValue(selectedTab.isAutoLine());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,11 +4,12 @@ import javafx.geometry.Insets;
|
|||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.TextArea;
|
import javafx.scene.control.TextArea;
|
||||||
import javafx.scene.layout.HBox;
|
import javafx.scene.layout.HBox;
|
||||||
import org.jcnc.jnotepad.init.Config;
|
import org.jcnc.jnotepad.ui.tab.JNotepadTab;
|
||||||
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
import org.jcnc.jnotepad.ui.tab.JNotepadTabPane;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.Properties;
|
|
||||||
|
import static org.jcnc.jnotepad.constants.TextConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态栏组件封装。
|
* 状态栏组件封装。
|
||||||
@ -19,16 +20,6 @@ import java.util.Properties;
|
|||||||
*/
|
*/
|
||||||
public class JNotepadStatusBox extends HBox {
|
public class JNotepadStatusBox extends HBox {
|
||||||
|
|
||||||
Config config = new Config();
|
|
||||||
Properties properties = config.readPropertiesFromFile();
|
|
||||||
String ROW = properties.getProperty("ROW");
|
|
||||||
|
|
||||||
String COLUMN = properties.getProperty("COLUMN");
|
|
||||||
|
|
||||||
String WORD_COUNT = properties.getProperty("WORD_COUNT");
|
|
||||||
|
|
||||||
String ENCODE = properties.getProperty("ENCODE");
|
|
||||||
|
|
||||||
private static final JNotepadStatusBox STATUS_BOX = new JNotepadStatusBox();
|
private static final JNotepadStatusBox STATUS_BOX = new JNotepadStatusBox();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +68,11 @@ public class JNotepadStatusBox extends HBox {
|
|||||||
* 更新字数统计
|
* 更新字数统计
|
||||||
*/
|
*/
|
||||||
public void updateWordCountStatusLabel() {
|
public void updateWordCountStatusLabel() {
|
||||||
TextArea textArea = JNotepadTabPane.getInstance().getSelected().getLineNumberTextArea().getMainTextArea();
|
JNotepadTabPane instance = JNotepadTabPane.getInstance();
|
||||||
|
if (instance.getSelected() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TextArea textArea = instance.getSelected().getLineNumberTextArea().getMainTextArea();
|
||||||
int caretPosition = textArea.getCaretPosition();
|
int caretPosition = textArea.getCaretPosition();
|
||||||
int row = getRow(caretPosition, textArea.getText());
|
int row = getRow(caretPosition, textArea.getText());
|
||||||
int column = getColumn(caretPosition, textArea.getText());
|
int column = getColumn(caretPosition, textArea.getText());
|
||||||
@ -87,12 +82,18 @@ public class JNotepadStatusBox extends HBox {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tab选中时,更新状态栏
|
* Tab选中时,更新状态栏
|
||||||
* 1. 状态栏更新当前选中tab的数字统计
|
* <br>1. 状态栏更新当前选中tab的数字统计
|
||||||
* 2. 状态栏更新当前选中tab的字符编码
|
* <br>2. 状态栏更新当前选中tab的字符编码
|
||||||
*/
|
*/
|
||||||
public void updateWhenTabSelected() {
|
public void updateWhenTabSelected() {
|
||||||
updateWordCountStatusLabel();
|
JNotepadTabPane instance = JNotepadTabPane.getInstance();
|
||||||
updateEncodingLabel(JNotepadTabPane.getInstance().getSelected().getCharset().name());
|
if (instance.getSelected() != null) {
|
||||||
|
updateWordCountStatusLabel();
|
||||||
|
JNotepadTab jNotepadTab = instance.getSelected();
|
||||||
|
if (jNotepadTab != null) {
|
||||||
|
updateEncodingLabel(jNotepadTab.getCharset().name());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,10 +1,7 @@
|
|||||||
package org.jcnc.jnotepad.view.manager;
|
package org.jcnc.jnotepad.view.manager;
|
||||||
|
|
||||||
import javafx.geometry.Insets;
|
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
import javafx.scene.control.Label;
|
|
||||||
import javafx.scene.layout.BorderPane;
|
import javafx.scene.layout.BorderPane;
|
||||||
import javafx.scene.layout.HBox;
|
|
||||||
import org.jcnc.jnotepad.exception.AppException;
|
import org.jcnc.jnotepad.exception.AppException;
|
||||||
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
||||||
import org.jcnc.jnotepad.ui.status.JNotepadStatusBox;
|
import org.jcnc.jnotepad.ui.status.JNotepadStatusBox;
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
"newItem": "ctrl+n",
|
"newItem": "ctrl+n",
|
||||||
"openItem": "ctrl+o",
|
"openItem": "ctrl+o",
|
||||||
"saveItem": "ctrl+s",
|
"saveItem": "ctrl+s",
|
||||||
"saveAsItem": "ctrl+shift+s",
|
"saveAsItem": "ctrl+alt+s",
|
||||||
"lineFeedItem": "",
|
"lineFeedItem": "",
|
||||||
|
|
||||||
"addItem": "",
|
"addItem": "",
|
||||||
|
|||||||
@ -3,15 +3,15 @@
|
|||||||
<!-- scanPeriod属性设置监测配置文件修改的时间间隔,默认单位为毫秒,在scan为true时才生效 -->
|
<!-- scanPeriod属性设置监测配置文件修改的时间间隔,默认单位为毫秒,在scan为true时才生效 -->
|
||||||
<!-- debug属性如果为true时,会打印出logback内部的日志信息 -->
|
<!-- debug属性如果为true时,会打印出logback内部的日志信息 -->
|
||||||
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
<configuration scan="true" scanPeriod="60 seconds" debug="false">
|
||||||
<!-- 定义参数常量 -->
|
<!-- 定义参数常量 -->JJ
|
||||||
<!-- 日志级别:TRACE<DEBUG<INFO<WARN<ERROR,其中常用的是DEBUG、INFO和ERROR -->
|
<!-- 日志级别:TRACE<DEBUG<INFO<WARN<ERROR,其中常用的是DEBUG、INFO和ERROR -->
|
||||||
<property name="log.level" value="debug"/>
|
<property name="log.level" value="debug"/>
|
||||||
<!-- 文件保留时间 -->
|
<!-- 文件保留时间 -->
|
||||||
<property name="log.maxHistory" value="30"/>
|
<property name="log.maxHistory" value="30"/>
|
||||||
<!-- 日志存储路径 -->
|
<!-- 日志存储路径 -->
|
||||||
<property name="log.filePath" value="logs"/>
|
<!--<property name="log.filePath" value="logs"/>-->
|
||||||
<!--打包时,请使用下方的路径-->
|
<!--打包时,请使用下方的路径-->
|
||||||
<!--<property name="log.filePath" value="../logs"/>-->
|
<property name="log.filePath" value="../logs"/>
|
||||||
<!-- 日志的显式格式 -->
|
<!-- 日志的显式格式 -->
|
||||||
<property name="log.pattern"
|
<property name="log.pattern"
|
||||||
value="时间:[%d{yyyy-MM-dd HH:mm:ss.SSS}] 线程:[%thread] 日志级别:[%-5level] 调用位置:[%logger{50} 参见:[\(%F:%L\)]] - 日志信息:[%msg]%n">
|
value="时间:[%d{yyyy-MM-dd HH:mm:ss.SSS}] 线程:[%thread] 日志级别:[%-5level] 调用位置:[%logger{50} 参见:[\(%F:%L\)]] - 日志信息:[%msg]%n">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user