@ -16,15 +16,14 @@ import com.teamdev.jxbrowser.engine.Engine;
import com.teamdev.jxbrowser.engine.EngineOptions ;
import com.teamdev.jxbrowser.engine.EngineOptions ;
import com.teamdev.jxbrowser.engine.RenderingMode ;
import com.teamdev.jxbrowser.engine.RenderingMode ;
import com.teamdev.jxbrowser.js.JsObject ;
import com.teamdev.jxbrowser.js.JsObject ;
import com.teamdev.jxbrowser.net.Network ;
import com.teamdev.jxbrowser.net.Scheme ;
import com.teamdev.jxbrowser.net.callback.InterceptRequestCallback ;
import com.teamdev.jxbrowser.view.swing.BrowserView ;
import com.teamdev.jxbrowser.view.swing.BrowserView ;
import java.awt.BorderLayout ;
import java.awt.BorderLayout ;
import java.awt.Dimension ;
import java.awt.Dimension ;
import java.util.Map ;
import java.util.Map ;
import java.util.Optional ;
import javax.swing.JDialog ;
import javax.swing.JDialog ;
import javax.swing.SwingUtilities ;
import javax.swing.SwingUtilities ;
import javax.swing.WindowConstants ;
import javax.swing.WindowConstants ;
@ -43,6 +42,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
private String namespace = "Pool" ;
private String namespace = "Pool" ;
private String variable = "data" ;
private String variable = "data" ;
private String expression = "update()" ;
private String expression = "update()" ;
private Scheme scheme ;
private NxInterceptRequestCallback requestCallback ;
private NewModernUIPane ( ) {
private NewModernUIPane ( ) {
super ( ) ;
super ( ) ;
@ -96,7 +97,13 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
}
}
private void initializeBrowser ( ) {
private void initializeBrowser ( ) {
Engine engine = Engine . newInstance ( EngineOptions . newBuilder ( RenderingMode . HARDWARE_ACCELERATED ) . addSwitch ( "--disable-google-traffic" ) . build ( ) ) ;
EngineOptions options ;
if ( scheme ! = null & & requestCallback ! = null ) {
options = EngineOptions . newBuilder ( RenderingMode . HARDWARE_ACCELERATED ) . addSwitch ( "--disable-google-traffic" ) . addScheme ( scheme , requestCallback ) . build ( ) ;
} else {
options = EngineOptions . newBuilder ( RenderingMode . HARDWARE_ACCELERATED ) . addSwitch ( "--disable-google-traffic" ) . build ( ) ;
}
Engine engine = Engine . newInstance ( options ) ;
browser = engine . newBrowser ( ) ;
browser = engine . newBrowser ( ) ;
// 初始化的时候,就把命名空间对象初始化好,确保window.a.b.c("a.b.c"为命名空间)对象都是初始化过的
// 初始化的时候,就把命名空间对象初始化好,确保window.a.b.c("a.b.c"为命名空间)对象都是初始化过的
@ -124,8 +131,9 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
* /
@Override
@Override
public void redirect ( String url , Map < String , String > map ) {
public void redirect ( String url , Map < String , String > map ) {
Network network = browser . engine ( ) . network ( ) ;
if ( requestCallback ! = null ) {
network . set ( InterceptRequestCallback . class , new NxInterceptRequestCallback ( network , map ) ) ;
requestCallback . setMap ( map ) ;
}
browser . navigation ( ) . loadUrl ( url ) ;
browser . navigation ( ) . loadUrl ( url ) ;
}
}
@ -169,8 +177,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
* /
@Override
@Override
public NewModernUIPane . Builder < T > withEMB ( final String path ) {
public NewModernUIPane . Builder < T > withEMB ( final String path ) {
Network network = pane . browser . engine ( ) . network ( ) ;
pane . scheme = Scheme . of ( "emb" ) ;
network . set ( InterceptRequestCallback . class , new NxComplexInterceptRequestCallback ( network , null ) ) ;
pane . requestCallback = new NxComplexInterceptRequestCallback ( null ) ;
pane . browser . navigation ( ) . loadUrl ( "emb:" + path ) ;
pane . browser . navigation ( ) . loadUrl ( "emb:" + path ) ;
return this ;
return this ;
}
}
@ -182,8 +190,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
* /
@Override
@Override
public NewModernUIPane . Builder < T > withURL ( final String url ) {
public NewModernUIPane . Builder < T > withURL ( final String url ) {
Network network = pane . browser . engine ( ) . network ( ) ;
pane . scheme = Scheme . of ( "file" ) ;
network . set ( InterceptRequestCallback . class , new NxInterceptRequestCallback ( network ) ) ;
pane . requestCallback = new NxComplexInterceptRequestCallback ( null ) ;
pane . browser . navigation ( ) . loadUrl ( url ) ;
pane . browser . navigation ( ) . loadUrl ( url ) ;
return this ;
return this ;
}
}
@ -195,8 +203,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
* /
@Override
@Override
public NewModernUIPane . Builder < T > withURL ( final String url , Map < String , String > map ) {
public NewModernUIPane . Builder < T > withURL ( final String url , Map < String , String > map ) {
Network network = pane . browser . engine ( ) . network ( ) ;
pane . scheme = Scheme . of ( "file" ) ;
network . set ( InterceptRequestCallback . class , new NxInterceptRequestCallback ( network , map ) ) ;
pane . requestCallback = new NxInterceptRequestCallback ( map ) ;
pane . browser . navigation ( ) . loadUrl ( url ) ;
pane . browser . navigation ( ) . loadUrl ( url ) ;
return this ;
return this ;
}
}
@ -208,8 +216,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
* /
@Override
@Override
public NewModernUIPane . Builder < T > withComponent ( AssembleComponent component ) {
public NewModernUIPane . Builder < T > withComponent ( AssembleComponent component ) {
Network network = pane . browser . engine ( ) . network ( ) ;
pane . scheme = Scheme . of ( "emb" ) ;
network . set ( InterceptRequestCallback . class , new NxComplexInterceptRequestCallback ( network , component ) ) ;
pane . requestCallback = new NxComplexInterceptRequestCallback ( component ) ;
pane . browser . navigation ( ) . loadUrl ( "emb:dynamic" ) ;
pane . browser . navigation ( ) . loadUrl ( "emb:dynamic" ) ;
return this ;
return this ;
}
}
@ -221,8 +229,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
* /
@Override
@Override
public NewModernUIPane . Builder < T > withComponent ( AssembleComponent component , Map < String , String > map ) {
public NewModernUIPane . Builder < T > withComponent ( AssembleComponent component , Map < String , String > map ) {
Network network = pane . browser . engine ( ) . network ( ) ;
pane . scheme = Scheme . of ( "emb" ) ;
network . set ( InterceptRequestCallback . class , new NxComplexInterceptRequestCallback ( network , component , map ) ) ;
pane . requestCallback = new NxComplexInterceptRequestCallback ( component , map ) ;
pane . browser . navigation ( ) . loadUrl ( "emb:dynamic" ) ;
pane . browser . navigation ( ) . loadUrl ( "emb:dynamic" ) ;
return this ;
return this ;
}
}
@ -235,8 +243,8 @@ public class NewModernUIPane<T> extends ModernUIPane<T> {
* /
* /
@Override
@Override
public NewModernUIPane . Builder < T > withHTML ( String html ) {
public NewModernUIPane . Builder < T > withHTML ( String html ) {
Network network = pane . browser . engine ( ) . network ( ) ;
pane . scheme = Scheme . of ( "html" ) ;
network . set ( InterceptRequestCallback . class , new NxInterceptRequestCallback ( network ) ) ;
pane . requestCallback = new NxInterceptRequestCallback ( ) ;
pane . browser . mainFrame ( ) . ifPresent ( frame - > {
pane . browser . mainFrame ( ) . ifPresent ( frame - > {
frame . loadHtml ( html ) ;
frame . loadHtml ( html ) ;
} ) ;
} ) ;