From b5fdc5298f609a29e71721470728b53b885a6aa7 Mon Sep 17 00:00:00 2001 From: ju Date: Wed, 6 Jun 2018 17:16:52 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-8604=20=E5=90=AF=E5=8A=A8=E7=94=BB?= =?UTF-8?q?=E9=9D=A2=E4=B8=AD=E7=9A=84=E2=80=9C=E6=AD=A3=E5=9C=A8=E5=90=AF?= =?UTF-8?q?=E5=8A=A8XXX=E6=A8=A1=E5=9D=97=E2=80=9D=E7=9A=84=E7=9B=91?= =?UTF-8?q?=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/fr/start/BaseDesigner.java | 6 +- .../src/com/fr/start/Designer.java | 3 + .../src/com/fr/start/ReportSplashPane.java | 189 ------------------ .../src/com/fr/start/SplashContext.java | 35 ++-- .../start/module/DesignerModuleActivator.java | 4 - .../com/fr/start/module/DesignerStartup.java | 11 +- .../fr/start/module/StartFinishActivator.java | 2 - 7 files changed, 27 insertions(+), 223 deletions(-) delete mode 100644 designer-realize/src/com/fr/start/ReportSplashPane.java diff --git a/designer-base/src/com/fr/start/BaseDesigner.java b/designer-base/src/com/fr/start/BaseDesigner.java index 5d723f579..4ec6e4199 100644 --- a/designer-base/src/com/fr/start/BaseDesigner.java +++ b/designer-base/src/com/fr/start/BaseDesigner.java @@ -13,11 +13,14 @@ import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerFrame; import com.fr.design.mainframe.toolbar.ToolBarMenuDock; import com.fr.design.utils.DesignUtils; +import com.fr.event.EventDispatcher; import com.fr.file.FILE; import com.fr.file.FILEFactory; import com.fr.file.FileFILE; import com.fr.general.ComparatorUtils; +import com.fr.locale.InterProviderFactory; import com.fr.log.FineLoggerFactory; +import com.fr.module.ModuleEvent; import com.fr.stable.OperatingSystem; import java.awt.*; @@ -39,7 +42,8 @@ public abstract class BaseDesigner extends ToolBarMenuDock { } private void init(String[] args) { - + //初始化 + EventDispatcher.fire(ModuleEvent.MajorModuleStarting, InterProviderFactory.getProvider().getLocText("FR-Designer_Initializing")); // 初始化look and feel.这个在预加载之前执行是因为lookAndFeel里的东西,预加载时也要用到 DesignUtils.initLookAndFeel(); diff --git a/designer-realize/src/com/fr/start/Designer.java b/designer-realize/src/com/fr/start/Designer.java index c790dc250..74a8758c5 100644 --- a/designer-realize/src/com/fr/start/Designer.java +++ b/designer-realize/src/com/fr/start/Designer.java @@ -39,10 +39,13 @@ import com.fr.design.module.DesignModuleFactory; import com.fr.design.module.DesignerModule; import com.fr.design.utils.concurrent.ThreadFactoryBuilder; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.event.EventDispatcher; import com.fr.general.ComparatorUtils; import com.fr.general.Inter; +import com.fr.locale.InterProviderFactory; import com.fr.module.Module; import com.fr.module.ModuleContext; +import com.fr.module.ModuleEvent; import com.fr.stable.BuildContext; import com.fr.stable.OperatingSystem; import com.fr.stable.ProductConstants; diff --git a/designer-realize/src/com/fr/start/ReportSplashPane.java b/designer-realize/src/com/fr/start/ReportSplashPane.java deleted file mode 100644 index 840d61110..000000000 --- a/designer-realize/src/com/fr/start/ReportSplashPane.java +++ /dev/null @@ -1,189 +0,0 @@ -package com.fr.start; - -import com.bulenkov.iconloader.IconLoader; -import com.bulenkov.iconloader.util.JBUI; -import com.fr.base.BaseUtils; -import com.fr.base.FRContext; -import com.fr.base.GraphHelper; -import com.fr.design.mainframe.bbs.BBSConstants; -import com.fr.general.GeneralContext; -import com.fr.general.Inter; -import com.fr.general.ModuleContext; -import com.fr.stable.OperatingSystem; -import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; -import com.fr.stable.module.ModuleAdapter; -import com.fr.stable.module.ModuleListener; - -import javax.swing.*; -import java.awt.*; -import java.util.Locale; -import java.util.Random; -import java.util.TimerTask; - -/** - * @author neil - * @date: 2015-3-13-上午9:47:58 - */ -public class ReportSplashPane extends SplashPane { - - private static final String OEM_PATH = "/com/fr/base/images/oem"; - private static final String SPLASH_MAC_CN = "splash_chinese_mac.png"; - private static final String SPLASH_MAC_EN = "splash_english_mac.png"; - - private static float JBUI_INIT_SCALE = JBUI.scale(1f); - - private static final Color MODULE_COLOR = new Color(255, 255, 255); - private static final int MODULE_INFO_X = uiScale(54); - private static final int MODULE_INFO_Y = uiScale(340); - - private static final Color THANK_COLOR = new Color(255, 255, 255, (int) (0.6 * 255 + 0.5)); - private static final int THANK_INFO_Y = uiScale(382); - - private static final String ARIAL_FONT_NAME = "Arial"; - private static final String YAHEI_FONT_NAME = "Microsoft YaHei"; - - private static final String GUEST = getRandomUser(); - - private String showText = ""; - - private String moduleID = ""; - private int loadingIndex = 0; - private String[] loading = new String[]{"..", "....", "......"}; - private java.util.Timer timer = new java.util.Timer(); - - private ModuleListener listener; - - private static float uiScale(float f) { - return f * JBUI_INIT_SCALE; - } - - private static int uiScale(int i) { - return (int) (i * JBUI_INIT_SCALE); - } - - public ReportSplashPane() { - init(); - } - - private void init() { - this.setBackground(null); - - timer.schedule(new TimerTask() { - public void run() { - loadingIndex++; - ReportSplashPane.this.setShowText(moduleID.isEmpty() ? StringUtils.EMPTY : moduleID + loading[loadingIndex % 3]); - ReportSplashPane.this.repaint(); - } - }, 0, 300); - - listener = new ModuleAdapter() { - @Override - public void onStartBefore(String moduleName, String moduleI18nName) { - moduleID = moduleI18nName; - loadingIndex++; - ReportSplashPane.this.setShowText(moduleID.isEmpty() ? StringUtils.EMPTY : moduleID + loading[loadingIndex % 3]); - ReportSplashPane.this.repaint(); - } - }; - } - - public ModuleListener getModuleListener() { - - return listener; - } - - protected void paintComponent(Graphics g) { - Icon icon = IconLoader.getIcon(StableUtils.pathJoin(OEM_PATH, getImageName())); - icon.paintIcon(null, g, 0, 0); - paintShowText((Graphics2D) g); - g.dispose(); - } - - public void setShowText(String text) { - this.showText = text; - } - - public Image getSplashImage() { - Icon icon = IconLoader.getIcon(StableUtils.pathJoin(OEM_PATH, getImageName())); - return ((ImageIcon) IconLoader.getIconSnapshot(icon)).getImage(); - } - - private void paintShowText(Graphics2D splashG2d) { - GraphHelper.applyRenderingHints(splashG2d); - - splashG2d.setPaint(MODULE_COLOR); - - Font font = null; - if (OperatingSystem.isWindows()) { - font = new Font(YAHEI_FONT_NAME, Font.PLAIN, uiScale(12)); - } - - if (font == null || isDialogFont(font)) { - font = createFont(ARIAL_FONT_NAME); - } - splashG2d.setFont(font); - - //加载模块信息 - GraphHelper.drawString(splashG2d, showText, MODULE_INFO_X, MODULE_INFO_Y); - - //每次随机感谢一位论坛用户 - if (shouldShowThanks()) { - splashG2d.setPaint(THANK_COLOR); - String content = Inter.getLocText("FR-Designer_Thanks-To") + GUEST; - GraphHelper.drawString(splashG2d, content, MODULE_INFO_X, THANK_INFO_Y); - } - } - - private boolean isDialogFont(Font font) { - return Font.DIALOG.equals(font.getFamily(Locale.US)); - } - - private Font createFont(String fontName) { - return new Font(fontName, Font.PLAIN, uiScale(12)); - } - - // 是否显示鸣谢文字 - private boolean shouldShowThanks() { - Locale[] hideLocales = {Locale.US, Locale.KOREA, Locale.JAPAN}; - for (Locale loc : hideLocales) { - if (FRContext.getLocale().equals(loc)) { - return false; - } - } - return true; - } - - private static String getRandomUser() { - String[] allGuest = BBSConstants.getAllGuest(); - if (allGuest.length == 0) { - return StringUtils.EMPTY; - } - int num = new Random().nextInt(allGuest.length); - return StringUtils.BLANK + allGuest[num]; - } - - /** - * 窗口关闭后取消定时获取模块信息的timer - */ - public void releaseTimer() { - timer.cancel(); - } - - /** - * 创建启动画面的背景图片 - * - * @return 背景图片 - */ - public Image createSplashBackground() { - String fileName = getImageName(); - return BaseUtils.readImage(StableUtils.pathJoin(OEM_PATH, fileName)); - } - - //获取图片文件名 - private String getImageName() { - boolean isChina = GeneralContext.isChineseEnv(); - //jdk1.8下透明有bug, 设置了setWindowTransparent后, JFrame直接最小化了, 先用mac下的加载图片 - return isChina ? SPLASH_MAC_CN : SPLASH_MAC_EN; - } -} diff --git a/designer-realize/src/com/fr/start/SplashContext.java b/designer-realize/src/com/fr/start/SplashContext.java index f8a1a3f67..e5021b2b3 100644 --- a/designer-realize/src/com/fr/start/SplashContext.java +++ b/designer-realize/src/com/fr/start/SplashContext.java @@ -2,10 +2,12 @@ package com.fr.start; import com.fr.base.FRContext; import com.fr.design.mainframe.bbs.BBSConstants; +import com.fr.event.Event; +import com.fr.event.EventDispatcher; +import com.fr.event.Listener; import com.fr.general.Inter; +import com.fr.module.ModuleEvent; import com.fr.stable.StringUtils; -import com.fr.stable.module.ModuleAdapter; -import com.fr.stable.module.ModuleListener; import java.util.Locale; import java.util.Random; @@ -32,8 +34,8 @@ public class SplashContext { private static final String GUEST = getRandomUser(); private ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); - - private ModuleListener listener; + + private Listener listener; public static SplashContext getInstance() { @@ -41,6 +43,7 @@ public class SplashContext { } private SplashContext() { + } /** @@ -50,18 +53,12 @@ public class SplashContext { this.splashStrategy = splashStrategy; } - /** - * 注册监听 - */ - public ModuleListener getModuleListener() { - initListener(); - return listener; - } - /** * 展示启动动画 */ public void show() { + //监听 + initListener(); splashStrategy.show(); } @@ -69,6 +66,8 @@ public class SplashContext { * 隐藏启动动画 */ public void hide() { + //取消监听 + EventDispatcher.stopListen(listener); splashStrategy.hide(); // 窗口关闭后取消定时获取模块信息的timer scheduler.shutdown(); @@ -84,16 +83,18 @@ public class SplashContext { updateModuleLog(moduleID.isEmpty() ? StringUtils.EMPTY : moduleID + loading[loadingIndex % 3]); } }, 0, 300, TimeUnit.MILLISECONDS); - - listener = new ModuleAdapter() { + + listener = new Listener() { + @Override - public void onStartBefore(String moduleName, String moduleI18nName) { - moduleID = moduleI18nName; + public void on(Event event, String i18n) { + + moduleID = i18n; loadingIndex++; updateModuleLog(moduleID.isEmpty() ? StringUtils.EMPTY : moduleID + loading[loadingIndex % 3]); - } }; + EventDispatcher.listen(ModuleEvent.MajorModuleStarting, listener); showThanks(); } diff --git a/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java b/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java index b6abbdf85..9b3ab946a 100644 --- a/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java +++ b/designer-realize/src/com/fr/start/module/DesignerModuleActivator.java @@ -6,7 +6,6 @@ import com.fr.general.ModuleContext; import com.fr.locale.InterMutableKey; import com.fr.module.Activator; import com.fr.module.extension.Prepare; -import com.fr.stable.module.ModuleListener; /** * Created by juhaoyu on 2018/1/31. @@ -18,10 +17,7 @@ public class DesignerModuleActivator extends Activator implements Prepare { @Override public void start() { - ModuleContext.registerModuleListener(getModule().upFindSingleton(ModuleListener.class)); ModuleContext.startModule(DesignerModule.class.getName()); - ModuleContext.clearModuleListener(); - DesignerSocketIO.init(); } diff --git a/designer-realize/src/com/fr/start/module/DesignerStartup.java b/designer-realize/src/com/fr/start/module/DesignerStartup.java index 3f150e043..54e8c1d9f 100644 --- a/designer-realize/src/com/fr/start/module/DesignerStartup.java +++ b/designer-realize/src/com/fr/start/module/DesignerStartup.java @@ -2,7 +2,6 @@ package com.fr.start.module; import com.fr.module.Activator; import com.fr.stable.CoreActivator; -import com.fr.stable.module.ModuleListener; import com.fr.start.Designer; import com.fr.start.EnvSwitcher; import com.fr.start.SplashContext; @@ -18,8 +17,6 @@ public class DesignerStartup extends Activator { startSub(PreStartActivator.class); //启动基础部分 startSub(BasicActivator.class); - //启动画面注册监听,必须在初始化国际化之后注册监听 - registerSplashListener(); String[] args = getModule().upFindSingleton(StartupArgs.class).get(); Designer designer = new Designer(args); //启动env @@ -34,13 +31,7 @@ public class DesignerStartup extends Activator { SplashContext.getInstance().hide(); startSub(StartFinishActivator.class); } - - /** - * 注册启动动画监听器 - */ - private void registerSplashListener() { - getModule().setSingleton(ModuleListener.class, SplashContext.getInstance().getModuleListener()); - } + @Override public void stop() { diff --git a/designer-realize/src/com/fr/start/module/StartFinishActivator.java b/designer-realize/src/com/fr/start/module/StartFinishActivator.java index f66459729..b9e165b26 100644 --- a/designer-realize/src/com/fr/start/module/StartFinishActivator.java +++ b/designer-realize/src/com/fr/start/module/StartFinishActivator.java @@ -2,7 +2,6 @@ package com.fr.start.module; import com.fr.design.fun.impl.GlobalListenerProviderManager; import com.fr.design.utils.DesignUtils; -import com.fr.general.ModuleContext; import com.fr.module.Activator; /** @@ -16,7 +15,6 @@ public class StartFinishActivator extends Activator { public void start() { DesignUtils.creatListeningServer(getStartPort(), startFileSuffix()); - ModuleContext.clearModuleListener(); GlobalListenerProviderManager.getInstance().init(); }