From bfc341f3b0113e61227940f8941f0ec33b91e954 Mon Sep 17 00:00:00 2001 From: Hades Date: Tue, 4 Jun 2019 19:56:13 +0800 Subject: [PATCH] update --- .../design/actions/community/VideoAction.java | 2 +- .../main/java/com/fr/design/i18n/Action.java | 21 +++++++++++++++ .../java/com/fr/design/i18n/ActionType.java | 6 +++++ .../java/com/fr/design/i18n/LocaleCenter.java | 15 ++++++++++- .../com/fr/design/i18n/LocaleDifference.java | 23 +++++++++++++--- .../impl/AbstractDefaultLocaleAction.java | 27 ++++++++++++++++--- .../design/i18n/impl/ChinaLocaleAction.java | 13 +++++++++ .../design/i18n/impl/JapanLocaleAction.java | 13 +++++++++ .../design/i18n/impl/KoreaLocaleAction.java | 11 ++++++++ .../design/i18n/impl/TaiWanLocaleAction.java | 11 ++++++-- .../fr/design/i18n/impl/USLocaleAction.java | 12 +++++++++ .../mainframe/toolbar/ToolBarMenuDock.java | 10 +++++-- .../start/CollectUserInformationDialog.java | 3 +-- .../main/java/com/fr/start/SplashContext.java | 5 ++-- 14 files changed, 153 insertions(+), 19 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/i18n/Action.java diff --git a/designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java b/designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java index 6eea8cc159..e405f3bb50 100644 --- a/designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java +++ b/designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java @@ -26,7 +26,7 @@ public class VideoAction extends UpdateAction @Override public void actionPerformed(ActionEvent arg0) { - BrowseUtils.browser(LocaleCenter.getInstance().getLocaleAction(GeneralContext.getLocale()).getUrls().get(ActionType.VIDEO)); + BrowseUtils.browser(LocaleCenter.getInstance().getLocaleAction().getUrls().get(ActionType.VIDEO)); } public static final MenuKeySet VIDEO = new MenuKeySet() { diff --git a/designer-base/src/main/java/com/fr/design/i18n/Action.java b/designer-base/src/main/java/com/fr/design/i18n/Action.java new file mode 100644 index 0000000000..a976ae4b7b --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/i18n/Action.java @@ -0,0 +1,21 @@ +package com.fr.design.i18n; + +/** + * 包装一些动作 + * @author Hades + * @date 2019/6/4 + */ +public interface Action { + + Action EMPTY_ACTION = new Action() { + @Override + public void todo() { + // do nothing + } + }; + + /** + * 具体动作 + */ + void todo(); +} diff --git a/designer-base/src/main/java/com/fr/design/i18n/ActionType.java b/designer-base/src/main/java/com/fr/design/i18n/ActionType.java index 1f6b9943a6..724d3df669 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/ActionType.java +++ b/designer-base/src/main/java/com/fr/design/i18n/ActionType.java @@ -1,5 +1,11 @@ package com.fr.design.i18n; +/** + * 不同语言环境下的action + * + * @author Hades + * @date 2019/5/30 + */ public enum ActionType { /** diff --git a/designer-base/src/main/java/com/fr/design/i18n/LocaleCenter.java b/designer-base/src/main/java/com/fr/design/i18n/LocaleCenter.java index 79476f15f4..20bc096113 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/LocaleCenter.java +++ b/designer-base/src/main/java/com/fr/design/i18n/LocaleCenter.java @@ -1,15 +1,24 @@ package com.fr.design.i18n; +import com.fr.design.DesignerEnvManager; import com.fr.design.i18n.impl.ChinaLocaleAction; import com.fr.design.i18n.impl.JapanLocaleAction; import com.fr.design.i18n.impl.KoreaLocaleAction; import com.fr.design.i18n.impl.TaiWanLocaleAction; import com.fr.design.i18n.impl.USLocaleAction; +import com.fr.general.ComparatorUtils; +import com.fr.general.GeneralContext; import java.util.HashMap; import java.util.Locale; import java.util.Map; +/** + * 不同语言环境的动作管理 + * + * @author Hades + * @date 2019/5/30 + */ public class LocaleCenter { private Map actionMap = new HashMap(); @@ -34,7 +43,11 @@ public class LocaleCenter { return Holder.INSTANCE; } - public LocaleDifference getLocaleAction(Locale locale) { + public LocaleDifference getLocaleAction() { + Locale locale = GeneralContext.getLocale(); + if (!ComparatorUtils.equals(locale, DesignerEnvManager.getEnvManager().getLanguage())) { + locale = DesignerEnvManager.getEnvManager().getLanguage(); + } LocaleDifference localeDifference = actionMap.get(locale); return localeDifference == null ? actionMap.get(Locale.CHINA) : localeDifference; } diff --git a/designer-base/src/main/java/com/fr/design/i18n/LocaleDifference.java b/designer-base/src/main/java/com/fr/design/i18n/LocaleDifference.java index 41a7b26cee..d18ef8b9fd 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/LocaleDifference.java +++ b/designer-base/src/main/java/com/fr/design/i18n/LocaleDifference.java @@ -1,10 +1,14 @@ package com.fr.design.i18n; import java.util.List; +import java.util.Locale; import java.util.Map; /** * 国际化之间有不同表现的动作 + * + * @author Hades + * @date 2019/5/30 */ public interface LocaleDifference { @@ -16,11 +20,17 @@ public interface LocaleDifference { /** - * 添加Action - * @param list 列表 - * @param action 对应action + * 哪些国际化需要执行该动作 + * @param locales */ - void addAction(List list, Object action); + void doAction(Locale ...locales); + + /** + * 构建具体的动作 + * @param action + * @return + */ + LocaleDifference buildAction(Action action); /** * 返回设计器启动画面路径 @@ -28,5 +38,10 @@ public interface LocaleDifference { */ String getSplashPath(); + /** + * 对应的国际化 + * @return + */ + Locale getLocale(); } diff --git a/designer-base/src/main/java/com/fr/design/i18n/impl/AbstractDefaultLocaleAction.java b/designer-base/src/main/java/com/fr/design/i18n/impl/AbstractDefaultLocaleAction.java index d190c990fc..9ed01d31d7 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/impl/AbstractDefaultLocaleAction.java +++ b/designer-base/src/main/java/com/fr/design/i18n/impl/AbstractDefaultLocaleAction.java @@ -1,16 +1,28 @@ package com.fr.design.i18n.impl; +import com.fr.design.i18n.Action; import com.fr.design.i18n.LocaleDifference; import com.fr.design.i18n.ActionType; import com.fr.general.CloudCenter; +import com.fr.general.ComparatorUtils; +import java.util.ArrayList; +import java.util.Arrays; import java.util.EnumMap; import java.util.List; +import java.util.Locale; import java.util.Map; +/** + * 一些默认的实现 + * + * @author Hades + * @date 2019/5/30 + */ public abstract class AbstractDefaultLocaleAction implements LocaleDifference { protected EnumMap urls = new EnumMap(ActionType.class); + private Action action = Action.EMPTY_ACTION; protected void init() { urls.put(ActionType.BBS, CloudCenter.getInstance().acquireUrlByKind("bbs")); @@ -28,14 +40,21 @@ public abstract class AbstractDefaultLocaleAction implements LocaleDifference { } @Override - public void addAction(List list, Object action) { - // do nothing + public void doAction(Locale ...locales) { + List localeList = Arrays.asList(locales); + if (localeList.contains(this.getLocale())) { + action.todo(); + } + } + + @Override + public LocaleDifference buildAction(Action action) { + this.action = action; + return this; } @Override public String getSplashPath() { return "/com/fr/design/images/splash_10_en.gif"; } - - } diff --git a/designer-base/src/main/java/com/fr/design/i18n/impl/ChinaLocaleAction.java b/designer-base/src/main/java/com/fr/design/i18n/impl/ChinaLocaleAction.java index c10c9b7142..d2fc2c7f94 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/impl/ChinaLocaleAction.java +++ b/designer-base/src/main/java/com/fr/design/i18n/impl/ChinaLocaleAction.java @@ -1,9 +1,22 @@ package com.fr.design.i18n.impl; +import java.util.Locale; + +/** + * 简体中文环境具体的表现动作 + * + * @author Hades + * @date 2019/5/30 + */ public class ChinaLocaleAction extends AbstractDefaultLocaleAction { @Override public String getSplashPath() { return "/com/fr/design/images/splash_10.gif"; } + + @Override + public Locale getLocale() { + return Locale.CHINA; + } } diff --git a/designer-base/src/main/java/com/fr/design/i18n/impl/JapanLocaleAction.java b/designer-base/src/main/java/com/fr/design/i18n/impl/JapanLocaleAction.java index 8a018bee04..81614bbb81 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/impl/JapanLocaleAction.java +++ b/designer-base/src/main/java/com/fr/design/i18n/impl/JapanLocaleAction.java @@ -3,6 +3,14 @@ package com.fr.design.i18n.impl; import com.fr.design.i18n.ActionType; import com.fr.general.CloudCenter; +import java.util.Locale; + +/** + * 日文环境具体的表现动作 + * + * @author Hades + * @date 2019/5/30 + */ public class JapanLocaleAction extends AbstractDefaultLocaleAction { @Override @@ -17,5 +25,10 @@ public class JapanLocaleAction extends AbstractDefaultLocaleAction { return "/com/fr/design/images/splash_10_jp.gif"; } + @Override + public Locale getLocale() { + return Locale.JAPAN; + } + } diff --git a/designer-base/src/main/java/com/fr/design/i18n/impl/KoreaLocaleAction.java b/designer-base/src/main/java/com/fr/design/i18n/impl/KoreaLocaleAction.java index 0216ecdbdb..5a5e9b8ed0 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/impl/KoreaLocaleAction.java +++ b/designer-base/src/main/java/com/fr/design/i18n/impl/KoreaLocaleAction.java @@ -1,6 +1,17 @@ package com.fr.design.i18n.impl; +import java.util.Locale; +/** + * 韩文环境具体的表现动作 + * + * @author Hades + * @date 2019/5/30 + */ public class KoreaLocaleAction extends AbstractDefaultLocaleAction { + @Override + public Locale getLocale() { + return Locale.KOREA; + } } diff --git a/designer-base/src/main/java/com/fr/design/i18n/impl/TaiWanLocaleAction.java b/designer-base/src/main/java/com/fr/design/i18n/impl/TaiWanLocaleAction.java index 2985e74162..f9e8df2af4 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/impl/TaiWanLocaleAction.java +++ b/designer-base/src/main/java/com/fr/design/i18n/impl/TaiWanLocaleAction.java @@ -4,7 +4,14 @@ import com.fr.design.i18n.ActionType; import com.fr.general.CloudCenter; import java.util.List; +import java.util.Locale; +/** + * 繁体中文具体的表现动作 + * + * @author Hades + * @date 2019/5/30 + */ public class TaiWanLocaleAction extends AbstractDefaultLocaleAction { @Override @@ -15,7 +22,7 @@ public class TaiWanLocaleAction extends AbstractDefaultLocaleAction { } @Override - public void addAction(List list, Object action) { - list.add(action); + public Locale getLocale() { + return Locale.TAIWAN; } } diff --git a/designer-base/src/main/java/com/fr/design/i18n/impl/USLocaleAction.java b/designer-base/src/main/java/com/fr/design/i18n/impl/USLocaleAction.java index bdd305761c..4acfc3db10 100644 --- a/designer-base/src/main/java/com/fr/design/i18n/impl/USLocaleAction.java +++ b/designer-base/src/main/java/com/fr/design/i18n/impl/USLocaleAction.java @@ -3,6 +3,14 @@ package com.fr.design.i18n.impl; import com.fr.design.i18n.ActionType; import com.fr.general.CloudCenter; +import java.util.Locale; + +/** + * 英文环境具体的表现动作 + * + * @author Hades + * @date 2019/5/30 + */ public class USLocaleAction extends AbstractDefaultLocaleAction { @Override @@ -13,4 +21,8 @@ public class USLocaleAction extends AbstractDefaultLocaleAction { urls.put(ActionType.ACTIVATION_CODE, CloudCenter.getInstance().acquireUrlByKind("frlogin.en")); } + @Override + public Locale getLocale() { + return Locale.US; + } } diff --git a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java index 52103026a2..3fad25f6f4 100644 --- a/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java +++ b/designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java @@ -47,6 +47,7 @@ import com.fr.design.gui.imenu.UIMenu; import com.fr.design.gui.imenu.UIMenuBar; import com.fr.design.gui.itoolbar.UILargeToolbar; import com.fr.design.gui.itoolbar.UIToolbar; +import com.fr.design.i18n.Action; import com.fr.design.i18n.LocaleCenter; import com.fr.design.mainframe.JTemplate; import com.fr.design.mainframe.ToolBarNewTemplatePane; @@ -533,7 +534,7 @@ public abstract class ToolBarMenuDock { * @return 社区菜单的子菜单 */ public ShortCut[] createCommunityShortCuts() { - java.util.List shortCuts = new ArrayList(); + final java.util.List shortCuts = new ArrayList(); shortCuts.add(new BBSAction()); shortCuts.add(new VideoAction()); shortCuts.add(new TutorialAction()); @@ -544,7 +545,12 @@ public abstract class ToolBarMenuDock { shortCuts.add(new CusDemandAction()); shortCuts.add(new CenterAction()); shortCuts.add(new SignAction()); - LocaleCenter.getInstance().getLocaleAction(GeneralContext.getLocale()).addAction(shortCuts, new FacebookFansAction()); + LocaleCenter.getInstance().getLocaleAction().buildAction(new Action() { + @Override + public void todo() { + shortCuts.add(new FacebookFansAction()); + } + }).doAction(Locale.TAIWAN); return shortCuts.toArray(new ShortCut[shortCuts.size()]); } diff --git a/designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java b/designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java index f74fb7966d..1ec0712810 100644 --- a/designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java +++ b/designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java @@ -124,9 +124,8 @@ public class CollectUserInformationDialog extends UIDialog { private void getKeyAction() { - Locale locale = GeneralContext.getLocale(); try { - Desktop.getDesktop().browse(new URI(LocaleCenter.getInstance().getLocaleAction(locale).getUrls().get(ActionType.ACTIVATION_CODE))); + Desktop.getDesktop().browse(new URI(LocaleCenter.getInstance().getLocaleAction().getUrls().get(ActionType.ACTIVATION_CODE))); } catch (Exception ignored) { } diff --git a/designer-realize/src/main/java/com/fr/start/SplashContext.java b/designer-realize/src/main/java/com/fr/start/SplashContext.java index 17a4897b3a..9fcdad122a 100644 --- a/designer-realize/src/main/java/com/fr/start/SplashContext.java +++ b/designer-realize/src/main/java/com/fr/start/SplashContext.java @@ -1,6 +1,5 @@ package com.fr.start; -import com.fr.design.DesignerEnvManager; import com.fr.design.i18n.LocaleCenter; import com.fr.design.mainframe.bbs.BBSConstants; import com.fr.event.Event; @@ -25,7 +24,7 @@ import java.util.concurrent.TimeUnit; public class SplashContext { public static final String SPLASH_PATH = getSplashPath(); - public static final String SPLASH_CACHE_NAME = SPLASH_PATH.substring(SPLASH_PATH.lastIndexOf("/") + 1); + public static final String SPLASH_CACHE_NAME = SPLASH_PATH.substring(SPLASH_PATH.lastIndexOf('/') + 1); private static final int FETCH_ONLINE_MAX_TIMES = 50; private static final SplashContext SPLASH_CONTEXT = new SplashContext(); @@ -167,6 +166,6 @@ public class SplashContext { } private static String getSplashPath() { - return LocaleCenter.getInstance().getLocaleAction(DesignerEnvManager.getEnvManager().getLanguage()).getSplashPath(); + return LocaleCenter.getInstance().getLocaleAction().getSplashPath(); } }