Browse Source

设计器内论坛登录

设计器右上角部分的登录与私人消息处理
master
李攀 8 years ago
parent
commit
c164b99aec
  1. 3
      designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java
  2. 35
      designer/src/com/fr/design/mainframe/bbs/LoginDialog.java
  3. 54
      designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java
  4. 17
      designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java
  5. 8
      designer_base/src/com/fr/design/extra/LoginContextListener.java
  6. 43
      designer_base/src/com/fr/design/extra/LoginPane.java
  7. 187
      designer_base/src/com/fr/design/extra/LoginWebBridge.java
  8. 61
      designer_base/src/com/fr/design/extra/LoginWebPane.java
  9. 37
      designer_base/src/com/fr/design/extra/PluginWebBridge.java
  10. 34
      designer_base/src/com/fr/design/extra/QQLoginDialog.java
  11. 44
      designer_base/src/com/fr/design/extra/QQLoginPane.java
  12. 103
      designer_base/src/com/fr/design/extra/QQLoginWebBridge.java
  13. 55
      designer_base/src/com/fr/design/extra/QQLoginWebPane.java
  14. 28
      designer_base/src/com/fr/design/extra/UserLoginContext.java
  15. 37
      designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java

3
designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java

@ -75,7 +75,6 @@ public class BBSLoginDialog extends UIDialog {
// 用户登录状态label // 用户登录状态label
private UserInfoLabel userInfoLabel; private UserInfoLabel userInfoLabel;
public UILabel getTipLabel() { public UILabel getTipLabel() {
return tipLabel; return tipLabel;
} }
@ -84,7 +83,6 @@ public class BBSLoginDialog extends UIDialog {
this.tipLabel = tipLabel; this.tipLabel = tipLabel;
} }
/** /**
* 构造函数 * 构造函数
* *
@ -213,7 +211,6 @@ public class BBSLoginDialog extends UIDialog {
DesignerEnvManager.getEnvManager().setBBSPassword(String.valueOf(passField.getPassword())); DesignerEnvManager.getEnvManager().setBBSPassword(String.valueOf(passField.getPassword()));
userInfoLabel.setUserName(nameField.getText()); userInfoLabel.setUserName(nameField.getText());
userInfoLabel.getUserInfoPane().markSignIn(nameField.getText()); userInfoLabel.getUserInfoPane().markSignIn(nameField.getText());
userInfoLabel.getUserInfoPane().getSwitchAccountLabel().setVisible(true);
BBSLoginDialog.this.setVisible(false); BBSLoginDialog.this.setVisible(false);
} }

35
designer/src/com/fr/design/mainframe/bbs/LoginDialog.java

@ -0,0 +1,35 @@
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 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(404, 234);
public LoginDialog(Frame frame, BasicPane pane) {
super(frame);
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
public void checkValid() throws Exception {
}
}

54
designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java

@ -5,12 +5,16 @@ 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.extra.LoginCheckContext; import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.LoginCheckListener; 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.UIPopupMenu;
import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerContext;
import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.general.DateUtils; import com.fr.general.DateUtils;
import com.fr.general.Inter;
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.stable.EncodeConstants; import com.fr.stable.EncodeConstants;
@ -41,7 +45,7 @@ public class UserInfoLabel extends UILabel{
private static final String MESSAGE_KEY = "messageCount"; private static final String MESSAGE_KEY = "messageCount";
private static final int MIN_MESSAGE_COUNT = 1; private static final int MIN_MESSAGE_COUNT = 1;
private static final int MENU_HEIGHT = 20;
//用户名 //用户名
private String userName; private String userName;
@ -87,6 +91,19 @@ public class UserInfoLabel extends UILabel{
bbsLoginDialog.showWindow(); bbsLoginDialog.showWindow();
} }
}); });
UserLoginContext.addLoginContextListener(new LoginContextListener() {
@Override
public void showLoginContext() {
LoginPane managerPane = new LoginPane();
UIDialog qqdlg = new LoginDialog(DesignerContext.getDesignerFrame(),managerPane);
LoginWebBridge.getHelper().setDialogHandle(qqdlg);
LoginWebBridge.getHelper().setUILabel(UserInfoLabel.this);
QQLoginWebBridge.getHelper().setLoginlabel();
qqdlg.setVisible(true);
}
});
} }
/** /**
@ -242,22 +259,41 @@ public class UserInfoLabel extends UILabel{
@Override @Override
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if(StringUtils.isNotEmpty(userName)) {
UIPopupMenu menu = new UIPopupMenu();
menu.setOnlyText(true);
menu.setPopupSize(userInfoPane.getWidth(),userInfoPane.getHeight()*3);
//私人消息
UIMenuItem priviteMessage = new UIMenuItem(Inter.getLocText("FR-Designer-BBSLogin_Privite-Message"));
priviteMessage.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
if(StringUtils.isNotEmpty(userName)){ if(StringUtils.isNotEmpty(userName)){
try { try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default"))); Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default")));
} catch (Exception exp) { } catch (Exception exp) {
FRContext.getLogger().info(exp.getMessage());
} }
return; return;
} }
if(bbsLoginDialog == null){
bbsLoginDialog = new BBSLoginDialog(DesignerContext.getDesignerFrame(),UserInfoLabel.this);
} }
bbsLoginDialog.clearLoginInformation();
bbsLoginDialog.setModal(true); });
bbsLoginDialog.showWindow(); //切换账号
UIMenuItem closeOther = new UIMenuItem(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account"));
closeOther.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
UserLoginContext.fireLoginContextListener();
} }
});
menu.add(priviteMessage);
menu.add(closeOther);
GUICoreUtils.showPopupMenu(menu, UserInfoLabel.this, 0, MENU_HEIGHT);
} else {
UserLoginContext.fireLoginContextListener();
}
}
}; };
} }

17
designer/src/com/fr/design/mainframe/bbs/UserInfoPane.java

@ -40,8 +40,6 @@ public class UserInfoPane extends BasicPane{
private static final int WAIT_TIME = 10000; private static final int WAIT_TIME = 10000;
private UserInfoLabel userInfoLabel; private UserInfoLabel userInfoLabel;
private ExitLabel switchAccountLabel;
public UserInfoLabel getUserInfoLabel() { public UserInfoLabel getUserInfoLabel() {
return userInfoLabel; return userInfoLabel;
@ -51,13 +49,6 @@ public class UserInfoPane extends BasicPane{
this.userInfoLabel = userInfoLabel; this.userInfoLabel = userInfoLabel;
} }
public ExitLabel getSwitchAccountLabel() {
return switchAccountLabel;
}
public void setSwitchAccountLabel(ExitLabel switchAccountLabel) {
this.switchAccountLabel = switchAccountLabel;
}
/** /**
* 构造函数 * 构造函数
@ -67,14 +58,12 @@ public class UserInfoPane extends BasicPane{
this.setLayout(new BorderLayout()); this.setLayout(new BorderLayout());
this.userInfoLabel = new UserInfoLabel(this); this.userInfoLabel = new UserInfoLabel(this);
this.switchAccountLabel = new ExitLabel(this);
this.markUnSignIn(); this.markUnSignIn();
autoLogin(); autoLogin();
autoPushLoginDialog(); autoPushLoginDialog();
this.add(userInfoLabel, BorderLayout.CENTER); this.add(userInfoLabel, BorderLayout.CENTER);
this.add(switchAccountLabel, BorderLayout.EAST);
} }
// 后台自动登录 // 后台自动登录
@ -164,11 +153,9 @@ public class UserInfoPane extends BasicPane{
*/ */
public void markUnSignIn(){ public void markUnSignIn(){
this.userInfoLabel.setText(Inter.getLocText("FR-Base_UnSignIn")); this.userInfoLabel.setText(Inter.getLocText("FR-Base_UnSignIn"));
this.switchAccountLabel.setVisible(false);
this.userInfoLabel.setOpaque(true); this.userInfoLabel.setOpaque(true);
this.userInfoLabel.setBackground(UN_LOGIN_BACKGROUND); this.userInfoLabel.setBackground(UN_LOGIN_BACKGROUND);
this.userInfoLabel.resetUserName(); this.userInfoLabel.resetUserName();
} }
/** /**
@ -179,11 +166,8 @@ public class UserInfoPane extends BasicPane{
public void markSignIn(String userName){ public void markSignIn(String userName){
this.userInfoLabel.setText(userName); this.userInfoLabel.setText(userName);
this.userInfoLabel.setUserName(userName); this.userInfoLabel.setUserName(userName);
this.switchAccountLabel.setVisible(true);
this.userInfoLabel.setOpaque(true); this.userInfoLabel.setOpaque(true);
this.userInfoLabel.setBackground(LOGIN_BACKGROUND); this.userInfoLabel.setBackground(LOGIN_BACKGROUND);
this.switchAccountLabel.setOpaque(true);
this.switchAccountLabel.setBackground(LOGIN_BACKGROUND);
} }
@Override @Override
@ -191,5 +175,4 @@ public class UserInfoPane extends BasicPane{
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
} }

8
designer_base/src/com/fr/design/extra/LoginContextListener.java

@ -0,0 +1,8 @@
package com.fr.design.extra;
/**
* Created by lp on 2016/8/16.
*/
public interface LoginContextListener {
void showLoginContext();
}

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

@ -0,0 +1,43 @@
package com.fr.design.extra;
import com.fr.design.dialog.BasicPane;
import com.fr.general.Inter;
import com.fr.stable.StableUtils;
import java.awt.*;
import java.io.File;
import java.net.URL;
/**
* Created by zhaohehe on 16/7/27.
*/
public class LoginPane extends BasicPane {
private static final String LATEST = "latest";
public LoginPane() {
setLayout(new BorderLayout());
if (System.getProperty("java.version").startsWith("1.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"));
}
} else {
}
}
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");
}
}

187
designer_base/src/com/fr/design/extra/LoginWebBridge.java

@ -0,0 +1,187 @@
package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.dialog.UIDialog;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.DesignerContext;
import com.fr.general.FRLogger;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import javafx.scene.web.WebEngine;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URI;
import javax.swing.*;
import java.awt.*;
import java.net.URLEncoder;
/**
* Created by zhaohehe on 16/8/1.
*/
public class LoginWebBridge {
private static final String LOGIN_SUCCESS_FLAG = "http://bbs.finereport.com";
private static final int TIME_OUT = 10000;
private static com.fr.design.extra.LoginWebBridge helper;
private UIDialog uiDialog;
private UILabel uiLabel;
private boolean testConnection() {
HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test"));
return client.isServerAlive();
}
public static com.fr.design.extra.LoginWebBridge getHelper() {
if (helper != null) {
return helper;
}
synchronized (com.fr.design.extra.LoginWebBridge.class) {
if (helper == null) {
helper = new com.fr.design.extra.LoginWebBridge();
}
return helper;
}
}
public static com.fr.design.extra.LoginWebBridge getHelper(WebEngine webEngine) {
getHelper();
helper.setEngine(webEngine);
return helper;
}
private WebEngine webEngine;
private LoginWebBridge() {
}
public void setEngine(WebEngine webEngine) {
this.webEngine = webEngine;
}
public void setDialogHandle(UIDialog uiDialog) {
this.uiDialog = uiDialog;
}
public void setUILabel(UILabel uiLabel) {
this.uiLabel = uiLabel;
}
/**
* 注册页面
*/
public void registerHref() {
try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default")));
}catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
}
}
/**
* 忘记密码
*/
public void forgetHref() {
try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default")));
}catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
}
}
/**
* 登录操作的回调
* @param username
* @param password
* @param callback
* @return
*/
public String defaultLogin(String username, String password) {
if (!StringUtils.isNotBlank(username) && !StringUtils.isNotBlank(password)) {
//用户名密码为空
return "-1";
}
if (!testConnection()) {
//网络测试连接不通过
return "-2";
}
if (login(username, password)) {
updateUserInfo(username, password);
loginSuccess(username);
return "0";
}else {
return "-3";
}
}
/**
* 关闭窗口
*/
public void closeWindow() {
if (uiDialog != null) {
uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
uiDialog.setVisible(false);
}
}
public void updateUserInfo(String username,String password) {
DesignerEnvManager.getEnvManager().setBBSName(username);
DesignerEnvManager.getEnvManager().setBBSPassword(password);
}
/**
* 关闭窗口并且重新赋值
* @param username
*/
public void loginSuccess(String username) {
closeWindow();
uiLabel.setText(username);
}
/**
* 弹出QQ授权页面
*/
public void showQQ() {
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);
}
});
}
public boolean login(String username, String password) {
if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
try {
username = URLEncoder.encode(username, EncodeConstants.ENCODING_GBK);
password = URLEncoder.encode(password, EncodeConstants.ENCODING_GBK);
} catch (UnsupportedEncodingException e) {
FRLogger.getLogger().error(e.getMessage());
}
String url = SiteCenter.getInstance().acquireUrlByKind("bbs.login") + "&username=" + username + "&password=" + password;
HttpClient client = new HttpClient(url);
client.setTimeout(TIME_OUT);
if (client.getResponseCodeNoException() == HttpURLConnection.HTTP_OK) {
try {
String res = client.getResponseText(EncodeConstants.ENCODING_GBK);
if (res.contains(LOGIN_SUCCESS_FLAG)) {
return true;
}
} catch (Exception e) {
FRLogger.getLogger().error(e.getMessage());
}
}
}
return false;
}
}

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

@ -0,0 +1,61 @@
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 zhaohehe on 16/7/26.
*/
public class LoginWebPane extends JFXPanel {
private WebEngine webEngine;
private LoginPane loginPane;
public LoginWebPane(final String installHome,LoginPane loginPane) {
this.loginPane = loginPane;
Platform.setImplicitExit(false);
Platform.runLater(new Runnable() {
@Override
public void run() {
BorderPane root = new BorderPane();
Scene scene = new Scene(root);
LoginWebPane.this.setScene(scene);
WebView webView = new WebView();
webEngine = webView.getEngine();
webEngine.load("file:///" + installHome + "/scripts/store/web/login.html");
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() {
@Override
public void handle(WebEvent<String> event) {
showAlert(event.getData());
}
});
JSObject obj = (JSObject) webEngine.executeScript("window");
obj.setMember("LoginHelper", LoginWebBridge.getHelper(webEngine));
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
public void run() {
JOptionPane.showMessageDialog(LoginWebPane.this, message);
}
});
}
}

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

@ -6,6 +6,7 @@ import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.exe.*; import com.fr.design.extra.exe.*;
import com.fr.general.FRLogger; import com.fr.general.FRLogger;
import com.fr.general.Inter; import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import com.fr.plugin.Plugin; import com.fr.plugin.Plugin;
import com.fr.plugin.PluginLicense; import com.fr.plugin.PluginLicense;
import com.fr.plugin.PluginLicenseManager; import com.fr.plugin.PluginLicenseManager;
@ -361,6 +362,42 @@ public class PluginWebBridge {
return false; return false;
} }
/**
* 获取系统登录的用户名
* @param callback
*/
public void getLoginInfo(final JSObject callback) {
Task<Void> task = new PluginTask<>(webEngine, callback, new GetLoginInfoExecutor());
new Thread(task).start();
}
/**
* 打开论坛消息界面
*/
public void getPriviteMessage() {
try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default")));
}catch (Exception exp) {
FRContext.getLogger().info(exp.getMessage());
}
}
/**
* 打开登录页面
*/
public void loginContent() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
UserLoginContext.fireLoginContextListener();
}
});
}
public void getUsername() {
}
/** /**
* 在本地浏览器里打开url * 在本地浏览器里打开url
* tips:重载的时候,需要给js调用的方法需要放在前面,否则可能不会被调用(此乃坑) * tips:重载的时候,需要给js调用的方法需要放在前面,否则可能不会被调用(此乃坑)

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

@ -0,0 +1,34 @@
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;
import javax.swing.*;
import java.awt.*;
/**
* Created by zhaohehe on 16/7/28.
*/
public class QQLoginDialog extends UIDialog {
private static final Dimension DEFAULT_SHOP = new Dimension(700, 500);
public QQLoginDialog(Frame frame, BasicPane pane) {
super(frame);
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
public void checkValid() throws Exception {
}
}

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

@ -0,0 +1,44 @@
package com.fr.design.extra;
import com.fr.design.dialog.BasicPane;
import com.fr.general.Inter;
import com.fr.stable.StableUtils;
import java.awt.*;
import java.io.File;
import java.net.URL;
/**
* Created by zhaohehe on 16/7/28.
*/
public class QQLoginPane extends BasicPane {
private static final String LATEST = "latest";
public QQLoginPane() {
setLayout(new BorderLayout());
if (System.getProperty("java.version").startsWith("1.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"));
}
} 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");
}
}

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

@ -0,0 +1,103 @@
package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.design.DesignerEnvManager;
import com.fr.design.dialog.UIDialog;
import com.fr.design.gui.ilable.UILabel;
import javafx.scene.web.WebEngine;
import org.json.JSONObject;
import javax.swing.*;
/**
* 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 UIDialog uiDialog;
private UILabel uiLabel;
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 setLoginlabel() {
username = DesignerEnvManager.getEnvManager().getBBSName();
}
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();
closeQQWindow();
closeParentWindow();
//设置label的用户名
uiLabel.setText(username);
}else {
}
}
}

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

@ -0,0 +1,55 @@
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 zhaohehe on 16/7/28.
*/
public class QQLoginWebPane extends JFXPanel {
private WebEngine webEngine;
public QQLoginWebPane(final String installHome) {
Platform.setImplicitExit(false);
Platform.runLater(new Runnable() {
@Override
public void run() {
BorderPane root = new BorderPane();
Scene scene = new Scene(root);
QQLoginWebPane.this.setScene(scene);
WebView webView = new WebView();
webEngine = webView.getEngine();
webEngine.load("file:///" + installHome + "/scripts/store/web/qqLogin.html");
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() {
@Override
public void handle(WebEvent<String> event) {
showAlert(event.getData());
}
});
JSObject obj = (JSObject) webEngine.executeScript("window");
obj.setMember("QQLoginHelper", QQLoginWebBridge.getHelper(webEngine));
webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView);
}
});
}
private void showAlert(final String message) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(QQLoginWebPane.this, message);
}
});
}
}

28
designer_base/src/com/fr/design/extra/UserLoginContext.java

@ -0,0 +1,28 @@
package com.fr.design.extra;
import java.util.ArrayList;
/**
* Created by lp on 2016/8/16.
*/
public class UserLoginContext {
private static ArrayList<LoginContextListener> fireLoginContextListener = new ArrayList<LoginContextListener>();
/**
* 触发登录框弹出的监听器
*/
public static void fireLoginContextListener() {
for (LoginContextListener l : fireLoginContextListener) {
l.showLoginContext();
}
}
/**
* 添加一个弹出登录框的监听事件
*
* @param l 登录框弹出监听事件
*/
public static void addLoginContextListener(LoginContextListener l) {
fireLoginContextListener.add(l);
}
}

37
designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java

@ -0,0 +1,37 @@
package com.fr.design.extra.exe;
import com.fr.design.DesignerEnvManager;
import com.fr.design.extra.Process;
/**
* Created by lp on 2016/8/16.
*/
public class GetLoginInfoExecutor implements Executor {
private String result = "[]";
@Override
public String getTaskFinishMessage() {
return result;
}
@Override
public Command[] getCommands() {
return new Command[]{
new Command() {
@Override
public String getExecuteMessage() {
return null;
}
@Override
public void run(Process<String> process) {
String username = DesignerEnvManager.getEnvManager().getBBSName();
if (username == null) {
}else {
result = username;
}
}
}
};
}
}
Loading…
Cancel
Save