From 776116ee0140591bdef8456d65509e18c6d6991d Mon Sep 17 00:00:00 2001 From: vito Date: Wed, 13 Apr 2016 00:18:32 +0800 Subject: [PATCH] =?UTF-8?q?web=E7=AB=AF=E7=9A=84=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E4=B8=8D=E7=8B=AC=E7=AB=8B=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fr/design/mainframe/bbs/BBSDialog.java | 13 +++-- .../fr/design/mainframe/bbs/BBSWebBridge.java | 51 ------------------- 2 files changed, 10 insertions(+), 54 deletions(-) delete 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 480fec9393..99ba8c28f1 100644 --- a/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java +++ b/designer/src/com/fr/design/mainframe/bbs/BBSDialog.java @@ -37,6 +37,8 @@ public class BBSDialog extends UIDialog { private JFXPanel jfxPanel; + private BBSDialog that;//保存一个引用给问页面调用 + public BBSDialog(Frame parent) { super(parent); @@ -44,7 +46,7 @@ public class BBSDialog extends UIDialog { JPanel panel = (JPanel) getContentPane(); initComponents(panel); setSize(new Dimension(OUTER_WIDTH, OUTER_HEIGHT)); - BBSWebBridge.getHelper().setDialogHandle(this); + that = this; } private void initComponents(JPanel contentPane) { @@ -60,8 +62,6 @@ 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)"); } }); @@ -89,6 +89,8 @@ public class BBSDialog extends UIDialog { view.setMinSize(widthDouble, heightDouble); view.setPrefSize(widthDouble, heightDouble); final WebEngine eng = view.getEngine(); + JSObject obj = (JSObject) eng.executeScript("window"); + obj.setMember("BBSWebBridge", that);//一定要在load页面之前加载接口 //webEngine的userAgent貌似支持移动设备的,任何其他浏览器的userAngent都会导致程序崩溃 //eng.setUserAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) Apple/WebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.76 Safari/537.36"); eng.load(url); @@ -140,6 +142,11 @@ public class BBSDialog extends UIDialog { } } + public void closeWindow() { + this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); + this.setVisible(false); + this.dispose(); + } /** * 略 */ diff --git a/designer/src/com/fr/design/mainframe/bbs/BBSWebBridge.java b/designer/src/com/fr/design/mainframe/bbs/BBSWebBridge.java deleted file mode 100644 index 283a12d6ab..0000000000 --- a/designer/src/com/fr/design/mainframe/bbs/BBSWebBridge.java +++ /dev/null @@ -1,51 +0,0 @@ -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; - } -}