Browse Source

Merge pull request #856 in BA/design from ~VITO/design:dev to dev

* commit 'f51dbd6c26425c4a9f7f05fefc9b8e373d0e16b3':
  移到designer_base
  pmd
  REPORT-2213 设计器右上角使用qq登录后,登录界面关不掉 & 这部分的代码质量
  REPORT-2335 插件管理界面以及右上角的登录界面,多次点击后,页面无法关闭
master
superman 8 years ago
parent
commit
da25a615de
  1. 9
      designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java
  2. 4
      designer/src/com/fr/design/report/freeze/RepeatAndFreezeSettingPane.java
  3. 4
      designer_base/src/com/fr/design/actions/server/PluginManagerAction.java
  4. 15
      designer_base/src/com/fr/design/extra/LoginDialog.java
  5. 152
      designer_base/src/com/fr/design/extra/LoginPane.java
  6. 123
      designer_base/src/com/fr/design/extra/LoginWebBridge.java
  7. 14
      designer_base/src/com/fr/design/extra/LoginWebPane.java
  8. 4
      designer_base/src/com/fr/design/extra/PluginWebBridge.java
  9. 4
      designer_base/src/com/fr/design/extra/QQLoginDialog.java
  10. 145
      designer_base/src/com/fr/design/extra/QQLoginPane.java
  11. 131
      designer_base/src/com/fr/design/extra/QQLoginWebBridge.java
  12. 81
      designer_base/src/com/fr/design/extra/QQLoginWebPane.java
  13. 36
      designer_base/src/com/fr/design/extra/ReuseWebBridge.java
  14. 54
      designer_base/src/com/fr/design/extra/ReuseWebPane.java
  15. 6
      designer_base/src/com/fr/design/extra/WebDialog.java
  16. 203
      designer_base/src/com/fr/design/extra/WebViewDlgHelper.java
  17. 4
      designer_base/src/com/fr/start/BaseDesigner.java

9
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.base.FRContext;
import com.fr.design.DesignerEnvManager; import com.fr.design.DesignerEnvManager;
import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.*; import com.fr.design.extra.*;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.gui.imenu.UIMenuItem; import com.fr.design.gui.imenu.UIMenuItem;
@ -103,17 +102,13 @@ public class UserInfoLabel extends UILabel {
if (StableUtils.getMajorJavaVersion() == 8) { if (StableUtils.getMajorJavaVersion() == 8) {
PluginWebBridge.getHelper().setUILabel(UserInfoLabel.this); PluginWebBridge.getHelper().setUILabel(UserInfoLabel.this);
} }
QQLoginWebBridge.getHelper().setUILabelInPlugin(UserInfoLabel.this); LoginWebBridge.getHelper().setUILabelInPlugin(UserInfoLabel.this);
UserLoginContext.addLoginContextListener(new LoginContextListener() { UserLoginContext.addLoginContextListener(new LoginContextListener() {
@Override @Override
public void showLoginContext() { public void showLoginContext() {
LoginPane managerPane = new LoginPane(); WebViewDlgHelper.createLoginDialog();
UIDialog qqdlg = new LoginDialog(DesignerContext.getDesignerFrame(), managerPane);
LoginWebBridge.getHelper().setDialogHandle(qqdlg);
LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this); LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this);
QQLoginWebBridge.getHelper().setLoginlabel();
qqdlg.setVisible(true);
clearLoginInformation(); clearLoginInformation();
updateInfoPane(); updateInfoPane();
} }

4
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.base.FRContext;
import com.fr.design.dialog.BasicPane; 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.icheckbox.UICheckBox;
import com.fr.design.gui.ilable.ActionLabel; import com.fr.design.gui.ilable.ActionLabel;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
@ -553,7 +553,7 @@ public class RepeatAndFreezeSettingPane extends BasicPane {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
try { try {
//Desktop.getDesktop().browse(new URI(url)); //Desktop.getDesktop().browse(new URI(url));
WebDialog.createPluginDialog(); WebViewDlgHelper.createPluginDialog();
RepeatAndFreezeSettingPane.this.getTopLevelAncestor().setVisible(false); RepeatAndFreezeSettingPane.this.getTopLevelAncestor().setVisible(false);
} catch (Exception exp) { } catch (Exception exp) {

4
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.base.BaseUtils;
import com.fr.design.actions.UpdateAction; 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.design.menu.MenuKeySet;
import com.fr.general.Inter; import com.fr.general.Inter;
@ -25,7 +25,7 @@ public class PluginManagerAction extends UpdateAction {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
WebDialog.createPluginDialog(); WebViewDlgHelper.createPluginDialog();
} }
public static final MenuKeySet PLUGIN_MANAGER = new MenuKeySet() { public static final MenuKeySet PLUGIN_MANAGER = new MenuKeySet() {

15
designer/src/com/fr/design/mainframe/bbs/LoginDialog.java → designer_base/src/com/fr/design/extra/LoginDialog.java

@ -1,32 +1,29 @@
package com.fr.design.mainframe.bbs; package com.fr.design.extra;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.UIDialog; import com.fr.design.dialog.UIDialog;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.Inter; import com.fr.stable.StableUtils;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.stable.StringUtils;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
/** /**
* Created by zhaohehe on 16/7/26. * Created by vito on 2017/5/5.
*/ */
public class LoginDialog extends UIDialog { public class LoginDialog extends UIDialog {
private static final Dimension DEFAULT_SHOP = new Dimension(401, 201); private static final Dimension DEFAULT_SHOP = new Dimension(401, 201);
public LoginDialog(Frame frame, BasicPane pane) { public LoginDialog(Frame frame, Component pane) {
super(frame); super(frame);
if (StableUtils.getMajorJavaVersion() == 8) {
setUndecorated(true); setUndecorated(true);
}
JPanel panel = (JPanel) getContentPane(); JPanel panel = (JPanel) getContentPane();
panel.setLayout(new BorderLayout()); panel.setLayout(new BorderLayout());
add(pane, BorderLayout.CENTER); add(pane, BorderLayout.CENTER);
setSize(DEFAULT_SHOP); setSize(DEFAULT_SHOP);
GUICoreUtils.centerWindow(this); GUICoreUtils.centerWindow(this);
setResizable(false); setResizable(false);
setTitle(Inter.getLocText("FR-Designer-Plugin_Manager"));
} }
@Override @Override

152
designer_base/src/com/fr/design/extra/LoginPane.java

@ -1,152 +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.design.gui.frpane.UITabbedPane;
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();
}
}
} else {
initTraditionalStore();
}
}
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<Boolean, Void>() {
@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<Double>() {
@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<Void, Void>() {
@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();
}
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));
}
}

123
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.Client;
import com.fr.design.extra.ucenter.XMLHelper; import com.fr.design.extra.ucenter.XMLHelper;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.DesignerContext;
import com.fr.general.SiteCenter; import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient; import com.fr.general.http.HttpClient;
import com.fr.json.JSONObject; import com.fr.json.JSONObject;
@ -14,10 +13,10 @@ import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javafx.scene.web.WebEngine; import javafx.scene.web.WebEngine;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
@ -47,50 +46,48 @@ public class LoginWebBridge {
//用户名,密码为空 //用户名,密码为空
private static final String LOGIN_INFO_EMPTY = "-5"; private static final String LOGIN_INFO_EMPTY = "-5";
private static final int TIME_OUT = 10000; 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 uiDialog;
private UIDialog qqDialog;
private UILabel uiLabel; private UILabel uiLabel;
private String userName; private String userName;
public int getMessageCount() { public LoginWebBridge() {
return messageCount; String username = DesignerEnvManager.getEnvManager().getBBSName();
} setUserName(username, uiLabel);
/**
* 测试论坛网络连接
* @return
*/
private boolean testConnection() {
HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test"));
return client.isServerAlive();
} }
public static com.fr.design.extra.LoginWebBridge getHelper() { public static LoginWebBridge getHelper() {
if (helper != null) { if (helper != null) {
return helper; return helper;
} }
synchronized (com.fr.design.extra.LoginWebBridge.class) { synchronized (LoginWebBridge.class) {
if (helper == null) { if (helper == null) {
helper = new com.fr.design.extra.LoginWebBridge(); helper = new LoginWebBridge();
} }
return helper; return helper;
} }
} }
public static com.fr.design.extra.LoginWebBridge getHelper(WebEngine webEngine) { public int getMessageCount() {
getHelper(); return messageCount;
helper.setEngine(webEngine);
return helper;
} }
private WebEngine webEngine; public void setUILabelInPlugin(UILabel uiLabel) {
this.pluginuiLabel = uiLabel;
}
public void setEngine(WebEngine webEngine) { public void setQqDialog(UIDialog qqDialog) {
this.webEngine = webEngine; closeQQWindow();
this.qqDialog = qqDialog;
} }
public void setDialogHandle(UIDialog uiDialog) { public void setDialogHandle(UIDialog uiDialog) {
closeWindow();
this.uiDialog = uiDialog; this.uiDialog = uiDialog;
} }
@ -98,13 +95,9 @@ public class LoginWebBridge {
this.uiLabel = uiLabel; this.uiLabel = uiLabel;
} }
public LoginWebBridge() {
String username = DesignerEnvManager.getEnvManager().getBBSName();
setUserName(username, uiLabel);
}
/** /**
* 设置显示的用户名 * 设置显示的用户名
*
* @param userName 登录用户名 * @param userName 登录用户名
* @param label label显示 * @param label label显示
*/ */
@ -115,12 +108,22 @@ public class LoginWebBridge {
if (StringUtils.isEmpty(userName)) { if (StringUtils.isEmpty(userName)) {
return; return;
} }
if(!StringUtils.isEmpty(this.userName)){ if (StringUtils.isNotEmpty(this.userName)) {
updateMessageCount(); updateMessageCount();
} }
this.userName = userName; this.userName = userName;
} }
/**
* 测试论坛网络连接
*
* @return
*/
private boolean testConnection() {
HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test"));
return client.isServerAlive();
}
/** /**
* 定时取后台论坛消息 * 定时取后台论坛消息
*/ */
@ -160,6 +163,7 @@ public class LoginWebBridge {
/** /**
* 设置获取的消息长度并设置显示 * 设置获取的消息长度并设置显示
*
* @param count * @param count
*/ */
public void setMessageCount(int count) { public void setMessageCount(int count) {
@ -217,6 +221,7 @@ public class LoginWebBridge {
/** /**
* 设计器端的用户登录 * 设计器端的用户登录
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @return 登录信息标志 * @return 登录信息标志
@ -227,6 +232,7 @@ public class LoginWebBridge {
/** /**
* 插件管理的用户登录部分 * 插件管理的用户登录部分
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @param uiLabel 设计器端的label * @param uiLabel 设计器端的label
@ -238,6 +244,7 @@ public class LoginWebBridge {
/** /**
* 登录操作 * 登录操作
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @param uiLabel 两边的label显示 * @param uiLabel 两边的label显示
@ -271,8 +278,8 @@ public class LoginWebBridge {
/** /**
* 更新后台的用户信息 * 更新后台的用户信息
*
* @param username 用户名 * @param username 用户名
* @param password 密码
*/ */
public void updateUserInfo(String username) { public void updateUserInfo(String username) {
this.userName = username; this.userName = username;
@ -280,6 +287,7 @@ public class LoginWebBridge {
/** /**
* 关闭窗口并且重新赋值 * 关闭窗口并且重新赋值
*
* @param username * @param username
*/ */
public void loginSuccess(String username, UILabel uiLabel) { public void loginSuccess(String username, UILabel uiLabel) {
@ -294,13 +302,7 @@ public class LoginWebBridge {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
//弹出qq登录的窗口 WebViewDlgHelper.createQQLoginDialog();
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);
} }
}); });
} }
@ -334,4 +336,47 @@ public class LoginWebBridge {
} }
return UNKNOWN_ERROR; 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;
}
}
} }

14
designer_base/src/com/fr/design/extra/LoginWebPane.java

@ -17,11 +17,7 @@ import javax.swing.*;
*/ */
public class LoginWebPane extends JFXPanel { public class LoginWebPane extends JFXPanel {
private WebEngine webEngine; public LoginWebPane(final String installHome) {
private LoginPane loginPane;
public LoginWebPane(final String installHome,LoginPane loginPane) {
this.loginPane = loginPane;
Platform.setImplicitExit(false); Platform.setImplicitExit(false);
Platform.runLater(new Runnable() { Platform.runLater(new Runnable() {
@Override @Override
@ -30,7 +26,7 @@ public class LoginWebPane extends JFXPanel {
Scene scene = new Scene(root); Scene scene = new Scene(root);
LoginWebPane.this.setScene(scene); LoginWebPane.this.setScene(scene);
WebView webView = new WebView(); WebView webView = new WebView();
webEngine = webView.getEngine(); WebEngine webEngine = webView.getEngine();
webEngine.load("file:///" + installHome + "/scripts/qqLogin/web/login.html"); webEngine.load("file:///" + installHome + "/scripts/qqLogin/web/login.html");
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { webEngine.setOnAlert(new EventHandler<WebEvent<String>>() {
@Override @Override
@ -39,17 +35,13 @@ public class LoginWebPane extends JFXPanel {
} }
}); });
JSObject obj = (JSObject) webEngine.executeScript("window"); JSObject obj = (JSObject) webEngine.executeScript("window");
obj.setMember("LoginHelper", LoginWebBridge.getHelper(webEngine)); obj.setMember("LoginHelper", LoginWebBridge.getHelper());
webView.setContextMenuEnabled(false);//屏蔽右键 webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView); root.setCenter(webView);
} }
}); });
} }
public void setEngine(WebEngine webEngine) {
this.webEngine = webEngine;
}
private void showAlert(final String message) { private void showAlert(final String message) {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override

4
designer_base/src/com/fr/design/extra/PluginWebBridge.java

@ -136,6 +136,7 @@ public class PluginWebBridge {
} }
public void setDialogHandle(UIDialog uiDialog) { public void setDialogHandle(UIDialog uiDialog) {
closeWindow();
this.uiDialog = uiDialog; this.uiDialog = uiDialog;
} }
@ -367,6 +368,7 @@ public class PluginWebBridge {
/** /**
* 获取系统登录的用户名 * 获取系统登录的用户名
*
* @param callback * @param callback
*/ */
public void getLoginInfo(final JSObject callback) { public void getLoginInfo(final JSObject callback) {
@ -493,6 +495,7 @@ public class PluginWebBridge {
/*-------------------------------登录部分的处理----------------------------------*/ /*-------------------------------登录部分的处理----------------------------------*/
/** /**
* 注册页面 * 注册页面
*/ */
@ -521,6 +524,7 @@ public class PluginWebBridge {
/** /**
* 登录操作的回调 * 登录操作的回调
*
* @param username * @param username
* @param password * @param password
* @return * @return

4
designer_base/src/com/fr/design/extra/QQLoginDialog.java

@ -1,6 +1,5 @@
package com.fr.design.extra; package com.fr.design.extra;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.UIDialog; import com.fr.design.dialog.UIDialog;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.Inter; import com.fr.general.Inter;
@ -14,7 +13,7 @@ import java.awt.*;
public class QQLoginDialog extends UIDialog { public class QQLoginDialog extends UIDialog {
private static final Dimension DEFAULT_SHOP = new Dimension(700, 500); private static final Dimension DEFAULT_SHOP = new Dimension(700, 500);
public QQLoginDialog(Frame frame, BasicPane pane) { public QQLoginDialog(Frame frame, Component pane) {
super(frame); super(frame);
setUndecorated(true); setUndecorated(true);
JPanel panel = (JPanel) getContentPane(); JPanel panel = (JPanel) getContentPane();
@ -24,7 +23,6 @@ public class QQLoginDialog extends UIDialog {
GUICoreUtils.centerWindow(this); GUICoreUtils.centerWindow(this);
setResizable(false); setResizable(false);
setTitle(Inter.getLocText("FR-Designer-Plugin_Manager")); setTitle(Inter.getLocText("FR-Designer-Plugin_Manager"));
} }
@Override @Override

145
designer_base/src/com/fr/design/extra/QQLoginPane.java

@ -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<Boolean, Void>() {
@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<Double>() {
@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<Void, Void>() {
@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();
}
}

131
designer_base/src/com/fr/design/extra/QQLoginWebBridge.java

@ -1,131 +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.FRLogger;
import com.fr.general.SiteCenter;
import javafx.scene.web.WebEngine;
import org.json.JSONObject;
import netscape.javascript.JSObject;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
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) {
this.uiDialog = uiDialog;
}
public void setQQDialogHandle(UIDialog uiDialog) {
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;
}
}
}

81
designer_base/src/com/fr/design/extra/QQLoginWebPane.java

@ -40,6 +40,7 @@ import java.awt.*;
public class QQLoginWebPane extends JFXPanel { public class QQLoginWebPane extends JFXPanel {
private WebEngine webEngine; private WebEngine webEngine;
private String url;
private static JSObject window; private static JSObject window;
@ -50,7 +51,9 @@ public class QQLoginWebPane extends JFXPanel {
private static int DEFAULT_CONFIRM_HEIGHT = 160; private static int DEFAULT_CONFIRM_HEIGHT = 160;
private static int DEFAULT_OFFEST = 20; private static int DEFAULT_OFFEST = 20;
class Delta { double x, y; } class Delta {
double x, y;
}
public QQLoginWebPane(final String installHome) { public QQLoginWebPane(final String installHome) {
Platform.setImplicitExit(false); Platform.setImplicitExit(false);
@ -62,7 +65,8 @@ public class QQLoginWebPane extends JFXPanel {
QQLoginWebPane.this.setScene(scene); QQLoginWebPane.this.setScene(scene);
final WebView webView = new WebView(); final WebView webView = new WebView();
webEngine = webView.getEngine(); 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(); final Stage primaryStage = new Stage();
@ -79,46 +83,51 @@ public class QQLoginWebPane extends JFXPanel {
} catch (Exception e) { } catch (Exception e) {
FRContext.getLogger().info(e.getMessage()); FRContext.getLogger().info(e.getMessage());
} }
webEngine.setConfirmHandler(new Callback<String, Boolean>() {
webView.getEngine().setConfirmHandler(new Callback<String, Boolean>() { @Override
@Override public Boolean call(String msg) { public Boolean call(String msg) {
Boolean confirmed = confirm(primaryStage, msg, installHome, webView); Boolean confirmed = confirm(primaryStage, msg, webView);
return confirmed; return confirmed;
} }
}); });
configWebEngine();
webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView);
}
});
}
private void configWebEngine() {
webEngine.locationProperty().addListener(new ChangeListener<String>() { webEngine.locationProperty().addListener(new ChangeListener<String>() {
@Override @Override
public void changed(ObservableValue<? extends String> observable, final String oldValue, String newValue) { public void changed(ObservableValue<? extends String> observable, final String oldValue, String newValue) {
disableLink(webEngine); disableLink(webEngine);
// webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转
if (ComparatorUtils.equals(newValue, "file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html") || ComparatorUtils.equals(newValue, SiteCenter.getInstance().acquireUrlByKind("bbs.mobile"))) { if (ComparatorUtils.equals(newValue, url) || ComparatorUtils.equals(newValue, SiteCenter.getInstance().acquireUrlByKind("bbs.mobile"))) {
return; return;
} }
QQLoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); LoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue);
} }
}); });
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { webEngine.setOnAlert(new EventHandler<WebEvent<String>>() {
@Override @Override
public void handle(WebEvent<String> event) { public void handle(WebEvent<String> event) {
showAlert(event.getData()); showAlert(event.getData());
} }
}); });
webEngine.getLoadWorker().stateProperty().addListener( webEngine.getLoadWorker().stateProperty().addListener(
new ChangeListener<Worker.State>() { new ChangeListener<Worker.State>() {
public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
if (newState == Worker.State.SUCCEEDED) { if (newState == Worker.State.SUCCEEDED) {
window = (JSObject) webEngine.executeScript("window"); window = (JSObject) webEngine.executeScript("window");
window.setMember("QQLoginHelper", QQLoginWebBridge.getHelper(webEngine)); window.setMember("QQLoginHelper", LoginWebBridge.getHelper());
} }
} }
} }
); );
webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView);
}
});
} }
private void showAlert(final String message) { private void showAlert(final String message) {
@ -138,7 +147,7 @@ public class QQLoginWebPane extends JFXPanel {
@Override @Override
public void run() { public void run() {
eng.executeScript("location.reload()"); eng.executeScript("location.reload()");
QQLoginWebBridge.getHelper().closeQQWindow(); LoginWebBridge.getHelper().closeQQWindow();
} }
}); });
} catch (Exception e) { } catch (Exception e) {
@ -146,7 +155,7 @@ 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(); final BooleanProperty confirmationResult = new SimpleBooleanProperty();
// initialize the confirmation dialog // initialize the confirmation dialog
final Stage dialog = new Stage(StageStyle.UTILITY); final Stage dialog = new Stage(StageStyle.UTILITY);
@ -162,7 +171,8 @@ public class QQLoginWebPane extends JFXPanel {
HBoxBuilder.create().styleClass("modal-dialog").children( HBoxBuilder.create().styleClass("modal-dialog").children(
LabelBuilder.create().text(msg).build(), LabelBuilder.create().text(msg).build(),
ButtonBuilder.create().text(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account")).defaultButton(true).onAction(new EventHandler<ActionEvent>() { ButtonBuilder.create().text(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account")).defaultButton(true).onAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) { @Override
public void handle(ActionEvent actionEvent) {
// take action and close the dialog. // take action and close the dialog.
confirmationResult.set(true); confirmationResult.set(true);
webView.getEngine().reload(); webView.getEngine().reload();
@ -170,7 +180,8 @@ public class QQLoginWebPane extends JFXPanel {
} }
}).build(), }).build(),
ButtonBuilder.create().text(Inter.getLocText("FR-Engine_Cancel")).cancelButton(true).onAction(new EventHandler<ActionEvent>() { ButtonBuilder.create().text(Inter.getLocText("FR-Engine_Cancel")).cancelButton(true).onAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) { @Override
public void handle(ActionEvent actionEvent) {
// abort action and close the dialog. // abort action and close the dialog.
confirmationResult.set(false); confirmationResult.set(false);
dialog.close(); dialog.close();
@ -180,35 +191,39 @@ public class QQLoginWebPane extends JFXPanel {
, Color.TRANSPARENT , Color.TRANSPARENT
) )
); );
configDrag(dialog);
// style and show the dialog.
dialog.getScene().getStylesheets().add(getClass().getResource("modal-dialog.css").toExternalForm());
dialog.setOnCloseRequest(new EventHandler<WindowEvent>() {
@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. // allow the dialog to be dragged around.
final Node root = dialog.getScene().getRoot(); final Node root = dialog.getScene().getRoot();
final Delta dragDelta = new Delta(); final Delta dragDelta = new Delta();
root.setOnMousePressed(new EventHandler<MouseEvent>() { root.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) { @Override
public void handle(MouseEvent mouseEvent) {
// record a delta distance for the drag and drop operation. // record a delta distance for the drag and drop operation.
dragDelta.x = dialog.getX() - mouseEvent.getScreenX(); dragDelta.x = dialog.getX() - mouseEvent.getScreenX();
dragDelta.y = dialog.getY() - mouseEvent.getScreenY(); dragDelta.y = dialog.getY() - mouseEvent.getScreenY();
} }
}); });
root.setOnMouseDragged(new EventHandler<MouseEvent>() { root.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) { @Override
public void handle(MouseEvent mouseEvent) {
dialog.setX(mouseEvent.getScreenX() + dragDelta.x); dialog.setX(mouseEvent.getScreenX() + dragDelta.x);
dialog.setY(mouseEvent.getScreenY() + dragDelta.y); 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<WindowEvent>(){
@Override
public void handle(WindowEvent event){
event.consume();
dialog.close();
}
});
dialog.showAndWait();
return confirmationResult.get();
} }
} }

36
designer_base/src/com/fr/design/extra/ReuseWebBridge.java

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

54
designer_base/src/com/fr/design/extra/ReuseWebPane.java

@ -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<WebEvent<String>>() {
@Override
public void handle(WebEvent<String> 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);
}
});
}
}

6
designer_base/src/com/fr/design/extra/WebDialog.java

@ -70,10 +70,10 @@ public class WebDialog {
/** /**
* 以关键词打开设计器商店 * 以关键词打开设计器商店
* <p> *
* // * @param keyword 关键词 * @param keyword 关键词
*/ */
public void createPluginDialog(String keyword) { public static void createPluginDialog(String keyword) {
PluginWebBridge.getHelper().openWithSearch(keyword); PluginWebBridge.getHelper().openWithSearch(keyword);
createPluginDialog(); createPluginDialog();
} }

203
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() == 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);
}
} 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<Boolean, Void>() {
@Override
protected Boolean doInBackground() throws Exception {
String username = DesignerEnvManager.getEnvManager().getBBSName();
String password = DesignerEnvManager.getEnvManager().getBBSPassword();
try {
PluginHelper.downloadPluginFile(scriptsId, username, password, new Process<Double>() {
@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<Void, Void>() {
@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();
}
}

4
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.DesignerEnvManager;
import com.fr.design.ExtraDesignClassManager; import com.fr.design.ExtraDesignClassManager;
import com.fr.design.RestartHelper; 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.HistoryTemplateListPane;
import com.fr.design.file.MutilTempalteTabPane; import com.fr.design.file.MutilTempalteTabPane;
import com.fr.design.file.TemplateTreePane; 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"); 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); 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) { if (r == JOptionPane.OK_OPTION) {
WebDialog.createPluginDialog(); WebViewDlgHelper.createPluginDialog();
} }
} }
timer.stop(); timer.stop();

Loading…
Cancel
Save