From 04a90491bfd60a02ec1487cd8e50365557832924 Mon Sep 17 00:00:00 2001 From: hades Date: Mon, 1 Jun 2020 10:48:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?KERNEL-4069=20JDK11=E9=80=82=E9=85=8D=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8=E7=9A=84=E7=B1=BB=E4=B8=8E?= =?UTF-8?q?mac=E4=B8=8B=E7=9A=84=E9=80=82=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/extra/LoginWebBridge.java | 12 - .../com/fr/design/extra/PluginWebBridge.java | 7 - .../com/fr/design/extra/QQLoginWebPane.java | 234 ------------------ .../com/fr/design/extra/WebViewDlgHelper.java | 15 -- .../os/impl/MacOsAddListenerAction.java | 11 +- 5 files changed, 10 insertions(+), 269 deletions(-) delete mode 100644 designer-base/src/main/java/com/fr/design/extra/QQLoginWebPane.java diff --git a/designer-base/src/main/java/com/fr/design/extra/LoginWebBridge.java b/designer-base/src/main/java/com/fr/design/extra/LoginWebBridge.java index 471e25109..0862c7447 100644 --- a/designer-base/src/main/java/com/fr/design/extra/LoginWebBridge.java +++ b/designer-base/src/main/java/com/fr/design/extra/LoginWebBridge.java @@ -196,18 +196,6 @@ public class LoginWebBridge { uiLabel.setBackground(LOGIN_BACKGROUND); } - /** - * 弹出QQ授权页面 - */ - public void showQQ() { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - WebViewDlgHelper.createQQLoginDialog(); - } - }); - } - /** * 关闭QQ授权窗口 */ diff --git a/designer-base/src/main/java/com/fr/design/extra/PluginWebBridge.java b/designer-base/src/main/java/com/fr/design/extra/PluginWebBridge.java index 10f65fa2b..159e6d6d9 100644 --- a/designer-base/src/main/java/com/fr/design/extra/PluginWebBridge.java +++ b/designer-base/src/main/java/com/fr/design/extra/PluginWebBridge.java @@ -533,13 +533,6 @@ public class PluginWebBridge { threadPoolExecutor.submit(task); } - /** - * 弹出QQ授权页面 - */ - public void showQQ() { - LoginWebBridge.getHelper().showQQ(); - } - /** * 通过QQ登录后通知登录 */ diff --git a/designer-base/src/main/java/com/fr/design/extra/QQLoginWebPane.java b/designer-base/src/main/java/com/fr/design/extra/QQLoginWebPane.java deleted file mode 100644 index 9c56738b4..000000000 --- a/designer-base/src/main/java/com/fr/design/extra/QQLoginWebPane.java +++ /dev/null @@ -1,234 +0,0 @@ -package com.fr.design.extra; - -import com.fr.design.dialog.FineJOptionPane; -import com.fr.general.CloudCenter; -import com.fr.general.ComparatorUtils; -import com.fr.general.IOUtils; -import com.fr.log.FineLoggerFactory; -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.Modality; -import javafx.stage.Screen; -import javafx.stage.Stage; -import javafx.stage.StageStyle; -import javafx.stage.WindowEvent; -import javafx.util.Callback; -import netscape.javascript.JSObject; - -import javax.swing.JOptionPane; -import javax.swing.SwingUtilities; -import java.awt.Toolkit; - -/** - * Created by zhaohehe on 16/7/28. - */ -public class QQLoginWebPane extends JFXPanel { - - private WebEngine webEngine; - private String url; - - 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() { - @Override - public void run() { - BorderPane root = new BorderPane(); - Scene scene = new Scene(root); - QQLoginWebPane.this.setScene(scene); - final WebView webView = new WebView(); - webEngine = webView.getEngine(); - url = "file:///" + installHome + "/scripts/qqLogin.html"; - webEngine.load(url); - - final Stage primaryStage = new Stage(); - - HBox layout = new HBox(); - try { - primaryStage.initStyle(StageStyle.TRANSPARENT); - primaryStage.setScene(new Scene(layout)); - webView.getScene().getStylesheets().add(IOUtils.getResource("modal-dialog.css", getClass()).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) { - FineLoggerFactory.getLogger().info(e.getMessage()); - } - webEngine.setConfirmHandler(new Callback() { - @Override - public Boolean call(String msg) { - Boolean confirmed = confirm(primaryStage, msg, webView); - return confirmed; - } - }); - configWebEngine(); - webView.setContextMenuEnabled(false);//屏蔽右键 - root.setCenter(webView); - } - }); - } - - private void configWebEngine() { - - webEngine.locationProperty().addListener(new ChangeListener() { - @Override - public void changed(ObservableValue observable, final String oldValue, String newValue) { - disableLink(webEngine); - // webView好像默认以手机版显示网页,浏览器里过滤掉这个跳转 - if (ComparatorUtils.equals(newValue, url) || ComparatorUtils.equals(newValue, CloudCenter.getInstance().acquireUrlByKind("bbs.mobile"))) { - return; - } - LoginWebBridge.getHelper().openUrlAtLocalWebBrowser(webEngine, newValue); - } - }); - - webEngine.setOnAlert(new EventHandler>() { - @Override - public void handle(WebEvent event) { - showAlert(event.getData()); - } - }); - - webEngine.getLoadWorker().stateProperty().addListener( - new ChangeListener() { - public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) { - if (newState == Worker.State.SUCCEEDED) { - window = (JSObject) webEngine.executeScript("window"); - window.setMember("QQLoginHelper", LoginWebBridge.getHelper()); - } - } - } - ); - } - - private void showAlert(final String message) { - SwingUtilities.invokeLater(new Runnable() { - @Override - public void run() { - FineJOptionPane.showMessageDialog(QQLoginWebPane.this, message); - } - }); - } - - private void disableLink(final WebEngine eng) { - try { - // webView端不跳转 虽然webView可以指定本地浏览器打开某个链接,但是当本地浏览器跳转到指定链接的同时,webView也做了跳转, - // 为了避免出现在一个600*400的资讯框里加载整个网页的情况,webView不跳转到新网页 - Platform.runLater(new Runnable() { - @Override - public void run() { - eng.executeScript("location.reload()"); - LoginWebBridge.getHelper().closeQQWindow(); - } - }); - } catch (Exception e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); - } - } - - private Boolean confirm(final Stage parent, String msg, final WebView webView) { - final BooleanProperty confirmationResult = new SimpleBooleanProperty(); - // initialize the confirmation dialog - final Stage dialog = new Stage(StageStyle.UTILITY); - dialog.setX(Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2 - DEFAULT_CONFIRM_WIDTH / 2.0D + 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.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(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_BBSLogin_Switch_Account")).defaultButton(true).onAction(new EventHandler() { - @Override - public void handle(ActionEvent actionEvent) { - // take action and close the dialog. - confirmationResult.set(true); - webView.getEngine().reload(); - dialog.close(); - } - }).build(), - ButtonBuilder.create().text(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Engine_Cancel")).cancelButton(true).onAction(new EventHandler() { - @Override - public void handle(ActionEvent actionEvent) { - // abort action and close the dialog. - confirmationResult.set(false); - dialog.close(); - } - }).build() - ).build() - , Color.TRANSPARENT - ) - ); - configDrag(dialog); - // style and show the dialog. - dialog.getScene().getStylesheets().add(IOUtils.getResource("modal-dialog.css", getClass()).toExternalForm()); - dialog.setOnCloseRequest(new EventHandler() { - @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. - final Node root = dialog.getScene().getRoot(); - final Delta dragDelta = new Delta(); - - root.setOnMousePressed(new EventHandler() { - @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() { - @Override - public void handle(MouseEvent mouseEvent) { - dialog.setX(mouseEvent.getScreenX() + dragDelta.x); - dialog.setY(mouseEvent.getScreenY() + dragDelta.y); - } - }); - } -} diff --git a/designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java b/designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java index 47d154146..2dea7108e 100644 --- a/designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java +++ b/designer-base/src/main/java/com/fr/design/extra/WebViewDlgHelper.java @@ -184,21 +184,6 @@ public class WebViewDlgHelper { } } - public static void createQQLoginDialog() { - try { - Class clazz = Class.forName("com.fr.design.extra.QQLoginWebPane"); - Constructor constructor = clazz.getConstructor(String.class); - Component webPane = (Component) constructor.newInstance(new File(installHome).getAbsolutePath()); - - UIDialog qqLoginDialog = new QQLoginDialog(DesignerContext.getDesignerFrame(), webPane); - LoginWebBridge.getHelper().setQQDialog(qqLoginDialog); - qqLoginDialog.setVisible(true); - } catch (Throwable ignored) { - // ignored - } - } - - private static void confirmDownLoadShopJS() { int rv = FineJOptionPane.showConfirmDialog( null, diff --git a/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java b/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java index 6386ecd73..3dd462b8f 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java @@ -9,6 +9,7 @@ import com.fr.invoke.Reflect; import com.fr.log.FineLoggerFactory; import com.fr.stable.os.support.OSBasedAction; +import java.awt.*; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; import java.lang.reflect.Proxy; @@ -32,7 +33,15 @@ public class MacOsAddListenerAction implements OSBasedAction { Reflect.on(application).call("setQuitHandler", quitInstance) .call("setAboutHandler", aboutInstance); } catch (ClassNotFoundException e) { - FineLoggerFactory.getLogger().error(e.getMessage(), e); + try { + Class quitHandler = Class.forName("java.awt.desktop.QuitHandler"); + Object quitInstance = getProxy(quitHandler, "handleQuitRequestWith", new QuitAction()); + Class aboutHandler = Class.forName("java.awt.desktop.AboutHandler"); + Object aboutInstance = getProxy(aboutHandler, "handleAbout", new AboutAction()); + Reflect.on(Desktop.getDesktop()).call("setQuitHandler", quitInstance).call("setAboutHandler", aboutInstance); + } catch (ClassNotFoundException ex) { + FineLoggerFactory.getLogger().error(ex.getMessage(), ex); + } } } From ff753001c487d64032ecb95aef35b7cffe418701 Mon Sep 17 00:00:00 2001 From: hades Date: Mon, 1 Jun 2020 11:50:11 +0800 Subject: [PATCH 2/2] =?UTF-8?q?KERNEL-4069=20=E6=B7=BB=E5=8A=A0=E6=B3=A8?= =?UTF-8?q?=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/os/impl/MacOsAddListenerAction.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java b/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java index 3dd462b8f..d2ab57620 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/MacOsAddListenerAction.java @@ -15,6 +15,10 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; /** + * com.apple.eawt.Application属于jdk1.8及以下mac jdk特有的api + * 在jdk9中被移除,由Desktop.getDesktop().setQuitHandler等jdk9.0引入的新api替代 + * 参见 https://stackoverflow.com/questions/38381824/how-can-i-use-apple-com-apple-eawt-functionality-on-java-8 + * * @author hades * @version 10.0 * Created by hades on 2020/3/13 @@ -33,6 +37,8 @@ public class MacOsAddListenerAction implements OSBasedAction { Reflect.on(application).call("setQuitHandler", quitInstance) .call("setAboutHandler", aboutInstance); } catch (ClassNotFoundException e) { + // 上面的不能移除,同时要保证再jdk1.8下面能运行 + // 抛出异常时 说明使用>=jdk9运行行设计器,但由于编译使用1.8构建,使用反射运行 try { Class quitHandler = Class.forName("java.awt.desktop.QuitHandler"); Object quitInstance = getProxy(quitHandler, "handleQuitRequestWith", new QuitAction());