From b39cc4dd83df49f833a7b6387aad09aced975ab5 Mon Sep 17 00:00:00 2001 From: vito Date: Tue, 12 Apr 2016 18:58:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=92=A8=E8=AF=A2=E6=A1=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/bbs/BBSDialog.java | 6 ++- .../fr/design/mainframe/bbs/BBSWebBridge.java | 51 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 designer/src/com/fr/design/mainframe/bbs/BBSWebBridge.java diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java index 52cd59165..480fec939 100644 --- a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java +++ b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java @@ -14,6 +14,7 @@ import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.web.WebEngine; import javafx.scene.web.WebView; +import netscape.javascript.JSObject; import javax.swing.*; @@ -43,6 +44,7 @@ public class BBSDialog extends UIDialog { JPanel panel = (JPanel) getContentPane(); initComponents(panel); setSize(new Dimension(OUTER_WIDTH, OUTER_HEIGHT)); + BBSWebBridge.getHelper().setDialogHandle(this); } private void initComponents(JPanel contentPane) { @@ -58,6 +60,8 @@ public class BBSDialog extends UIDialog { Platform.runLater(new Runnable() { @Override public void run() { + JSObject obj = (JSObject) eng.executeScript("window"); + obj.setMember("BBSWebBridge", BBSWebBridge.getHelper(eng)); eng.executeScript("history.go(0)"); } }); @@ -112,7 +116,7 @@ public class BBSDialog extends UIDialog { } }); } - + // 在本地浏览器里打开url private void openUrlAtLocalWebBrowser(WebEngine eng,String url){ if(Desktop.isDesktopSupported()){ diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSWebBridge.java b/designer/src/com/fr/design/mainframe/bbs/BBSWebBridge.java new file mode 100644 index 000000000..283a12d6a --- /dev/null +++ b/designer/src/com/fr/design/mainframe/bbs/BBSWebBridge.java @@ -0,0 +1,51 @@ +package com.fr.design.mainframe.bbs; + +import com.fr.design.dialog.UIDialog; +import javafx.scene.web.WebEngine; + +import javax.swing.*; + +/** + * Created by vito on 16/4/12. + */ +public class BBSWebBridge { + private static BBSWebBridge bbsWebBridge; + private WebEngine webEngine; + private UIDialog uiDialog; + + public static BBSWebBridge getHelper() { + if (bbsWebBridge != null) { + return bbsWebBridge; + } + synchronized (BBSWebBridge.class) { + if (bbsWebBridge == null) { + bbsWebBridge = new BBSWebBridge(); + } + return bbsWebBridge; + } + } + + public static BBSWebBridge getHelper(WebEngine webEngine) { + getHelper(); + bbsWebBridge.setEngine(webEngine); + return bbsWebBridge; + } + + private void setEngine(WebEngine webEngine) { + this.webEngine = webEngine; + } + + private BBSWebBridge() {} + + public void closeWindow() { + if (uiDialog != null) { + uiDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + uiDialog.setVisible(false); + uiDialog.dispose(); + } + } + + public void setDialogHandle(UIDialog uiDialog){ + this.uiDialog = uiDialog; + } +}