diff --git a/SECURITY.md b/SECURITY.md index f4a5c8fb6..bb210138d 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -3,7 +3,7 @@ ## Supported Versions(支持的版本) | Version | Supported | -| ------- | ------------------ | +|---------|--------------------| | 1.0.x | :white_check_mark: | ## Reporting a Vulnerability(报告漏洞) diff --git a/cg/src/main/java/com/tlcsdm/cg/provider/CgMenubarConfigrationProvider.java b/cg/src/main/java/com/tlcsdm/cg/provider/CgMenubarConfigrationProvider.java index a2b2163b7..1cf6c5cd5 100644 --- a/cg/src/main/java/com/tlcsdm/cg/provider/CgMenubarConfigrationProvider.java +++ b/cg/src/main/java/com/tlcsdm/cg/provider/CgMenubarConfigrationProvider.java @@ -28,7 +28,6 @@ package com.tlcsdm.cg.provider; import cn.hutool.core.net.NetUtil; -import cn.hutool.log.StaticLog; import com.tlcsdm.cg.CgSample; import com.tlcsdm.cg.util.CgConstant; import com.tlcsdm.cg.util.I18nUtils; @@ -37,6 +36,7 @@ import com.tlcsdm.core.javafx.control.DependencyTableView; import com.tlcsdm.core.javafx.controlsfx.FxAction; import com.tlcsdm.core.javafx.controlsfx.FxActionGroup; +import com.tlcsdm.core.javafx.controlsfx.FxLanguageActionGroup; import com.tlcsdm.core.javafx.dialog.FxAlerts; import com.tlcsdm.core.javafx.dialog.FxButtonType; import com.tlcsdm.core.javafx.dialog.FxDialog; @@ -44,10 +44,8 @@ import com.tlcsdm.core.javafx.dialog.LogConsoleDialog; import com.tlcsdm.core.javafx.helper.LayoutHelper; import com.tlcsdm.core.javafx.richtext.hyperlink.TextHyperlinkArea; -import com.tlcsdm.core.javafx.util.Config; import com.tlcsdm.core.javafx.util.FxXmlHelper; import com.tlcsdm.core.javafx.util.JavaFxSystemUtil; -import com.tlcsdm.core.javafx.util.Keys; import com.tlcsdm.core.util.CoreUtil; import com.tlcsdm.core.util.DependencyInfo; import com.tlcsdm.core.util.DependencyInfo.Dependency; @@ -60,13 +58,12 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; import org.controlsfx.control.action.Action; -import org.controlsfx.control.action.ActionCheck; +import org.controlsfx.control.action.ActionGroup; import org.controlsfx.control.action.ActionUtils; import java.io.File; import java.util.Collection; import java.util.List; -import java.util.Locale; import java.util.function.Consumer; import static org.controlsfx.control.action.ActionUtils.ACTION_SEPARATOR; @@ -181,105 +178,25 @@ public class CgMenubarConfigrationProvider implements MenubarConfigration { private final Action release = FxAction.release(actionEvent -> CoreUtil.openWeb(CgConstant.PROJECT_RELEASE_URL)); - CheckLangAction chinese = new CheckLangAction(CgConstant.LANGUAGE_CHINESE); - CheckLangAction english = new CheckLangAction(CgConstant.LANGUAGE_ENGLISH); - CheckLangAction japanese = new CheckLangAction(CgConstant.LANGUAGE_JAPANESE); + private final ActionGroup languageGroup = new FxLanguageActionGroup((s) -> { + if (FxAlerts.confirmOkCancel(I18nUtils.get("cg.menubar.setting.language.dialog.title"), + I18nUtils.get("cg.menubar.setting.language.dialog.message"))) { + FXSampler.getStage().close(); + Platform.runLater(() -> new FXSampler().start(new Stage())); + } + }).create(); private final Collection actions = List.of( FxActionGroup.file(export, induct, ACTION_SEPARATOR, restart, exit), - FxActionGroup.setting(systemSetting, FxActionGroup.language(chinese, english, japanese)), + FxActionGroup.setting(systemSetting, languageGroup), FxActionGroup.tool(logConsole, pathWatch, colorPicker, screenshot), FxActionGroup.help(openSysConfig, openLogDir, openUserData, ACTION_SEPARATOR, contactSupport, submitFeedback, ACTION_SEPARATOR, api, css, fxml, ACTION_SEPARATOR, helpContent, release, about)); - /** - * 初始化action - */ - private void initActions() { - // 语言设置 - if (Config.defaultLocale.equals(Locale.ENGLISH)) { - english.setSelected(true); - } else if (Config.defaultLocale.equals(Locale.SIMPLIFIED_CHINESE)) { - chinese.setSelected(true); - } else if (Config.defaultLocale.equals(Locale.JAPANESE)) { - japanese.setSelected(true); - } - chinese.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (oldValue) { - return; - } - if (newValue) { - english.setSelected(false); - japanese.setSelected(false); - } - }); - english.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (oldValue) { - return; - } - if (newValue) { - japanese.setSelected(false); - chinese.setSelected(false); - } - }); - japanese.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (oldValue) { - return; - } - if (newValue) { - english.setSelected(false); - chinese.setSelected(false); - } - }); - } - @Override public MenuBar setMenuBar(MenuBar menuBar) { - initActions(); ActionUtils.updateMenuBar(menuBar, actions); return menuBar; } - @ActionCheck - private static class CheckLangAction extends Action { - - public CheckLangAction(String name) { - super(name); - init(); - } - - private void init() { - setEventHandler(ae -> { - String languageType = getText(); - if (CgConstant.LANGUAGE_CHINESE.equals(languageType)) { - if (Config.defaultLocale == Locale.SIMPLIFIED_CHINESE) { - return; - } - Config.set(Keys.Locale, Locale.SIMPLIFIED_CHINESE); - } else if (CgConstant.LANGUAGE_ENGLISH.equals(languageType)) { - if (Config.defaultLocale == Locale.ENGLISH) { - return; - } - Config.set(Keys.Locale, Locale.ENGLISH); - } else if (CgConstant.LANGUAGE_JAPANESE.equals(languageType)) { - if (Config.defaultLocale == Locale.JAPANESE) { - return; - } - Config.set(Keys.Locale, Locale.JAPANESE); - } - if (FxAlerts.confirmOkCancel(I18nUtils.get("cg.menubar.setting.language.dialog.title"), - I18nUtils.get("cg.menubar.setting.language.dialog.message"))) { - FXSampler.getStage().close(); - Platform.runLater(() -> { - try { - new FXSampler().start(new Stage()); - } catch (Exception e) { - StaticLog.error(e); - } - }); - } - }); - } - } - } diff --git a/cg/src/main/java/com/tlcsdm/cg/util/CgConstant.java b/cg/src/main/java/com/tlcsdm/cg/util/CgConstant.java index 33d8ba52f..d5a5b0980 100644 --- a/cg/src/main/java/com/tlcsdm/cg/util/CgConstant.java +++ b/cg/src/main/java/com/tlcsdm/cg/util/CgConstant.java @@ -73,18 +73,6 @@ public class CgConstant { * 可由VersionCheckerService实现类修改数据 */ public static String PROJECT_RELEASE_URL = "https://github.com/unknowIfGuestInDream/javafxTool/releases?q=cg&expanded=true"; - /** - * 简体中文 - */ - public static final String LANGUAGE_CHINESE = "简体中文"; - /** - * 英文 - */ - public static final String LANGUAGE_ENGLISH = "English"; - /** - * 日文 - */ - public static final String LANGUAGE_JAPANESE = "日本語"; /** * 默认项目版本号 */ diff --git a/core/src/main/java/com/tlcsdm/core/javafx/controlsfx/ConfigLanguageAction.java b/core/src/main/java/com/tlcsdm/core/javafx/controlsfx/ConfigLanguageAction.java new file mode 100644 index 000000000..02cc44bc6 --- /dev/null +++ b/core/src/main/java/com/tlcsdm/core/javafx/controlsfx/ConfigLanguageAction.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2023 unknowIfGuestInDream. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of unknowIfGuestInDream, any associated website, nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.tlcsdm.core.javafx.controlsfx; + +import com.tlcsdm.core.javafx.util.Config; +import com.tlcsdm.core.javafx.util.Keys; +import org.controlsfx.control.action.Action; +import org.controlsfx.control.action.ActionCheck; + +import java.util.Locale; +import java.util.function.Consumer; + +/** + * 语言action. + * + * @author unknowIfGuestInDream + */ +@ActionCheck +public class ConfigLanguageAction extends Action { + + public ConfigLanguageAction(LanguageType language, Consumer consumer) { + super(language.getText()); + setEventHandler(ae -> { + if (LanguageType.CHINESE.equals(language)) { + if (Config.defaultLocale == Locale.SIMPLIFIED_CHINESE) { + return; + } + Config.set(Keys.Locale, Locale.SIMPLIFIED_CHINESE); + } else if (LanguageType.ENGLISH.equals(language)) { + if (Config.defaultLocale == Locale.ENGLISH) { + return; + } + Config.set(Keys.Locale, Locale.ENGLISH); + } else if (LanguageType.JAPANESE.equals(language)) { + if (Config.defaultLocale == Locale.JAPANESE) { + return; + } + Config.set(Keys.Locale, Locale.JAPANESE); + } + consumer.accept(null); + }); + } + +} diff --git a/core/src/main/java/com/tlcsdm/core/javafx/controlsfx/FxLanguageActionGroup.java b/core/src/main/java/com/tlcsdm/core/javafx/controlsfx/FxLanguageActionGroup.java new file mode 100644 index 000000000..6dd543d6d --- /dev/null +++ b/core/src/main/java/com/tlcsdm/core/javafx/controlsfx/FxLanguageActionGroup.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 unknowIfGuestInDream. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of unknowIfGuestInDream, any associated website, nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.tlcsdm.core.javafx.controlsfx; + +import com.tlcsdm.core.javafx.util.Config; +import org.controlsfx.control.action.ActionGroup; + +import java.util.Locale; +import java.util.function.Consumer; + +/** + * 语言切换ActionGroup. + * + * @author unknowIfGuestInDream + */ +public class FxLanguageActionGroup { + ConfigLanguageAction chinese; + ConfigLanguageAction english; + ConfigLanguageAction japanese; + + public FxLanguageActionGroup(Consumer consumer) { + chinese = new ConfigLanguageAction(LanguageType.CHINESE, consumer); + english = new ConfigLanguageAction(LanguageType.ENGLISH, consumer); + japanese = new ConfigLanguageAction(LanguageType.JAPANESE, consumer); + // 语言设置 + if (Config.defaultLocale.equals(Locale.ENGLISH)) { + english.setSelected(true); + } else if (Config.defaultLocale.equals(Locale.SIMPLIFIED_CHINESE)) { + chinese.setSelected(true); + } else if (Config.defaultLocale.equals(Locale.JAPANESE)) { + japanese.setSelected(true); + } + chinese.selectedProperty().addListener((observable, oldValue, newValue) -> { + if (oldValue) { + return; + } + if (newValue) { + english.setSelected(false); + japanese.setSelected(false); + } + }); + english.selectedProperty().addListener((observable, oldValue, newValue) -> { + if (oldValue) { + return; + } + if (newValue) { + japanese.setSelected(false); + chinese.setSelected(false); + } + }); + japanese.selectedProperty().addListener((observable, oldValue, newValue) -> { + if (oldValue) { + return; + } + if (newValue) { + english.setSelected(false); + chinese.setSelected(false); + } + }); + } + + public ActionGroup create() { + return FxActionGroup.language(chinese, english, japanese); + } +} diff --git a/core/src/main/java/com/tlcsdm/core/javafx/controlsfx/LanguageType.java b/core/src/main/java/com/tlcsdm/core/javafx/controlsfx/LanguageType.java new file mode 100644 index 000000000..0b2cfd775 --- /dev/null +++ b/core/src/main/java/com/tlcsdm/core/javafx/controlsfx/LanguageType.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 unknowIfGuestInDream. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of unknowIfGuestInDream, any associated website, nor the + * names of its contributors may be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL UNKNOWIFGUESTINDREAM BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package com.tlcsdm.core.javafx.controlsfx; + +/** + * 支持的语言类型. + * + * @author unknowIfGuestInDream + */ +public enum LanguageType { + CHINESE("简体中文"), + ENGLISH("English"), + JAPANESE("日本語"); + + private final String text; + + LanguageType(String text) { + this.text = text; + } + + public String getText() { + return this.text; + } +} diff --git a/qe/src/main/java/com/tlcsdm/qe/provider/QeMenubarConfigrationProvider.java b/qe/src/main/java/com/tlcsdm/qe/provider/QeMenubarConfigrationProvider.java index 0684aa493..f5d57321c 100644 --- a/qe/src/main/java/com/tlcsdm/qe/provider/QeMenubarConfigrationProvider.java +++ b/qe/src/main/java/com/tlcsdm/qe/provider/QeMenubarConfigrationProvider.java @@ -28,12 +28,12 @@ package com.tlcsdm.qe.provider; import cn.hutool.core.net.NetUtil; -import cn.hutool.log.StaticLog; import com.tlcsdm.core.httpserver.SimpleHttpServer; import com.tlcsdm.core.javafx.FxApp; import com.tlcsdm.core.javafx.control.DependencyTableView; import com.tlcsdm.core.javafx.controlsfx.FxAction; import com.tlcsdm.core.javafx.controlsfx.FxActionGroup; +import com.tlcsdm.core.javafx.controlsfx.FxLanguageActionGroup; import com.tlcsdm.core.javafx.dialog.FxAlerts; import com.tlcsdm.core.javafx.dialog.FxButtonType; import com.tlcsdm.core.javafx.dialog.FxDialog; @@ -41,10 +41,8 @@ import com.tlcsdm.core.javafx.dialog.LogConsoleDialog; import com.tlcsdm.core.javafx.helper.LayoutHelper; import com.tlcsdm.core.javafx.richtext.hyperlink.TextHyperlinkArea; -import com.tlcsdm.core.javafx.util.Config; import com.tlcsdm.core.javafx.util.FxXmlHelper; import com.tlcsdm.core.javafx.util.JavaFxSystemUtil; -import com.tlcsdm.core.javafx.util.Keys; import com.tlcsdm.core.util.CoreUtil; import com.tlcsdm.core.util.DependencyInfo; import com.tlcsdm.core.util.DependencyInfo.Dependency; @@ -60,13 +58,12 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; import org.controlsfx.control.action.Action; -import org.controlsfx.control.action.ActionCheck; +import org.controlsfx.control.action.ActionGroup; import org.controlsfx.control.action.ActionUtils; import java.io.File; import java.util.Collection; import java.util.List; -import java.util.Locale; import java.util.function.Consumer; import static org.controlsfx.control.action.ActionUtils.ACTION_SEPARATOR; @@ -181,105 +178,25 @@ public class QeMenubarConfigrationProvider implements MenubarConfigration { private final Action release = FxAction.release(actionEvent -> CoreUtil.openWeb(QeConstant.PROJECT_RELEASE_URL)); - CheckLangAction chinese = new CheckLangAction(QeConstant.LANGUAGE_CHINESE); - CheckLangAction english = new CheckLangAction(QeConstant.LANGUAGE_ENGLISH); - CheckLangAction japanese = new CheckLangAction(QeConstant.LANGUAGE_JAPANESE); + private final ActionGroup languageGroup = new FxLanguageActionGroup((s) -> { + if (FxAlerts.confirmOkCancel(I18nUtils.get("qe.menubar.setting.language.dialog.title"), + I18nUtils.get("qe.menubar.setting.language.dialog.message"))) { + FXSampler.getStage().close(); + Platform.runLater(() -> new FXSampler().start(new Stage())); + } + }).create(); private final Collection actions = List.of( FxActionGroup.file(export, induct, ACTION_SEPARATOR, restart, exit), - FxActionGroup.setting(systemSetting, FxActionGroup.language(chinese, english, japanese)), + FxActionGroup.setting(systemSetting, languageGroup), FxActionGroup.tool(logConsole, pathWatch, colorPicker, screenshot), FxActionGroup.help(openSysConfig, openLogDir, openUserData, ACTION_SEPARATOR, contactSupport, submitFeedback, ACTION_SEPARATOR, api, css, fxml, ACTION_SEPARATOR, helpContent, release, about)); - /** - * 初始化action - */ - private void initActions() { - // 语言设置 - if (Config.defaultLocale.equals(Locale.ENGLISH)) { - english.setSelected(true); - } else if (Config.defaultLocale.equals(Locale.SIMPLIFIED_CHINESE)) { - chinese.setSelected(true); - } else if (Config.defaultLocale.equals(Locale.JAPANESE)) { - japanese.setSelected(true); - } - chinese.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (oldValue) { - return; - } - if (newValue) { - english.setSelected(false); - japanese.setSelected(false); - } - }); - english.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (oldValue) { - return; - } - if (newValue) { - japanese.setSelected(false); - chinese.setSelected(false); - } - }); - japanese.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (oldValue) { - return; - } - if (newValue) { - english.setSelected(false); - chinese.setSelected(false); - } - }); - } - @Override public MenuBar setMenuBar(MenuBar menuBar) { - initActions(); ActionUtils.updateMenuBar(menuBar, actions); return menuBar; } - @ActionCheck - private static class CheckLangAction extends Action { - - public CheckLangAction(String name) { - super(name); - init(); - } - - private void init() { - setEventHandler(ae -> { - String languageType = getText(); - if (QeConstant.LANGUAGE_CHINESE.equals(languageType)) { - if (Config.defaultLocale == Locale.SIMPLIFIED_CHINESE) { - return; - } - Config.set(Keys.Locale, Locale.SIMPLIFIED_CHINESE); - } else if (QeConstant.LANGUAGE_ENGLISH.equals(languageType)) { - if (Config.defaultLocale == Locale.ENGLISH) { - return; - } - Config.set(Keys.Locale, Locale.ENGLISH); - } else if (QeConstant.LANGUAGE_JAPANESE.equals(languageType)) { - if (Config.defaultLocale == Locale.JAPANESE) { - return; - } - Config.set(Keys.Locale, Locale.JAPANESE); - } - if (FxAlerts.confirmOkCancel(I18nUtils.get("qe.menubar.setting.language.dialog.title"), - I18nUtils.get("qe.menubar.setting.language.dialog.message"))) { - FXSampler.getStage().close(); - Platform.runLater(() -> { - try { - new FXSampler().start(new Stage()); - } catch (Exception e) { - StaticLog.error(e); - } - }); - } - }); - } - } - } diff --git a/qe/src/main/java/com/tlcsdm/qe/util/QeConstant.java b/qe/src/main/java/com/tlcsdm/qe/util/QeConstant.java index faad59c37..d6a59a666 100644 --- a/qe/src/main/java/com/tlcsdm/qe/util/QeConstant.java +++ b/qe/src/main/java/com/tlcsdm/qe/util/QeConstant.java @@ -73,18 +73,6 @@ public class QeConstant { * 可由VersionCheckerService实现类修改数据 */ public static String PROJECT_RELEASE_URL = "https://github.com/unknowIfGuestInDream/javafxTool/releases?q=qe&expanded=true"; - /** - * 简体中文 - */ - public static final String LANGUAGE_CHINESE = "简体中文"; - /** - * 英文 - */ - public static final String LANGUAGE_ENGLISH = "English"; - /** - * 日文 - */ - public static final String LANGUAGE_JAPANESE = "日本語"; /** * 默认项目版本号 */ diff --git a/smc/src/main/java/com/tlcsdm/smc/provider/SmcMenubarConfigrationProvider.java b/smc/src/main/java/com/tlcsdm/smc/provider/SmcMenubarConfigrationProvider.java index d5be32f8e..038bdc003 100644 --- a/smc/src/main/java/com/tlcsdm/smc/provider/SmcMenubarConfigrationProvider.java +++ b/smc/src/main/java/com/tlcsdm/smc/provider/SmcMenubarConfigrationProvider.java @@ -27,13 +27,11 @@ package com.tlcsdm.smc.provider; -import static org.controlsfx.control.action.ActionUtils.ACTION_SEPARATOR; - -import cn.hutool.log.StaticLog; import com.tlcsdm.core.javafx.FxApp; import com.tlcsdm.core.javafx.control.DependencyTableView; import com.tlcsdm.core.javafx.controlsfx.FxAction; import com.tlcsdm.core.javafx.controlsfx.FxActionGroup; +import com.tlcsdm.core.javafx.controlsfx.FxLanguageActionGroup; import com.tlcsdm.core.javafx.dialog.FxAlerts; import com.tlcsdm.core.javafx.dialog.FxButtonType; import com.tlcsdm.core.javafx.dialog.FxDialog; @@ -41,10 +39,8 @@ import com.tlcsdm.core.javafx.dialog.LogConsoleDialog; import com.tlcsdm.core.javafx.helper.LayoutHelper; import com.tlcsdm.core.javafx.richtext.hyperlink.TextHyperlinkArea; -import com.tlcsdm.core.javafx.util.Config; import com.tlcsdm.core.javafx.util.FxXmlHelper; import com.tlcsdm.core.javafx.util.JavaFxSystemUtil; -import com.tlcsdm.core.javafx.util.Keys; import com.tlcsdm.core.util.CoreUtil; import com.tlcsdm.core.util.DependencyInfo; import com.tlcsdm.core.util.DependencyInfo.Dependency; @@ -61,15 +57,16 @@ import javafx.scene.layout.VBox; import javafx.stage.Stage; import org.controlsfx.control.action.Action; -import org.controlsfx.control.action.ActionCheck; +import org.controlsfx.control.action.ActionGroup; import org.controlsfx.control.action.ActionUtils; import java.io.File; import java.util.Collection; import java.util.List; -import java.util.Locale; import java.util.function.Consumer; +import static org.controlsfx.control.action.ActionUtils.ACTION_SEPARATOR; + /** * @author unknowIfGuestInDream */ @@ -178,105 +175,25 @@ public class SmcMenubarConfigrationProvider implements MenubarConfigration { private final Action release = FxAction.release(actionEvent -> CoreUtil.openWeb(SmcConstant.PROJECT_RELEASE_URL)); - CheckLangAction chinese = new CheckLangAction(SmcConstant.LANGUAGE_CHINESE); - CheckLangAction english = new CheckLangAction(SmcConstant.LANGUAGE_ENGLISH); - CheckLangAction japanese = new CheckLangAction(SmcConstant.LANGUAGE_JAPANESE); + private final ActionGroup languageGroup = new FxLanguageActionGroup((s) -> { + if (FxAlerts.confirmOkCancel(I18nUtils.get("smc.menubar.setting.language.dialog.title"), + I18nUtils.get("smc.menubar.setting.language.dialog.message"))) { + FXSampler.getStage().close(); + Platform.runLater(() -> new FXSampler().start(new Stage())); + } + }).create(); private final Collection actions = List.of( FxActionGroup.file(export, induct, ACTION_SEPARATOR, restart, exit), - FxActionGroup.setting(preferences, FxActionGroup.language(chinese, english, japanese)), + FxActionGroup.setting(preferences, languageGroup), FxActionGroup.tool(logConsole, pathWatch, colorPicker, screenshot), FxActionGroup.help(openSysConfig, openLogDir, openUserData, ACTION_SEPARATOR, contactSupport, submitFeedback, ACTION_SEPARATOR, api, css, fxml, ACTION_SEPARATOR, helpContent, release, about)); - /** - * 初始化action - */ - private void initActions() { - // 语言设置 - if (Config.defaultLocale.equals(Locale.ENGLISH)) { - english.setSelected(true); - } else if (Config.defaultLocale.equals(Locale.SIMPLIFIED_CHINESE)) { - chinese.setSelected(true); - } else if (Config.defaultLocale.equals(Locale.JAPANESE)) { - japanese.setSelected(true); - } - chinese.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (oldValue) { - return; - } - if (newValue) { - english.setSelected(false); - japanese.setSelected(false); - } - }); - english.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (oldValue) { - return; - } - if (newValue) { - japanese.setSelected(false); - chinese.setSelected(false); - } - }); - japanese.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (oldValue) { - return; - } - if (newValue) { - english.setSelected(false); - chinese.setSelected(false); - } - }); - } - @Override public MenuBar setMenuBar(MenuBar menuBar) { - initActions(); ActionUtils.updateMenuBar(menuBar, actions); return menuBar; } - @ActionCheck - private static class CheckLangAction extends Action { - - public CheckLangAction(String name) { - super(name); - init(); - } - - private void init() { - setEventHandler(ae -> { - String languageType = getText(); - if (SmcConstant.LANGUAGE_CHINESE.equals(languageType)) { - if (Config.defaultLocale == Locale.SIMPLIFIED_CHINESE) { - return; - } - Config.set(Keys.Locale, Locale.SIMPLIFIED_CHINESE); - } else if (SmcConstant.LANGUAGE_ENGLISH.equals(languageType)) { - if (Config.defaultLocale == Locale.ENGLISH) { - return; - } - Config.set(Keys.Locale, Locale.ENGLISH); - } else if (SmcConstant.LANGUAGE_JAPANESE.equals(languageType)) { - if (Config.defaultLocale == Locale.JAPANESE) { - return; - } - Config.set(Keys.Locale, Locale.JAPANESE); - } - if (FxAlerts.confirmOkCancel(I18nUtils.get("smc.menubar.setting.language.dialog.title"), - I18nUtils.get("smc.menubar.setting.language.dialog.message"))) { - FXSampler.getStage().close(); - Platform.runLater(() -> { - try { - new FXSampler().start(new Stage()); - } catch (Exception e) { - StaticLog.error(e); - } - }); - } - }); - } - } - } diff --git a/smc/src/main/java/com/tlcsdm/smc/util/SmcConstant.java b/smc/src/main/java/com/tlcsdm/smc/util/SmcConstant.java index 99cad46f1..0dc5b59bc 100644 --- a/smc/src/main/java/com/tlcsdm/smc/util/SmcConstant.java +++ b/smc/src/main/java/com/tlcsdm/smc/util/SmcConstant.java @@ -73,18 +73,6 @@ public class SmcConstant { * 可由VersionCheckerService实现类修改数据 */ public static String PROJECT_RELEASE_URL = "https://github.com/unknowIfGuestInDream/javafxTool/releases?q=smc&expanded=true"; - /** - * 简体中文 - */ - public static final String LANGUAGE_CHINESE = "简体中文"; - /** - * 英文 - */ - public static final String LANGUAGE_ENGLISH = "English"; - /** - * 日文 - */ - public static final String LANGUAGE_JAPANESE = "日本語"; /** * 默认项目版本号 */