➕ 添加置顶功能 ⚡️ 优化配置文件读取
This commit is contained in:
parent
fbc1d020d9
commit
eb7eb2552c
@ -12,7 +12,6 @@ module org.jcnc.jnotepad {
|
|||||||
requires ch.qos.logback.core;
|
requires ch.qos.logback.core;
|
||||||
requires ch.qos.logback.classic;
|
requires ch.qos.logback.classic;
|
||||||
requires com.ibm.icu;
|
requires com.ibm.icu;
|
||||||
exports org.jcnc.jnotepad.init;
|
|
||||||
exports org.jcnc.jnotepad.app.config;
|
exports org.jcnc.jnotepad.app.config;
|
||||||
exports org.jcnc.jnotepad;
|
exports org.jcnc.jnotepad;
|
||||||
exports org.jcnc.jnotepad.tool;
|
exports org.jcnc.jnotepad.tool;
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import javafx.stage.Stage;
|
|||||||
import org.jcnc.jnotepad.app.config.LoadJnotepadConfig;
|
import org.jcnc.jnotepad.app.config.LoadJnotepadConfig;
|
||||||
import org.jcnc.jnotepad.app.config.LoadLanguageConfig;
|
import org.jcnc.jnotepad.app.config.LoadLanguageConfig;
|
||||||
import org.jcnc.jnotepad.app.config.LoadShortcutKeyConfig;
|
import org.jcnc.jnotepad.app.config.LoadShortcutKeyConfig;
|
||||||
|
import org.jcnc.jnotepad.app.config.LocalizationConfig;
|
||||||
import org.jcnc.jnotepad.constants.AppConstants;
|
import org.jcnc.jnotepad.constants.AppConstants;
|
||||||
import org.jcnc.jnotepad.controller.manager.Controller;
|
import org.jcnc.jnotepad.controller.manager.Controller;
|
||||||
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
import org.jcnc.jnotepad.ui.LineNumberTextArea;
|
||||||
@ -22,7 +23,7 @@ import java.util.Objects;
|
|||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.TITLE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动程序
|
* 启动程序
|
||||||
@ -34,19 +35,19 @@ public class LunchApp extends Application {
|
|||||||
* 线程池
|
* 线程池
|
||||||
*/
|
*/
|
||||||
private static final ExecutorService THREAD_POOL = Executors.newCachedThreadPool();
|
private static final ExecutorService THREAD_POOL = Executors.newCachedThreadPool();
|
||||||
|
LocalizationConfig localizationConfig = LocalizationConfig.getLocalizationConfig();
|
||||||
Controller controller = Controller.getInstance();
|
Controller controller = Controller.getInstance();
|
||||||
Scene scene;
|
Scene scene;
|
||||||
/**
|
/**
|
||||||
* 配置文件数组
|
* 配置文件数组
|
||||||
*/
|
*/
|
||||||
static List<LoadJnotepadConfig> loadJnotepadConfigs = new ArrayList<>();
|
static List<LoadJnotepadConfig<?>> loadJnotepadConfigs = new ArrayList<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// 快捷键配置文件
|
|
||||||
loadJnotepadConfigs.add(new LoadShortcutKeyConfig());
|
|
||||||
// 语言配置文件
|
// 语言配置文件
|
||||||
loadJnotepadConfigs.add(new LoadLanguageConfig());
|
loadJnotepadConfigs.add(new LoadLanguageConfig());
|
||||||
|
// 快捷键配置文件
|
||||||
|
loadJnotepadConfigs.add(new LoadShortcutKeyConfig());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -69,16 +70,16 @@ public class LunchApp extends Application {
|
|||||||
Platform.runLater(() -> controller.updateUiWithNewTextArea(textArea));
|
Platform.runLater(() -> controller.updateUiWithNewTextArea(textArea));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
primaryStage.setTitle(TITLE);
|
ViewManager viewManager = ViewManager.getInstance(scene);
|
||||||
|
viewManager.initScreen(scene);
|
||||||
|
// 加载配置文件
|
||||||
|
View.getInstance().initJnotepadConfigs(loadJnotepadConfigs);
|
||||||
|
primaryStage.setTitle(localizationConfig.getTitle());
|
||||||
primaryStage.setWidth(width);
|
primaryStage.setWidth(width);
|
||||||
primaryStage.setHeight(length);
|
primaryStage.setHeight(length);
|
||||||
primaryStage.setScene(scene);
|
primaryStage.setScene(scene);
|
||||||
primaryStage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResource(icon)).toString()));
|
primaryStage.getIcons().add(new Image(Objects.requireNonNull(getClass().getResource(icon)).toString()));
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
ViewManager viewManager = ViewManager.getInstance(scene);
|
|
||||||
viewManager.initScreen(scene);
|
|
||||||
// 初始化快捷键
|
|
||||||
View.getInstance().initJnotepadConfigs(loadJnotepadConfigs);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package org.jcnc.jnotepad.app.config;
|
package org.jcnc.jnotepad.app.config;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.PROPERTIES;
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.TEXT_WRAP;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 内存中,运行过程中的全局配置项
|
* 内存中,运行过程中的全局配置项
|
||||||
@ -11,6 +9,7 @@ import static org.jcnc.jnotepad.constants.TextConstants.TEXT_WRAP;
|
|||||||
public class GlobalConfig {
|
public class GlobalConfig {
|
||||||
|
|
||||||
private static final GlobalConfig APP_GLOBAL_CONFIG = new GlobalConfig();
|
private static final GlobalConfig APP_GLOBAL_CONFIG = new GlobalConfig();
|
||||||
|
LocalizationConfig localizationConfig = LocalizationConfig.getLocalizationConfig();
|
||||||
|
|
||||||
private GlobalConfig() {
|
private GlobalConfig() {
|
||||||
}
|
}
|
||||||
@ -21,12 +20,12 @@ public class GlobalConfig {
|
|||||||
* @return true, 自动换行;false,不自动换行
|
* @return true, 自动换行;false,不自动换行
|
||||||
*/
|
*/
|
||||||
public boolean getAutoLineConfig() {
|
public boolean getAutoLineConfig() {
|
||||||
return Boolean.parseBoolean(PROPERTIES.getProperty(TEXT_WRAP, "true"));
|
return Boolean.parseBoolean(localizationConfig.getTextWrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAutoLineConfig(boolean isAutoLine) {
|
public void setAutoLineConfig(boolean isAutoLine) {
|
||||||
String autoLineConfig = String.valueOf(isAutoLine);
|
String autoLineConfig = String.valueOf(isAutoLine);
|
||||||
PROPERTIES.setProperty(TEXT_WRAP, autoLineConfig);
|
localizationConfig.setTextWrap(autoLineConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GlobalConfig getConfig() {
|
public static GlobalConfig getConfig() {
|
||||||
|
|||||||
@ -1,21 +1,23 @@
|
|||||||
package org.jcnc.jnotepad.app.config;
|
package org.jcnc.jnotepad.app.config;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
import javafx.scene.input.KeyCombination;
|
import javafx.scene.input.KeyCombination;
|
||||||
import org.jcnc.jnotepad.app.entity.ShortcutKey;
|
import org.jcnc.jnotepad.app.entity.ShortcutKey;
|
||||||
|
import org.jcnc.jnotepad.exception.AppException;
|
||||||
import org.jcnc.jnotepad.tool.LogUtil;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
import org.jcnc.jnotepad.tool.PopUpUtil;
|
import org.jcnc.jnotepad.tool.PopUpUtil;
|
||||||
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.constants.AppConstants.CONFIG_NAME;
|
import static org.jcnc.jnotepad.constants.AppConstants.CONFIG_NAME;
|
||||||
import static org.jcnc.jnotepad.constants.AppConstants.CONFIG_SHORTCUT_KEY_NAME;
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.JNOTEPAD_CONFIG;
|
import static org.jcnc.jnotepad.constants.TextConstants.JNOTEPAD_CONFIG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,9 +26,36 @@ import static org.jcnc.jnotepad.constants.TextConstants.JNOTEPAD_CONFIG;
|
|||||||
*
|
*
|
||||||
* @author gewuyou
|
* @author gewuyou
|
||||||
*/
|
*/
|
||||||
public abstract class LoadJnotepadConfig {
|
public abstract class LoadJnotepadConfig<T> {
|
||||||
Logger logger = LogUtil.getLogger(this.getClass());
|
Logger logger = LogUtil.getLogger(this.getClass());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 返回json配置文件的json节点
|
||||||
|
*
|
||||||
|
* @param inputStream 输入流
|
||||||
|
* @return java.lang.String
|
||||||
|
* @apiNote
|
||||||
|
* @since 2023/8/25 17:17
|
||||||
|
*/
|
||||||
|
protected JsonNode getConfigJson(InputStream inputStream) {
|
||||||
|
StringBuffer jsonData = new StringBuffer();
|
||||||
|
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
jsonData.append(line);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
PopUpUtil.errorAlert("错误", "读写错误", "配置文件读写错误!");
|
||||||
|
}
|
||||||
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
JsonNode jsonNode;
|
||||||
|
try {
|
||||||
|
jsonNode = objectMapper.readTree(jsonData.toString());
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
throw new AppException(e.getMessage());
|
||||||
|
}
|
||||||
|
return jsonNode;
|
||||||
|
}
|
||||||
|
|
||||||
public final void load() {
|
public final void load() {
|
||||||
// 判断是否存在这个配置文件
|
// 判断是否存在这个配置文件
|
||||||
@ -49,41 +78,7 @@ public abstract class LoadJnotepadConfig {
|
|||||||
* @return java.util.List<java.util.LinkedHashMap < java.lang.String, java.lang.String>>
|
* @return java.util.List<java.util.LinkedHashMap < java.lang.String, java.lang.String>>
|
||||||
* @since 2023/8/25 15:18
|
* @since 2023/8/25 15:18
|
||||||
*/
|
*/
|
||||||
protected List<LinkedHashMap<String, String>> parseConfig(InputStream inputStream) {
|
protected abstract T parseConfig(InputStream inputStream);
|
||||||
StringBuffer jsonData = new StringBuffer();
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
jsonData.append(line);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
PopUpUtil.errorAlert("错误", "读写错误", "配置文件读写错误!");
|
|
||||||
}
|
|
||||||
// 转json对象
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
Map<String, List<Object>> mainConfig = null;
|
|
||||||
try {
|
|
||||||
mainConfig = mapper.readValue(jsonData.toString(), new TypeReference<HashMap<String, List<Object>>>() {
|
|
||||||
});
|
|
||||||
} catch (JsonProcessingException e) {
|
|
||||||
PopUpUtil.errorAlert("错误", "解析错误", "配置文件解析错误!");
|
|
||||||
logger.error("配置文件解析错误!", e);
|
|
||||||
}
|
|
||||||
if (mainConfig == null) {
|
|
||||||
logger.error("未获取到主要配置文件!");
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
return mainConfig.get(CONFIG_SHORTCUT_KEY_NAME)
|
|
||||||
.stream()
|
|
||||||
.map(e -> {
|
|
||||||
if (e instanceof LinkedHashMap) {
|
|
||||||
return (LinkedHashMap<String, String>) e;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Invalid element type");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createConfig() {
|
private void createConfig() {
|
||||||
List<ShortcutKey> shortcutKeyList = getShortcutKeys();
|
List<ShortcutKey> shortcutKeyList = getShortcutKeys();
|
||||||
|
|||||||
@ -1,31 +1,41 @@
|
|||||||
package org.jcnc.jnotepad.app.config;
|
package org.jcnc.jnotepad.app.config;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
import java.util.LinkedHashMap;
|
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
||||||
import java.util.List;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.CONFIG;
|
import java.io.InputStream;
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.LANGUAGE_MAP;
|
|
||||||
|
import static org.jcnc.jnotepad.constants.TextConstants.LANGUAGE_FILE_MAP;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载语言配置文件
|
* 加载语言配置文件
|
||||||
*
|
*
|
||||||
* @author gewuyou
|
* @author gewuyou
|
||||||
* @see [相关类/方法]
|
|
||||||
*/
|
*/
|
||||||
public class LoadLanguageConfig extends LoadJnotepadConfig {
|
public class LoadLanguageConfig extends LoadJnotepadConfig<String> {
|
||||||
|
Logger log = LogUtil.getLogger(this.getClass());
|
||||||
|
|
||||||
|
LocalizationConfig localizationConfig = LocalizationConfig.getLocalizationConfig();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String parseConfig(InputStream inputStream) {
|
||||||
|
return getConfigJson(inputStream).get("language").asText();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadConfig(InputStream inputStream) {
|
protected void loadConfig(InputStream inputStream) {
|
||||||
List<LinkedHashMap<String, String>> configData = parseConfig(inputStream);
|
log.info("正在加载语言配置文件...");
|
||||||
String language = "";
|
String language = parseConfig(inputStream);
|
||||||
for (LinkedHashMap<String, String> config : configData) {
|
|
||||||
language = config.get("language");
|
|
||||||
if (language != null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!"".equals(language) && language != null) {
|
if (!"".equals(language) && language != null) {
|
||||||
CONFIG.setLanguagePackName(LANGUAGE_MAP.get(language));
|
log.info("正在加载语言包:{}", language);
|
||||||
|
localizationConfig.setLanguagePackName(LANGUAGE_FILE_MAP.get(language));
|
||||||
|
// 刷新语言包
|
||||||
|
localizationConfig.initLocalizationConfig();
|
||||||
|
JNotepadMenuBar jNotepadMenuBar = JNotepadMenuBar.getMenuBar();
|
||||||
|
// 刷新菜单栏
|
||||||
|
jNotepadMenuBar.initMenuBar();
|
||||||
|
jNotepadMenuBar.toggleLanguageCheck(language);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package org.jcnc.jnotepad.app.config;
|
package org.jcnc.jnotepad.app.config;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
import javafx.scene.input.KeyCombination;
|
import javafx.scene.input.KeyCombination;
|
||||||
import org.jcnc.jnotepad.tool.LogUtil;
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
@ -7,18 +8,41 @@ import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
import static org.jcnc.jnotepad.constants.AppConstants.CONFIG_SHORTCUT_KEY_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 加载快捷键实现
|
* 加载快捷键实现
|
||||||
*
|
*
|
||||||
* @author gewuyou 一个大转盘
|
* @author gewuyou 一个大转盘
|
||||||
*/
|
*/
|
||||||
public class LoadShortcutKeyConfig extends LoadJnotepadConfig {
|
public class LoadShortcutKeyConfig extends LoadJnotepadConfig<List<LinkedHashMap<String, String>>> {
|
||||||
Logger log = LogUtil.getLogger(this.getClass());
|
Logger log = LogUtil.getLogger(this.getClass());
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<LinkedHashMap<String, String>> parseConfig(InputStream inputStream) {
|
||||||
|
JsonNode shortcutKeyNode = getConfigJson(inputStream).get(CONFIG_SHORTCUT_KEY_NAME);
|
||||||
|
if (shortcutKeyNode == null || !shortcutKeyNode.isArray()) {
|
||||||
|
logger.error("未获取到主要配置文件!");
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<LinkedHashMap<String, String>> shortcutKeyList = new ArrayList<>();
|
||||||
|
for (JsonNode node : shortcutKeyNode) {
|
||||||
|
if (node.isObject()) {
|
||||||
|
LinkedHashMap<String, String> shortcutKey = new LinkedHashMap<>();
|
||||||
|
Iterator<Map.Entry<String, JsonNode>> fields = node.fields();
|
||||||
|
while (fields.hasNext()) {
|
||||||
|
Map.Entry<String, JsonNode> entry = fields.next();
|
||||||
|
shortcutKey.put(entry.getKey(), entry.getValue().asText());
|
||||||
|
|
||||||
|
}
|
||||||
|
shortcutKeyList.add(shortcutKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return shortcutKeyList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadConfig(InputStream inputStream) {
|
protected void loadConfig(InputStream inputStream) {
|
||||||
List<LinkedHashMap<String, String>> configData = parseConfig(inputStream);
|
List<LinkedHashMap<String, String>> configData = parseConfig(inputStream);
|
||||||
|
|||||||
@ -0,0 +1,314 @@
|
|||||||
|
package org.jcnc.jnotepad.app.config;
|
||||||
|
|
||||||
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
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.TextConstants.TEXT_WRAP;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地化配置文件
|
||||||
|
*
|
||||||
|
* @author gewuyou
|
||||||
|
*/
|
||||||
|
public class LocalizationConfig {
|
||||||
|
Logger logger = LogUtil.getLogger(this.getClass());
|
||||||
|
private static final LocalizationConfig LOCALIZATION_CONFIG = new LocalizationConfig();
|
||||||
|
private final Properties properties = new Properties();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 本地化语言包名,默认英文
|
||||||
|
*/
|
||||||
|
private String languagePackName = EN_LANGUAGE_PACK_NAME;
|
||||||
|
|
||||||
|
private LocalizationConfig() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化本地化语言包
|
||||||
|
*
|
||||||
|
* @since 2023/8/25 18:18
|
||||||
|
*/
|
||||||
|
public void initLocalizationConfig() {
|
||||||
|
// 设置语言包
|
||||||
|
try (InputStream inputStream = new FileInputStream(languagePackName)) {
|
||||||
|
// 使用 UTF-8 编码
|
||||||
|
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
||||||
|
properties.load(reader);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// 如果读取出错,则调用初始化方法
|
||||||
|
initializePropertiesFile();
|
||||||
|
}
|
||||||
|
logger.info("初始化本地化语言包成功!");
|
||||||
|
title = properties.getProperty("title", "JNotepad");
|
||||||
|
sava = properties.getProperty("SAVA");
|
||||||
|
file = properties.getProperty("FILE");
|
||||||
|
newly = properties.getProperty("NEW");
|
||||||
|
open = properties.getProperty("OPEN");
|
||||||
|
savaAs = properties.getProperty("SAVA_AS");
|
||||||
|
set = properties.getProperty("SET");
|
||||||
|
wordWrap = properties.getProperty("WORD_WRAP");
|
||||||
|
plugin = properties.getProperty("PLUGIN");
|
||||||
|
addPlugin = properties.getProperty("ADD_PLUGIN");
|
||||||
|
statistics = properties.getProperty("STATISTICS");
|
||||||
|
openConfigurationFile = properties.getProperty("OPEN_CONFIGURATION_FILE");
|
||||||
|
top = properties.getProperty("TOP");
|
||||||
|
language = properties.getProperty("LANGUAGE");
|
||||||
|
chinese = properties.getProperty("CHINESE");
|
||||||
|
english = properties.getProperty("ENGLISH");
|
||||||
|
textWrap = properties.getProperty(TEXT_WRAP, "true");
|
||||||
|
newFile = properties.getProperty("NEW_FILE");
|
||||||
|
unknown = properties.getProperty("UNKNOWN");
|
||||||
|
row = properties.getProperty("ROW");
|
||||||
|
column = properties.getProperty("COLUMN");
|
||||||
|
wordCount = properties.getProperty("WORD_COUNT");
|
||||||
|
encode = properties.getProperty("ENCODE");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化属性配置文件。
|
||||||
|
* 如果属性文件不存在,将创建一个新的属性文件并设置默认属性。
|
||||||
|
*/
|
||||||
|
public void initializePropertiesFile() {
|
||||||
|
switch (languagePackName) {
|
||||||
|
case CH_LANGUAGE_PACK_NAME -> {
|
||||||
|
setChineseLanguagePack();
|
||||||
|
createLanguagePacks(languagePackName, properties);
|
||||||
|
}
|
||||||
|
case EN_LANGUAGE_PACK_NAME -> {
|
||||||
|
setEnglishLanguagePack();
|
||||||
|
createLanguagePacks(languagePackName, properties);
|
||||||
|
}
|
||||||
|
default -> logger.error("语言包加载错误!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createLanguagePacks(String languagePackName, Properties languagePack) {
|
||||||
|
try (OutputStream outputStream = new FileOutputStream(languagePackName)) {
|
||||||
|
// 使用 UTF-8 编码
|
||||||
|
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
|
||||||
|
languagePack.store(writer, languagePackName);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
logger.info("未检测到语言包!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setChineseLanguagePack() {
|
||||||
|
properties.clear();
|
||||||
|
// 设置默认属性
|
||||||
|
properties.setProperty("TITLE", "JNotepad");
|
||||||
|
properties.setProperty("NEW_FILE", "新建文件");
|
||||||
|
properties.setProperty("SAVA", "保存");
|
||||||
|
properties.setProperty("FILE", "文件");
|
||||||
|
properties.setProperty("NEW", "新建");
|
||||||
|
properties.setProperty("OPEN", "打开");
|
||||||
|
properties.setProperty("SAVA_AS", "另存为");
|
||||||
|
properties.setProperty("SET", "设置");
|
||||||
|
properties.setProperty("WORD_WRAP", "自动换行");
|
||||||
|
properties.setProperty("OPEN_CONFIGURATION_FILE", "打开配置文件");
|
||||||
|
properties.setProperty("PLUGIN", "插件");
|
||||||
|
properties.setProperty("ADD_PLUGIN", "增加插件");
|
||||||
|
properties.setProperty("STATISTICS", "统计字数");
|
||||||
|
properties.setProperty("ROW", "行数");
|
||||||
|
properties.setProperty("COLUMN", "列数");
|
||||||
|
properties.setProperty("WORD_COUNT", "字数");
|
||||||
|
properties.setProperty("ENCODE", "编码");
|
||||||
|
properties.setProperty("TOP", "窗口置顶");
|
||||||
|
properties.setProperty("LANGUAGE", "语言");
|
||||||
|
properties.setProperty("CHINESE", "中文");
|
||||||
|
properties.setProperty("ENGLISH", "英文");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setEnglishLanguagePack() {
|
||||||
|
properties.clear();
|
||||||
|
properties.setProperty("TITLE", "JNotepad");
|
||||||
|
properties.setProperty("NEW_FILE", "New File");
|
||||||
|
properties.setProperty("SAVA", "Save");
|
||||||
|
properties.setProperty("FILE", "File");
|
||||||
|
properties.setProperty("NEW", "New");
|
||||||
|
properties.setProperty("OPEN", "Open");
|
||||||
|
properties.setProperty("SAVA_AS", "Save As");
|
||||||
|
properties.setProperty("SET", "Settings");
|
||||||
|
properties.setProperty("WORD_WRAP", "Word Wrap");
|
||||||
|
properties.setProperty("OPEN_CONFIGURATION_FILE", "Open Configuration File");
|
||||||
|
properties.setProperty("PLUGIN", "Plugins");
|
||||||
|
properties.setProperty("ADD_PLUGIN", "Add Plugin");
|
||||||
|
properties.setProperty("STATISTICS", "Word Count");
|
||||||
|
properties.setProperty("ROW", "Row");
|
||||||
|
properties.setProperty("COLUMN", "Column");
|
||||||
|
properties.setProperty("WORD_COUNT", "Word Count");
|
||||||
|
properties.setProperty("ENCODE", "Encoding");
|
||||||
|
properties.setProperty("TOP", "Window Top");
|
||||||
|
properties.setProperty("LANGUAGE", "Language");
|
||||||
|
properties.setProperty("CHINESE", "Chinese");
|
||||||
|
properties.setProperty("ENGLISH", "English");
|
||||||
|
}
|
||||||
|
|
||||||
|
private String textWrap;
|
||||||
|
/// 应用程序文本
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
///菜单栏文本
|
||||||
|
|
||||||
|
private String sava;
|
||||||
|
|
||||||
|
private String file;
|
||||||
|
|
||||||
|
private String newly;
|
||||||
|
|
||||||
|
private String open;
|
||||||
|
|
||||||
|
private String savaAs;
|
||||||
|
|
||||||
|
private String set;
|
||||||
|
|
||||||
|
private String wordWrap;
|
||||||
|
|
||||||
|
private String plugin;
|
||||||
|
|
||||||
|
private String addPlugin;
|
||||||
|
|
||||||
|
private String statistics;
|
||||||
|
|
||||||
|
private String openConfigurationFile;
|
||||||
|
|
||||||
|
private String top;
|
||||||
|
|
||||||
|
private String language;
|
||||||
|
|
||||||
|
private String chinese;
|
||||||
|
|
||||||
|
private String english;
|
||||||
|
|
||||||
|
/// NewFile 文本常量
|
||||||
|
|
||||||
|
private String newFile;
|
||||||
|
/// EncodingDetector 文本常量
|
||||||
|
private String unknown;
|
||||||
|
|
||||||
|
/// JNotepadStatusBox
|
||||||
|
private String row;
|
||||||
|
|
||||||
|
private String column;
|
||||||
|
|
||||||
|
private String wordCount;
|
||||||
|
|
||||||
|
private String encode;
|
||||||
|
|
||||||
|
public static LocalizationConfig getLocalizationConfig() {
|
||||||
|
return LOCALIZATION_CONFIG;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLanguagePackName(String languagePackName) {
|
||||||
|
this.languagePackName = languagePackName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSava() {
|
||||||
|
return sava;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFile() {
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewly() {
|
||||||
|
return newly;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOpen() {
|
||||||
|
return open;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSavaAs() {
|
||||||
|
return savaAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSet() {
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWordWrap() {
|
||||||
|
return wordWrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddPlugin() {
|
||||||
|
return addPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatistics() {
|
||||||
|
return statistics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOpenConfigurationFile() {
|
||||||
|
return openConfigurationFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTop() {
|
||||||
|
return top;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanguage() {
|
||||||
|
return language;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChinese() {
|
||||||
|
return chinese;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEnglish() {
|
||||||
|
return english;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewFile() {
|
||||||
|
return newFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUnknown() {
|
||||||
|
return unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRow() {
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getColumn() {
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWordCount() {
|
||||||
|
return wordCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEncode() {
|
||||||
|
return encode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLanguagePackName() {
|
||||||
|
return languagePackName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTextWrap() {
|
||||||
|
return textWrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextWrap(String textWrap) {
|
||||||
|
this.textWrap = textWrap;
|
||||||
|
properties.setProperty(TEXT_WRAP, textWrap);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,9 +1,7 @@
|
|||||||
package org.jcnc.jnotepad.constants;
|
package org.jcnc.jnotepad.constants;
|
||||||
|
|
||||||
import org.jcnc.jnotepad.init.Config;
|
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文本常量
|
* 文本常量
|
||||||
@ -15,47 +13,10 @@ import java.util.Properties;
|
|||||||
* @author gewuyou
|
* @author gewuyou
|
||||||
*/
|
*/
|
||||||
public class TextConstants {
|
public class TextConstants {
|
||||||
|
|
||||||
private TextConstants() {
|
private TextConstants() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final Config CONFIG = new Config();
|
|
||||||
public static final Properties PROPERTIES = CONFIG.readPropertiesFromFile();
|
|
||||||
|
|
||||||
/// 应用程序文本常量
|
|
||||||
public static final String TITLE = PROPERTIES.getProperty("title", "JNotepad");
|
|
||||||
|
|
||||||
///菜单栏文本常量
|
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
public static final String OPEN_CONFIGURATION_FILE = PROPERTIES.getProperty("OPEN_CONFIGURATION_FILE");
|
|
||||||
|
|
||||||
public static final String TOP = PROPERTIES.getProperty("TOP");
|
|
||||||
|
|
||||||
public static final String LANGUAGE = PROPERTIES.getProperty("LANGUAGE");
|
|
||||||
|
|
||||||
public static final String CHINESE = PROPERTIES.getProperty("CHINESE");
|
|
||||||
|
|
||||||
public static final String ENGLISH = PROPERTIES.getProperty("ENGLISH");
|
|
||||||
|
|
||||||
|
|
||||||
/// GlobalConfig文本常量
|
/// GlobalConfig文本常量
|
||||||
/**
|
/**
|
||||||
@ -63,30 +24,20 @@ public class TextConstants {
|
|||||||
*/
|
*/
|
||||||
public static final String TEXT_WRAP = "text.wrap";
|
public static final String TEXT_WRAP = "text.wrap";
|
||||||
|
|
||||||
/// NewFile 文本常量
|
|
||||||
|
|
||||||
public static final String NEW_FILE = PROPERTIES.getProperty("NEW_FILE");
|
|
||||||
|
|
||||||
/// Config 文本常量
|
/// Config 文本常量
|
||||||
|
|
||||||
public static final String JNOTEPAD_CH_LANGUAGE_PACK_NAME = PROPERTIES.getProperty("JNotepad ch_language_pack");
|
public static final String CH_LANGUAGE_PACK_NAME = "ch_language_pack.txt";
|
||||||
public static final String JNOTEPAD_EN_LANGUAGE_PACK_NAME = PROPERTIES.getProperty("JNotepad en_language_pack");
|
public static final String EN_LANGUAGE_PACK_NAME = "en_language_pack.txt";
|
||||||
|
|
||||||
/// EncodingDetector 文本常量
|
public static final String ENGLISH = "english";
|
||||||
public static final String UNKNOWN = PROPERTIES.getProperty("UNKNOWN");
|
|
||||||
|
|
||||||
/// JNotepadStatusBox
|
public static final String CHINESE = "chinese";
|
||||||
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");
|
|
||||||
/// 语言映射
|
/// 语言映射
|
||||||
public static final Map<String, String> LANGUAGE_MAP = Map.of(
|
public static final Map<String, String> LANGUAGE_FILE_MAP = Map.of(
|
||||||
"chinese", "JNotepad ch_language_pack",
|
CHINESE, CH_LANGUAGE_PACK_NAME,
|
||||||
"english", "JNotepad en_language_pack"
|
ENGLISH, EN_LANGUAGE_PACK_NAME
|
||||||
);
|
);
|
||||||
/// 配置文件文本常量
|
/// 配置文件文本常量
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -2,14 +2,13 @@ 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.app.config.LocalizationConfig;
|
||||||
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 static org.jcnc.jnotepad.constants.TextConstants.NEW_FILE;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新建文件事件的事件处理程序。
|
* 新建文件事件的事件处理程序。
|
||||||
@ -35,7 +34,7 @@ public class NewFile implements EventHandler<ActionEvent> {
|
|||||||
// TODO: refactor:统一TextArea新建、绑定监听器入口
|
// TODO: refactor:统一TextArea新建、绑定监听器入口
|
||||||
ViewManager viewManager = ViewManager.getInstance();
|
ViewManager viewManager = ViewManager.getInstance();
|
||||||
// 将Tab页添加到TabPane中
|
// 将Tab页添加到TabPane中
|
||||||
JNotepadTabPane.getInstance().addNewTab(new JNotepadTab(NEW_FILE
|
JNotepadTabPane.getInstance().addNewTab(new JNotepadTab(LocalizationConfig.getLocalizationConfig().getNewFile()
|
||||||
+ viewManager.selfIncreaseAndGetTabIndex(),
|
+ viewManager.selfIncreaseAndGetTabIndex(),
|
||||||
textArea));
|
textArea));
|
||||||
|
|
||||||
|
|||||||
@ -22,11 +22,11 @@ public class OpenConfig extends OpenHandler {
|
|||||||
// 显示文件选择对话框,并获取选中的文件
|
// 显示文件选择对话框,并获取选中的文件
|
||||||
File file = new File(CONFIG_NAME);
|
File file = new File(CONFIG_NAME);
|
||||||
LogUtil.getLogger(this.getClass()).info("已调用打开配置文件功能");
|
LogUtil.getLogger(this.getClass()).info("已调用打开配置文件功能");
|
||||||
|
LogUtil.getLogger(this.getClass()).info("{}", file);
|
||||||
// 创建打开文件的任务
|
// 创建打开文件的任务
|
||||||
Task<Void> openFileTask = getVoidTask(controller, file);
|
Task<Void> openFileTask = getVoidTask(controller, file);
|
||||||
// 创建并启动线程执行任务
|
// 创建并启动线程执行任务
|
||||||
Thread thread = new Thread(openFileTask);
|
Thread thread = new Thread(openFileTask);
|
||||||
thread.start();
|
thread.start();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@ 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.app.config.LocalizationConfig;
|
||||||
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,8 +18,6 @@ import java.io.IOException;
|
|||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.NEW_FILE;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 控制器类,实现ControllerInterface接口,用于管理文本编辑器的各种操作和事件处理。
|
* 控制器类,实现ControllerInterface接口,用于管理文本编辑器的各种操作和事件处理。
|
||||||
* 包括打开关联文件、创建文本区域、处理行分隔、新建文件、打开文件、自动保存等功能。
|
* 包括打开关联文件、创建文本区域、处理行分隔、新建文件、打开文件、自动保存等功能。
|
||||||
@ -89,7 +88,7 @@ public class Controller implements ControllerInterface {
|
|||||||
textBuilder.append(line).append("\n");
|
textBuilder.append(line).append("\n");
|
||||||
}
|
}
|
||||||
String text = textBuilder.toString();
|
String text = textBuilder.toString();
|
||||||
|
LogUtil.getLogger(this.getClass()).info("已调用读取文件功能");
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
textArea.getMainTextArea().setText(text);
|
textArea.getMainTextArea().setText(text);
|
||||||
JNotepadTab tab = createNewTab(file.getName(), textArea, encoding);
|
JNotepadTab tab = createNewTab(file.getName(), textArea, encoding);
|
||||||
@ -112,7 +111,7 @@ public class Controller implements ControllerInterface {
|
|||||||
@Override
|
@Override
|
||||||
public void updateUiWithNewTextArea(LineNumberTextArea textArea) {
|
public void updateUiWithNewTextArea(LineNumberTextArea textArea) {
|
||||||
ViewManager viewManager = ViewManager.getInstance();
|
ViewManager viewManager = ViewManager.getInstance();
|
||||||
String tabTitle = NEW_FILE + viewManager.selfIncreaseAndGetTabIndex();
|
String tabTitle = LocalizationConfig.getLocalizationConfig().getNewFile() + viewManager.selfIncreaseAndGetTabIndex();
|
||||||
JNotepadTabPane.getInstance().addNewTab(new JNotepadTab(tabTitle, textArea));
|
JNotepadTabPane.getInstance().addNewTab(new JNotepadTab(tabTitle, textArea));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,135 +0,0 @@
|
|||||||
package org.jcnc.jnotepad.init;
|
|
||||||
|
|
||||||
import org.jcnc.jnotepad.tool.LogUtil;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
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.TextConstants.JNOTEPAD_CH_LANGUAGE_PACK_NAME;
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.JNOTEPAD_EN_LANGUAGE_PACK_NAME;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author 许轲
|
|
||||||
* 该类负责配置文件的读取和初始化操作。
|
|
||||||
*/
|
|
||||||
public class Config {
|
|
||||||
|
|
||||||
private String languagePackName;
|
|
||||||
|
|
||||||
Logger logger = LogUtil.getLogger(this.getClass());
|
|
||||||
|
|
||||||
public void setLanguagePackName(String languagePackName) {
|
|
||||||
this.languagePackName = languagePackName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLanguagePackName() {
|
|
||||||
return languagePackName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 从文件中读取属性配置。
|
|
||||||
*
|
|
||||||
* @return 包含从文件中读取的属性的 Properties 对象。
|
|
||||||
*/
|
|
||||||
public Properties readPropertiesFromFile() {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
// 设置语言包
|
|
||||||
languagePackName = EN_LANGUAGE_PACK_NAME;
|
|
||||||
try (InputStream inputStream = new FileInputStream(languagePackName)) {
|
|
||||||
// 使用 UTF-8 编码
|
|
||||||
InputStreamReader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8);
|
|
||||||
properties.load(reader);
|
|
||||||
} catch (IOException e) {
|
|
||||||
// 如果读取出错,则调用初始化方法
|
|
||||||
initializePropertiesFile();
|
|
||||||
}
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 初始化属性配置文件。
|
|
||||||
* 如果属性文件不存在,将创建一个新的属性文件并设置默认属性。
|
|
||||||
*/
|
|
||||||
public void initializePropertiesFile() {
|
|
||||||
Properties chLanguagePack = getChineseLanguagePack();
|
|
||||||
|
|
||||||
Properties enLanguagePack = getEnglishLanguagePack();
|
|
||||||
|
|
||||||
try (OutputStream outputStream = new FileOutputStream(CH_LANGUAGE_PACK_NAME)) {
|
|
||||||
// 使用 UTF-8 编码
|
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
|
|
||||||
chLanguagePack.store(writer, JNOTEPAD_CH_LANGUAGE_PACK_NAME);
|
|
||||||
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
logger.info("未检测到中文语言包!");
|
|
||||||
}
|
|
||||||
|
|
||||||
try (OutputStream outputStream = new FileOutputStream(EN_LANGUAGE_PACK_NAME)) {
|
|
||||||
// 使用 UTF-8 编码
|
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
|
|
||||||
enLanguagePack.store(writer, JNOTEPAD_EN_LANGUAGE_PACK_NAME);
|
|
||||||
|
|
||||||
} catch (IOException ignored) {
|
|
||||||
logger.info("未检测到英文语言包!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Properties getChineseLanguagePack() {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
// 设置默认属性
|
|
||||||
properties.setProperty("TITLE", "JNotepad");
|
|
||||||
properties.setProperty("NEW_FILE", "新建文件");
|
|
||||||
properties.setProperty("SAVA", "保存");
|
|
||||||
properties.setProperty("FILE", "文件");
|
|
||||||
properties.setProperty("NEW", "新建");
|
|
||||||
properties.setProperty("OPEN", "打开");
|
|
||||||
properties.setProperty("SAVA_AS", "另存为");
|
|
||||||
properties.setProperty("SET", "设置");
|
|
||||||
properties.setProperty("WORD_WRAP", "自动换行");
|
|
||||||
properties.setProperty("OPEN_CONFIGURATION_FILE", "打开配置文件");
|
|
||||||
properties.setProperty("PLUGIN", "插件");
|
|
||||||
properties.setProperty("ADD_PLUGIN", "增加插件");
|
|
||||||
properties.setProperty("STATISTICS", "统计字数");
|
|
||||||
properties.setProperty("ROW", "行数");
|
|
||||||
properties.setProperty("COLUMN", "列数");
|
|
||||||
properties.setProperty("WORD_COUNT", "字数");
|
|
||||||
properties.setProperty("ENCODE", "编码");
|
|
||||||
properties.setProperty("TOP", "窗口置顶");
|
|
||||||
properties.setProperty("LANGUAGE", "语言");
|
|
||||||
properties.setProperty("CHINESE", "中文");
|
|
||||||
properties.setProperty("ENGLISH", "英文");
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Properties getEnglishLanguagePack() {
|
|
||||||
Properties properties = new Properties();
|
|
||||||
|
|
||||||
properties.setProperty("TITLE", "JNotepad");
|
|
||||||
properties.setProperty("NEW_FILE", "New File");
|
|
||||||
properties.setProperty("SAVA", "Save");
|
|
||||||
properties.setProperty("FILE", "File");
|
|
||||||
properties.setProperty("NEW", "New");
|
|
||||||
properties.setProperty("OPEN", "Open");
|
|
||||||
properties.setProperty("SAVA_AS", "Save As");
|
|
||||||
properties.setProperty("SET", "Settings");
|
|
||||||
properties.setProperty("WORD_WRAP", "Word Wrap");
|
|
||||||
properties.setProperty("OPEN_CONFIGURATION_FILE", "Open Configuration File");
|
|
||||||
properties.setProperty("PLUGIN", "Plugins");
|
|
||||||
properties.setProperty("ADD_PLUGIN", "Add Plugin");
|
|
||||||
properties.setProperty("STATISTICS", "Word Count");
|
|
||||||
properties.setProperty("ROW", "Row");
|
|
||||||
properties.setProperty("COLUMN", "Column");
|
|
||||||
properties.setProperty("WORD_COUNT", "Word Count");
|
|
||||||
properties.setProperty("ENCODE", "Encoding");
|
|
||||||
properties.setProperty("TOP", "Window Top");
|
|
||||||
properties.setProperty("LANGUAGE", "Language");
|
|
||||||
properties.setProperty("CHINESE", "Chinese");
|
|
||||||
properties.setProperty("ENGLISH", "English");
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -3,6 +3,7 @@ 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 org.jcnc.jnotepad.app.config.LocalizationConfig;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
@ -10,8 +11,6 @@ import java.io.File;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.UNKNOWN;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编码检测工具类
|
* 编码检测工具类
|
||||||
@ -19,7 +18,7 @@ import static org.jcnc.jnotepad.constants.TextConstants.UNKNOWN;
|
|||||||
* @author 许轲
|
* @author 许轲
|
||||||
*/
|
*/
|
||||||
public class EncodingDetector {
|
public class EncodingDetector {
|
||||||
|
static LocalizationConfig localizationConfig = LocalizationConfig.getLocalizationConfig();
|
||||||
private static final Logger LOG = LogUtil.getLogger(EncodingDetector.class);
|
private static final Logger LOG = LogUtil.getLogger(EncodingDetector.class);
|
||||||
/**
|
/**
|
||||||
* 编码侦测概率,阈值:50%
|
* 编码侦测概率,阈值:50%
|
||||||
@ -42,11 +41,11 @@ public class EncodingDetector {
|
|||||||
charsetDetector.setText(inputStream);
|
charsetDetector.setText(inputStream);
|
||||||
CharsetMatch[] matchList = charsetDetector.detectAll();
|
CharsetMatch[] matchList = charsetDetector.detectAll();
|
||||||
if (matchList == null || matchList.length == 0) {
|
if (matchList == null || matchList.length == 0) {
|
||||||
return UNKNOWN;
|
return localizationConfig.getUnknown();
|
||||||
}
|
}
|
||||||
CharsetMatch maxConfidence = matchList[0];
|
CharsetMatch maxConfidence = matchList[0];
|
||||||
if (maxConfidence.getConfidence() < THRESHOLD_CONFIDENCE) {
|
if (maxConfidence.getConfidence() < THRESHOLD_CONFIDENCE) {
|
||||||
return UNKNOWN;
|
return localizationConfig.getUnknown();
|
||||||
}
|
}
|
||||||
for (int i = 1; i < matchList.length; i++) {
|
for (int i = 1; i < matchList.length; i++) {
|
||||||
CharsetMatch match = matchList[i];
|
CharsetMatch match = matchList[i];
|
||||||
@ -60,7 +59,7 @@ public class EncodingDetector {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("", e);
|
LOG.error("", e);
|
||||||
}
|
}
|
||||||
return UNKNOWN;
|
return localizationConfig.getUnknown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,7 +70,7 @@ public class EncodingDetector {
|
|||||||
*/
|
*/
|
||||||
public static Charset detectEncodingCharset(File file) {
|
public static Charset detectEncodingCharset(File file) {
|
||||||
String charset = detectEncoding(file);
|
String charset = detectEncoding(file);
|
||||||
if (charset.equals(UNKNOWN)) {
|
if (charset.equals(localizationConfig.getUnknown())) {
|
||||||
return Charset.defaultCharset();
|
return Charset.defaultCharset();
|
||||||
}
|
}
|
||||||
return Charset.forName(charset);
|
return Charset.forName(charset);
|
||||||
|
|||||||
@ -40,6 +40,7 @@ public class FileUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存页面方法
|
* 保存页面方法
|
||||||
*
|
*
|
||||||
|
|||||||
@ -1,19 +1,22 @@
|
|||||||
package org.jcnc.jnotepad.ui.menu;
|
package org.jcnc.jnotepad.ui.menu;
|
||||||
|
|
||||||
import javafx.scene.control.CheckMenuItem;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.scene.control.Menu;
|
import javafx.scene.control.*;
|
||||||
import javafx.scene.control.MenuBar;
|
|
||||||
import javafx.scene.control.MenuItem;
|
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import org.jcnc.jnotepad.app.config.GlobalConfig;
|
import org.jcnc.jnotepad.app.config.GlobalConfig;
|
||||||
|
import org.jcnc.jnotepad.app.config.LocalizationConfig;
|
||||||
import org.jcnc.jnotepad.controller.event.handler.*;
|
import org.jcnc.jnotepad.controller.event.handler.*;
|
||||||
|
import org.jcnc.jnotepad.tool.LogUtil;
|
||||||
|
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.slf4j.Logger;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.*;
|
import static org.jcnc.jnotepad.constants.TextConstants.CHINESE;
|
||||||
|
import static org.jcnc.jnotepad.constants.TextConstants.ENGLISH;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 封装菜单栏组件。
|
* 封装菜单栏组件。
|
||||||
@ -28,10 +31,15 @@ public class JNotepadMenuBar extends MenuBar {
|
|||||||
*/
|
*/
|
||||||
JNotepadTabPane jNotepadTabPane = JNotepadTabPane.getInstance();
|
JNotepadTabPane jNotepadTabPane = JNotepadTabPane.getInstance();
|
||||||
|
|
||||||
|
JNotepadStatusBox jNotepadStatusBox = JNotepadStatusBox.getInstance();
|
||||||
|
|
||||||
private static final JNotepadMenuBar MENU_BAR = new JNotepadMenuBar();
|
private static final JNotepadMenuBar MENU_BAR = new JNotepadMenuBar();
|
||||||
|
|
||||||
|
LocalizationConfig localizationConfig = LocalizationConfig.getLocalizationConfig();
|
||||||
|
Logger logger = LogUtil.getLogger(this.getClass());
|
||||||
|
|
||||||
private JNotepadMenuBar() {
|
private JNotepadMenuBar() {
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,22 +102,38 @@ public class JNotepadMenuBar extends MenuBar {
|
|||||||
/**
|
/**
|
||||||
* 中文选项
|
* 中文选项
|
||||||
*/
|
*/
|
||||||
private MenuItem chineseItem;
|
private RadioMenuItem chineseItem;
|
||||||
/**
|
/**
|
||||||
* 英文选项
|
* 英文选项
|
||||||
*/
|
*/
|
||||||
private MenuItem englishItem;
|
private RadioMenuItem englishItem;
|
||||||
private final Map<String, MenuItem> itemMap = new HashMap<>();
|
private final Map<String, MenuItem> itemMap = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置当前语言选中状态
|
||||||
|
*
|
||||||
|
* @param language 语言
|
||||||
|
* @since 2023/8/25 22:49
|
||||||
|
*/
|
||||||
|
public void toggleLanguageCheck(String language) {
|
||||||
|
switch (language) {
|
||||||
|
case CHINESE -> chineseItem.setSelected(true);
|
||||||
|
case ENGLISH -> englishItem.setSelected(true);
|
||||||
|
default -> {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化菜单栏
|
* 初始化菜单栏
|
||||||
*/
|
*/
|
||||||
private void init() {
|
public void initMenuBar() {
|
||||||
initFileMenu();
|
initFileMenu();
|
||||||
initLanguageMenu();
|
initLanguageMenu();
|
||||||
initSettingMenu();
|
initSettingMenu();
|
||||||
initPluginMenu();
|
initPluginMenu();
|
||||||
|
this.getMenus().clear();
|
||||||
// 菜单栏
|
// 菜单栏
|
||||||
this.getMenus().addAll(fileMenu, setMenu, pluginMenu);
|
this.getMenus().addAll(fileMenu, setMenu, pluginMenu);
|
||||||
initEventHandlers();
|
initEventHandlers();
|
||||||
@ -119,35 +143,41 @@ public class JNotepadMenuBar extends MenuBar {
|
|||||||
* 初始化语言菜单
|
* 初始化语言菜单
|
||||||
*/
|
*/
|
||||||
private void initLanguageMenu() {
|
private void initLanguageMenu() {
|
||||||
|
logger.info("初始化语言菜单:{}", localizationConfig.getLanguage());
|
||||||
// 语言菜单
|
// 语言菜单
|
||||||
languageMenu = new Menu(LANGUAGE);
|
languageMenu = new Menu(localizationConfig.getLanguage());
|
||||||
|
ToggleGroup languageToggleGroup = new ToggleGroup();
|
||||||
|
|
||||||
chineseItem = new MenuItem(CHINESE);
|
chineseItem = new RadioMenuItem(localizationConfig.getChinese());
|
||||||
itemMap.put("chineseItem", chineseItem);
|
itemMap.put("chineseItem", chineseItem);
|
||||||
|
languageToggleGroup.getToggles().add(chineseItem);
|
||||||
|
|
||||||
englishItem = new MenuItem(ENGLISH);
|
englishItem = new RadioMenuItem(localizationConfig.getEnglish());
|
||||||
itemMap.put("englishItem", englishItem);
|
itemMap.put("englishItem", englishItem);
|
||||||
|
languageToggleGroup.getToggles().add(englishItem);
|
||||||
|
|
||||||
languageMenu.getItems().addAll(chineseItem, englishItem);
|
languageMenu.getItems().addAll(chineseItem, englishItem);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化文件菜单
|
* 初始化文件菜单
|
||||||
*/
|
*/
|
||||||
private void initFileMenu() {
|
private void initFileMenu() {
|
||||||
|
logger.info("初始化文件菜单:{}", localizationConfig.getFile());
|
||||||
// 文件菜单
|
// 文件菜单
|
||||||
fileMenu = new Menu(FILE);
|
fileMenu = new Menu(localizationConfig.getFile());
|
||||||
|
|
||||||
newItem = new MenuItem(NEW);
|
newItem = new MenuItem(localizationConfig.getNewly());
|
||||||
itemMap.put("newItem", newItem);
|
itemMap.put("newItem", newItem);
|
||||||
|
|
||||||
openItem = new MenuItem(OPEN);
|
openItem = new MenuItem(localizationConfig.getOpen());
|
||||||
itemMap.put("openItem", openItem);
|
itemMap.put("openItem", openItem);
|
||||||
|
|
||||||
saveItem = new MenuItem(SAVA);
|
saveItem = new MenuItem(localizationConfig.getSava());
|
||||||
itemMap.put("saveItem", saveItem);
|
itemMap.put("saveItem", saveItem);
|
||||||
|
|
||||||
saveAsItem = new MenuItem(SAVA_AS);
|
saveAsItem = new MenuItem(localizationConfig.getSavaAs());
|
||||||
itemMap.put("saveAsItem", saveAsItem);
|
itemMap.put("saveAsItem", saveAsItem);
|
||||||
|
|
||||||
fileMenu.getItems().addAll(newItem, openItem, saveItem, saveAsItem);
|
fileMenu.getItems().addAll(newItem, openItem, saveItem, saveAsItem);
|
||||||
@ -157,17 +187,18 @@ public class JNotepadMenuBar extends MenuBar {
|
|||||||
* 初始化设置菜单
|
* 初始化设置菜单
|
||||||
*/
|
*/
|
||||||
private void initSettingMenu() {
|
private void initSettingMenu() {
|
||||||
|
logger.info("初始化设置菜单:{}", localizationConfig.getSet());
|
||||||
// 设置菜单
|
// 设置菜单
|
||||||
setMenu = new Menu(SET);
|
setMenu = new Menu(localizationConfig.getSet());
|
||||||
|
|
||||||
lineFeedItem = new CheckMenuItem(WORD_WRAP);
|
lineFeedItem = new CheckMenuItem(localizationConfig.getWordWrap());
|
||||||
itemMap.put("lineFeedItem", lineFeedItem);
|
itemMap.put("lineFeedItem", lineFeedItem);
|
||||||
lineFeedItem.selectedProperty().set(true);
|
lineFeedItem.selectedProperty().set(true);
|
||||||
|
|
||||||
topItem = new CheckMenuItem(TOP);
|
topItem = new CheckMenuItem(localizationConfig.getTop());
|
||||||
itemMap.put("topItem", topItem);
|
itemMap.put("topItem", topItem);
|
||||||
|
|
||||||
openConfigItem = new MenuItem(OPEN_CONFIGURATION_FILE);
|
openConfigItem = new MenuItem(localizationConfig.getOpenConfigurationFile());
|
||||||
itemMap.put("openConfigItem", openConfigItem);
|
itemMap.put("openConfigItem", openConfigItem);
|
||||||
|
|
||||||
itemMap.put("languageMenu", languageMenu);
|
itemMap.put("languageMenu", languageMenu);
|
||||||
@ -178,12 +209,13 @@ public class JNotepadMenuBar extends MenuBar {
|
|||||||
* 初始化插件菜单
|
* 初始化插件菜单
|
||||||
*/
|
*/
|
||||||
private void initPluginMenu() {
|
private void initPluginMenu() {
|
||||||
|
logger.info("初始化插件菜单:{}", localizationConfig.getPlugin());
|
||||||
// 插件菜单
|
// 插件菜单
|
||||||
pluginMenu = new Menu(PLUGIN);
|
pluginMenu = new Menu(localizationConfig.getPlugin());
|
||||||
addItem = new MenuItem(ADD_PLUGIN);
|
addItem = new MenuItem(localizationConfig.getAddPlugin());
|
||||||
itemMap.put("addItem", addItem);
|
itemMap.put("addItem", addItem);
|
||||||
|
|
||||||
countItem = new MenuItem(STATISTICS);
|
countItem = new MenuItem(localizationConfig.getStatistics());
|
||||||
itemMap.put("countItem", countItem);
|
itemMap.put("countItem", countItem);
|
||||||
|
|
||||||
pluginMenu.getItems().addAll(addItem, countItem);
|
pluginMenu.getItems().addAll(addItem, countItem);
|
||||||
@ -214,8 +246,20 @@ public class JNotepadMenuBar extends MenuBar {
|
|||||||
// 设置窗口为置顶
|
// 设置窗口为置顶
|
||||||
primaryStage.setAlwaysOnTop(after);
|
primaryStage.setAlwaysOnTop(after);
|
||||||
});
|
});
|
||||||
|
// todo 切换语言并将语言修改设置回本地
|
||||||
|
englishItem.setOnAction(new OpenHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent actionEvent) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
chineseItem.setOnAction(new OpenHandler() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent actionEvent) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, MenuItem> getItemMap() {
|
public Map<String, MenuItem> getItemMap() {
|
||||||
return itemMap;
|
return itemMap;
|
||||||
|
|||||||
@ -4,13 +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.app.config.LocalizationConfig;
|
||||||
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.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import static org.jcnc.jnotepad.constants.TextConstants.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 状态栏组件封装。
|
* 状态栏组件封装。
|
||||||
* 1. 文字统计
|
* 1. 文字统计
|
||||||
@ -21,27 +20,31 @@ import static org.jcnc.jnotepad.constants.TextConstants.*;
|
|||||||
public class JNotepadStatusBox extends HBox {
|
public class JNotepadStatusBox extends HBox {
|
||||||
|
|
||||||
private static final JNotepadStatusBox STATUS_BOX = new JNotepadStatusBox();
|
private static final JNotepadStatusBox STATUS_BOX = new JNotepadStatusBox();
|
||||||
|
LocalizationConfig localizationConfig = LocalizationConfig.getLocalizationConfig();
|
||||||
/**
|
/**
|
||||||
* 字数统计及光标
|
* 字数统计及光标
|
||||||
*/
|
*/
|
||||||
private final Label statusLabel;
|
private Label statusLabel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 显示文本编码
|
* 显示文本编码
|
||||||
*/
|
*/
|
||||||
private final Label enCodingLabel;
|
private Label enCodingLabel;
|
||||||
|
|
||||||
private JNotepadStatusBox() {
|
private JNotepadStatusBox() {
|
||||||
|
initStatusBox();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initStatusBox() {
|
||||||
|
this.getChildren().clear();
|
||||||
// 创建状态栏
|
// 创建状态栏
|
||||||
statusLabel = new Label(ROW + ":1 \t" + COLUMN + ":1 \t" + WORD_COUNT + ":0 ");
|
statusLabel = new Label(localizationConfig.getRow() + ":1 \t" + localizationConfig.getColumn() + ":1 \t" + localizationConfig.getWordCount() + ":0 ");
|
||||||
// 创建新的标签以显示编码信息
|
// 创建新的标签以显示编码信息
|
||||||
enCodingLabel = new Label();
|
enCodingLabel = new Label();
|
||||||
|
updateEncodingLabel();
|
||||||
this.getChildren().add(statusLabel);
|
this.getChildren().add(statusLabel);
|
||||||
this.getChildren().add(enCodingLabel);
|
this.getChildren().add(enCodingLabel);
|
||||||
this.getProperties().put("borderpane-margin", new Insets(5, 10, 5, 10));
|
this.getProperties().put("borderpane-margin", new Insets(5, 10, 5, 10));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JNotepadStatusBox getInstance() {
|
public static JNotepadStatusBox getInstance() {
|
||||||
@ -61,7 +64,7 @@ public class JNotepadStatusBox extends HBox {
|
|||||||
if (encoding == null) {
|
if (encoding == null) {
|
||||||
encoding = Charset.defaultCharset().name();
|
encoding = Charset.defaultCharset().name();
|
||||||
}
|
}
|
||||||
this.enCodingLabel.setText("\t" + ENCODE + ": " + encoding);
|
this.enCodingLabel.setText("\t" + localizationConfig.getEncode() + ": " + encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -77,7 +80,7 @@ public class JNotepadStatusBox extends HBox {
|
|||||||
int row = getRow(caretPosition, textArea.getText());
|
int row = getRow(caretPosition, textArea.getText());
|
||||||
int column = getColumn(caretPosition, textArea.getText());
|
int column = getColumn(caretPosition, textArea.getText());
|
||||||
int length = textArea.getLength();
|
int length = textArea.getLength();
|
||||||
this.statusLabel.setText(ROW + ": " + row + " \t" + COLUMN + ": " + column + " \t" + WORD_COUNT + ": " + length);
|
this.statusLabel.setText(localizationConfig.getRow() + ": " + row + " \t" + localizationConfig.getColumn() + ": " + column + " \t" + localizationConfig.getWordCount() + ": " + length);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -21,8 +21,8 @@ public class View {
|
|||||||
* @param loadJnotepadConfigs 需要加载的配置文件数组
|
* @param loadJnotepadConfigs 需要加载的配置文件数组
|
||||||
* @since 2023/8/24 15:29
|
* @since 2023/8/24 15:29
|
||||||
*/
|
*/
|
||||||
public void initJnotepadConfigs(List<LoadJnotepadConfig> loadJnotepadConfigs) {
|
public void initJnotepadConfigs(List<LoadJnotepadConfig<?>> loadJnotepadConfigs) {
|
||||||
for (LoadJnotepadConfig loadJnotepadConfig : loadJnotepadConfigs) {
|
for (LoadJnotepadConfig<?> loadJnotepadConfig : loadJnotepadConfigs) {
|
||||||
initJnotepadConfig(loadJnotepadConfig);
|
initJnotepadConfig(loadJnotepadConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,7 +33,7 @@ public class View {
|
|||||||
* @param loadJnotepadConfig 配置文件
|
* @param loadJnotepadConfig 配置文件
|
||||||
* @since 2023/8/24 15:29
|
* @since 2023/8/24 15:29
|
||||||
*/
|
*/
|
||||||
public void initJnotepadConfig(LoadJnotepadConfig loadJnotepadConfig) {
|
public void initJnotepadConfig(LoadJnotepadConfig<?> loadJnotepadConfig) {
|
||||||
loadJnotepadConfig.load();
|
loadJnotepadConfig.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user