diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java index 52cd591657..480fec9393 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 0000000000..283a12d6ab --- /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; + } +}