Browse Source

Merge pull request #312 in BA/design from ~LEE/design:dev to dev

* commit 'ba40379e97ea38e0fc41401433fa9545a5af267f':
  QQ授权切换账号的时候的confirm用javafx重新获取,重写处理
master
superman 8 years ago
parent
commit
71150e11fc
  1. 7
      designer/src/com/fr/design/mainframe/bbs/UserInfoLabel.java
  2. 10
      designer_base/src/com/fr/design/DesignerEnvManager.java
  3. 110
      designer_base/src/com/fr/design/extra/LoginWebBridge.java
  4. 3
      designer_base/src/com/fr/design/extra/QQLoginWebBridge.java
  5. 130
      designer_base/src/com/fr/design/extra/QQLoginWebPane.java
  6. 5
      designer_base/src/com/fr/design/extra/exe/GetLoginInfoExecutor.java
  7. 36
      designer_base/src/com/fr/design/extra/modal-dialog.css

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

@ -78,7 +78,10 @@ public class UserInfoLabel extends UILabel{
this.addMouseListener(userInfoAdapter);
this.setHorizontalAlignment(SwingConstants.CENTER);
this.setText(userName);
setUserName(userName);
LoginWebBridge loginWebBridge = new LoginWebBridge();
loginWebBridge.setUserName(userName, UserInfoLabel.this);
LoginCheckContext.addLoginCheckListener(new LoginCheckListener() {
@Override
public void loginChecked() {
@ -187,7 +190,6 @@ public class UserInfoLabel extends UILabel{
if(StringUtils.isEmpty(this.userName)){
updateMessageCount();
}
//往designerenvmanger里写一下
DesignerEnvManager.getEnvManager().setBBSName(userName);
this.userName = userName;
@ -216,7 +218,6 @@ public class UserInfoLabel extends UILabel{
} catch (Exception e) {
}
}
sleep(CHECK_MESSAGE_TIME);
}
}

10
designer_base/src/com/fr/design/DesignerEnvManager.java

@ -93,6 +93,8 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
private String bbsName;
//当前设计器用户的论坛密码
private String bbsPassword;
//当前设计器用户的昵称显示(带消息)
private String inShowBBsName;
//上一次登录弹窗的时间, 为了控制一天只弹一次窗口
private String lastShowBBSTime;
//上一次资讯弹窗时间, 为了控制一天只弹一次
@ -1148,6 +1150,14 @@ public class DesignerEnvManager implements XMLReadable, XMLWriter {
public void setBBSPassword(String bbsPassword) {
this.bbsPassword = bbsPassword;
}
public void setInShowBBsName(String inShowBBsName) {
this.inShowBBsName = inShowBBsName;
}
public String getInShowBBsName() {
return inShowBBsName;
}
public String getLastShowBBSTime() {
return lastShowBBSTime;

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

@ -8,6 +8,7 @@ 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.json.JSONObject;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import javafx.scene.web.WebEngine;
@ -18,12 +19,21 @@ import java.net.URI;
import javax.swing.*;
import java.awt.*;
import java.net.URLEncoder;
import java.util.HashMap;
/**
* Created by zhaohehe on 16/8/1.
*/
public class LoginWebBridge {
//默认查询消息时间, 30s
private static final long CHECK_MESSAGE_TIME = 30 * 1000L;
//数据查询正常的标志 ok
private static final String SUCCESS_MESSAGE_STATUS = "ok";
//消息条数
private int messageCount;
//最低消息的条数
private static final int MIN_MESSAGE_COUNT = 0;
private static final String LOGIN_SUCCESS_FLAG = "http://bbs.finereport.com";
private static final String LOGININ = "0";
private static final String LOGIN_INFO_EMPTY = "-1";
@ -34,6 +44,11 @@ public class LoginWebBridge {
private static com.fr.design.extra.LoginWebBridge helper;
private UIDialog uiDialog;
private UILabel uiLabel;
private String userName;
public int getMessageCount() {
return messageCount;
}
private boolean testConnection() {
HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test"));
@ -60,9 +75,6 @@ public class LoginWebBridge {
private WebEngine webEngine;
private LoginWebBridge() {
}
public void setEngine(WebEngine webEngine) {
this.webEngine = webEngine;
}
@ -75,6 +87,90 @@ public class LoginWebBridge {
this.uiLabel = uiLabel;
}
public LoginWebBridge() {
String username = DesignerEnvManager.getEnvManager().getBBSName();
setUserName(username, uiLabel);
}
public void setUserName(String userName, UILabel label) {
if (uiLabel == null) {
this.uiLabel = label;
}
if(StringUtils.isEmpty(userName)){
return;
}
if(!StringUtils.isEmpty(this.userName)){
updateMessageCount();
}
//往designerenvmanger里写一下
DesignerEnvManager.getEnvManager().setBBSName(userName);
this.userName = userName;
}
private void updateMessageCount(){
//启动获取消息更新的线程
//登陆状态, 根据存起来的用户名密码, 每1分钟发起一次请求, 更新消息条数.
Thread updateMessageThread = new Thread(new Runnable() {
@Override
public void run() {
sleep(CHECK_MESSAGE_TIME);
//从env中获取username, 因为如果注销的话, env的里username会被清空.
while(StringUtils.isNotEmpty(DesignerEnvManager.getEnvManager().getBBSName())){
HashMap<String, String> para = new HashMap<String, String>();
para.put("username", encode(encode(userName)));
HttpClient getMessage = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.message"), para);
getMessage.asGet();
if(getMessage.isServerAlive()){
try {
String res = getMessage.getResponseText();
JSONObject jo = new JSONObject(res);
if (jo.getString("status").equals(SUCCESS_MESSAGE_STATUS)) {
setMessageCount(Integer.parseInt(jo.getString("message")));
}
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
}
}
sleep(CHECK_MESSAGE_TIME);
}
}
});
updateMessageThread.start();
}
public void setMessageCount(int count) {
if (count == MIN_MESSAGE_COUNT) {
uiLabel.setText(DesignerEnvManager.getEnvManager().getBBSName());
DesignerEnvManager.getEnvManager().setInShowBBsName(DesignerEnvManager.getEnvManager().getBBSName());
return;
}
this.messageCount = count;
StringBuilder sb = new StringBuilder();
sb.append(StringUtils.BLANK).append(this.userName)
.append("(").append(this.messageCount)
.append(")").append(StringUtils.BLANK);
DesignerEnvManager.getEnvManager().setInShowBBsName(sb.toString());
uiLabel.setText(sb.toString());
}
private String encode(String str){
try {
return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8);
} catch (UnsupportedEncodingException e) {
return str;
}
}
private void sleep(long millis){
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
FRContext.getLogger().error(e.getMessage());
}
}
/**
* 注册页面
*/
@ -113,6 +209,7 @@ public class LoginWebBridge {
if (login(username, password)) {
updateUserInfo(username, password);
loginSuccess(username);
setUserName(username, uiLabel);
return LOGININ;
}else {
return LOGININFO_ERROR;
@ -152,6 +249,7 @@ public class LoginWebBridge {
public void updateUserInfo(String username,String password) {
DesignerEnvManager.getEnvManager().setBBSName(username);
DesignerEnvManager.getEnvManager().setBBSPassword(password);
this.userName = username;
}
/**

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

@ -7,6 +7,7 @@ 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.*;
@ -68,6 +69,8 @@ public class QQLoginWebBridge {
username = DesignerEnvManager.getEnvManager().getBBSName();
}
private static JSObject window;
public static com.fr.design.extra.QQLoginWebBridge getHelper(WebEngine webEngine) {
getHelper();
helper.setEngine(webEngine);

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

@ -1,21 +1,38 @@
package com.fr.design.extra;
import com.fr.base.FRContext;
import com.fr.general.ComparatorUtils;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.SiteCenter;
import javafx.application.Platform;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.embed.swing.JFXPanel;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.ButtonBuilder;
import javafx.scene.control.LabelBuilder;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.HBoxBuilder;
import javafx.scene.paint.Color;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebEvent;
import javafx.scene.web.WebView;
import javafx.stage.*;
import javafx.util.Callback;
import netscape.javascript.JSObject;
import javax.swing.*;
import java.awt.*;
/**
* Created by zhaohehe on 16/7/28.
@ -24,6 +41,17 @@ public class QQLoginWebPane extends JFXPanel {
private WebEngine webEngine;
private static JSObject window;
private static int DEFAULT_PRIMARYSTAGE_WIDTH = 100;
private static int DEFAULT_PRIMARYSTAGE_HEIGHT = 100;
private static int DEFAULT_CONFIRM_WIDTH = 450;
private static int DEFAULT_CONFIRM_HEIGHT = 160;
private static int DEFAULT_OFFEST = 20;
class Delta { double x, y; }
public QQLoginWebPane(final String installHome) {
Platform.setImplicitExit(false);
Platform.runLater(new Runnable() {
@ -32,9 +60,33 @@ public class QQLoginWebPane extends JFXPanel {
BorderPane root = new BorderPane();
Scene scene = new Scene(root);
QQLoginWebPane.this.setScene(scene);
WebView webView = new WebView();
final WebView webView = new WebView();
webEngine = webView.getEngine();
webEngine.load("file:///" + installHome + "/scripts/qqLogin/web/qqLogin.html");
final Stage primaryStage = new Stage();
HBox layout = new HBox();
try {
primaryStage.initStyle(StageStyle.TRANSPARENT);
primaryStage.setScene(new Scene(layout));
webView.getScene().getStylesheets().add(getClass().getResource("modal-dialog.css").toExternalForm());
primaryStage.initStyle(StageStyle.UTILITY);
primaryStage.setScene(new Scene(new Group(), DEFAULT_PRIMARYSTAGE_WIDTH, DEFAULT_PRIMARYSTAGE_HEIGHT));
primaryStage.setX(0);
primaryStage.setY(Screen.getPrimary().getBounds().getHeight() + DEFAULT_PRIMARYSTAGE_HEIGHT);
primaryStage.show();
}catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
}
webView.getEngine().setConfirmHandler(new Callback<String, Boolean>() {
@Override public Boolean call(String msg) {
Boolean confirmed = confirm(primaryStage, msg, installHome, webView);
return confirmed;
}
});
webEngine.locationProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, final String oldValue, String newValue) {
@ -52,8 +104,12 @@ public class QQLoginWebPane extends JFXPanel {
showAlert(event.getData());
}
});
JSObject obj = (JSObject) webEngine.executeScript("window");
obj.setMember("QQLoginHelper", QQLoginWebBridge.getHelper(webEngine));
webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends Worker.State> observable, Worker.State oldValue, Worker.State newValue) -> {
if (newValue == Worker.State.SUCCEEDED) {
window = (JSObject) webEngine.executeScript("window");
window.setMember("QQLoginHelper", QQLoginWebBridge.getHelper(webEngine));
}
});
webView.setContextMenuEnabled(false);//屏蔽右键
root.setCenter(webView);
}
@ -84,4 +140,72 @@ public class QQLoginWebPane extends JFXPanel {
FRLogger.getLogger().error(e.getMessage());
}
}
private Boolean confirm(final Stage parent, String msg, final String installHome,final WebView webView) {
final BooleanProperty confirmationResult = new SimpleBooleanProperty();
// initialize the confirmation dialog
final Stage dialog = new Stage(StageStyle.UTILITY);
dialog.setTitle(Inter.getLocText("FR-Designer-BBSLogin_Switch-Account"));
dialog.setX(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2 - DEFAULT_CONFIRM_WIDTH / 2 + DEFAULT_OFFEST);
dialog.setY(Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2 + DEFAULT_OFFEST);
dialog.setHeight(DEFAULT_CONFIRM_HEIGHT);
dialog.setWidth(DEFAULT_CONFIRM_WIDTH);
dialog.setIconified(false);
dialog.setAlwaysOnTop(true);
dialog.initOwner(parent);
dialog.initModality(Modality.WINDOW_MODAL);
dialog.setScene(
new Scene(
HBoxBuilder.create().styleClass("modal-dialog").children(
LabelBuilder.create().text(msg).build(),
ButtonBuilder.create().text(Inter.getLocText("")).defaultButton(true).onAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
// take action and close the dialog.
confirmationResult.set(true);
webView.getEngine().reload();
dialog.close();
}
}).build(),
ButtonBuilder.create().text(Inter.getLocText("FR-Engine_Cancel")).cancelButton(true).onAction(new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent actionEvent) {
// abort action and close the dialog.
confirmationResult.set(false);
dialog.close();
}
}).build()
).build()
, Color.TRANSPARENT
)
);
// allow the dialog to be dragged around.
final Node root = dialog.getScene().getRoot();
final Delta dragDelta = new Delta();
root.setOnMousePressed(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
// record a delta distance for the drag and drop operation.
dragDelta.x = dialog.getX() - mouseEvent.getScreenX();
dragDelta.y = dialog.getY() - mouseEvent.getScreenY();
}
});
root.setOnMouseDragged(new EventHandler<MouseEvent>() {
@Override public void handle(MouseEvent mouseEvent) {
dialog.setX(mouseEvent.getScreenX() + dragDelta.x);
dialog.setY(mouseEvent.getScreenY() + dragDelta.y);
}
});
// style and show the dialog.
dialog.getScene().getStylesheets().add(getClass().getResource("modal-dialog.css").toExternalForm());
dialog.setOnCloseRequest(new EventHandler<WindowEvent>(){
@Override
public void handle(WindowEvent event){
event.consume();
dialog.close();
}
});
dialog.showAndWait();
return confirmationResult.get();
}
}

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

@ -27,9 +27,10 @@ public class GetLoginInfoExecutor implements Executor {
@Override
public void run(Process<String> process) {
String username = DesignerEnvManager.getEnvManager().getBBSName();
if (StringUtils.isEmpty(username)) {
String inShowUsername = DesignerEnvManager.getEnvManager().getInShowBBsName();
if (StringUtils.isEmpty(username) && StringUtils.isEmpty(inShowUsername)) {
}else {
result = username;
result = inShowUsername;
}
}
}

36
designer_base/src/com/fr/design/extra/modal-dialog.css

@ -0,0 +1,36 @@
/**
* modal-dialog.css
* place in same directory as WebViewConfirm.java
* ensure your build system copies the file to your build output directory
*/
.root {
-fx-glass-color: white;
}
.modal-dialog {
-fx-padding: 20;
-fx-spacing: 10;
-fx-alignment: center;
-fx-font-size: 14;
-fx-background-color: linear-gradient(to bottom, derive(-fx-glass-color, 20%), -fx-glass-color);
-fx-border-color: derive(-fx-glass-color, -20%);
-fx-border-width: 5;
-fx-background-insets: 12;
-fx-border-insets: 10;
-fx-border-radius: 6;
-fx-background-radius: 6;
}
.modal-dialog:pressed {
-fx-cursor: move;
}
.modal-dialog .button:pressed {
-fx-cursor: default;
}
.confirmation-results {
-fx-background-color: cornsilk;
-fx-padding: 5;
}
Loading…
Cancel
Save