Browse Source

REPORT-8604 启动画面中的“正在启动XXX模块”的监听

master
ju 7 years ago
parent
commit
b5fdc5298f
  1. 6
      designer-base/src/com/fr/start/BaseDesigner.java
  2. 3
      designer-realize/src/com/fr/start/Designer.java
  3. 189
      designer-realize/src/com/fr/start/ReportSplashPane.java
  4. 35
      designer-realize/src/com/fr/start/SplashContext.java
  5. 4
      designer-realize/src/com/fr/start/module/DesignerModuleActivator.java
  6. 11
      designer-realize/src/com/fr/start/module/DesignerStartup.java
  7. 2
      designer-realize/src/com/fr/start/module/StartFinishActivator.java

6
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();

3
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;

189
designer-realize/src/com/fr/start/ReportSplashPane.java

@ -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;
}
}

35
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<String> 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<String>() {
@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();
}

4
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();
}

11
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() {

2
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();
}

Loading…
Cancel
Save