From 3b736749f5744fc30bdf39543c383240c1feb84a Mon Sep 17 00:00:00 2001 From: vito Date: Fri, 5 May 2017 16:33:35 +0800 Subject: [PATCH 1/4] =?UTF-8?q?REPORT-2335=20=E6=8F=92=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E7=95=8C=E9=9D=A2=E4=BB=A5=E5=8F=8A=E5=8F=B3=E4=B8=8A?= =?UTF-8?q?=E8=A7=92=E7=9A=84=E7=99=BB=E5=BD=95=E7=95=8C=E9=9D=A2=EF=BC=8C?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=E7=82=B9=E5=87=BB=E5=90=8E=EF=BC=8C=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=97=A0=E6=B3=95=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/bbs/LoginDialog.java | 10 ++-- .../src/com/fr/design/extra/LoginPane.java | 12 ----- .../com/fr/design/extra/LoginWebBridge.java | 1 + .../com/fr/design/extra/PluginWebBridge.java | 10 ++-- .../com/fr/design/extra/QQLoginWebBridge.java | 11 ++-- .../com/fr/design/extra/ReuseWebBridge.java | 36 ------------- .../src/com/fr/design/extra/ReuseWebPane.java | 54 ------------------- .../src/com/fr/design/extra/WebDialog.java | 6 +-- 8 files changed, 21 insertions(+), 119 deletions(-) delete mode 100644 designer_base/src/com/fr/design/extra/ReuseWebBridge.java delete mode 100644 designer_base/src/com/fr/design/extra/ReuseWebPane.java diff --git a/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java b/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java index e3013e4877..2155b2437d 100644 --- a/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java +++ b/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java @@ -3,10 +3,7 @@ package com.fr.design.mainframe.bbs; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.UIDialog; import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.general.Inter; -import com.fr.general.SiteCenter; -import com.fr.general.http.HttpClient; -import com.fr.stable.StringUtils; +import com.fr.stable.StableUtils; import javax.swing.*; import java.awt.*; @@ -19,14 +16,15 @@ public class LoginDialog extends UIDialog { public LoginDialog(Frame frame, BasicPane pane) { super(frame); - setUndecorated(true); + if (StableUtils.getMajorJavaVersion() == 8) { + setUndecorated(true); + } JPanel panel = (JPanel) getContentPane(); panel.setLayout(new BorderLayout()); add(pane, BorderLayout.CENTER); setSize(DEFAULT_SHOP); GUICoreUtils.centerWindow(this); setResizable(false); - setTitle(Inter.getLocText("FR-Designer-Plugin_Manager")); } @Override diff --git a/designer_base/src/com/fr/design/extra/LoginPane.java b/designer_base/src/com/fr/design/extra/LoginPane.java index 41a2ce8ce4..c751a987c0 100644 --- a/designer_base/src/com/fr/design/extra/LoginPane.java +++ b/designer_base/src/com/fr/design/extra/LoginPane.java @@ -4,7 +4,6 @@ import com.fr.base.FRContext; import com.fr.design.DesignerEnvManager; import com.fr.design.RestartHelper; import com.fr.design.dialog.BasicPane; -import com.fr.design.gui.frpane.UITabbedPane; import com.fr.general.ComparatorUtils; import com.fr.general.IOUtils; import com.fr.general.Inter; @@ -53,8 +52,6 @@ public class LoginPane extends BasicPane { updateShopScripts(); } } - } else { - initTraditionalStore(); } } @@ -140,13 +137,4 @@ public class LoginPane extends BasicPane { } }.execute(); } - - private void initTraditionalStore() { - UITabbedPane tabbedPane = new UITabbedPane(); - add(tabbedPane, BorderLayout.CENTER); - PluginInstalledPane installedPane = new PluginInstalledPane(); - tabbedPane.addTab(installedPane.tabTitle(), installedPane); - tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_Update"), new PluginUpdatePane(tabbedPane)); - tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane)); - } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/LoginWebBridge.java b/designer_base/src/com/fr/design/extra/LoginWebBridge.java index 41ed99beb9..49719142c1 100644 --- a/designer_base/src/com/fr/design/extra/LoginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/LoginWebBridge.java @@ -91,6 +91,7 @@ public class LoginWebBridge { } public void setDialogHandle(UIDialog uiDialog) { + closeWindow(); this.uiDialog = uiDialog; } diff --git a/designer_base/src/com/fr/design/extra/PluginWebBridge.java b/designer_base/src/com/fr/design/extra/PluginWebBridge.java index 12c3e85c41..f1759f016b 100644 --- a/designer_base/src/com/fr/design/extra/PluginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/PluginWebBridge.java @@ -136,6 +136,7 @@ public class PluginWebBridge { } public void setDialogHandle(UIDialog uiDialog) { + closeWindow(); this.uiDialog = uiDialog; } @@ -367,6 +368,7 @@ public class PluginWebBridge { /** * 获取系统登录的用户名 + * * @param callback */ public void getLoginInfo(final JSObject callback) { @@ -381,7 +383,7 @@ public class PluginWebBridge { try { String loginUrl = SiteCenter.getInstance().acquireUrlByKind("bbs.default"); Desktop.getDesktop().browse(new URI(loginUrl)); - }catch (Exception exp) { + } catch (Exception exp) { FRContext.getLogger().info(exp.getMessage()); } } @@ -493,13 +495,14 @@ public class PluginWebBridge { /*-------------------------------登录部分的处理----------------------------------*/ + /** * 注册页面 */ public void registerHref() { try { Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register"))); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } } @@ -510,7 +513,7 @@ public class PluginWebBridge { public void forgetHref() { try { Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.reset"))); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } } @@ -521,6 +524,7 @@ public class PluginWebBridge { /** * 登录操作的回调 + * * @param username * @param password * @return diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java b/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java index d0bcc27e12..7c2dd3e50e 100644 --- a/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java @@ -3,15 +3,13 @@ package com.fr.design.extra; import com.fr.design.DesignerEnvManager; import com.fr.design.dialog.UIDialog; import com.fr.design.gui.ilable.UILabel; -import com.fr.general.FRLogger; import com.fr.general.SiteCenter; import javafx.scene.web.WebEngine; -import org.json.JSONObject; import netscape.javascript.JSObject; +import org.json.JSONObject; import javax.swing.*; import java.awt.*; -import java.io.IOException; import java.net.URI; /** @@ -50,10 +48,12 @@ public class QQLoginWebBridge { } public void setDialogHandle(UIDialog uiDialog) { + closeParentWindow(); this.uiDialog = uiDialog; } public void setQQDialogHandle(UIDialog uiDialog) { + closeQQWindow(); this.qqDialog = uiDialog; } @@ -99,6 +99,7 @@ public class QQLoginWebBridge { /** * 获取用户信息 + * * @param userInfo */ public void getLoginInfo(String userInfo) { @@ -113,12 +114,12 @@ public class QQLoginWebBridge { DesignerEnvManager.getEnvManager().setBBSName(username); DesignerEnvManager.getEnvManager().setBbsUid(uid); DesignerEnvManager.getEnvManager().setInShowBBsName(username); - }else if (status.equals(LOGINFAILED)){ + } else if (status.equals(LOGINFAILED)) { //账号没有QQ授权 closeQQWindow(); try { Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("QQ_binding"))); - }catch (Exception exp) { + } catch (Exception exp) { } } } diff --git a/designer_base/src/com/fr/design/extra/ReuseWebBridge.java b/designer_base/src/com/fr/design/extra/ReuseWebBridge.java deleted file mode 100644 index 413f862759..0000000000 --- a/designer_base/src/com/fr/design/extra/ReuseWebBridge.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.fr.design.extra; - -import javafx.scene.web.WebEngine; - -/** - * Created by vito on 2016/9/28. - */ -public class ReuseWebBridge { - public static ReuseWebBridge helper; - private WebEngine webEngine; - - public static ReuseWebBridge getHelper() { - if (helper != null) { - return helper; - } - synchronized (ReuseWebBridge.class) { - if (helper == null) { - helper = new ReuseWebBridge(); - } - return helper; - } - } - - public static ReuseWebBridge getHelper(WebEngine webEngine) { - getHelper(); - helper.setEngine(webEngine); - return helper; - } - - private ReuseWebBridge() { - } - - public void setEngine(WebEngine webEngine) { - this.webEngine = webEngine; - } -} diff --git a/designer_base/src/com/fr/design/extra/ReuseWebPane.java b/designer_base/src/com/fr/design/extra/ReuseWebPane.java deleted file mode 100644 index b48957e0f8..0000000000 --- a/designer_base/src/com/fr/design/extra/ReuseWebPane.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.fr.design.extra; - -import javafx.application.Platform; -import javafx.embed.swing.JFXPanel; -import javafx.event.EventHandler; -import javafx.scene.Scene; -import javafx.scene.layout.BorderPane; -import javafx.scene.web.WebEngine; -import javafx.scene.web.WebEvent; -import javafx.scene.web.WebView; -import netscape.javascript.JSObject; - -import javax.swing.*; - -/** - * Created by vito on 2016/9/28. - */ -public class ReuseWebPane extends JFXPanel { - private WebEngine webEngine; - - public ReuseWebPane(final String mainJs) { - Platform.setImplicitExit(false); - Platform.runLater(new Runnable() { - @Override - public void run() { - BorderPane root = new BorderPane(); - Scene scene = new Scene(root); - ReuseWebPane.this.setScene(scene); - WebView webView = new WebView(); - webEngine = webView.getEngine(); - webEngine.load("file:///" + mainJs); - webEngine.setOnAlert(new EventHandler>() { - @Override - public void handle(WebEvent event) { - showAlert(event.getData()); - } - }); - JSObject obj = (JSObject) webEngine.executeScript("window"); - obj.setMember("ReuseHelper", ReuseWebBridge.getHelper(webEngine)); - webView.setContextMenuEnabled(false);//屏蔽右键 - root.setCenter(webView); - } - }); - } - - private void showAlert(final String message) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - JOptionPane.showMessageDialog(ReuseWebPane.this, message); - } - }); - } -} diff --git a/designer_base/src/com/fr/design/extra/WebDialog.java b/designer_base/src/com/fr/design/extra/WebDialog.java index ed7d735631..22a4e5ac81 100644 --- a/designer_base/src/com/fr/design/extra/WebDialog.java +++ b/designer_base/src/com/fr/design/extra/WebDialog.java @@ -70,10 +70,10 @@ public class WebDialog { /** * 以关键词打开设计器商店 - *

- * // * @param keyword 关键词 + * + * @param keyword 关键词 */ - public void createPluginDialog(String keyword) { + public static void createPluginDialog(String keyword) { PluginWebBridge.getHelper().openWithSearch(keyword); createPluginDialog(); } From 33ab06ff91f6d467c383f844ac90f5060683722e Mon Sep 17 00:00:00 2001 From: vito Date: Fri, 5 May 2017 16:38:27 +0800 Subject: [PATCH 2/4] =?UTF-8?q?REPORT-2213=20=E8=AE=BE=E8=AE=A1=E5=99=A8?= =?UTF-8?q?=E5=8F=B3=E4=B8=8A=E8=A7=92=E4=BD=BF=E7=94=A8qq=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E5=90=8E=EF=BC=8C=E7=99=BB=E5=BD=95=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E5=85=B3=E4=B8=8D=E6=8E=89=20&=20=E8=BF=99=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=9A=84=E4=BB=A3=E7=A0=81=E8=B4=A8=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../design/mainframe/bbs/UserInfoLabel.java | 9 +- .../freeze/RepeatAndFreezeSettingPane.java | 4 +- .../actions/server/PluginManagerAction.java | 4 +- .../src/com/fr/design/extra/LoginDialog.java | 32 +++ .../src/com/fr/design/extra/LoginPane.java | 140 ------------ .../com/fr/design/extra/LoginWebBridge.java | 150 ++++++++----- .../src/com/fr/design/extra/LoginWebPane.java | 14 +- .../com/fr/design/extra/QQLoginDialog.java | 4 +- .../src/com/fr/design/extra/QQLoginPane.java | 145 ------------- .../com/fr/design/extra/QQLoginWebBridge.java | 132 ------------ .../com/fr/design/extra/QQLoginWebPane.java | 6 +- .../com/fr/design/extra/WebViewDlgHelper.java | 203 ++++++++++++++++++ .../src/com/fr/start/BaseDesigner.java | 4 +- 13 files changed, 347 insertions(+), 500 deletions(-) create mode 100644 designer_base/src/com/fr/design/extra/LoginDialog.java delete mode 100644 designer_base/src/com/fr/design/extra/LoginPane.java delete mode 100644 designer_base/src/com/fr/design/extra/QQLoginPane.java delete mode 100644 designer_base/src/com/fr/design/extra/QQLoginWebBridge.java create mode 100644 designer_base/src/com/fr/design/extra/WebViewDlgHelper.java diff --git a/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java index f6e3d3e7ca..90d84059b3 100644 --- a/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java +++ b/designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java @@ -5,7 +5,6 @@ package com.fr.design.mainframe.bbs; import com.fr.base.FRContext; import com.fr.design.DesignerEnvManager; -import com.fr.design.dialog.UIDialog; import com.fr.design.extra.*; import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.imenu.UIMenuItem; @@ -103,17 +102,13 @@ public class UserInfoLabel extends UILabel { if (StableUtils.getMajorJavaVersion() == 8) { PluginWebBridge.getHelper().setUILabel(UserInfoLabel.this); } - QQLoginWebBridge.getHelper().setUILabelInPlugin(UserInfoLabel.this); + LoginWebBridge.getHelper().setUILabelInPlugin(UserInfoLabel.this); UserLoginContext.addLoginContextListener(new LoginContextListener() { @Override public void showLoginContext() { - LoginPane managerPane = new LoginPane(); - UIDialog qqdlg = new LoginDialog(DesignerContext.getDesignerFrame(), managerPane); - LoginWebBridge.getHelper().setDialogHandle(qqdlg); + WebViewDlgHelper.createLoginDialog(); LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this); - QQLoginWebBridge.getHelper().setLoginlabel(); - qqdlg.setVisible(true); clearLoginInformation(); updateInfoPane(); } diff --git a/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java b/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java index 46bc378ae8..af5906c336 100644 --- a/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java +++ b/designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java @@ -10,7 +10,7 @@ import javax.swing.event.ChangeListener; import com.fr.base.FRContext; import com.fr.design.dialog.BasicPane; -import com.fr.design.extra.WebDialog; +import com.fr.design.extra.WebViewDlgHelper; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.ilable.ActionLabel; import com.fr.design.gui.ilable.UILabel; @@ -553,7 +553,7 @@ public class RepeatAndFreezeSettingPane extends BasicPane { public void actionPerformed(ActionEvent e) { try { //Desktop.getDesktop().browse(new URI(url)); - WebDialog.createPluginDialog(); + WebViewDlgHelper.createPluginDialog(); RepeatAndFreezeSettingPane.this.getTopLevelAncestor().setVisible(false); } catch (Exception exp) { diff --git a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java index 08dc91b07e..bd77bfa0c1 100644 --- a/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java +++ b/designer_base/src/com/fr/design/actions/server/PluginManagerAction.java @@ -2,7 +2,7 @@ package com.fr.design.actions.server; import com.fr.base.BaseUtils; import com.fr.design.actions.UpdateAction; -import com.fr.design.extra.WebDialog; +import com.fr.design.extra.WebViewDlgHelper; import com.fr.design.menu.MenuKeySet; import com.fr.general.Inter; @@ -25,7 +25,7 @@ public class PluginManagerAction extends UpdateAction { @Override public void actionPerformed(ActionEvent e) { - WebDialog.createPluginDialog(); + WebViewDlgHelper.createPluginDialog(); } public static final MenuKeySet PLUGIN_MANAGER = new MenuKeySet() { diff --git a/designer_base/src/com/fr/design/extra/LoginDialog.java b/designer_base/src/com/fr/design/extra/LoginDialog.java new file mode 100644 index 0000000000..32d4dca030 --- /dev/null +++ b/designer_base/src/com/fr/design/extra/LoginDialog.java @@ -0,0 +1,32 @@ +package com.fr.design.extra; + +import com.fr.design.dialog.UIDialog; +import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.stable.StableUtils; + +import javax.swing.*; +import java.awt.*; + +/** + * Created by vito on 2017/5/5. + */ +public class LoginDialog extends UIDialog { + private static final Dimension DEFAULT_SHOP = new Dimension(401, 201); + + public LoginDialog(Frame frame, Component pane) { + super(frame); + if (StableUtils.getMajorJavaVersion() == 8) { + setUndecorated(true); + } + JPanel panel = (JPanel) getContentPane(); + panel.setLayout(new BorderLayout()); + add(pane, BorderLayout.CENTER); + setSize(DEFAULT_SHOP); + GUICoreUtils.centerWindow(this); + setResizable(false); + } + + @Override + public void checkValid() throws Exception { + } +} diff --git a/designer_base/src/com/fr/design/extra/LoginPane.java b/designer_base/src/com/fr/design/extra/LoginPane.java deleted file mode 100644 index c751a987c0..0000000000 --- a/designer_base/src/com/fr/design/extra/LoginPane.java +++ /dev/null @@ -1,140 +0,0 @@ -package com.fr.design.extra; - -import com.fr.base.FRContext; -import com.fr.design.DesignerEnvManager; -import com.fr.design.RestartHelper; -import com.fr.design.dialog.BasicPane; -import com.fr.general.ComparatorUtils; -import com.fr.general.IOUtils; -import com.fr.general.Inter; -import com.fr.general.SiteCenter; -import com.fr.general.http.HttpClient; -import com.fr.plugin.PluginVerifyException; -import com.fr.stable.StableUtils; - -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.concurrent.ExecutionException; - -/** - * Created by zhaohehe on 16/7/27. - */ -public class LoginPane extends BasicPane { - private static final String LATEST = "latest"; - - public LoginPane() { - setLayout(new BorderLayout()); - if (StableUtils.getMajorJavaVersion() == 8) { - String installHome; - if (StableUtils.isDebug()) { - URL url = ClassLoader.getSystemResource(""); - installHome = url.getPath(); - addPane(installHome); - } else { - installHome = StableUtils.getInstallHome(); - File file = new File(StableUtils.pathJoin(installHome, "scripts")); - if (!file.exists()) { - int rv = JOptionPane.showConfirmDialog( - this, - 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(); - } - } else { - addPane(installHome); - updateShopScripts(); - } - } - } - } - - private void addPane(String installHome) { - LoginWebPane webPane = new LoginWebPane(new File(installHome).getAbsolutePath(),LoginPane.this); - add(webPane, BorderLayout.CENTER); - } - - @Override - protected String title4PopupWindow() { - return Inter.getLocText("FR-Designer-Plugin_Manager"); - } - - private void downloadShopScripts() { - new SwingWorker() { - @Override - protected Boolean doInBackground() throws Exception { - String id = "shop_scripts"; - String username = DesignerEnvManager.getEnvManager().getBBSName(); - String password = DesignerEnvManager.getEnvManager().getBBSPassword(); - try { - PluginHelper.downloadPluginFile(id, username, password, new Process() { - @Override - public void process(Double integer) { - } - }); - } catch (PluginVerifyException e) { - JOptionPane.showMessageDialog(LoginPane.this, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - return false; - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - return false; - } - return true; - } - - @Override - protected void done() { - try { - if (get()) { - IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); - int rv = JOptionPane.showOptionDialog( - LoginPane.this, - Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.YES_NO_OPTION, - JOptionPane.INFORMATION_MESSAGE, - null, - new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")}, - null - ); - if (rv == JOptionPane.OK_OPTION) { - RestartHelper.restart(); - } - } - } catch (InterruptedException | ExecutionException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - } - }.execute(); - } - - private void updateShopScripts() { - new SwingWorker() { - @Override - protected Void doInBackground() throws Exception { - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("store.version") + "&version=" + PluginStoreConstants.VERSION); - if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { - if (!ComparatorUtils.equals(httpClient.getResponseText(), LATEST)) { - int rv = JOptionPane.showConfirmDialog( - LoginPane.this, - Inter.getLocText("FR-Designer-Plugin_Shop_Need_Update"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE - ); - if (rv == JOptionPane.OK_OPTION) { - downloadShopScripts(); - } - } - } - return null; - } - }.execute(); - } -} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/LoginWebBridge.java b/designer_base/src/com/fr/design/extra/LoginWebBridge.java index 49719142c1..611166bc02 100644 --- a/designer_base/src/com/fr/design/extra/LoginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/LoginWebBridge.java @@ -6,7 +6,6 @@ import com.fr.design.dialog.UIDialog; import com.fr.design.extra.ucenter.Client; import com.fr.design.extra.ucenter.XMLHelper; import com.fr.design.gui.ilable.UILabel; -import com.fr.design.mainframe.DesignerContext; import com.fr.general.SiteCenter; import com.fr.general.http.HttpClient; import com.fr.json.JSONObject; @@ -14,10 +13,10 @@ import com.fr.stable.EncodeConstants; import com.fr.stable.StringUtils; import javafx.scene.web.WebEngine; -import java.io.UnsupportedEncodingException; -import java.net.URI; import javax.swing.*; import java.awt.*; +import java.io.UnsupportedEncodingException; +import java.net.URI; import java.net.URLEncoder; import java.util.HashMap; import java.util.LinkedList; @@ -47,47 +46,44 @@ public class LoginWebBridge { //用户名,密码为空 private static final String LOGIN_INFO_EMPTY = "-5"; private static final int TIME_OUT = 10000; + private static final String LOGIN_SUCCESS = "ok"; + private static final String LOGIN_FAILED = "failed"; - private static com.fr.design.extra.LoginWebBridge helper; + private static LoginWebBridge helper; + private UILabel pluginuiLabel; private UIDialog uiDialog; + private UIDialog qqDialog; private UILabel uiLabel; private String userName; - public int getMessageCount() { - return messageCount; - } - - /** - * 测试论坛网络连接 - * @return - */ - private boolean testConnection() { - HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test")); - return client.isServerAlive(); + public LoginWebBridge() { + String username = DesignerEnvManager.getEnvManager().getBBSName(); + setUserName(username, uiLabel); } - public static com.fr.design.extra.LoginWebBridge getHelper() { + public static LoginWebBridge getHelper() { if (helper != null) { return helper; } - synchronized (com.fr.design.extra.LoginWebBridge.class) { + synchronized (LoginWebBridge.class) { if (helper == null) { - helper = new com.fr.design.extra.LoginWebBridge(); + helper = new LoginWebBridge(); } return helper; } } - public static com.fr.design.extra.LoginWebBridge getHelper(WebEngine webEngine) { - getHelper(); - helper.setEngine(webEngine); - return helper; + public int getMessageCount() { + return messageCount; } - private WebEngine webEngine; + public void setUILabelInPlugin(UILabel uiLabel) { + this.pluginuiLabel = uiLabel; + } - public void setEngine(WebEngine webEngine) { - this.webEngine = webEngine; + public void setQqDialog(UIDialog qqDialog) { + closeQQWindow(); + this.qqDialog = qqDialog; } public void setDialogHandle(UIDialog uiDialog) { @@ -99,50 +95,56 @@ public class LoginWebBridge { this.uiLabel = uiLabel; } - public LoginWebBridge() { - String username = DesignerEnvManager.getEnvManager().getBBSName(); - setUserName(username, uiLabel); - } - /** * 设置显示的用户名 + * * @param userName 登录用户名 - * @param label label显示 + * @param label label显示 */ public void setUserName(String userName, UILabel label) { if (uiLabel == null) { this.uiLabel = label; } - if(StringUtils.isEmpty(userName)){ + if (StringUtils.isEmpty(userName)) { return; } - if(!StringUtils.isEmpty(this.userName)){ + if (!StringUtils.isEmpty(this.userName)) { updateMessageCount(); } this.userName = userName; } + /** + * 测试论坛网络连接 + * + * @return + */ + private boolean testConnection() { + HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test")); + return client.isServerAlive(); + } + /** * 定时取后台论坛消息 */ - public void updateMessageCount(){ + public void updateMessageCount() { //启动获取消息更新的线程 //登陆状态, 根据存起来的用户名密码, 每1分钟发起一次请求, 更新消息条数. Thread updateMessageThread = new Thread(new Runnable() { @Override public void run() { sleep(CHECK_MESSAGE_TIME); - while(StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())){ + while (StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())) { HashMap para = new HashMap<>(); int uid = DesignerEnvManager.getEnvManager().getBbsUid(); para.put("uid", String.valueOf(uid)); HttpClient getMessage = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.message"), para); getMessage.asGet(); - if(getMessage.isServerAlive()){ + if (getMessage.isServerAlive()) { try { String res = getMessage.getResponseText(); if (res.equals(FAILED_MESSAGE_STATUS)) { - }else { + } else { JSONObject jo = new JSONObject(res); if (jo.getString("status").equals(SUCCESS_MESSAGE_STATUS)) { setMessageCount(Integer.parseInt(jo.getString("message"))); @@ -161,6 +163,7 @@ public class LoginWebBridge { /** * 设置获取的消息长度,并设置显示 + * * @param count */ public void setMessageCount(int count) { @@ -178,7 +181,7 @@ public class LoginWebBridge { uiLabel.setText(sb.toString()); } - private String encode(String str){ + private String encode(String str) { try { return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8); } catch (UnsupportedEncodingException e) { @@ -186,7 +189,7 @@ public class LoginWebBridge { } } - private void sleep(long millis){ + private void sleep(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { @@ -200,7 +203,7 @@ public class LoginWebBridge { public void registerHref() { try { Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register"))); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } } @@ -211,13 +214,14 @@ public class LoginWebBridge { public void forgetHref() { try { Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.reset"))); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } } /** * 设计器端的用户登录 + * * @param username 用户名 * @param password 密码 * @return 登录信息标志 @@ -228,9 +232,10 @@ public class LoginWebBridge { /** * 插件管理的用户登录部分 + * * @param username 用户名 * @param password 密码 - * @param uiLabel 设计器端的label + * @param uiLabel 设计器端的label * @return 登录信息标志 */ public String pluginManageLogin(String username, String password, UILabel uiLabel) { @@ -239,9 +244,10 @@ public class LoginWebBridge { /** * 登录操作 + * * @param username 用户名 * @param password 密码 - * @param uiLabel 两边的label显示 + * @param uiLabel 两边的label显示 * @return 登录信息标志 */ public String login(String username, String password, UILabel uiLabel) { @@ -272,8 +278,8 @@ public class LoginWebBridge { /** * 更新后台的用户信息 + * * @param username 用户名 - * @param password 密码 */ public void updateUserInfo(String username) { this.userName = username; @@ -281,6 +287,7 @@ public class LoginWebBridge { /** * 关闭窗口并且重新赋值 + * * @param username */ public void loginSuccess(String username, UILabel uiLabel) { @@ -295,13 +302,7 @@ public class LoginWebBridge { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { - //弹出qq登录的窗口 - QQLoginPane managerPane = new QQLoginPane(); - UIDialog qqlog = new QQLoginDialog(DesignerContext.getDesignerFrame(),managerPane); - QQLoginWebBridge.getHelper().setDialogHandle(uiDialog); - QQLoginWebBridge.getHelper().setQQDialogHandle(qqlog); - QQLoginWebBridge.getHelper().setUILabel(uiLabel); - qqlog.setVisible(true); + WebViewDlgHelper.createQQLoginDialog(); } }); } @@ -327,12 +328,55 @@ public class LoginWebBridge { } else { return UNKNOWN_ERROR;//未知错误,-3 } - }else { + } else { return NET_FAILED; } - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } return UNKNOWN_ERROR; } + + /** + * 关闭QQ授权窗口 + */ + public void closeQQWindow() { + if (qqDialog != null) { + qqDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + qqDialog.setVisible(false); + } + } + + /** + * 获取用户信息 + * + * @param userInfo + */ + public void getLoginInfo(String userInfo) { + org.json.JSONObject jo = new org.json.JSONObject(userInfo); + String status = jo.get("status").toString(); + if (status.equals(LOGIN_SUCCESS)) { + String username = jo.get("username").toString(); + int uid = Integer.parseInt(jo.get("uid") == null ? "" : jo.get("uid").toString()); + closeWindow(); + closeQQWindow(); + pluginuiLabel.setText(username); + DesignerEnvManager.getEnvManager().setBBSName(username); + DesignerEnvManager.getEnvManager().setBbsUid(uid); + DesignerEnvManager.getEnvManager().setInShowBBsName(username); + } else if (status.equals(LOGIN_FAILED)) { + //账号没有QQ授权 + closeQQWindow(); + try { + Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("QQ_binding"))); + } catch (Exception exp) { + } + } + } + + public void openUrlAtLocalWebBrowser(WebEngine eng, String url) { + if (url.indexOf("qqLogin.html") > 0) { + return; + } + } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/LoginWebPane.java b/designer_base/src/com/fr/design/extra/LoginWebPane.java index b49db6ace7..ee0a3275aa 100644 --- a/designer_base/src/com/fr/design/extra/LoginWebPane.java +++ b/designer_base/src/com/fr/design/extra/LoginWebPane.java @@ -17,11 +17,7 @@ import javax.swing.*; */ public class LoginWebPane extends JFXPanel { - private WebEngine webEngine; - private LoginPane loginPane; - - public LoginWebPane(final String installHome,LoginPane loginPane) { - this.loginPane = loginPane; + public LoginWebPane(final String installHome) { Platform.setImplicitExit(false); Platform.runLater(new Runnable() { @Override @@ -30,7 +26,7 @@ public class LoginWebPane extends JFXPanel { Scene scene = new Scene(root); LoginWebPane.this.setScene(scene); WebView webView = new WebView(); - webEngine = webView.getEngine(); + WebEngine webEngine = webView.getEngine(); webEngine.load("file:///" + installHome + "/scripts/qqLogin/web/login.html"); webEngine.setOnAlert(new EventHandler>() { @Override @@ -39,17 +35,13 @@ public class LoginWebPane extends JFXPanel { } }); JSObject obj = (JSObject) webEngine.executeScript("window"); - obj.setMember("LoginHelper", LoginWebBridge.getHelper(webEngine)); + obj.setMember("LoginHelper", LoginWebBridge.getHelper()); webView.setContextMenuEnabled(false);//屏蔽右键 root.setCenter(webView); } }); } - public void setEngine(WebEngine webEngine) { - this.webEngine = webEngine; - } - private void showAlert(final String message) { SwingUtilities.invokeLater(new Runnable() { @Override diff --git a/designer_base/src/com/fr/design/extra/QQLoginDialog.java b/designer_base/src/com/fr/design/extra/QQLoginDialog.java index 1a64161741..71224c3a8d 100644 --- a/designer_base/src/com/fr/design/extra/QQLoginDialog.java +++ b/designer_base/src/com/fr/design/extra/QQLoginDialog.java @@ -1,6 +1,5 @@ package com.fr.design.extra; -import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.UIDialog; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.general.Inter; @@ -14,7 +13,7 @@ import java.awt.*; public class QQLoginDialog extends UIDialog { private static final Dimension DEFAULT_SHOP = new Dimension(700, 500); - public QQLoginDialog(Frame frame, BasicPane pane) { + public QQLoginDialog(Frame frame, Component pane) { super(frame); setUndecorated(true); JPanel panel = (JPanel) getContentPane(); @@ -24,7 +23,6 @@ public class QQLoginDialog extends UIDialog { GUICoreUtils.centerWindow(this); setResizable(false); setTitle(Inter.getLocText("FR-Designer-Plugin_Manager")); - } @Override diff --git a/designer_base/src/com/fr/design/extra/QQLoginPane.java b/designer_base/src/com/fr/design/extra/QQLoginPane.java deleted file mode 100644 index 2bbdd7e539..0000000000 --- a/designer_base/src/com/fr/design/extra/QQLoginPane.java +++ /dev/null @@ -1,145 +0,0 @@ -package com.fr.design.extra; - -import com.fr.base.FRContext; -import com.fr.design.DesignerEnvManager; -import com.fr.design.RestartHelper; -import com.fr.design.dialog.BasicPane; -import com.fr.general.ComparatorUtils; -import com.fr.general.IOUtils; -import com.fr.general.Inter; -import com.fr.general.SiteCenter; -import com.fr.general.http.HttpClient; -import com.fr.plugin.PluginVerifyException; -import com.fr.stable.StableUtils; - -import javax.swing.*; -import java.awt.*; -import java.io.File; -import java.net.HttpURLConnection; -import java.net.URL; -import java.util.concurrent.ExecutionException; - -/** - * Created by zhaohehe on 16/7/28. - */ -public class QQLoginPane extends BasicPane { - private static final String LATEST = "latest"; - - public QQLoginPane() { - setLayout(new BorderLayout()); - if (StableUtils.getMajorJavaVersion() == 8) { - String installHome; - if (StableUtils.isDebug()) { - URL url = ClassLoader.getSystemResource(""); - installHome = url.getPath(); - addPane(installHome); - } else { - installHome = StableUtils.getInstallHome(); - File file = new File(StableUtils.pathJoin(installHome, "scripts")); - if (!file.exists()) { - int rv = JOptionPane.showConfirmDialog( - this, - 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(); - } - } else { - addPane(installHome); - updateShopScripts(); - } - } - } else { - } - } - - private void addPane(String installHome) { - QQLoginWebPane webPane = new QQLoginWebPane(new File(installHome).getAbsolutePath()); - add(webPane, BorderLayout.CENTER); - } - - - @Override - protected String title4PopupWindow() { - return Inter.getLocText("FR-Designer-Plugin_Manager"); - } - - - private void downloadShopScripts() { - new SwingWorker() { - @Override - protected Boolean doInBackground() throws Exception { - String id = "shop_scripts"; - String username = DesignerEnvManager.getEnvManager().getBBSName(); - String password = DesignerEnvManager.getEnvManager().getBBSPassword(); - try { - PluginHelper.downloadPluginFile(id, username, password, new Process() { - @Override - public void process(Double integer) { - } - }); - } catch (PluginVerifyException e) { - JOptionPane.showMessageDialog(QQLoginPane.this, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); - return false; - } catch (Exception e) { - FRContext.getLogger().error(e.getMessage(), e); - return false; - } - return true; - } - - @Override - protected void done() { - - try { - if (get()) { - IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); - int rv = JOptionPane.showOptionDialog( - QQLoginPane.this, - Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.YES_NO_OPTION, - JOptionPane.INFORMATION_MESSAGE, - null, - new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")}, - null - ); - if (rv == JOptionPane.OK_OPTION) { - RestartHelper.restart(); - } - } - } catch (InterruptedException | ExecutionException e) { - FRContext.getLogger().error(e.getMessage(), e); - } - - } - }.execute(); - } - - private void updateShopScripts() { - new SwingWorker() { - @Override - protected Void doInBackground() throws Exception { - HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("store.version") + "&version=" + PluginStoreConstants.VERSION); - if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { - if (!ComparatorUtils.equals(httpClient.getResponseText(), LATEST)) { - int rv = JOptionPane.showConfirmDialog( - QQLoginPane.this, - Inter.getLocText("FR-Designer-Plugin_Shop_Need_Update"), - Inter.getLocText("FR-Designer-Plugin_Warning"), - JOptionPane.OK_CANCEL_OPTION, - JOptionPane.INFORMATION_MESSAGE - ); - if (rv == JOptionPane.OK_OPTION) { - downloadShopScripts(); - } - } - } - return null; - } - }.execute(); - } -} \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java b/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java deleted file mode 100644 index 7c2dd3e50e..0000000000 --- a/designer_base/src/com/fr/design/extra/QQLoginWebBridge.java +++ /dev/null @@ -1,132 +0,0 @@ -package com.fr.design.extra; - -import com.fr.design.DesignerEnvManager; -import com.fr.design.dialog.UIDialog; -import com.fr.design.gui.ilable.UILabel; -import com.fr.general.SiteCenter; -import javafx.scene.web.WebEngine; -import netscape.javascript.JSObject; -import org.json.JSONObject; - -import javax.swing.*; -import java.awt.*; -import java.net.URI; - -/** - * Created by lp on 2016/8/10. - */ -public class QQLoginWebBridge { - - private static com.fr.design.extra.QQLoginWebBridge helper; - private WebEngine webEngine; - private static String LOGINSUCCESS = "ok"; - private static String LOGINFAILED = "failed"; - private UIDialog uiDialog; - private UILabel uiLabel; - private UILabel pluginuiLabel; - private UIDialog qqDialog; - private String username; - - - private QQLoginWebBridge() { - } - - public static com.fr.design.extra.QQLoginWebBridge getHelper() { - if (helper != null) { - return helper; - } - synchronized (com.fr.design.extra.QQLoginWebBridge.class) { - if (helper == null) { - helper = new com.fr.design.extra.QQLoginWebBridge(); - } - return helper; - } - } - - public void setEngine(WebEngine webEngine) { - this.webEngine = webEngine; - } - - public void setDialogHandle(UIDialog uiDialog) { - closeParentWindow(); - this.uiDialog = uiDialog; - } - - public void setQQDialogHandle(UIDialog uiDialog) { - closeQQWindow(); - this.qqDialog = uiDialog; - } - - public void setUILabel(UILabel uiLabel) { - this.uiLabel = uiLabel; - } - - public void setUILabelInPlugin(UILabel uiLabel) { - this.pluginuiLabel = uiLabel; - } - - public void setLoginlabel() { - username = DesignerEnvManager.getEnvManager().getBBSName(); - } - - private static JSObject window; - - public static com.fr.design.extra.QQLoginWebBridge getHelper(WebEngine webEngine) { - getHelper(); - helper.setEngine(webEngine); - return helper; - } - - /** - * 关闭QQ授权窗口 - */ - public void closeQQWindow() { - if (qqDialog != null) { - qqDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - qqDialog.setVisible(false); - } - } - - /** - * 关闭父窗口 - */ - public void closeParentWindow() { - if (uiDialog != null) { - uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - uiDialog.setVisible(false); - } - } - - /** - * 获取用户信息 - * - * @param userInfo - */ - public void getLoginInfo(String userInfo) { - JSONObject jo = new JSONObject(userInfo); - String status = jo.get("status").toString(); - if (status.equals(LOGINSUCCESS)) { - String username = jo.get("username").toString(); - int uid = Integer.parseInt(jo.get("uid") == null ? "" : jo.get("uid").toString()); - closeQQWindow(); - closeParentWindow(); - pluginuiLabel.setText(username); - DesignerEnvManager.getEnvManager().setBBSName(username); - DesignerEnvManager.getEnvManager().setBbsUid(uid); - DesignerEnvManager.getEnvManager().setInShowBBsName(username); - } else if (status.equals(LOGINFAILED)) { - //账号没有QQ授权 - closeQQWindow(); - try { - Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("QQ_binding"))); - } catch (Exception exp) { - } - } - } - - public void openUrlAtLocalWebBrowser(WebEngine eng, String url) { - if (url.indexOf("qqLogin.html") > 0) { - return; - } - } -} diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebPane.java b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java index 5861bb9ed1..7dfa277eba 100644 --- a/designer_base/src/com/fr/design/extra/QQLoginWebPane.java +++ b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java @@ -95,7 +95,7 @@ public class QQLoginWebPane extends JFXPanel { if (ComparatorUtils.equals(newValue, "file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html") || ComparatorUtils.equals(newValue, SiteCenter.getInstance().acquireUrlByKind("bbs.mobile"))) { return; } - QQLoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); + LoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); } }); webEngine.setOnAlert(new EventHandler>() { @@ -109,7 +109,7 @@ public class QQLoginWebPane extends JFXPanel { public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { if (newState == Worker.State.SUCCEEDED) { window = (JSObject) webEngine.executeScript("window"); - window.setMember("QQLoginHelper", QQLoginWebBridge.getHelper(webEngine)); + window.setMember("QQLoginHelper", LoginWebBridge.getHelper()); } } } @@ -138,7 +138,7 @@ public class QQLoginWebPane extends JFXPanel { @Override public void run() { eng.executeScript("location.reload()"); - QQLoginWebBridge.getHelper().closeQQWindow(); + LoginWebBridge.getHelper().closeQQWindow(); } }); } catch (Exception e) { diff --git a/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java new file mode 100644 index 0000000000..f07a4edd5e --- /dev/null +++ b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java @@ -0,0 +1,203 @@ +package com.fr.design.extra; + +import com.fr.base.FRContext; +import com.fr.design.DesignerEnvManager; +import com.fr.design.RestartHelper; +import com.fr.design.dialog.BasicPane; +import com.fr.design.dialog.UIDialog; +import com.fr.design.gui.frpane.UITabbedPane; +import com.fr.design.mainframe.DesignerContext; +import com.fr.general.ComparatorUtils; +import com.fr.general.IOUtils; +import com.fr.general.Inter; +import com.fr.general.SiteCenter; +import com.fr.general.http.HttpClient; +import com.fr.plugin.PluginVerifyException; +import com.fr.stable.StableUtils; + +import javax.swing.*; +import java.awt.*; +import java.io.File; +import java.net.HttpURLConnection; +import java.util.concurrent.ExecutionException; + +/** + * Created by vito on 2016/9/28. + */ +public class WebViewDlgHelper { + private static final String LATEST = "latest"; + private static final String SHOP_SCRIPTS = "shop_scripts"; + private static final int VERSION_8 = 8; + // 调试时,使用installHome = ClassLoader.getSystemResource("").getPath()代替下面 + private static String installHome = StableUtils.getInstallHome(); + + public static void createPluginDialog() { + if (StableUtils.getMajorJavaVersion() >= VERSION_8) { + String relativePath = "/scripts/store/web/index.html"; + String mainJsPath = StableUtils.pathJoin(new File(installHome).getAbsolutePath(), relativePath); + File file = new File(mainJsPath); + 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); + } + } else { + updateShopScripts(SHOP_SCRIPTS); + showPluginDlg(mainJsPath); + } + } else { + BasicPane traditionalStorePane = new BasicPane() { + @Override + protected String title4PopupWindow() { + return Inter.getLocText("FR-Designer-Plugin_Manager"); + } + }; + traditionalStorePane.setLayout(new BorderLayout()); + traditionalStorePane.add(initTraditionalStore(), BorderLayout.CENTER); + UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(), traditionalStorePane); + dlg.setVisible(true); + } + } + + /** + * 以关键词打开设计器商店 + * + * @param keyword 关键词 + */ + public static void createPluginDialog(String keyword) { + PluginWebBridge.getHelper().openWithSearch(keyword); + createPluginDialog(); + } + + public static void createLoginDialog() { + if (StableUtils.getMajorJavaVersion() == 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); + } + } else { + showLoginDlg(); + updateShopScripts(SHOP_SCRIPTS); + } + } + } + + public static void createQQLoginDialog() { + QQLoginWebPane webPane = new QQLoginWebPane(new File(installHome).getAbsolutePath()); + UIDialog qqlog = new QQLoginDialog(DesignerContext.getDesignerFrame(), webPane); + LoginWebBridge.getHelper().setQqDialog(qqlog); + qqlog.setVisible(true); + } + + private static void showPluginDlg(String mainJsPath) { + BasicPane managerPane = new ShopManagerPane(new PluginWebPane(mainJsPath)); + UIDialog dlg = new ShopDialog(DesignerContext.getDesignerFrame(), managerPane); + PluginWebBridge.getHelper().setDialogHandle(dlg); + dlg.setVisible(true); + } + + private static void showLoginDlg() { + LoginWebPane webPane = new LoginWebPane(new File(installHome).getAbsolutePath()); + UIDialog qqdlg = new LoginDialog(DesignerContext.getDesignerFrame(), webPane); + LoginWebBridge.getHelper().setDialogHandle(qqdlg); + qqdlg.setVisible(true); + } + + private static Component initTraditionalStore() { + UITabbedPane tabbedPane = new UITabbedPane(); + PluginInstalledPane installedPane = new PluginInstalledPane(); + tabbedPane.addTab(installedPane.tabTitle(), installedPane); + tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_Update"), new PluginUpdatePane(tabbedPane)); + tabbedPane.addTab(Inter.getLocText("FR-Designer-Plugin_All_Plugins"), new PluginFromStorePane(tabbedPane)); + return tabbedPane; + } + + private static void downloadShopScripts(final String scriptsId) { + new SwingWorker() { + @Override + protected Boolean doInBackground() throws Exception { + String username = DesignerEnvManager.getEnvManager().getBBSName(); + String password = DesignerEnvManager.getEnvManager().getBBSPassword(); + try { + PluginHelper.downloadPluginFile(scriptsId, username, password, new Process() { + @Override + public void process(Double integer) { + } + }); + } catch (PluginVerifyException e) { + JOptionPane.showMessageDialog(null, e.getMessage(), Inter.getLocText("FR-Designer-Plugin_Warning"), JOptionPane.ERROR_MESSAGE); + return false; + } catch (Exception e) { + FRContext.getLogger().error(e.getMessage(), e); + return false; + } + return true; + } + + @Override + protected void done() { + + try { + if (get()) { + IOUtils.unzip(new File(StableUtils.pathJoin(PluginHelper.DOWNLOAD_PATH, PluginHelper.TEMP_FILE)), StableUtils.getInstallHome()); + int rv = JOptionPane.showOptionDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Shop_Installed"), + Inter.getLocText("FR-Designer-Plugin_Warning"), + JOptionPane.YES_NO_OPTION, + JOptionPane.INFORMATION_MESSAGE, + null, + new String[]{Inter.getLocText("FR-Designer-Basic_Restart_Designer"), Inter.getLocText("FR-Designer-Basic_Restart_Designer_Later")}, + null + ); + if (rv == JOptionPane.OK_OPTION) { + RestartHelper.restart(); + } + } + } catch (InterruptedException | ExecutionException e) { + FRContext.getLogger().error(e.getMessage(), e); + } + + } + }.execute(); + } + + private static void updateShopScripts(final String scriptsId) { + new SwingWorker() { + @Override + protected Void doInBackground() throws Exception { + HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("store.version") + "&version=" + PluginStoreConstants.VERSION); + if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { + String text = httpClient.getResponseText(); + if (!ComparatorUtils.equals(text, LATEST)) { + int rv = JOptionPane.showConfirmDialog( + null, + Inter.getLocText("FR-Designer-Plugin_Shop_Need_Update"), + Inter.getLocText("FR-Designer-Plugin_Warning"), + JOptionPane.OK_CANCEL_OPTION, + JOptionPane.INFORMATION_MESSAGE + ); + if (rv == JOptionPane.OK_OPTION) { + downloadShopScripts(scriptsId); + } + } + } + return null; + } + }.execute(); + } +} diff --git a/designer_base/src/com/fr/start/BaseDesigner.java b/designer_base/src/com/fr/start/BaseDesigner.java index 0e036c5340..301a9191ff 100644 --- a/designer_base/src/com/fr/start/BaseDesigner.java +++ b/designer_base/src/com/fr/start/BaseDesigner.java @@ -7,7 +7,7 @@ import com.fr.base.FRContext; import com.fr.design.DesignerEnvManager; import com.fr.design.ExtraDesignClassManager; import com.fr.design.RestartHelper; -import com.fr.design.extra.WebDialog; +import com.fr.design.extra.WebViewDlgHelper; import com.fr.design.file.HistoryTemplateListPane; import com.fr.design.file.MutilTempalteTabPane; import com.fr.design.file.TemplateTreePane; @@ -127,7 +127,7 @@ public abstract class BaseDesigner extends ToolBarMenuDock { String text = StableUtils.join(plugins, ",") + ": " + Inter.getLocText("FR-Designer_Plugin_Should_Update_Please_Contact_Developer"); int r = JOptionPane.showConfirmDialog(null, text, Inter.getLocText("FR-Designer_Plugin_Should_Update_Title"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE); if (r == JOptionPane.OK_OPTION) { - WebDialog.createPluginDialog(); + WebViewDlgHelper.createPluginDialog(); } } timer.stop(); From 25521cf932cea359490bdfb25da2ad9219837d12 Mon Sep 17 00:00:00 2001 From: vito Date: Fri, 5 May 2017 16:58:53 +0800 Subject: [PATCH 3/4] pmd --- .../com/fr/design/extra/LoginWebBridge.java | 2 +- .../com/fr/design/extra/QQLoginWebPane.java | 127 ++++++++++-------- .../com/fr/design/extra/WebViewDlgHelper.java | 2 +- 3 files changed, 73 insertions(+), 58 deletions(-) diff --git a/designer_base/src/com/fr/design/extra/LoginWebBridge.java b/designer_base/src/com/fr/design/extra/LoginWebBridge.java index 611166bc02..6592e1601f 100644 --- a/designer_base/src/com/fr/design/extra/LoginWebBridge.java +++ b/designer_base/src/com/fr/design/extra/LoginWebBridge.java @@ -108,7 +108,7 @@ public class LoginWebBridge { if (StringUtils.isEmpty(userName)) { return; } - if (!StringUtils.isEmpty(this.userName)) { + if (StringUtils.isNotEmpty(this.userName)) { updateMessageCount(); } this.userName = userName; diff --git a/designer_base/src/com/fr/design/extra/QQLoginWebPane.java b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java index 7dfa277eba..f3c96d2194 100644 --- a/designer_base/src/com/fr/design/extra/QQLoginWebPane.java +++ b/designer_base/src/com/fr/design/extra/QQLoginWebPane.java @@ -40,6 +40,7 @@ import java.awt.*; public class QQLoginWebPane extends JFXPanel { private WebEngine webEngine; + private String url; private static JSObject window; @@ -50,7 +51,9 @@ public class QQLoginWebPane extends JFXPanel { private static int DEFAULT_CONFIRM_HEIGHT = 160; private static int DEFAULT_OFFEST = 20; - class Delta { double x, y; } + class Delta { + double x, y; + } public QQLoginWebPane(final String installHome) { Platform.setImplicitExit(false); @@ -62,7 +65,8 @@ public class QQLoginWebPane extends JFXPanel { QQLoginWebPane.this.setScene(scene); final WebView webView = new WebView(); webEngine = webView.getEngine(); - webEngine.load("file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html"); + url = "file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html"; + webEngine.load(url); final Stage primaryStage = new Stage(); @@ -76,51 +80,56 @@ public class QQLoginWebPane extends JFXPanel { primaryStage.setX(0); primaryStage.setY(Screen.getPrimary().getBounds().getHeight() + DEFAULT_PRIMARYSTAGE_HEIGHT); primaryStage.show(); - }catch (Exception e) { + } catch (Exception e) { FRContext.getLogger().info(e.getMessage()); } - - webView.getEngine().setConfirmHandler(new Callback() { - @Override public Boolean call(String msg) { - Boolean confirmed = confirm(primaryStage, msg, installHome, webView); - return confirmed; - } - }); - - webEngine.locationProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, final String oldValue, String newValue) { - disableLink(webEngine); - // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 - if (ComparatorUtils.equals(newValue, "file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html") || ComparatorUtils.equals(newValue, SiteCenter.getInstance().acquireUrlByKind("bbs.mobile"))) { - return; - } - LoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); - } - }); - webEngine.setOnAlert(new EventHandler>() { + webEngine.setConfirmHandler(new Callback() { @Override - public void handle(WebEvent event) { - showAlert(event.getData()); + public Boolean call(String msg) { + Boolean confirmed = confirm(primaryStage, msg, webView); + return confirmed; } }); - webEngine.getLoadWorker().stateProperty().addListener( - new ChangeListener() { - public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { - if (newState == Worker.State.SUCCEEDED) { - window = (JSObject) webEngine.executeScript("window"); - window.setMember("QQLoginHelper", LoginWebBridge.getHelper()); - } - } - } - ); - + configWebEngine(); webView.setContextMenuEnabled(false);//屏蔽右键 root.setCenter(webView); } }); } + private void configWebEngine() { + + webEngine.locationProperty().addListener(new ChangeListener() { + @Override + public void changed(ObservableValue observable, final String oldValue, String newValue) { + disableLink(webEngine); + // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 + if (ComparatorUtils.equals(newValue, url) || ComparatorUtils.equals(newValue, SiteCenter.getInstance().acquireUrlByKind("bbs.mobile"))) { + return; + } + LoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); + } + }); + + webEngine.setOnAlert(new EventHandler>() { + @Override + public void handle(WebEvent event) { + showAlert(event.getData()); + } + }); + + webEngine.getLoadWorker().stateProperty().addListener( + new ChangeListener() { + public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { + if (newState == Worker.State.SUCCEEDED) { + window = (JSObject) webEngine.executeScript("window"); + window.setMember("QQLoginHelper", LoginWebBridge.getHelper()); + } + } + } + ); + } + private void showAlert(final String message) { SwingUtilities.invokeLater(new Runnable() { @Override @@ -146,12 +155,12 @@ public class QQLoginWebPane extends JFXPanel { } } - private Boolean confirm(final Stage parent, String msg, final String installHome,final WebView webView) { + private Boolean confirm(final Stage parent, String msg, final WebView webView) { final BooleanProperty confirmationResult = new SimpleBooleanProperty(); // initialize the confirmation dialog final Stage dialog = new Stage(StageStyle.UTILITY); - dialog.setX(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2 - DEFAULT_CONFIRM_WIDTH / 2 + DEFAULT_OFFEST); - dialog.setY(Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2 + DEFAULT_OFFEST); + dialog.setX(Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - DEFAULT_CONFIRM_WIDTH / 2 + DEFAULT_OFFEST); + dialog.setY(Toolkit.getDefaultToolkit().getScreenSize().getHeight() / 2 + DEFAULT_OFFEST); dialog.setHeight(DEFAULT_CONFIRM_HEIGHT); dialog.setWidth(DEFAULT_CONFIRM_WIDTH); dialog.setIconified(false); @@ -162,7 +171,8 @@ public class QQLoginWebPane extends JFXPanel { HBoxBuilder.create().styleClass("modal-dialog").children( LabelBuilder.create().text(msg).build(), ButtonBuilder.create().text(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account")).defaultButton(true).onAction(new EventHandler() { - @Override public void handle(ActionEvent actionEvent) { + @Override + public void handle(ActionEvent actionEvent) { // take action and close the dialog. confirmationResult.set(true); webView.getEngine().reload(); @@ -170,7 +180,8 @@ public class QQLoginWebPane extends JFXPanel { } }).build(), ButtonBuilder.create().text(Inter.getLocText("FR-Engine_Cancel")).cancelButton(true).onAction(new EventHandler() { - @Override public void handle(ActionEvent actionEvent) { + @Override + public void handle(ActionEvent actionEvent) { // abort action and close the dialog. confirmationResult.set(false); dialog.close(); @@ -180,35 +191,39 @@ public class QQLoginWebPane extends JFXPanel { , Color.TRANSPARENT ) ); + configDrag(dialog); + // style and show the dialog. + dialog.getScene().getStylesheets().add(getClass().getResource("modal-dialog.css").toExternalForm()); + dialog.setOnCloseRequest(new EventHandler() { + @Override + public void handle(WindowEvent event) { + event.consume(); + dialog.close(); + } + }); + dialog.showAndWait(); + return confirmationResult.get(); + } + + private void configDrag(final Stage dialog) { // allow the dialog to be dragged around. final Node root = dialog.getScene().getRoot(); final Delta dragDelta = new Delta(); root.setOnMousePressed(new EventHandler() { - @Override public void handle(MouseEvent mouseEvent) { + @Override + public void handle(MouseEvent mouseEvent) { // record a delta distance for the drag and drop operation. dragDelta.x = dialog.getX() - mouseEvent.getScreenX(); dragDelta.y = dialog.getY() - mouseEvent.getScreenY(); } }); root.setOnMouseDragged(new EventHandler() { - @Override public void handle(MouseEvent mouseEvent) { + @Override + public void handle(MouseEvent mouseEvent) { dialog.setX(mouseEvent.getScreenX() + dragDelta.x); dialog.setY(mouseEvent.getScreenY() + dragDelta.y); } }); - // style and show the dialog. - dialog.getScene().getStylesheets().add(getClass().getResource("modal-dialog.css").toExternalForm()); - - dialog.setOnCloseRequest(new EventHandler(){ - @Override - public void handle(WindowEvent event){ - event.consume(); - dialog.close(); - } - }); - - dialog.showAndWait(); - return confirmationResult.get(); } } \ No newline at end of file diff --git a/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java index f07a4edd5e..481498fc88 100644 --- a/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java +++ b/designer_base/src/com/fr/design/extra/WebViewDlgHelper.java @@ -76,7 +76,7 @@ public class WebViewDlgHelper { } public static void createLoginDialog() { - if (StableUtils.getMajorJavaVersion() == 8) { + if (StableUtils.getMajorJavaVersion() == VERSION_8) { File file = new File(StableUtils.pathJoin(installHome, "scripts")); if (!file.exists()) { int rv = JOptionPane.showConfirmDialog( From f51dbd6c26425c4a9f7f05fefc9b8e373d0e16b3 Mon Sep 17 00:00:00 2001 From: vito Date: Fri, 5 May 2017 17:01:38 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E7=A7=BB=E5=88=B0designer=5Fbase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/bbs/LoginDialog.java | 33 ------------------- 1 file changed, 33 deletions(-) delete mode 100644 designer/src/com/fr/design/mainframe/bbs/LoginDialog.java diff --git a/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java b/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java deleted file mode 100644 index 2155b2437d..0000000000 --- a/designer/src/com/fr/design/mainframe/bbs/LoginDialog.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.fr.design.mainframe.bbs; - -import com.fr.design.dialog.BasicPane; -import com.fr.design.dialog.UIDialog; -import com.fr.design.utils.gui.GUICoreUtils; -import com.fr.stable.StableUtils; - -import javax.swing.*; -import java.awt.*; - -/** - * Created by zhaohehe on 16/7/26. - */ -public class LoginDialog extends UIDialog { - private static final Dimension DEFAULT_SHOP = new Dimension(401, 201); - - public LoginDialog(Frame frame, BasicPane pane) { - super(frame); - if (StableUtils.getMajorJavaVersion() == 8) { - setUndecorated(true); - } - JPanel panel = (JPanel) getContentPane(); - panel.setLayout(new BorderLayout()); - add(pane, BorderLayout.CENTER); - setSize(DEFAULT_SHOP); - GUICoreUtils.centerWindow(this); - setResizable(false); - } - - @Override - public void checkValid() throws Exception { - } -}