Java 类javafx.scene.web.WebEvent 实例源码

项目:box-java-sdk-v2    文件:JavaFxOAuthFlow.java   
private EventHandler<WebEvent<String>> createEventHandler() {
    return new EventHandler<WebEvent<String>>() {

        @Override
        public void handle(WebEvent<String> event) {
            if (event.getSource() instanceof WebEngine) {
                WebEngine engine = (WebEngine) event.getSource();
                String url = engine.getLocation();
                String code = getResponseValueFromUrl(url);
                if (StringUtils.isNotEmpty(code)) {
                    webEngine.getLoadWorker().cancel();
                    startCreateOAuth(code);
                }
            }
        }
    };
}
项目:mars-sim    文件:DatePicker.java   
private void initPicker(WebView webView) {
  // attach a handler for an alert function call which will set the DatePicker's date property.
  webView.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
    @Override public void handle(WebEvent<String> event) {
      try { date.set(jQueryUiDateFormat.parse(event.getData())); } catch (ParseException e) { /* no action required */ }
    }
  });

  // place the webView holding the jQuery date picker inside this node.
  this.getChildren().add(webView);

  // monitor the date for changes and update the formatted date string to keep it in sync.
  date.addListener(new ChangeListener<Date>() {
    @Override public void changed(ObservableValue<? extends Date> observableValue, Date oldDate, Date newDate) {
      dateString.set(dateFormat.format(newDate));
    }
  });

  // workaround as I don't know how to size the stack to the size of the enclosed WebPane's html content.
  this.setMaxSize(330, 280);//307, 241);
}
项目:GMapsFX    文件:MainApp2.java   
@Override
public void start(final Stage stage) throws Exception {
    mapComponent = new GoogleMapView();
    mapComponent.addMapInitializedListener(this);
    mapComponent.setDisableDoubleClick(true);
    mapComponent.getWebview().getEngine().setOnAlert((WebEvent<String> event) -> {
     //   System.out.println("Event event: " + event);
    });

    BorderPane bp = new BorderPane();

    bp.setCenter(mapComponent);

    Scene scene = new Scene(bp);
    stage.setScene(scene);
    stage.show();

}
项目:javafx-demos    文件:DatePicker.java   
private void initPicker(WebView webView) {
  // attach a handler for an alert function call which will set the DatePicker's date property.
  webView.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
    @Override public void handle(WebEvent<String> event) {
      try { date.set(jQueryUiDateFormat.parse(event.getData())); } catch (ParseException e) { /* no action required */ }
    }
  });

  // place the webView holding the jQuery date picker inside this node.
  this.getChildren().add(webView);

  // monitor the date for changes and update the formatted date string to keep it in sync.
  date.addListener(new ChangeListener<Date>() {
    @Override public void changed(ObservableValue<? extends Date> observableValue, Date oldDate, Date newDate) {
      dateString.set(dateFormat.format(newDate));
    }
  });

  // workaround as I don't know how to size the stack to the size of the enclosed WebPane's html content.
  this.setMaxSize(320, 250);
}
项目:javafx-demos    文件:DatePicker.java   
private void initPicker(WebView webView) {
  // attach a handler for an alert function call which will set the DatePicker's date property.
  webView.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
    @Override public void handle(WebEvent<String> event) {
      try { date.set(jQueryUiDateFormat.parse(event.getData())); } catch (ParseException e) { /* no action required */ }
    }
  });

  // place the webView holding the jQuery date picker inside this node.
  this.getChildren().add(webView);

  // monitor the date for changes and update the formatted date string to keep it in sync.
  date.addListener(new ChangeListener<Date>() {
    @Override public void changed(ObservableValue<? extends Date> observableValue, Date oldDate, Date newDate) {
      dateString.set(dateFormat.format(newDate));
    }
  });

  // workaround as I don't know how to size the stack to the size of the enclosed WebPane's html content.
  this.setMaxSize(307, 241);
}
项目:HealthCheckUtility    文件:JavaToJavascriptBridge.java   
private AlertEventHandlerWrapper(
        WebEngine engine,
        EventHandler<WebEvent<String>> wrappedHandler) {

    this.engine = engine;
    this.wrappedHandler = wrappedHandler;
}
项目:HealthCheckUtility    文件:JavaToJavascriptBridge.java   
@Override
public void handle(WebEvent<String> arg0) {
    if (arg0.getData().contains(CONNECT_BACKEND_MAGIC_WORD)) {
        String varname = arg0.getData().substring(
                CONNECT_BACKEND_MAGIC_WORD.length());

        connectToWebEngine(engine, varname);
    }
    else if (wrappedHandler != null) wrappedHandler.handle(arg0);
}
项目:willow-browser    文件:DialogFactory.java   
public EventHandler<WebEvent<String>> createAlertHandler() {
    return stringWebEvent -> {
        AlertHandler alertHandler = new AlertHandler(
                stringWebEvent.getData(),
                event -> {
                    webView.setDisable(false);
                    removeViewOverlay();
                }
        );
        overlayView(alertHandler);

        // todo block until the user accepts the alert.
    };
}
项目:travelimg    文件:GoogleMapScene.java   
private void handleAlert(WebEvent<String> event) {
    LOGGER.debug("Got alert {}", event);

    String data = event.getData();

    if (data.equals("map-loaded")) {
        if (onLoadedCallback != null) {
            onLoadedCallback.run();
        }
    } else if (data.contains("click")) {

        String type = data.substring(0, data.indexOf("("));
        String params = data.substring(data.indexOf("(") + 1, data.indexOf(")"));

        String latLng[] = params.split(",");

        if (latLng.length != 2) {
            return;
        }

        try {
            double latitude = Double.parseDouble(latLng[0].trim());
            double longitude = Double.parseDouble(latLng[1].trim());

            if (type.equals("double-click") && doubleClickCallback != null) {

                doubleClickCallback.accept(new LatLong(latitude, longitude));


            } else if (type.equals("click") && clickCallback != null) {
                clickCallback.accept(new LatLong(latitude, longitude));
            } else if (type.equals("marker-click") && markerClickCallback != null) {
                 markerClickCallback.accept(new LatLong(latitude,longitude));
            }
        } catch (NumberFormatException ex) {
            LOGGER.debug("Failed to parse click event from map");
        }
    }
}
项目:semtool    文件:BrowserPlaySheet2.java   
public BrowserPlaySheet2( String htmlPath ) {
    setLayout( new BorderLayout() );
    add( jfxPanel );

    fileName = "file:///"
            + new File( DIHelper.getInstance().getLocalStore(), htmlPath );

    Platform.setImplicitExit( false );
    Platform.runLater( new Runnable() {
        @Override
        public void run() {
            WebView view = new WebView();
            scene = new Scene( view );
            jfxPanel.setScene( scene );

            engine = view.getEngine();
            engine.setOnAlert(
                    new EventHandler<WebEvent<String>>() {
                        @Override
                        public void handle( WebEvent<String> event ) {
                            log.debug( "handling event: " + event );
                            if ( "document:loaded".equals( event.getData() ) ) {
                                log.debug( "Document is loaded." );
                                sendToWebView();
                            }
                            else if ( event.getData().startsWith( "download:csv" ) ) {
                                log.debug( "Downloading CSV file from browser." );
                                downloadCSV( event.getData().substring( 12 ) );
                            }
                        }

                    }
            );
        }
    } );
}
项目:netentionj-desktop    文件:DialogFactory.java   
public EventHandler<WebEvent<String>> createAlertHandler() {
    return stringWebEvent -> {
        AlertHandler alertHandler = new AlertHandler(
                stringWebEvent.getData(),
                event -> {
                    webView.setDisable(false);
                    removeViewOverlay();
                }
        );
        overlayView(alertHandler);

        // todo block until the user accepts the alert.
    };
}
项目:javafxwebview    文件:WebViewDemo.java   
private void createWebView(Stage primaryStage, String page) {

    // create the JavaFX webview
    final WebView webView = new WebView();

    // connect the FruitsService instance as "fruitsService" 
    // javascript variable
    connectBackendObject(
            webView.getEngine(),
            "fruitsService", new FruitsService());

    // connect the CalculatorService instance as "calculatorService" 
    // javascript variable      
    connectBackendObject(
            webView.getEngine(),
            "calculatorService", new CalculatorService());

    // show "alert" Javascript messages in stdout (useful to debug) 
    webView.getEngine().setOnAlert(new EventHandler<WebEvent<String>>(){
        @Override
        public void handle(WebEvent<String> arg0) {
            System.err.println("alertwb1: " + arg0.getData());
        }
    });

    // load index.html
    webView.getEngine().load(
            getClass().getResource(page).
            toExternalForm());

    primaryStage.setScene(new Scene(webView));
    primaryStage.setTitle("WebView with Java backend");     
    primaryStage.show();
}
项目:javafxwebview    文件:Java2JavascriptUtils.java   
private AlertEventHandlerWrapper(
        WebEngine engine, 
        EventHandler<WebEvent<String>> wrappedHandler) {

    this.engine = engine;
    this.wrappedHandler = wrappedHandler;
}
项目:javafxwebview    文件:Java2JavascriptUtils.java   
@Override
public void handle(WebEvent<String> arg0) {
    if (arg0.getData().contains(CONNECT_BACKEND_MAGIC_WORD)) {
        String varname = arg0.getData().substring(
                CONNECT_BACKEND_MAGIC_WORD.length());

        connectToWebEngine(engine, varname);
    }
    else if (wrappedHandler != null) wrappedHandler.handle(arg0);
}
项目:simplejavayoutubeuploader    文件:TagTextArea.java   
private void initPicker(final WebView webView) {
    webView.getEngine().loadContent(getInlineHtml());
    webView.setContextMenuEnabled(false);
    webView.getEngine().setOnAlert(new EventHandler<WebEvent<String>>() {
        @Override
        public void handle(final WebEvent<String> event) {
            tags.set(event.getData());
        }
    });

    getChildren().add(webView);
}
项目:EmbeddedTomcatLauncher    文件:EmbeddedServerBrowserFrame.java   
/**
 * JavaScriptのalert()のハンドラ.<br>
 *
 * @return
 */
private EventHandler<WebEvent<String>> createAlertHandler() {
    return new EventHandler<WebEvent<String>>() {
        @Override
        public void handle(final WebEvent<String> stringWebEvent) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    String message = stringWebEvent.getData();
                    JOptionPane.showMessageDialog(EmbeddedServerBrowserFrame.this, message);
                }
            });
        }
    };
}
项目:HealthCheckUtility    文件:JavaToJavascriptBridge.java   
/**
 * Registers a backend Java object as a Javascript variable.
 * The real connection to the webEngine comes when the javascript performs
 * an special "alert" message by invoking
 * "alert('__CONNECT__BACKEND__varname')" where varname is the javascript
 * variable we want to make available.
 *
 * The call to this function has to be performed before the engine loads the
 * first page (where the alert call should take place).
 *
 * @param webEngine The webEngine to register the new variable.
 * @param varname The name of the variable in javascript.
 * @param backend The Java backend object.
 */
public static void connectBackendObject(
        final WebEngine webEngine,
        final String varname,
        final Object backend) {

    registerBackendObject(webEngine, varname, backend);

    // create a onAlertChangeListener. We always want to listen
    // to onAlert events, since via this event, the javascript front-end
    // will send us an special "alert" message asking to connect the
    // backend object as soon as possible(*).
    // However, if the programmer also wants to set
    // his own onAlert handler for this web engine,
    // we will create a handlerwrapper with our
    // behavior plus the programmer's one.

    // (*) It was impossible for me to re-connect the backend object
    // when the users navigates from one page to another page where the
    // backend object was also needed. The navigation erases any javascript
    // variables, so the backend has to be reconnected. However,
    // The recommended state change listeners on
    // webEngine were executed too late, after javascript code asking for the
    // backend object is executed, so it was not a solution.
    // The only way I found is to place a custom javacript "signaling"
    // code to ask Java to reconnect the backend object.
    // The solution was "alert", because we can listen to alert calls from
    // javascript, so via an special "alert" message, we can connect the
    // backend object again.
    // It is not a bad solution, because the programmer has only to inlude
    // a simple additional script (such as "mybackend.js") in the page
    // before any other scripts uses the backend variable.
    if (!webEnginesWithAlertChangeListener.contains(webEngine)) {
        if (webEngine.getOnAlert() == null) {
            webEngine.setOnAlert(new AlertEventHandlerWrapper(webEngine,
                    null));
        }

        webEngine.onAlertProperty().addListener(
                new ChangeListener<EventHandler<WebEvent<String>>>() {

                    @Override
                    public void changed(
                            ObservableValue
                                    <? extends EventHandler<WebEvent<String>>> arg0,
                            EventHandler<WebEvent<String>> previous,
                            final EventHandler<WebEvent<String>> newHandler) {

                        if (!changing) { // avoid recursive calls
                            changing = true;
                            webEngine.setOnAlert(
                                    new AlertEventHandlerWrapper(
                                            webEngine,
                                            newHandler));
                            changing = false;
                        }
                    }
                });
    }
    webEnginesWithAlertChangeListener.add(webEngine);
}
项目:openjfx-8u-dev-tests    文件:ResizeTest.java   
public void handle(WebEvent<Rectangle2D> t) {
    newHeight = t.getData().getHeight();
    newWidth = t.getData().getWidth();
    resizeCalled = true;
}
项目:openjfx-8u-dev-tests    文件:StatusbarTextTest.java   
public void handle(WebEvent<String> t) {
    newText = t.getData();
    statusTextChanged = true;
}
项目:openjfx-8u-dev-tests    文件:AlertTest.java   
public void handle(WebEvent<String> t) {
    messageReceived = t.getData();
    alertCalled = true;
}
项目:openjfx-8u-dev-tests    文件:VisibilityTest.java   
public void handle(WebEvent<Boolean> t) {
    isVisible = t.getData().booleanValue();
    System.out.println(isVisible);
    visibilityHandlerCalled = true;
}
项目:FxDock    文件:DemoBrowser.java   
protected void handleStatusChange(WebEvent<String> ev)
{
    statusField.setText(ev.getData());
}
项目:GMapsFX    文件:JavaFxWebEngine.java   
public void setOnAlert(EventHandler<WebEvent<String>> eventHandler) {
    webEngine.setOnAlert(eventHandler);
}
项目:javafxwebview    文件:Java2JavascriptUtils.java   
/**
 * Registers a backend Java object as a Javascript variable.
 * The real connection to the webEngine comes when the javascript performs
 * an special "alert" message by invoking 
 * "alert('__CONNECT__BACKEND__varname')" where varname is the javascript
 * variable we want to make available.
 * 
 * The call to this function has to be performed before the engine loads the
 * first page (where the alert call should take place).
 * 
 * @param webEngine The webEngine to register the new variable.
 * @param varname The name of the variable in javascript.
 * @param backend The Java backend object.
 */
public static void connectBackendObject(
        final WebEngine webEngine,
        final String varname, 
        final Object backend) {

    registerBackendObject(webEngine, varname, backend);

    // create a onAlertChangeListener. We always want to listen
    // to onAlert events, since via this event, the javascript front-end
    // will send us an special "alert" message asking to connect the 
    // backend object as soon as possible(*). 
    // However, if the programmer also wants to set
    // his own onAlert handler for this web engine, 
    // we will create a handlerwrapper with our
    // behavior plus the programmer's one.

    // (*) It was impossible for me to re-connect the backend object
    // when the users navigates from one page to another page where the
    // backend object was also needed. The navigation erases any javascript
    // variables, so the backend has to be reconnected. However,
    // The recommended state change listeners on
    // webEngine were executed too late, after javascript code asking for the
    // backend object is executed, so it was not a solution.
    // The only way I found is to place a custom javacript "signaling" 
    // code to ask Java to reconnect the backend object.
    // The solution was "alert", because we can listen to alert calls from
    // javascript, so via an special "alert" message, we can connect the
    // backend object again.
    // It is not a bad solution, because the programmer has only to inlude
    // a simple additional script (such as "mybackend.js") in the page 
    // before any other scripts uses the backend variable.
    if (!webEnginesWithAlertChangeListener.contains(webEngine)) {
        if (webEngine.getOnAlert() == null) {
            webEngine.setOnAlert(new AlertEventHandlerWrapper(webEngine,
                    null));
        }

        webEngine.onAlertProperty().addListener(
            new ChangeListener<EventHandler<WebEvent<String>>>() {

                @Override
                public void changed(
                        ObservableValue
                        <? extends EventHandler<WebEvent<String>>> arg0,
                        EventHandler<WebEvent<String>> previous,
                        final EventHandler<WebEvent<String>> newHandler) {

                    if (!changing) { // avoid recursive calls
                        changing = true;
                        webEngine.setOnAlert(
                            new AlertEventHandlerWrapper(
                                    webEngine, 
                                    newHandler));
                        changing = false;
                    }
                }
        });
    }
    webEnginesWithAlertChangeListener.add(webEngine);
}
项目:javafx-download-jdk    文件:SimpleBrowser.java   
public SimpleBrowser load(final String location, final Runnable onLoad) {
        logger.info("navigating to {}", location);

        webEngine.load(location);

        webEngine.setOnAlert(new EventHandler<WebEvent<String>>() {
            @Override
            public void handle(WebEvent<String> webEvent) {
                LoggerFactory.getLogger("wk-alert").info(webEvent.getData());
            }
        });

        final int eventId = random.nextInt();

        webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<Worker.State>() {
            @Override
            public void changed(ObservableValue<? extends Worker.State> ov, Worker.State t, Worker.State t1) {
//                logger.info("state: {},{} - for page {}", t, t1, location);

                if (t1 == Worker.State.SUCCEEDED) {
                    if(jQueryLoads.putIfAbsent(eventId, onLoad) != null){
                        return;
                    }

                    if(onLoad != null){
                        logger.info("registered event: {} for location {}, {}, {}", eventId, location, t, t1);
                        jQueryLoads.put(eventId, onLoad);
                    }

                    if (useFirebug) {
                        webEngine.executeScript("if (!document.getElementById('FirebugLite')){E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');E['setAttribute']('id', 'FirebugLite');E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');E['setAttribute']('FirebugLite', '4');(document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);E = new Image;E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');}");
                    }

                    if(useJQuery && !useFirebug){
                        embedJQuery(eventId);
                    }
                }
            }
        });

        return this;
    }
项目:ui4j    文件:WebKitPage.java   
@Override
public void handle(WebEvent<String> event) {
    handler.handle(new DialogEvent(event.getData()));
}