boot-fx/src/main/java/net/java/html/boot/fx/FXBrowsers.java
changeset 1037 e390a06dbfac
parent 1006 a0f79e32d526
     1.1 --- a/boot-fx/src/main/java/net/java/html/boot/fx/FXBrowsers.java	Fri Oct 02 08:57:14 2015 +0200
     1.2 +++ b/boot-fx/src/main/java/net/java/html/boot/fx/FXBrowsers.java	Thu Dec 17 22:23:41 2015 +0100
     1.3 @@ -113,9 +113,11 @@
     1.4      ) {
     1.5          Object[] context = new Object[args.length + 1];
     1.6          System.arraycopy(args, 0, context, 1, args.length);
     1.7 -        context[0] = new Load(webView);
     1.8 +        final Load load = new Load(webView, null);
     1.9 +        context[0] = load;
    1.10          BrowserBuilder.newBrowser(context).
    1.11              loadPage(url.toExternalForm()).
    1.12 +            loadFinished(load).
    1.13              loadClass(onPageLoad).
    1.14              invoke(methodName, args).
    1.15              showAndWait();
    1.16 @@ -194,10 +196,11 @@
    1.17      ) {
    1.18          Object[] newCtx = new Object[context.length + 1];
    1.19          System.arraycopy(context, 0, newCtx, 1, context.length);
    1.20 -        newCtx[0] = new Load(webView);
    1.21 +        final Load load = new Load(webView, onPageLoad);
    1.22 +        newCtx[0] = load;
    1.23          BrowserBuilder.newBrowser(newCtx).
    1.24                  loadPage(url.toExternalForm()).
    1.25 -                loadFinished(onPageLoad).
    1.26 +                loadFinished(load).
    1.27                  classloader(loader).
    1.28                  showAndWait();
    1.29      }
    1.30 @@ -227,15 +230,25 @@
    1.31          if (!(ud instanceof Load)) {
    1.32              throw new IllegalArgumentException();
    1.33          }
    1.34 -        ((Load)ud).execute(code);
    1.35 +        ((Load)ud).ctx.execute(code);
    1.36      }
    1.37      
    1.38 -    private static class Load extends AbstractFXPresenter {
    1.39 +    private static class Load extends AbstractFXPresenter implements Runnable {
    1.40          private final WebView webView;
    1.41 +        private final Runnable myLoad;
    1.42 +        private BrwsrCtx ctx;
    1.43  
    1.44 -        public Load(WebView webView) {
    1.45 +        public Load(WebView webView, Runnable onLoad) {
    1.46 +            this.webView = webView;
    1.47 +            this.myLoad = onLoad;
    1.48              webView.setUserData(this);
    1.49 -            this.webView = webView;
    1.50 +        }
    1.51 +
    1.52 +        public void run() {
    1.53 +            ctx = BrwsrCtx.findDefault(Load.class);
    1.54 +            if (myLoad != null) {
    1.55 +                myLoad.run();
    1.56 +            }
    1.57          }
    1.58          
    1.59          @Override