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