|
|
|
@ -8,6 +8,7 @@ import com.fr.design.i18n.Toolkit;
|
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
import com.fr.web.struct.AssembleComponent; |
|
|
|
|
import com.teamdev.jxbrowser.chromium.Browser; |
|
|
|
|
import com.teamdev.jxbrowser.chromium.BrowserType; |
|
|
|
|
import com.teamdev.jxbrowser.chromium.JSValue; |
|
|
|
|
import com.teamdev.jxbrowser.chromium.events.LoadListener; |
|
|
|
|
import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter; |
|
|
|
@ -18,11 +19,11 @@ import com.teamdev.jxbrowser.chromium.swing.BrowserView;
|
|
|
|
|
import javax.swing.JDialog; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import javax.swing.WindowConstants; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @author richie |
|
|
|
@ -37,11 +38,11 @@ public class ModernUIPane<T> extends BasicPane {
|
|
|
|
|
private String variable = "data"; |
|
|
|
|
private String expression = "update()"; |
|
|
|
|
|
|
|
|
|
private ModernUIPane() { |
|
|
|
|
initialize(); |
|
|
|
|
private ModernUIPane(BrowserType browserType) { |
|
|
|
|
initialize(browserType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initialize() { |
|
|
|
|
private void initialize(BrowserType browserType) { |
|
|
|
|
if (browser == null) { |
|
|
|
|
setLayout(new BorderLayout()); |
|
|
|
|
Assistant.addChromiumSwitches("--disable-google-traffic"); |
|
|
|
@ -76,10 +77,10 @@ public class ModernUIPane<T> extends BasicPane {
|
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
Assistant.addChromiumSwitches("--remote-debugging-port=9222"); |
|
|
|
|
initializeBrowser(); |
|
|
|
|
initializeBrowser(browserType); |
|
|
|
|
add(new BrowserView(browser), BorderLayout.CENTER); |
|
|
|
|
} else { |
|
|
|
|
initializeBrowser(); |
|
|
|
|
initializeBrowser(browserType); |
|
|
|
|
add(new BrowserView(browser), BorderLayout.CENTER); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -97,8 +98,8 @@ public class ModernUIPane<T> extends BasicPane {
|
|
|
|
|
debugger.loadURL(browser.getRemoteDebuggingURL()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initializeBrowser() { |
|
|
|
|
browser = new Browser(); |
|
|
|
|
private void initializeBrowser(BrowserType browserType) { |
|
|
|
|
browser = new Browser(browserType); |
|
|
|
|
// 初始化的时候,就把命名空间对象初始化好,确保window.a.b.c("a.b.c"为命名空间)对象都是初始化过的
|
|
|
|
|
browser.addScriptContextListener(new ScriptContextAdapter() { |
|
|
|
|
@Override |
|
|
|
@ -145,14 +146,22 @@ public class ModernUIPane<T> extends BasicPane {
|
|
|
|
|
public T update() { |
|
|
|
|
JSValue jsValue = browser.executeJavaScriptAndReturnValue("window." + namespace + "." + expression); |
|
|
|
|
if (jsValue.isObject()) { |
|
|
|
|
return (T)jsValue.asJavaObject(); |
|
|
|
|
return (T) jsValue.asJavaObject(); |
|
|
|
|
} |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class Builder<T> { |
|
|
|
|
|
|
|
|
|
private ModernUIPane<T> pane = new ModernUIPane<>(); |
|
|
|
|
private ModernUIPane<T> pane; |
|
|
|
|
|
|
|
|
|
public Builder() { |
|
|
|
|
this(BrowserType.HEAVYWEIGHT); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Builder(BrowserType browserType) { |
|
|
|
|
this.pane = new ModernUIPane<>(browserType); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Builder<T> prepare(ScriptContextListener contextListener) { |
|
|
|
|
pane.browser.addScriptContextListener(contextListener); |
|
|
|
|