Browse Source

REPORT-2213 设计器右上角使用qq登录后,登录界面关不掉 & 这部分的代码质量

master
vito 8 years ago
parent
commit
33ab06ff91
  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. 32
      designer_base/src/com/fr/design/extra/LoginDialog.java
  5. 140
      designer_base/src/com/fr/design/extra/LoginPane.java
  6. 150
      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/QQLoginDialog.java
  9. 145
      designer_base/src/com/fr/design/extra/QQLoginPane.java
  10. 132
      designer_base/src/com/fr/design/extra/QQLoginWebBridge.java
  11. 6
      designer_base/src/com/fr/design/extra/QQLoginWebPane.java
  12. 203
      designer_base/src/com/fr/design/extra/WebViewDlgHelper.java
  13. 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() {

32
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 {
}
}

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

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

150
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,47 +46,44 @@ 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) {
@ -99,50 +95,56 @@ 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显示
*/ */
public void setUserName(String userName, UILabel label) { public void setUserName(String userName, UILabel label) {
if (uiLabel == null) { if (uiLabel == null) {
this.uiLabel = label; this.uiLabel = label;
} }
if(StringUtils.isEmpty(userName)){ if (StringUtils.isEmpty(userName)) {
return; return;
} }
if(!StringUtils.isEmpty(this.userName)){ if (!StringUtils.isEmpty(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();
}
/** /**
* 定时取后台论坛消息 * 定时取后台论坛消息
*/ */
public void updateMessageCount(){ public void updateMessageCount() {
//启动获取消息更新的线程 //启动获取消息更新的线程
//登陆状态, 根据存起来的用户名密码, 每1分钟发起一次请求, 更新消息条数. //登陆状态, 根据存起来的用户名密码, 每1分钟发起一次请求, 更新消息条数.
Thread updateMessageThread = new Thread(new Runnable() { Thread updateMessageThread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {
sleep(CHECK_MESSAGE_TIME); sleep(CHECK_MESSAGE_TIME);
while(StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())){ while (StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())) {
HashMap<String, String> para = new HashMap<>(); HashMap<String, String> para = new HashMap<>();
int uid = DesignerEnvManager.getEnvManager().getBbsUid(); int uid = DesignerEnvManager.getEnvManager().getBbsUid();
para.put("uid", String.valueOf(uid)); para.put("uid", String.valueOf(uid));
HttpClient getMessage = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.message"), para); HttpClient getMessage = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.message"), para);
getMessage.asGet(); getMessage.asGet();
if(getMessage.isServerAlive()){ if (getMessage.isServerAlive()) {
try { try {
String res = getMessage.getResponseText(); String res = getMessage.getResponseText();
if (res.equals(FAILED_MESSAGE_STATUS)) { if (res.equals(FAILED_MESSAGE_STATUS)) {
}else { } else {
JSONObject jo = new JSONObject(res); JSONObject jo = new JSONObject(res);
if (jo.getString("status").equals(SUCCESS_MESSAGE_STATUS)) { if (jo.getString("status").equals(SUCCESS_MESSAGE_STATUS)) {
setMessageCount(Integer.parseInt(jo.getString("message"))); setMessageCount(Integer.parseInt(jo.getString("message")));
@ -161,6 +163,7 @@ public class LoginWebBridge {
/** /**
* 设置获取的消息长度并设置显示 * 设置获取的消息长度并设置显示
*
* @param count * @param count
*/ */
public void setMessageCount(int count) { public void setMessageCount(int count) {
@ -178,7 +181,7 @@ public class LoginWebBridge {
uiLabel.setText(sb.toString()); uiLabel.setText(sb.toString());
} }
private String encode(String str){ private String encode(String str) {
try { try {
return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8); return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
@ -186,7 +189,7 @@ public class LoginWebBridge {
} }
} }
private void sleep(long millis){ private void sleep(long millis) {
try { try {
Thread.sleep(millis); Thread.sleep(millis);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -200,7 +203,7 @@ public class LoginWebBridge {
public void registerHref() { public void registerHref() {
try { try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register"))); Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register")));
}catch (Exception e) { } catch (Exception e) {
FRContext.getLogger().info(e.getMessage()); FRContext.getLogger().info(e.getMessage());
} }
} }
@ -211,13 +214,14 @@ public class LoginWebBridge {
public void forgetHref() { public void forgetHref() {
try { try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.reset"))); Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.reset")));
}catch (Exception e) { } catch (Exception e) {
FRContext.getLogger().info(e.getMessage()); FRContext.getLogger().info(e.getMessage());
} }
} }
/** /**
* 设计器端的用户登录 * 设计器端的用户登录
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @return 登录信息标志 * @return 登录信息标志
@ -228,9 +232,10 @@ public class LoginWebBridge {
/** /**
* 插件管理的用户登录部分 * 插件管理的用户登录部分
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @param uiLabel 设计器端的label * @param uiLabel 设计器端的label
* @return 登录信息标志 * @return 登录信息标志
*/ */
public String pluginManageLogin(String username, String password, UILabel uiLabel) { public String pluginManageLogin(String username, String password, UILabel uiLabel) {
@ -239,9 +244,10 @@ public class LoginWebBridge {
/** /**
* 登录操作 * 登录操作
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @param uiLabel 两边的label显示 * @param uiLabel 两边的label显示
* @return 登录信息标志 * @return 登录信息标志
*/ */
public String login(String username, String password, UILabel uiLabel) { public String login(String username, String password, UILabel uiLabel) {
@ -272,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;
@ -281,6 +287,7 @@ public class LoginWebBridge {
/** /**
* 关闭窗口并且重新赋值 * 关闭窗口并且重新赋值
*
* @param username * @param username
*/ */
public void loginSuccess(String username, UILabel uiLabel) { public void loginSuccess(String username, UILabel uiLabel) {
@ -295,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);
} }
}); });
} }
@ -327,12 +328,55 @@ public class LoginWebBridge {
} else { } else {
return UNKNOWN_ERROR;//未知错误,-3 return UNKNOWN_ERROR;//未知错误,-3
} }
}else { } else {
return NET_FAILED; return NET_FAILED;
} }
}catch (Exception e) { } catch (Exception e) {
FRContext.getLogger().info(e.getMessage()); FRContext.getLogger().info(e.getMessage());
} }
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/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();
}
}

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

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

6
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"))) { if (ComparatorUtils.equals(newValue, "file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html") || 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>>() {
@ -109,7 +109,7 @@ public class QQLoginWebPane extends JFXPanel {
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());
} }
} }
} }
@ -138,7 +138,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) {

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() == 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