Browse Source

KERNEL-582 国际化定制的地方会越来越多,想办法去掉这种if else写法

bugfix/10.0
Hades 6 years ago
parent
commit
f04c4cfdf9
  1. 16
      designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java
  2. 32
      designer-base/src/main/java/com/fr/design/i18n/ActionType.java
  3. 41
      designer-base/src/main/java/com/fr/design/i18n/LocaleCenter.java
  4. 32
      designer-base/src/main/java/com/fr/design/i18n/LocaleDifference.java
  5. 41
      designer-base/src/main/java/com/fr/design/i18n/impl/AbstractDefaultLocaleAction.java
  6. 9
      designer-base/src/main/java/com/fr/design/i18n/impl/ChinaLocaleAction.java
  7. 21
      designer-base/src/main/java/com/fr/design/i18n/impl/JapanLocaleAction.java
  8. 6
      designer-base/src/main/java/com/fr/design/i18n/impl/KoreaLocaleAction.java
  9. 21
      designer-base/src/main/java/com/fr/design/i18n/impl/TaiWanLocaleAction.java
  10. 16
      designer-base/src/main/java/com/fr/design/i18n/impl/USLocaleAction.java
  11. 5
      designer-base/src/main/java/com/fr/design/mainframe/toolbar/ToolBarMenuDock.java
  12. 21
      designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java
  13. 10
      designer-realize/src/main/java/com/fr/start/SplashContext.java

16
designer-base/src/main/java/com/fr/design/actions/community/VideoAction.java

@ -1,15 +1,15 @@
package com.fr.design.actions.community;
import com.fr.base.BaseUtils;
import com.fr.design.actions.UpdateAction;
import com.fr.design.i18n.ActionType;
import com.fr.design.i18n.LocaleCenter;
import com.fr.design.menu.MenuKeySet;
import com.fr.design.utils.BrowseUtils;
import com.fr.general.CloudCenter;
import com.fr.general.GeneralContext;
import com.fr.general.IOUtils;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.Locale;
public class VideoAction extends UpdateAction
{
@ -19,20 +19,14 @@ public class VideoAction extends UpdateAction
this.setMenuKeySet(VIDEO);
this.setName(getMenuKeySet().getMenuName());
this.setMnemonic(getMenuKeySet().getMnemonic());
this.setSmallIcon(BaseUtils.readIcon("/com/fr/design/images/bbs/video.png"));
this.setSmallIcon(IOUtils.readIcon("/com/fr/design/images/bbs/video.png"));
}
@Override
public void actionPerformed(ActionEvent arg0)
{
String url;
if (GeneralContext.getLocale().equals(Locale.US)) {
url = CloudCenter.getInstance().acquireUrlByKind("bbs.video.en");
} else {
url = CloudCenter.getInstance().acquireUrlByKind("bbs.video");
}
BrowseUtils.browser(url);
BrowseUtils.browser(LocaleCenter.getInstance().getLocaleAction(GeneralContext.getLocale()).getUrls().get(ActionType.VIDEO));
}
public static final MenuKeySet VIDEO = new MenuKeySet() {

32
designer-base/src/main/java/com/fr/design/i18n/ActionType.java

@ -0,0 +1,32 @@
package com.fr.design.i18n;
public enum ActionType {
/**
* 视频教学
*/
VIDEO("video"),
/**
* 激活码
*/
ACTIVATION_CODE("activationCode"),
/**
* 帮助文档
*/
HELP_DOCUMENT("helpDocument"),
/**
* 论坛
*/
BBS("bbs");
private String description;
ActionType(String description) {
this.description = description;
}
}

41
designer-base/src/main/java/com/fr/design/i18n/LocaleCenter.java

@ -0,0 +1,41 @@
package com.fr.design.i18n;
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 java.util.HashMap;
import java.util.Locale;
import java.util.Map;
public class LocaleCenter {
private Map<Locale, LocaleDifference> actionMap = new HashMap<Locale, LocaleDifference>();
private LocaleCenter() {
init();
}
private void init() {
actionMap.put(Locale.CHINA, new ChinaLocaleAction());
actionMap.put(Locale.US, new USLocaleAction());
actionMap.put(Locale.TAIWAN, new TaiWanLocaleAction());
actionMap.put(Locale.JAPAN, new JapanLocaleAction());
actionMap.put(Locale.KOREA, new KoreaLocaleAction());
}
private static class Holder {
private static final LocaleCenter INSTANCE = new LocaleCenter();
}
public static LocaleCenter getInstance() {
return Holder.INSTANCE;
}
public LocaleDifference getLocaleAction(Locale locale) {
LocaleDifference localeDifference = actionMap.get(locale);
return localeDifference == null ? actionMap.get(Locale.CHINA) : localeDifference;
}
}

32
designer-base/src/main/java/com/fr/design/i18n/LocaleDifference.java

@ -0,0 +1,32 @@
package com.fr.design.i18n;
import java.util.List;
import java.util.Map;
/**
* 国际化之间有不同表现的动作
*/
public interface LocaleDifference {
/**
* 返回该国际化所有的url
* @return url
*/
Map<ActionType, String> getUrls();
/**
* 添加Action
* @param list 列表
* @param action 对应action
*/
void addAction(List list, Object action);
/**
* 返回设计器启动画面路径
* @return 路径
*/
String getSplashPath();
}

41
designer-base/src/main/java/com/fr/design/i18n/impl/AbstractDefaultLocaleAction.java

@ -0,0 +1,41 @@
package com.fr.design.i18n.impl;
import com.fr.design.i18n.LocaleDifference;
import com.fr.design.i18n.ActionType;
import com.fr.general.CloudCenter;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
public abstract class AbstractDefaultLocaleAction implements LocaleDifference {
protected EnumMap<ActionType, String> urls = new EnumMap<ActionType, String>(ActionType.class);
protected void init() {
urls.put(ActionType.BBS, CloudCenter.getInstance().acquireUrlByKind("bbs"));
urls.put(ActionType.VIDEO, CloudCenter.getInstance().acquireUrlByKind("bbs.video"));
urls.put(ActionType.ACTIVATION_CODE, CloudCenter.getInstance().acquireUrlByKind("frlogin.cn"));
urls.put(ActionType.HELP_DOCUMENT, CloudCenter.getInstance().acquireUrlByKind("help.zh_CN.10"));
}
@Override
public Map<ActionType, String> getUrls() {
if (urls.isEmpty()) {
init();
}
return urls;
}
@Override
public void addAction(List list, Object action) {
// do nothing
}
@Override
public String getSplashPath() {
return "/com/fr/design/images/splash_10_en.gif";
}
}

9
designer-base/src/main/java/com/fr/design/i18n/impl/ChinaLocaleAction.java

@ -0,0 +1,9 @@
package com.fr.design.i18n.impl;
public class ChinaLocaleAction extends AbstractDefaultLocaleAction {
@Override
public String getSplashPath() {
return "/com/fr/design/images/splash_10.gif";
}
}

21
designer-base/src/main/java/com/fr/design/i18n/impl/JapanLocaleAction.java

@ -0,0 +1,21 @@
package com.fr.design.i18n.impl;
import com.fr.design.i18n.ActionType;
import com.fr.general.CloudCenter;
public class JapanLocaleAction extends AbstractDefaultLocaleAction {
@Override
protected void init() {
super.init();
urls.put(ActionType.ACTIVATION_CODE, CloudCenter.getInstance().acquireUrlByKind("frlogin.jp"));
}
@Override
public String getSplashPath() {
return "/com/fr/design/images/splash_10_jp.gif";
}
}

6
designer-base/src/main/java/com/fr/design/i18n/impl/KoreaLocaleAction.java

@ -0,0 +1,6 @@
package com.fr.design.i18n.impl;
public class KoreaLocaleAction extends AbstractDefaultLocaleAction {
}

21
designer-base/src/main/java/com/fr/design/i18n/impl/TaiWanLocaleAction.java

@ -0,0 +1,21 @@
package com.fr.design.i18n.impl;
import com.fr.design.i18n.ActionType;
import com.fr.general.CloudCenter;
import java.util.List;
public class TaiWanLocaleAction extends AbstractDefaultLocaleAction {
@Override
protected void init() {
super.init();
urls.put(ActionType.VIDEO, CloudCenter.getInstance().acquireUrlByKind("bbs.video.zh_TW"));
urls.put(ActionType.ACTIVATION_CODE, CloudCenter.getInstance().acquireUrlByKind("frlogin.tw"));
}
@Override
public void addAction(List list, Object action) {
list.add(action);
}
}

16
designer-base/src/main/java/com/fr/design/i18n/impl/USLocaleAction.java

@ -0,0 +1,16 @@
package com.fr.design.i18n.impl;
import com.fr.design.i18n.ActionType;
import com.fr.general.CloudCenter;
public class USLocaleAction extends AbstractDefaultLocaleAction {
@Override
protected void init() {
super.init();
urls.put(ActionType.VIDEO, CloudCenter.getInstance().acquireUrlByKind("bbs.video.en"));
urls.put(ActionType.HELP_DOCUMENT, CloudCenter.getInstance().acquireUrlByKind("help.en_US.10"));
urls.put(ActionType.ACTIVATION_CODE, CloudCenter.getInstance().acquireUrlByKind("frlogin.en"));
}
}

5
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.LocaleCenter;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.ToolBarNewTemplatePane;
import com.fr.design.menu.MenuDef;
@ -543,9 +544,7 @@ public abstract class ToolBarMenuDock {
shortCuts.add(new CusDemandAction());
shortCuts.add(new CenterAction());
shortCuts.add(new SignAction());
if (Locale.TAIWAN.equals(GeneralContext.getLocale())) {
shortCuts.add(new FacebookFansAction());
}
LocaleCenter.getInstance().getLocaleAction(GeneralContext.getLocale()).addAction(shortCuts, new FacebookFansAction());
return shortCuts.toArray(new ShortCut[shortCuts.size()]);
}

21
designer-realize/src/main/java/com/fr/start/CollectUserInformationDialog.java

@ -7,11 +7,11 @@ import com.fr.design.gui.icontainer.UIScrollPane;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.itextarea.DescriptionTextArea;
import com.fr.design.gui.itextfield.UITextField;
import com.fr.design.i18n.ActionType;
import com.fr.design.i18n.LocaleCenter;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.ActiveKeyGenerator;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.CloudCenter;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralContext;
import javax.swing.*;
@ -31,11 +31,6 @@ public class CollectUserInformationDialog extends UIDialog {
private static final int ONLINE_VERIFY_TIMEOUT = 30 * 1000;
private static final String CN_LOGIN_HTML = CloudCenter.getInstance().acquireUrlByKind("frlogin.cn");
private static final String EN_LOGIN_HTML = CloudCenter.getInstance().acquireUrlByKind("frlogin.en");
private static final String TW_LOGIN_HTML = CloudCenter.getInstance().acquireUrlByKind("frlogin.tw");
private static final String JP_LOGIN_HTML = CloudCenter.getInstance().acquireUrlByKind("frlogin.jp");
private UITextField keyTextField;
private ActionListener actionListener = new ActionListener() {
@ -130,18 +125,8 @@ public class CollectUserInformationDialog extends UIDialog {
private void getKeyAction() {
Locale locale = GeneralContext.getLocale();
String url = EN_LOGIN_HTML;
if (ComparatorUtils.equals(locale, Locale.TAIWAN)) {
url = TW_LOGIN_HTML;
}
if (ComparatorUtils.equals(locale, Locale.CHINA)) {
url = CN_LOGIN_HTML;
}
if (ComparatorUtils.equals(locale, Locale.JAPAN)) {
url = JP_LOGIN_HTML;
}
try {
Desktop.getDesktop().browse(new URI(url));
Desktop.getDesktop().browse(new URI(LocaleCenter.getInstance().getLocaleAction(locale).getUrls().get(ActionType.ACTIVATION_CODE)));
} catch (Exception ignored) {
}

10
designer-realize/src/main/java/com/fr/start/SplashContext.java

@ -1,6 +1,7 @@
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;
import com.fr.event.EventDispatcher;
@ -166,13 +167,6 @@ public class SplashContext {
}
private static String getSplashPath() {
Locale locale = DesignerEnvManager.getEnvManager().getLanguage();
if (Locale.US.equals(locale) || Locale.KOREA.equals(locale) || Locale.TAIWAN.equals(locale)) {
return "/com/fr/design/images/splash_10_en.gif";
} else if (Locale.JAPAN.equals(locale)) {
return "/com/fr/design/images/splash_10_jp.gif";
} else {
return "/com/fr/design/images/splash_10.gif";
}
return LocaleCenter.getInstance().getLocaleAction(DesignerEnvManager.getEnvManager().getLanguage()).getSplashPath();
}
}

Loading…
Cancel
Save