diff --git a/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java b/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java index 4491fef8e5..11e36baef2 100644 --- a/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java +++ b/designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java @@ -1,5 +1,5 @@ /** - * + * */ package com.fr.design.mainframe.bbs; @@ -27,157 +27,175 @@ import java.util.Date; /** * @author neil - * * @date: 2015-3-5-上午11:19:50 */ -public class UserInfoPane extends BasicPane{ - - //默认未登录颜色 - private static final Color UN_LOGIN_BACKGROUND = UIConstants.TEMPLATE_TAB_PANE_BACKGROUND; - private static final Color LOGIN_BACKGROUND = new Color(184, 220, 242); - private static final int WIDTH = 104; - private static final int HEIGHT = 24; - - //登录成功 - private static final String LOGININ = "0"; - - // 登录框弹出间隔时间 - private static final int LOGIN_DIFF_DAY = 7; - // 等待国际化等相关初始化工作完成之后再弹出登录框 - private static final int WAIT_TIME = 10000; - - private UserInfoLabel userInfoLabel; - - - public UserInfoLabel getUserInfoLabel() { - return userInfoLabel; - } - - public void setUserInfoLabel(UserInfoLabel userInfoLabel) { - this.userInfoLabel = userInfoLabel; - } - - - /** - * 构造函数 - */ - public UserInfoPane() { - this.setPreferredSize(new Dimension(WIDTH,HEIGHT)); - this.setLayout(new BorderLayout()); - - this.userInfoLabel = new UserInfoLabel(this); - - this.markUnSignIn(); - addEnvChangedListener(); - autoPushLoginDialog(); - - this.add(userInfoLabel, BorderLayout.CENTER); - } - - private void addEnvChangedListener(){ - GeneralContext.addEnvChangedListener(new EnvChangedListener() { - @Override - public void envChanged() { - String username = ConfigManager.getProviderInstance().getBbsUsername(); - if (StringUtils.isEmpty(username)){ - markUnSignIn(); - } else { - markSignIn(username); - } - } - }); - } - - - // 计算xml保存的上次弹框时间和当前时间的时间差 - private int getDiffFromLastLogin(){ - String lastBBSTime = DesignerEnvManager.getEnvManager().getLastShowBBSTime(); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); - Date lastBBSDate = null; - try { - if(lastBBSTime != null){ - synchronized (this) { - lastBBSDate = sdf.parse(lastBBSTime); - } - Calendar calender = Calendar.getInstance(); - calender.setTime(lastBBSDate); - int dayOld = calender.get(Calendar.DAY_OF_YEAR); - calender.setTime(new Date()); - int dayNew = calender.get(Calendar.DAY_OF_YEAR); - return dayNew - dayOld; - } - } catch (ParseException e) { - FRLogger.getLogger().error(e.getMessage()); - } - return 1; - } - - private void autoPushLoginDialog(){ - Thread showBBSThread = new Thread(new Runnable() { - - @Override - public void run() { - try { - // 等国际化等加载完毕再启动线程弹出登录框 - Thread.sleep(WAIT_TIME); - if(!FRContext.isChineseEnv()){ - return; - } - - //七天弹一次, 如果xml中和当前时间相差小于7天, 就不弹了 - if(getDiffFromLastLogin() < LOGIN_DIFF_DAY){ - return; - } - - } catch (InterruptedException e) { - FRContext.getLogger().error(e.getMessage()); - } - - String userName = ConfigManager.getProviderInstance().getBbsUsername(); - if(StringUtils.isNotEmpty(userName)){ - return; - } - - BBSLoginDialog bbsLoginDialog = userInfoLabel.getBbsLoginDialog(); - if(bbsLoginDialog == null){ - bbsLoginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(),userInfoLabel); - userInfoLabel.setBbsLoginDialog(bbsLoginDialog); - } - - bbsLoginDialog.showWindow(); - DesignerEnvManager.getEnvManager().setLastShowBBSTime(DateUtils.DATEFORMAT2.format(new Date())); - } - - }); - showBBSThread.start(); - } - - /** - * 标志未登录状态, 面板设置为灰色 - * - */ - public void markUnSignIn(){ - this.userInfoLabel.setText(Inter.getLocText("FR-Base_UnSignIn")); - this.userInfoLabel.setOpaque(true); - this.userInfoLabel.setBackground(UN_LOGIN_BACKGROUND); - this.userInfoLabel.resetUserName(); - } - - /** - * 标志登陆状态, 面包设置为蓝色 - * @param userName 用户名 - * - */ - public void markSignIn(String userName){ - this.userInfoLabel.setText(userName); - this.userInfoLabel.setUserName(userName); - this.userInfoLabel.setOpaque(true); - this.userInfoLabel.setBackground(LOGIN_BACKGROUND); - } - - @Override - protected String title4PopupWindow() { - return StringUtils.EMPTY; - } +public class UserInfoPane extends BasicPane { + + /** + * 默认未登录颜色 + */ + private static final Color UN_LOGIN_BACKGROUND = UIConstants.TEMPLATE_TAB_PANE_BACKGROUND; + private static final Color LOGIN_BACKGROUND = new Color(184, 220, 242); + private static final int WIDTH = 104; + private static final int HEIGHT = 24; + + /** + * 登录成功 + */ + private static final String LOGININ = "0"; + + /** + * 登录框弹出间隔时间 + */ + private static final int LOGIN_DIFF_DAY = 7; + /** + * 等待国际化等相关初始化工作完成之后再弹出登录框 + */ + private static final int WAIT_TIME = 10000; + + private UserInfoLabel userInfoLabel; + + + private static UserInfoPane instance = new UserInfoPane(); + + + public static UserInfoPane getInstance() { + return instance; + } + + /** + * 构造函数 + */ + private UserInfoPane() { + this.setPreferredSize(new Dimension(WIDTH, HEIGHT)); + this.setLayout(new BorderLayout()); + + this.userInfoLabel = new UserInfoLabel(this); + + this.markUnSignIn(); + addEnvChangedListener(); + autoPushLoginDialog(); + + this.add(userInfoLabel, BorderLayout.CENTER); + } + + public UserInfoLabel getUserInfoLabel() { + return userInfoLabel; + } + + public void setUserInfoLabel(UserInfoLabel userInfoLabel) { + this.userInfoLabel = userInfoLabel; + } + + + /** + * 标志未登录状态, 面板设置为灰色 + */ + public void markUnSignIn() { + this.userInfoLabel.setText(Inter.getLocText("FR-Base_UnSignIn")); + this.userInfoLabel.setOpaque(true); + this.userInfoLabel.setBackground(UN_LOGIN_BACKGROUND); + this.userInfoLabel.resetUserName(); + } + + /** + * 标志登陆状态, 面包设置为蓝色 + * + * @param userName 用户名 + */ + public void markSignIn(String userName) { + this.userInfoLabel.setText(userName); + this.userInfoLabel.setUserName(userName); + this.userInfoLabel.setOpaque(true); + this.userInfoLabel.setBackground(LOGIN_BACKGROUND); + } + + @Override + protected String title4PopupWindow() { + return StringUtils.EMPTY; + } + + private void addEnvChangedListener() { + GeneralContext.addEnvChangedListener(new EnvChangedListener() { + @Override + public void envChanged() { + String username = ConfigManager.getProviderInstance().getBbsUsername(); + if (StringUtils.isEmpty(username)) { + markUnSignIn(); + } else { + markSignIn(username); + } + } + }); + } + + + /** + * 计算xml保存的上次弹框时间和当前时间的时间差 + * + * @return 时间差 + */ + private int getDiffFromLastLogin() { + String lastBBSTime = DesignerEnvManager.getEnvManager().getLastShowBBSTime(); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date lastBBSDate; + try { + if (lastBBSTime != null) { + synchronized (this) { + lastBBSDate = sdf.parse(lastBBSTime); + } + Calendar calender = Calendar.getInstance(); + calender.setTime(lastBBSDate); + int dayOld = calender.get(Calendar.DAY_OF_YEAR); + calender.setTime(new Date()); + int dayNew = calender.get(Calendar.DAY_OF_YEAR); + return dayNew - dayOld; + } + } catch (ParseException e) { + FRLogger.getLogger().error(e.getMessage()); + } + return 1; + } + + private void autoPushLoginDialog() { + Thread showBBSThread = new Thread(new Runnable() { + + @Override + public void run() { + try { + // 等国际化等加载完毕再启动线程弹出登录框 + Thread.sleep(WAIT_TIME); + if (!FRContext.isChineseEnv()) { + return; + } + + //七天弹一次, 如果xml中和当前时间相差小于7天, 就不弹了 + if (getDiffFromLastLogin() < LOGIN_DIFF_DAY) { + return; + } + + } catch (InterruptedException e) { + FRContext.getLogger().error(e.getMessage()); + } + + String userName = ConfigManager.getProviderInstance().getBbsUsername(); + if (StringUtils.isNotEmpty(userName)) { + return; + } + + BBSLoginDialog bbsLoginDialog = userInfoLabel.getBbsLoginDialog(); + if (bbsLoginDialog == null) { + bbsLoginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(), userInfoLabel); + userInfoLabel.setBbsLoginDialog(bbsLoginDialog); + } + + bbsLoginDialog.showWindow(); + DesignerEnvManager.getEnvManager().setLastShowBBSTime(DateUtils.DATEFORMAT2.format(new Date())); + } + + }); + showBBSThread.start(); + } + } \ No newline at end of file diff --git a/designer/src/com/fr/start/Designer.java b/designer/src/com/fr/start/Designer.java index 8f47abaf41..5be65d3e3a 100644 --- a/designer/src/com/fr/start/Designer.java +++ b/designer/src/com/fr/start/Designer.java @@ -364,7 +364,7 @@ public class Designer extends BaseDesigner { @Override public Component createBBSLoginPane() { if (userInfoPane == null) { - userInfoPane = new UserInfoPane(); + userInfoPane = UserInfoPane.getInstance(); } return userInfoPane; } diff --git a/designer_base/src/com/fr/design/extra/LoginDialog.java b/designer_base/src/com/fr/design/extra/LoginDialog.java index 6ae8a63f96..33983baf21 100644 --- a/designer_base/src/com/fr/design/extra/LoginDialog.java +++ b/designer_base/src/com/fr/design/extra/LoginDialog.java @@ -4,8 +4,12 @@ import com.fr.design.dialog.UIDialog; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.stable.StableUtils; -import javax.swing.*; -import java.awt.*; +import javax.swing.JPanel; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.Dialog; +import java.awt.Dimension; +import java.awt.Frame; /** * Created by vito on 2017/5/5. @@ -15,6 +19,15 @@ public class LoginDialog extends UIDialog { public LoginDialog(Frame frame, Component pane) { super(frame); + init(pane); + } + + public LoginDialog(Dialog dialog, Component pane) { + super(dialog); + init(pane); + } + + private void init(Component pane) { if (StableUtils.getMajorJavaVersion() == 8) { setUndecorated(true); } diff --git a/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java index 59fb612765..461f950bdb 100644 --- a/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java +++ b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java @@ -22,6 +22,9 @@ import javax.swing.JOptionPane; import javax.swing.SwingWorker; import java.awt.BorderLayout; import java.awt.Component; +import java.awt.Dialog; +import java.awt.Frame; +import java.awt.Window; import java.io.File; import java.io.IOException; import java.lang.reflect.Constructor; @@ -133,18 +136,22 @@ public class WebViewDlgHelper { if (StableUtils.getMajorJavaVersion() == VERSION_8) { File file = new File(StableUtils.pathJoin(installHome, "scripts")); if (!file.exists()) { - int rv = JOptionPane.showConfirmDialog( - null, - Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE - ); - if (rv == JOptionPane.OK_OPTION) { - downloadShopScripts(SHOP_SCRIPTS); - } + confirmDownLoadShopJS(); } else { - showLoginDlg(); + showLoginDlg(DesignerContext.getDesignerFrame()); + updateShopScripts(SHOP_SCRIPTS); + } + } + } + + + public static void createLoginDialog(Window parent) { + if (StableUtils.getMajorJavaVersion() == VERSION_8) { + File file = new File(StableUtils.pathJoin(installHome, "scripts")); + if (!file.exists()) { + confirmDownLoadShopJS(); + } else { + showLoginDlg(parent); updateShopScripts(SHOP_SCRIPTS); } } @@ -164,6 +171,20 @@ public class WebViewDlgHelper { } } + + private static void confirmDownLoadShopJS() { + int rv = JOptionPane.showConfirmDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Shop_Need_Install"), + Inter.getLocText("FR-Designer-Plugin_Warning"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE + ); + if (rv == JOptionPane.OK_OPTION) { + downloadShopScripts(SHOP_SCRIPTS); + } + } + private static void showPluginDlg(String mainJsPath) { try { Class clazz = Class.forName("com.fr.design.extra.PluginWebPane"); @@ -179,13 +200,17 @@ public class WebViewDlgHelper { } } - private static void showLoginDlg() { + private static void showLoginDlg(Window window) { try { Class clazz = Class.forName("com.fr.design.extra.LoginWebPane"); Constructor constructor = clazz.getConstructor(String.class); Component webPane = (Component) constructor.newInstance(installHome); - - UIDialog qqdlg = new LoginDialog(DesignerContext.getDesignerFrame(), webPane); + UIDialog qqdlg; + if (window instanceof Dialog) { + qqdlg = new LoginDialog((Dialog) window, webPane); + } else { + qqdlg = new LoginDialog((Frame) window, webPane); + } LoginWebBridge.getHelper().setDialogHandle(qqdlg); qqdlg.setVisible(true); } catch (Throwable ignored) {