Search in sources :

Example 1 with PopupFeatures

use of javafx.scene.web.PopupFeatures in project Gargoyle by callakrsos.

the class WebViewExam method start.

/***********************************************************************************/
/* 이벤트 구현 */
@Override
public void start(Stage primaryStage) throws Exception {
    WebView view = new WebView();
    WebEngine engine = view.getEngine();
    engine.setJavaScriptEnabled(true);
    engine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {

        @Override
        public WebEngine call(PopupFeatures p) {
            Stage stage = new Stage(StageStyle.UTILITY);
            WebView wv2 = new WebView();
            VBox vBox = new VBox(5);
            vBox.getChildren().add(wv2);
            vBox.getChildren().add(new Button("업로딩"));
            wv2.getEngine().setJavaScriptEnabled(true);
            stage.setScene(new Scene(vBox));
            stage.show();
            return wv2.getEngine();
        }
    });
    engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {

        @Override
        public void changed(ObservableValue ov, State oldState, State newState) {
            if (newState == Worker.State.SUCCEEDED) {
                primaryStage.setTitle(engine.getLocation());
            }
        }
    });
    engine.setConfirmHandler(new Callback<String, Boolean>() {

        @Override
        public Boolean call(String param) {
            System.out.println("confirm handler : " + param);
            return true;
        }
    });
    engine.setOnAlert((WebEvent<String> wEvent) -> {
        System.out.println("Alert Event  -  Message:  " + wEvent.getData());
    });
    engine.load("http://localhost:15501/MemoWebapp/SmartEditor2.html");
    primaryStage.setScene(new Scene(new BorderPane(view), 1200, 700));
    primaryStage.show();
}
Also used : BorderPane(javafx.scene.layout.BorderPane) PopupFeatures(javafx.scene.web.PopupFeatures) ObservableValue(javafx.beans.value.ObservableValue) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) Button(javafx.scene.control.Button) State(javafx.concurrent.Worker.State) Stage(javafx.stage.Stage) WebView(javafx.scene.web.WebView) WebEvent(javafx.scene.web.WebEvent) VBox(javafx.scene.layout.VBox)

Example 2 with PopupFeatures

use of javafx.scene.web.PopupFeatures in project Gargoyle by callakrsos.

the class FxUtil method openBrowser.

public static WebView openBrowser(Node parent, String content, boolean isLink) {
    WebView view = new WebView();
    WebEngine engine = view.getEngine();
    engine.setOnError(err -> {
        String message = err.getMessage();
        DialogUtil.showMessageDialog(FxUtil.getWindow(parent), message);
    });
    view.setOnKeyPressed(key -> {
        if (key.getCode() == KeyCode.F12) {
            FxUtil.createStageAndShow("Simple Web Console", new WebViewConsole(view));
        }
    });
    engine.setJavaScriptEnabled(true);
    engine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {

        @Override
        public WebEngine call(PopupFeatures p) {
            // Stage stage = new Stage();
            // WebView wv2 = new WebView();
            //
            // wv2.getEngine().setJavaScriptEnabled(true);
            //
            // stage.setScene(new Scene(wv2, BROWSER_WIDTH,
            // BROWSER_HEIGHT));
            // stage.initOwner(parent == null ? (Window) null :
            // parent.getScene().getWindow());
            // stage.show();
            WebView openBrowser = openBrowser(view, "", false);
            return openBrowser.getEngine();
        }
    });
    engine.setOnAlert(ev -> {
        DialogUtil.showMessageDialog(ev.getData());
    });
    engine.setConfirmHandler(new Callback<String, Boolean>() {

        @Override
        public Boolean call(String param) {
            Optional<Pair<String, String>> showYesOrNoDialog = DialogUtil.showYesOrNoDialog("Confirm.", param);
            if (showYesOrNoDialog.isPresent()) {
                Pair<String, String> pair = showYesOrNoDialog.get();
                if (pair == null)
                    return false;
                return "Y".equals(pair.getValue());
            }
            return false;
        }
    });
    engine.setOnAlert((WebEvent<String> wEvent) -> {
        System.out.println("Alert Event  -  Message:  " + wEvent.getData());
    });
    if (isLink)
        engine.load(content);
    else
        engine.loadContent(content);
    BorderPane root = new BorderPane(view);
    TextField txtLink = new TextField(content);
    txtLink.addEventHandler(KeyEvent.KEY_PRESSED, ev -> {
        if (KeyCode.ENTER == ev.getCode())
            engine.load(txtLink.getText());
    });
    root.setTop(txtLink);
    engine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {

        @Override
        public void changed(ObservableValue<? extends State> observable, State oldValue, State newValue) {
            // if (newValue == State.SUCCEEDED) {
            String location = engine.getLocation();
            txtLink.setText(location);
        // }
        }
    });
    FxUtil.createStageAndShow(new Scene(root, BROWSER_WIDTH, BROWSER_HEIGHT), stage -> {
        stage.initOwner(parent == null ? (Window) null : parent.getScene().getWindow());
    });
    return view;
}
Also used : Window(javafx.stage.Window) BorderPane(javafx.scene.layout.BorderPane) Optional(java.util.Optional) PopupFeatures(javafx.scene.web.PopupFeatures) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) State(javafx.concurrent.Worker.State) TextField(javafx.scene.control.TextField) WebView(javafx.scene.web.WebView) WebEvent(javafx.scene.web.WebEvent) WebViewConsole(com.kyj.fx.voeditor.visual.component.console.WebViewConsole) Pair(javafx.util.Pair)

Aggregations

State (javafx.concurrent.Worker.State)2 Scene (javafx.scene.Scene)2 BorderPane (javafx.scene.layout.BorderPane)2 PopupFeatures (javafx.scene.web.PopupFeatures)2 WebEngine (javafx.scene.web.WebEngine)2 WebEvent (javafx.scene.web.WebEvent)2 WebView (javafx.scene.web.WebView)2 WebViewConsole (com.kyj.fx.voeditor.visual.component.console.WebViewConsole)1 Optional (java.util.Optional)1 ObservableValue (javafx.beans.value.ObservableValue)1 Button (javafx.scene.control.Button)1 TextField (javafx.scene.control.TextField)1 VBox (javafx.scene.layout.VBox)1 Stage (javafx.stage.Stage)1 Window (javafx.stage.Window)1 Pair (javafx.util.Pair)1