javafx.scene.web.WebView Java Examples

The following examples show how to use javafx.scene.web.WebView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RFXWebView.java    From marathonv5 with Apache License 2.0 7 votes vote down vote up
private void init(Node source) {
    WebView webview = (WebView) source;
    if (webview.getProperties().get("marathon_listener_installed") == null) {
        webview.getProperties().put("marathon_listener_installed", Boolean.TRUE);
        WebEngine webEngine = webview.getEngine();
        if (webEngine.getLoadWorker().stateProperty().get() == State.SUCCEEDED) {
            loadScript(webview);
        }
        webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
            @Override
            public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {
                if (newState == State.SUCCEEDED) {
                    loadScript(webview);
                }
            }
        });
    }
    JavaFXWebViewElement.init(source);
}
 
Example #2
Source File: HtmlWebView.java    From Learn-Java-12-Programming with MIT License 6 votes vote down vote up
public void start(Stage primaryStage) {
    try {
        WebView wv = new WebView();
        WebEngine we = wv.getEngine();
        String html = "<html><center><h2>Hello, world!</h2></center></html>";
        we.loadContent(html, "text/html");

        Scene scene = new Scene(wv, 200, 60);

        primaryStage.setTitle("My HTML page");
        primaryStage.setScene(scene);
        primaryStage.onCloseRequestProperty()
                .setValue(e -> System.out.println("Bye! See you later!"));
        primaryStage.show();
    } catch (Exception ex){
        ex.printStackTrace();
    }
}
 
Example #3
Source File: DialogsTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@BeforeClass(timeOut = 9000)
public static void initializeContext() throws Exception {
    final JFXPanel p = new JFXPanel();
    final URL u = DialogsTest.class.getResource("/org/netbeans/api/htmlui/empty.html");
    Platform.runLater(new Runnable() {
        @Override
        public void run() {
            WebView v = new WebView();
            Scene s = new Scene(v);
            p.setScene(s);
            HtmlToolkit.getDefault().load(v, u, new Runnable() {
                @Override
                public void run() {
                    ctx = BrwsrCtx.findDefault(DialogsTest.class);
                    down.countDown();
                }
            }, null);
        }
    });
    down.await();
    JFrame f = new JFrame();
    f.getContentPane().add(p);
    f.pack();
    f.setVisible(true);
}
 
Example #4
Source File: VirtualCursor.java    From haxademic with MIT License 6 votes vote down vote up
public Browser(int w, int h) {
			this.w = w;
			this.h = h;
			thiss = this;
			webView = new WebView();
			webEngine = webView.getEngine();
			getChildren().add(webView);
			//apply the styles
//			getStyleClass().add("browser");
			// load the web page
			
			// load page & attach js bridge to call up to java
			P.println(webEngine.getUserAgent());
			webEngine.load("http://192.168.1.3:3333/touchless/sdk/javascript/#mode=kiosk&customerId=hovercraft&deviceId=1234567890");

			P.out("Adding js callback!");
			JSObject win = (JSObject) webEngine.executeScript("window");
			win.setMember("native", thiss);
		}
 
Example #5
Source File: WebViewDemo.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) {

    StackPane root = new StackPane();
    WebView x = new WebView();
    WebEngine ex = x.getEngine();
    ex.load("https://github.com/travis-ci/travis-ci");

    root.getChildren().add(x);
    java.net.CookieHandler.setDefault(null);
    Scene scene = new Scene(root, 1024, 768);

    primaryStage.setTitle("Hello World!");
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example #6
Source File: WelcomeInstance.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private Node createContent()
{
    browser = new WebView();
    final WebEngine engine = browser.getEngine();

    String url = Preferences.welcome;
    if (url.isEmpty())
    {
        final URL resource = getClass().getResource("welcome.html");
        url = resource.toExternalForm();
    }
    logger.log(Level.CONFIG, "Welcome URL: " + url);
    engine.load(url);

    return browser;
}
 
Example #7
Source File: HelpBrowser.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
HelpBrowser(final AppDescriptor app)
{
    this.app = app;

    browser = new WebView();
    dock_item = new DockItem(this, new BorderPane(browser))
    {
        // Add 'Web URL'
        @Override
        protected void fillInformation(final StringBuilder info)
        {
            super.fillInformation(info);
            info.append("\n");
            info.append(Messages.HelpPage).append(browser.getEngine().getLocation());
        }
    };
    dock_item.addClosedNotification(this::dispose);
    DockPane.getActiveDockPane().addTab(dock_item);

    JobManager.schedule(app.getDisplayName(), this::loadHelp);
}
 
Example #8
Source File: IndexService.java    From xJavaFxTool-spring with Apache License 2.0 6 votes vote down vote up
/**
 * @Title: addWebView
 * @Description: 添加WebView视图
 */
public void addWebView(String title, String url, String iconPath) {
    WebView browser = new WebView();
    WebEngine webEngine = browser.getEngine();
    if (url.startsWith("http")) {
        webEngine.load(url);
    } else {
        webEngine.load(IndexController.class.getResource(url).toExternalForm());
    }
    if (indexController.getSingleWindowBootCheckBox().isSelected()) {
        JavaFxViewUtil.getNewStage(title, iconPath, new BorderPane(browser));
        return;
    }
    Tab tab = new Tab(title);
    if (StringUtils.isNotEmpty(iconPath)) {
        ImageView imageView = new ImageView(new Image(iconPath));
        imageView.setFitHeight(18);
        imageView.setFitWidth(18);
        tab.setGraphic(imageView);
    }
    tab.setContent(browser);
    indexController.getTabPaneMain().getTabs().add(tab);
    indexController.getTabPaneMain().getSelectionModel().select(tab);
}
 
Example #9
Source File: OrsonChartsFXDemo.java    From jfree-fxdemos with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private SplitPane createChartPane() {
    CategoryDataset3D dataset = SampleData.createCompanyRevenueDataset();
    Chart3D chart = AreaChart3DFXDemo1.createChart(dataset);
    Chart3DViewer viewer = new Chart3DViewer(chart);
  
    this.splitter = new SplitPane();
    splitter.setOrientation(Orientation.VERTICAL);
    final BorderPane borderPane = new BorderPane();
    borderPane.setCenter(viewer);
    
   // Bind canvas size to stack pane size.
    viewer.prefWidthProperty().bind(borderPane.widthProperty());
    viewer.prefHeightProperty().bind(borderPane.heightProperty());

    final StackPane sp2 = new StackPane();
    
    this.chartDescription = new WebView();
    WebEngine webEngine = chartDescription.getEngine();
    webEngine.load(AreaChart3DFXDemo1.class.getResource("AreaChart3DFXDemo1.html").toString());
    
    sp2.getChildren().add(chartDescription);  
    splitter.getItems().addAll(borderPane, sp2);
    splitter.setDividerPositions(0.70f, 0.30f);
    return splitter;
}
 
Example #10
Source File: Browser.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
public void loadPage(TextField textField, //ProgressBar progressBar,
		WebEngine webEngine, WebView webView) {

	String route = textField.getText();
	if (route !=null)
		if (!route.substring(0, 7).equals("http://")) {
			route = "http://" + route;
			textField.setText(route);
		}

	System.out.println("Loading route: " + route);
	//progressBar.progressProperty().bind(webEngine.getLoadWorker().progressProperty());

	webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
		@Override
		public void changed(ObservableValue<? extends State> value,
				State oldState, State newState) {
			if(newState == State.SUCCEEDED){
				System.out.println("Location loaded + " + webEngine.getLocation());
			}
		}
	});
	webEngine.load(route);


}
 
Example #11
Source File: MapSelectionTest.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
@Test
void detailsButtonShowsDetails() throws Exception {
  final Node previewContainer = mock(Node.class);
  mapSelection.setPreviewContainer(previewContainer);

  final WebView previewWindow = mock(WebView.class);
  final var webEngine = mockWebEngine();
  when(previewWindow.getEngine()).thenReturn(webEngine);
  mapSelection.setPreviewWindow(previewWindow);

  final GameChooserEntry gameChooserEntry = mockGameChooserEntryWithNotes();
  mapSelection.setSelectedGame(gameChooserEntry);

  mapSelection.showDetails();

  verify(previewContainer).setVisible(true);
  verify(webEngine).loadContent(mapNotes.trim() + mapName);
}
 
Example #12
Source File: SlidePane.java    From AsciidocFX with Apache License 2.0 6 votes vote down vote up
@PostConstruct
public void afterInit() {
    threadService.runActionLater(() -> {
        getWindow().setMember("afx", controller);
        ReadOnlyObjectProperty<Worker.State> stateProperty = webEngine().getLoadWorker().stateProperty();
        WebView popupView = new WebView();
        Stage stage = new Stage();
        stage.initModality(Modality.WINDOW_MODAL);
        stage.setScene(new Scene(popupView));
        stage.setTitle("AsciidocFX");
        InputStream logoStream = SlidePane.class.getResourceAsStream("/logo.png");
        stage.getIcons().add(new Image(logoStream));
        webEngine().setCreatePopupHandler(param -> {
            if (!stage.isShowing()) {
                stage.show();
                popupView.requestFocus();
            }
            return popupView.getEngine();
        });
        stateProperty.addListener(this::stateListener);
    });
}
 
Example #13
Source File: WebViewHyperlinkListenerDemo.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
	// controls
	WebView webView = createWebView();
	Label urlLabel = createUrlLabel();
	CheckBox listenerAttachedBox = createListenerAttachedBox();
	CheckBox cancelEventBox = createCancelEventBox();

	// listener
	WebViewHyperlinkListener listener = event -> {
		showEventOnLabel(event, urlLabel);
		return cancelEventBox.isSelected();
	};
	manageListener(webView, listener, listenerAttachedBox.selectedProperty());

	// put together
	VBox box = new VBox(webView, listenerAttachedBox, cancelEventBox, urlLabel);
	java.net.CookieHandler.setDefault(null);
	Scene scene = new Scene(box);
	primaryStage.setScene(scene);
	primaryStage.show();
}
 
Example #14
Source File: AlgorithmBenchmarker.java    From JImageHash with MIT License 6 votes vote down vote up
/**
 * Spawn a full screen windows with a webview displaying the html content
 * 
 * @param stage       of the window
 * @param htmlContent the content to display
 */
private void spawnNewWindow(Stage stage, String htmlContent) {

	WebView webView = new WebView();
	webView.getEngine().loadContent(htmlContent);

	// Fullscreen

	Rectangle2D screen = Screen.getPrimary().getVisualBounds();

	double w = screen.getWidth();
	double h = screen.getHeight();
	Scene scene = new Scene(webView, w, h);
	stage.setTitle("Image Hash Benchmarker");
	stage.getIcons().add(new Image("imageHashLogo.png"));
	stage.setScene(scene);
	stage.show();
}
 
Example #15
Source File: Demo_VirtualCursor.java    From haxademic with MIT License 6 votes vote down vote up
protected void initWebView() {
	// build WebView & JavaFX components on JavaFX thread
	
	// init WebView component
	// load page & attach js bridge to call up to java
	webView = new WebView();  // webView.setDisable(true);	// disable keyboard/mouse
	webEngine = webView.getEngine();
	webEngine.load("http://192.168.1.3:3333/touchless/sdk/javascript/#mode=kiosk&customerId=hovercraft&deviceId=1234567890&debug=true");
	P.println("webEngine.getUserAgent()", webEngine.getUserAgent());
	
	// init js bridge with this class as the deletage
	JSObject win = (JSObject) webEngine.executeScript("window");
	win.setMember("native", this);
	
	// add WebView to FXPanel/JFrame
	Scene scene = new Scene(webView, jframe.getWidth(), jframe.getHeight(), Color.web("#666970"));
	fxPanel.setScene(scene);
	jframe.setContentPane(fxPanel);
	
	// set special window properties
	// fxPanel.setFocusable(false);
	// fxPanel.setFocusTraversalKeysEnabled(true);
	// fxPanel.requestFocus();
	// fxPanel.requestFocusInWindow();
}
 
Example #16
Source File: JavaFXWebViewElement.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static void init(Node source) {
    WebView webview = (WebView) source;
    if (webview.getProperties().get("marathon_player_installed") == null) {
        webview.getProperties().put("marathon_player_installed", Boolean.TRUE);
        WebEngine webEngine = webview.getEngine();
        if (webEngine.getLoadWorker().stateProperty().get() == State.SUCCEEDED) {
            loadScript(webview, webEngine);
        }
        webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
            @Override
            public void changed(ObservableValue<? extends State> ov, State oldState, State newState) {
                if (newState == State.SUCCEEDED) {
                    loadScript(webview, webEngine);
                }
            }
        });
    }
}
 
Example #17
Source File: WebViewHyperlinkListenerDemo.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Attaches/detaches the specified listener to/from the specified web view according to the specified property's
 * value.
 *
 * @param webView
 *            the {@link WebView} to which the listener will be added
 * @param listener
 *            the added listener
 * @param attachedProperty
 *            defines whether the listener is attached or not
 */
private static void manageListener(WebView webView, WebViewHyperlinkListener listener,
		BooleanProperty attachedProperty) {
	attachedProperty.set(true);
	ListenerHandle listenerHandle = WebViews.addHyperlinkListener(webView, listener);

	attachedProperty.addListener((obs, wasAttached, isAttached) -> {
		if (isAttached) {
			listenerHandle.attach();
			System.out.println("LISTENER: attached.");
		} else {
			listenerHandle.detach();
			System.out.println("LISTENER: detached.");
		}
	});
}
 
Example #18
Source File: DeferredHtmlRendering.java    From ReactFX with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    TextArea textArea = new TextArea();
    WebView webView = new WebView();
    WebEngine engine = webView.getEngine();

    EventStreams.valuesOf(textArea.textProperty())
            .successionEnds(Duration.ofMillis(500))
            .subscribe(html -> engine.loadContent(html));

    SplitPane root = new SplitPane();
    root.getItems().addAll(textArea, webView);
    Scene scene = new Scene(root);
    primaryStage.setScene(scene);
    primaryStage.show();
}
 
Example #19
Source File: GlobalUI.java    From SONDY with GNU General Public License v3.0 6 votes vote down vote up
public void about(){
    final Stage stage = new Stage();
    stage.setResizable(false);
    stage.initModality(Modality.WINDOW_MODAL);
    stage.initStyle(StageStyle.UTILITY);
    stage.setTitle("About SONDY");
    WebView webView = new WebView();
    webView.getEngine().loadContent(getReferences());
    webView.setMaxWidth(Main.columnWidthLEFT);
    webView.setMinWidth(Main.columnWidthLEFT);
    webView.setMaxHeight(Main.columnWidthLEFT);
    webView.setMinHeight(Main.columnWidthLEFT);
    Scene scene = new Scene(VBoxBuilder.create().children(new Label("SONDY "+Main.version),new Label("Main developper: Adrien Guille <[email protected]>"),webView).alignment(Pos.CENTER).padding(new Insets(10)).spacing(3).build());
    scene.getStylesheets().add("resources/fr/ericlab/sondy/css/GlobalStyle.css");
    stage.setScene(scene);
    stage.show();
}
 
Example #20
Source File: DatePicker.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #21
Source File: CN1CSSCLI.java    From CodenameOne with GNU General Public License v2.0 6 votes vote down vote up
private static void startImpl(Stage stage) throws Exception {
    System.out.println("Opening JavaFX Webview to render some CSS styles");
    web = new WebView();
    web.getEngine().getLoadWorker().exceptionProperty().addListener(new ChangeListener<Throwable>() {
        @Override
        public void changed(ObservableValue<? extends Throwable> ov, Throwable t, Throwable t1) {
            System.out.println("Received exception: "+t1.getMessage());
        }
    });
    
    Scene scene = new Scene(web, 400, 800, Color.web("#666670"));
    stage.setScene(scene);
    stage.show();
    synchronized(lock) {
        lock.notify();
    }
}
 
Example #22
Source File: WebViewContextMenuTest.java    From oim-fx with MIT License 6 votes vote down vote up
private void createContextMenu(WebView webView) {
	ContextMenu contextMenu = new ContextMenu();
	MenuItem reload = new MenuItem("Reload");
	reload.setOnAction(e -> webView.getEngine().reload());
	MenuItem savePage = new MenuItem("Save Page");
	savePage.setOnAction(e -> System.out.println("Save page..."));
	MenuItem hideImages = new MenuItem("Hide Images");
	hideImages.setOnAction(e -> System.out.println("Hide Images..."));
	contextMenu.getItems().addAll(reload, savePage, hideImages);

	webView.setOnMousePressed(e -> {
		if (e.getButton() == MouseButton.SECONDARY) {
			contextMenu.show(webView, e.getScreenX(), e.getScreenY());
		} else {
			contextMenu.hide();
		}
	});
}
 
Example #23
Source File: BradleyTerryPluginView.java    From AILibs with GNU Affero General Public License v3.0 5 votes vote down vote up
public BradleyTerryPluginView(final BradleyTerryPluginModel model) {
	super(model, new FlowPane());
	Platform.runLater(() -> {
		WebView view = new WebView();
		FlowPane node = this.getNode();
		node.getChildren().add(this.left);
		node.getChildren().add(this.right);
		node.getChildren().add(this.parent);
		this.left.setOnMouseClicked(e -> {
			DefaultGUIEventBus.getInstance().postEvent(new NodeClickedEvent(null, this.getLeftChild(model.getCurrentlySelectedNode())));
			this.parent.setDisable(false);
		});
		this.right.setOnMouseClicked(e -> {
			DefaultGUIEventBus.getInstance().postEvent(new NodeClickedEvent(null, this.getRightChild(model.getCurrentlySelectedNode())));
			this.parent.setDisable(false);
		});
		this.parent.setOnMouseClicked(e -> {
			String parentOfCurrent = this.getModel().getParentOfCurrentNode();
			DefaultGUIEventBus.getInstance().postEvent(new NodeClickedEvent(null, parentOfCurrent));
			if (!this.getModel().getParents().containsKey(parentOfCurrent)) {
				this.parent.setDisable(true);
			}
		});

		node.getChildren().add(view);
		this.engine = view.getEngine();
		this.engine.loadContent("Nothing there yet.");
	});
}
 
Example #24
Source File: NbBrowsers.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static void load(WebView view, URL page, final Runnable onPageLoad, ClassLoader loader, Object... args) {
    class ApplySkin implements Runnable {
        @Override
        public void run() {
            applyNbSkin();
            onPageLoad.run();
        }
    }
    load0(view, page, new ApplySkin(), loader, args);
}
 
Example #25
Source File: JavaFxHtmlToolkit.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Object initHtmlComponent(JComponent c, Consumer<String> titleDisplayer) {
    JFXPanel p = (JFXPanel) c;
    Platform.setImplicitExit(false);
    WebView webView = new WebView();
    BorderPane bp = new BorderPane();
    Scene scene = new Scene(bp, Color.ALICEBLUE);

    class X implements ChangeListener<String>, Runnable {

        private String title;

        public X() {
            super();
        }

        @Override
        public void changed(ObservableValue<? extends String> ov, String t, String t1) {
            title = webView.getEngine().getTitle();
            EventQueue.invokeLater(this);
        }

        @Override
        public void run() {
            if (title != null) {
                titleDisplayer.accept(title);
            }
        }
    }
    final X x = new X();
    webView.getEngine().titleProperty().addListener(x);
    HtmlToolkit.getDefault().execute(x);
    bp.setCenter(webView);
    p.setScene(scene);
    return webView;
}
 
Example #26
Source File: HtmlWebView.java    From Learn-Java-12-Programming with MIT License 5 votes vote down vote up
public void start10(Stage primaryStage) {

        Text txt = new Text("Enjoy searching the Web!");

        WebView wv = new WebView();
        WebEngine we = wv.getEngine();
        we.load("http://www.google.com");
        //wv.setZoom(1.5);

/*
        WebHistory history = we.getHistory();
        ObservableList<WebHistory.Entry> entries = history.getEntries();
        for(WebHistory.Entry entry: entries){
            String url = entry.getUrl();
            String title = entry.getTitle();
            Date date = entry.getLastVisitedDate();
        }
*/

        VBox vb = new VBox(txt, wv);
        vb.setSpacing(20);
        vb.setAlignment(Pos.CENTER);
        vb.setStyle("-fx-font-size: 20px;-fx-background-color: lightblue;");
        vb.setPadding(new Insets(10, 10, 10, 10));

        Scene scene = new Scene(vb,750,500);
        primaryStage.setScene(scene);
        primaryStage.setTitle("JavaFX with the window to another server");
        primaryStage.onCloseRequestProperty()
                .setValue(e -> System.out.println("Bye! See you later!"));
        primaryStage.show();
    }
 
Example #27
Source File: SamplePage.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected WebView getWebView() {
    if (engine == null) {
        webView = new WebView();
        webView.setContextMenuEnabled(false);
        engine = webView.getEngine();
    }
    return webView;
}
 
Example #28
Source File: WebViewSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public WebViewSample() {
    WebView webView = new WebView();
    
    final WebEngine webEngine = webView.getEngine();
    webEngine.load(DEFAULT_URL);
    
    final TextField locationField = new TextField(DEFAULT_URL);
    webEngine.locationProperty().addListener(new ChangeListener<String>() {
        @Override public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
            locationField.setText(newValue);
        }
    });
    EventHandler<ActionEvent> goAction = new EventHandler<ActionEvent>() {
        @Override public void handle(ActionEvent event) {
            webEngine.load(locationField.getText().startsWith("http://") 
                    ? locationField.getText() 
                    : "http://" + locationField.getText());
        }
    };
    locationField.setOnAction(goAction);
    
    Button goButton = new Button("Go");
    goButton.setDefaultButton(true);
    goButton.setOnAction(goAction);
    
    // Layout logic
    HBox hBox = new HBox(5);
    hBox.getChildren().setAll(locationField, goButton);
    HBox.setHgrow(locationField, Priority.ALWAYS);
    
    VBox vBox = new VBox(5);
    vBox.getChildren().setAll(hBox, webView);
    VBox.setVgrow(webView, Priority.ALWAYS);

    getChildren().add(vBox);
}
 
Example #29
Source File: ACEEditor.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void initComponent() {
    webView = new WebView();
    String externalForm = ACEEditor.class.getResource("/Ace.html").toExternalForm();
    WebEngine engine = webView.getEngine();
    engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
        @Override
        public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
            if (newValue != State.SUCCEEDED) {
                return;
            }
            JSObject window = (JSObject) engine.executeScript("window");
            window.setMember("java", ACEEditor.this);
            engine.executeScript("console.log = function(message)\n" + "{\n" + "    java.log(message);\n" + "};");
            ACEEditor.this.engine = engine;
            setOptions(new JSONObject().put("showLineNumbers", showLinenumbers).put("firstLineNumber", startLineNumber)
                    .put("overwrite", false));
            loadPreferences();
            hookKeyBindings();
        }
    });
    engine.load(externalForm);
    ToolBarContainer container = ToolBarContainer.createDefaultContainer(Orientation.RIGHT);
    if (withToolbar) {
        ToolBarPanel toolBarPanel = container.getToolBarPanel();
        createToolBars(toolBarPanel);
    }
    container.setContent(webView);
    this.node = container;
}
 
Example #30
Source File: ArrayTester.java    From GMapsFX with Apache License 2.0 5 votes vote down vote up
@Override
public void start(final Stage stage) throws Exception {
    
    webview = new WebView();
    webengine = new JavaFxWebEngine(webview.getEngine());
    JavascriptRuntime.setDefaultWebEngine( webengine );
    
    BorderPane bp = new BorderPane();
    bp.setCenter(webview);
    
    webengine.getLoadWorker().stateProperty().addListener(
            new ChangeListener<Worker.State>() {
                public void changed(ObservableValue ov, Worker.State oldState, Worker.State newState) {
                    if (newState == Worker.State.SUCCEEDED) {
                        runTests();
                        //Platform.exit();
                    }
                }
            });
    webengine.load(getClass().getResource("/com/lynden/gmapsfx/html/arrays.html").toExternalForm());
    
    Scene scene = new Scene(bp, 600, 600);
    
    stage.setScene(scene);
    stage.show();
    
}