🐛 修复 BUG 当切换语言时,下方状态栏无法切换的bug,⚡️ 优化 切换语言的逻辑
This commit is contained in:
parent
20bf5e75f4
commit
ab2030a0e2
@ -200,6 +200,7 @@ public class LocalizationConfig {
|
||||
private String unknown;
|
||||
|
||||
/// JNotepadStatusBox
|
||||
|
||||
private String row;
|
||||
|
||||
private String column;
|
||||
|
||||
@ -3,6 +3,7 @@ package org.jcnc.jnotepad.app.init;
|
||||
import org.jcnc.jnotepad.app.config.LocalizationConfig;
|
||||
import org.jcnc.jnotepad.tool.LogUtil;
|
||||
import org.jcnc.jnotepad.ui.menu.JNotepadMenuBar;
|
||||
import org.jcnc.jnotepad.ui.status.JNotepadStatusBox;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.io.InputStream;
|
||||
@ -37,6 +38,7 @@ public class LoadLanguageConfig extends LoadJnotepadConfig<String> {
|
||||
// 刷新菜单栏
|
||||
jNotepadMenuBar.initMenuBar();
|
||||
jNotepadMenuBar.toggleLanguageCheck(language);
|
||||
JNotepadStatusBox.getInstance().initStatusBox();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import org.jcnc.jnotepad.exception.AppException;
|
||||
import org.jcnc.jnotepad.json.DataGenerator;
|
||||
import org.jcnc.jnotepad.json.MyData;
|
||||
import org.jcnc.jnotepad.tool.JsonUtil;
|
||||
@ -65,10 +66,6 @@ public class TextConstants {
|
||||
public static final String CHINESE = "chinese";
|
||||
|
||||
public static final String LOWER_LANGUAGE = "language";
|
||||
|
||||
private static final String BUTTON_NAME = "buttonName";
|
||||
|
||||
private static final String SHORTCUT_KEY_VALUE = "shortcutKeyValue";
|
||||
/**
|
||||
* 语言映射
|
||||
*/
|
||||
@ -86,7 +83,7 @@ public class TextConstants {
|
||||
try {
|
||||
JNOTEPAD_CONFIG = createShortcutKeyJsonString();
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new AppException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,9 +5,15 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据生成类,用于生成示例数据。
|
||||
* @author 许轲
|
||||
*/
|
||||
public class DataGenerator {
|
||||
// 快捷键常量
|
||||
|
||||
|
||||
private DataGenerator() {
|
||||
}
|
||||
/// 快捷键常量
|
||||
|
||||
private static final String CTRL_N = "ctrl+n";
|
||||
private static final String CTRL_O = "ctrl+o";
|
||||
private static final String CTRL_S = "ctrl+s";
|
||||
|
||||
@ -4,6 +4,8 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 数据模型类,用于表示 MyData 对象的数据结构。
|
||||
*
|
||||
* @author 许轲
|
||||
*/
|
||||
public class MyData {
|
||||
private String language;
|
||||
@ -16,8 +18,6 @@ public class MyData {
|
||||
private String buttonName;
|
||||
private String shortcutKeyValue;
|
||||
|
||||
public ShortcutKey() {}
|
||||
|
||||
public String getButtonName() {
|
||||
return buttonName;
|
||||
}
|
||||
@ -35,8 +35,6 @@ public class MyData {
|
||||
}
|
||||
}
|
||||
|
||||
public MyData() {}
|
||||
|
||||
public String getLanguage() {
|
||||
return language;
|
||||
}
|
||||
|
||||
@ -11,9 +11,10 @@ import org.jcnc.jnotepad.exception.AppException;
|
||||
* @author songdragon
|
||||
*/
|
||||
public class JsonUtil {
|
||||
private JsonUtil() {
|
||||
}
|
||||
|
||||
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
|
||||
;
|
||||
|
||||
public static String toJsonString(Object o) {
|
||||
try {
|
||||
|
||||
@ -1,9 +1,6 @@
|
||||
package org.jcnc.jnotepad.ui.menu;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.*;
|
||||
@ -15,7 +12,6 @@ import org.jcnc.jnotepad.controller.event.handler.*;
|
||||
import org.jcnc.jnotepad.exception.AppException;
|
||||
import org.jcnc.jnotepad.tool.JsonUtil;
|
||||
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.JNotepadTabPane;
|
||||
import org.jcnc.jnotepad.view.init.View;
|
||||
@ -42,8 +38,6 @@ public class JNotepadMenuBar extends MenuBar {
|
||||
*/
|
||||
JNotepadTabPane jNotepadTabPane = JNotepadTabPane.getInstance();
|
||||
|
||||
JNotepadStatusBox jNotepadStatusBox = JNotepadStatusBox.getInstance();
|
||||
|
||||
private static final JNotepadMenuBar MENU_BAR = new JNotepadMenuBar();
|
||||
|
||||
LocalizationConfig localizationConfig = LocalizationConfig.getLocalizationConfig();
|
||||
@ -262,8 +256,9 @@ public class JNotepadMenuBar extends MenuBar {
|
||||
public void handle(ActionEvent actionEvent) {
|
||||
try {
|
||||
setCurrentLanguage(ENGLISH);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new AppException(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -272,8 +267,9 @@ public class JNotepadMenuBar extends MenuBar {
|
||||
public void handle(ActionEvent actionEvent) {
|
||||
try {
|
||||
setCurrentLanguage(CHINESE);
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new RuntimeException(e);
|
||||
throw new AppException(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -286,6 +282,10 @@ public class JNotepadMenuBar extends MenuBar {
|
||||
* @since 2023/8/26 16:16
|
||||
*/
|
||||
private void setCurrentLanguage(String language) throws JsonProcessingException {
|
||||
// 如果当前已是该语言则不执行该方法
|
||||
if (localizationConfig.getLanguagePackName().equals(LANGUAGE_FILE_MAP.get(language))) {
|
||||
return;
|
||||
}
|
||||
boolean flag = false;
|
||||
// 获取本地配置文件
|
||||
logger.info("尝试读取本地配置文件!");
|
||||
@ -299,7 +299,7 @@ public class JNotepadMenuBar extends MenuBar {
|
||||
logger.error("读取失败,配置文件错误或不存在配置文件!");
|
||||
flag = true;
|
||||
}
|
||||
ObjectNode json = null;
|
||||
ObjectNode json;
|
||||
|
||||
if (!flag) {
|
||||
json = JsonUtil.OBJECT_MAPPER.readValue(jsonData.toString(), ObjectNode.class);
|
||||
|
||||
@ -35,6 +35,11 @@ public class JNotepadStatusBox extends HBox {
|
||||
initStatusBox();
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化状态栏组件
|
||||
*
|
||||
* @since 2023/8/27 9:33
|
||||
*/
|
||||
public void initStatusBox() {
|
||||
this.getChildren().clear();
|
||||
// 创建状态栏
|
||||
@ -42,6 +47,7 @@ public class JNotepadStatusBox extends HBox {
|
||||
// 创建新的标签以显示编码信息
|
||||
enCodingLabel = new Label();
|
||||
updateEncodingLabel();
|
||||
updateWhenTabSelected();
|
||||
this.getChildren().add(statusLabel);
|
||||
this.getChildren().add(enCodingLabel);
|
||||
this.getProperties().put("borderpane-margin", new Insets(5, 10, 5, 10));
|
||||
|
||||
@ -21,8 +21,10 @@ public class ViewManager {
|
||||
|
||||
|
||||
// 主界面布局
|
||||
private BorderPane root; // 主布局
|
||||
|
||||
/**
|
||||
* 主布局
|
||||
*/
|
||||
private BorderPane root;
|
||||
|
||||
private static ViewManager instance = null;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user