Search in sources :

Example 16 with WebView

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

the class SimpleTextView method miOpenHtmlWevViewOnAction.

@FXML
public void miOpenHtmlWevViewOnAction() {
    String content = codeArea.getText();
    try {
        WebView webView = new WebView();
        webView.getEngine().loadContent(content);
        FxUtil.createStageAndShow(webView, stage -> {
            stage.setAlwaysOnTop(true);
            stage.initOwner(getScene().getWindow());
            stage.focusedProperty().addListener((oba, o, n) -> {
                if (!n)
                    stage.close();
            });
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : WebView(javafx.scene.web.WebView) FXML(javafx.fxml.FXML)

Example 17 with WebView

use of javafx.scene.web.WebView 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)

Example 18 with WebView

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

the class MimeViewerExam method start.

@Override
public void start(Stage primaryStage) throws Exception {
    WebView center = new WebView();
    WebEngine engine = center.getEngine();
    URL resource = MimeViewerExam.class.getResource("Sample.html");
    // String externalForm = resource.toExternalForm();
    String readToString = FileUtil.readToString(resource.openStream());
    System.out.println("##########################################");
    System.out.println("mime string");
    System.out.println(readToString);
    System.out.println("##########################################");
    final MessageBuilder builder = new DefaultMessageBuilder();
    final Message message = builder.parseMessage(resource.openStream());
    Body body = ((Entity) message).getBody();
    StringBuilder sb = new StringBuilder();
    extracted(sb, body);
    Document parse = Jsoup.parse(sb.toString());
    Elements select = parse.select("img");
    select.forEach(e -> {
        String attr = e.attr("src");
        if (attr.startsWith("cid:")) {
            String cid = attr.replace("cid:", "");
            String string = meta.get(cid);
            e.attr("src", "data:image/jpg;base64,".concat(string));
        }
    });
    System.out.println("##########################################");
    System.out.println("html string");
    System.out.println(sb.toString());
    System.out.println("##########################################");
    System.out.println(parse.toString());
    engine.loadContent(sb.toString(), "text/html");
    primaryStage.setScene(new Scene(new BorderPane(center)));
    primaryStage.show();
}
Also used : Entity(org.apache.james.mime4j.dom.Entity) BorderPane(javafx.scene.layout.BorderPane) Message(org.apache.james.mime4j.dom.Message) DefaultMessageBuilder(org.apache.james.mime4j.message.DefaultMessageBuilder) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) URL(java.net.URL) MessageBuilder(org.apache.james.mime4j.dom.MessageBuilder) DefaultMessageBuilder(org.apache.james.mime4j.message.DefaultMessageBuilder) WebView(javafx.scene.web.WebView) Body(org.apache.james.mime4j.dom.Body) TextBody(org.apache.james.mime4j.dom.TextBody) BinaryBody(org.apache.james.mime4j.dom.BinaryBody)

Example 19 with WebView

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

the class HtmlEditorExam method start.

@Override
public void start(Stage stage) {
    stage.setTitle("HTMLEditor Sample");
    stage.setWidth(500);
    stage.setHeight(500);
    Scene scene = new Scene(new Group());
    VBox root = new VBox();
    root.setPadding(new Insets(8, 8, 8, 8));
    root.setSpacing(5);
    root.setAlignment(Pos.BOTTOM_LEFT);
    final HTMLEditor htmlEditor = new HTMLEditor();
    htmlEditor.setPrefHeight(245);
    htmlEditor.setHtmlText(INITIAL_TEXT);
    final WebView browser = new WebView();
    final WebEngine webEngine = browser.getEngine();
    ScrollPane scrollPane = new ScrollPane();
    scrollPane.getStyleClass().add("noborder-scroll-pane");
    scrollPane.setStyle("-fx-background-color: white");
    scrollPane.setContent(browser);
    scrollPane.setFitToWidth(true);
    scrollPane.setPrefHeight(180);
    Button showHTMLButton = new Button("Load Content in Browser");
    root.setAlignment(Pos.CENTER);
    showHTMLButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent arg0) {
            webEngine.loadContent(htmlEditor.getHtmlText());
        }
    });
    root.getChildren().addAll(htmlEditor, showHTMLButton, scrollPane);
    scene.setRoot(root);
    stage.setScene(scene);
    stage.show();
}
Also used : Group(javafx.scene.Group) Insets(javafx.geometry.Insets) Button(javafx.scene.control.Button) ScrollPane(javafx.scene.control.ScrollPane) ActionEvent(javafx.event.ActionEvent) HTMLEditor(javafx.scene.web.HTMLEditor) Scene(javafx.scene.Scene) WebView(javafx.scene.web.WebView) VBox(javafx.scene.layout.VBox) WebEngine(javafx.scene.web.WebEngine)

Aggregations

WebView (javafx.scene.web.WebView)19 Scene (javafx.scene.Scene)13 WebEngine (javafx.scene.web.WebEngine)8 ObservableValue (javafx.beans.value.ObservableValue)4 BorderPane (javafx.scene.layout.BorderPane)4 StackPane (javafx.scene.layout.StackPane)4 DarculaLookAndFeelInfo (com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo)3 State (javafx.concurrent.Worker.State)3 JFXPanel (javafx.embed.swing.JFXPanel)3 Button (javafx.scene.control.Button)3 VBox (javafx.scene.layout.VBox)3 URL (java.net.URL)2 ChangeListener (javafx.beans.value.ChangeListener)2 FXML (javafx.fxml.FXML)2 Group (javafx.scene.Group)2 Label (javafx.scene.control.Label)2 ScrollPane (javafx.scene.control.ScrollPane)2 PopupFeatures (javafx.scene.web.PopupFeatures)2 WebEvent (javafx.scene.web.WebEvent)2 JSObject (netscape.javascript.JSObject)2