|
|
@ -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,31 +83,41 @@ 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; |
|
|
|
} |
|
|
|
} |
|
|
|
LoginWebBridge.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) { |
|
|
@ -114,11 +128,6 @@ public class QQLoginWebPane extends JFXPanel { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
webView.setContextMenuEnabled(false);//屏蔽右键
|
|
|
|
|
|
|
|
root.setCenter(webView); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void showAlert(final String message) { |
|
|
|
private void showAlert(final String message) { |
|
|
@ -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(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |