Search in sources :

Example 26 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)

Example 27 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 28 with WebView

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

the class SimpleTextView method miOpenNamoWebViewOnAction.

/**
	 * Mime 데이터타입을 Html컨텐츠형태로 조회하기 위한 웹 뷰를 오픈함.
	 * @작성자 : KYJ
	 * @작성일 : 2016. 12. 29.
	 */
@FXML
public void miOpenNamoWebViewOnAction() {
    String content = codeArea.getText();
    try {
        WebView webView = new WebView();
        //			new ContentMimeHtmlAdapter(content)
        //			String encodeToString = Base64.getEncoder().encodeToString(content.getBytes());
        //
        //			byte[] decode = Base64.getDecoder().decode(encodeToString);
        //			String string = new String(decode);
        //			MimeBodyPart part = new MimeBodyPart(new ByteArrayInputStream(content.getBytes()));
        //			Enumeration allHeaders = part.getAllHeaders();
        //			while(allHeaders.hasMoreElements())
        //			{
        //				javax.mail.Header nextElement = (Header) allHeaders.nextElement();
        //
        //				System.out.println(nextElement.getName());
        //				System.out.println(nextElement.getValue());
        //			}
        //
        //			DataHandler dataHandler = part.getDataHandler();
        //			Object transferData = dataHandler.getTransferData(new DataFlavor("text/html"));
        //			System.out.println(transferData);
        //			ContentMimeHtmlAdapter adapter = new ContentMimeHtmlAdapter(content);
        //			File tempFile = adapter.toTempFile();
        //			byte[] decode = Base64.getMimeDecoder().decode(content.getBytes("UTF-8"));
        //			String string = new String(decode);
        FxUtil.createStageAndShow(webView, stage -> {
            stage.setAlwaysOnTop(true);
            stage.initOwner(getScene().getWindow());
            stage.focusedProperty().addListener((oba, o, n) -> {
                if (!n)
                    stage.close();
            });
        });
        javafx.application.Platform.runLater(() -> {
            try {
                MimeToHtmlAdapter adapter = new MimeToHtmlAdapter(content);
                webView.getEngine().loadContent(adapter.getContent());
            } catch (Exception e) {
                e.printStackTrace();
            }
        });
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MimeToHtmlAdapter(com.kyj.fx.voeditor.visual.framework.word.MimeToHtmlAdapter) WebView(javafx.scene.web.WebView) FXML(javafx.fxml.FXML)

Example 29 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 30 with WebView

use of javafx.scene.web.WebView in project POL-POM-5 by PhoenicisOrg.

the class ApplicationPanel method populateCenter.

private void populateCenter() {
    this.appDescription = new WebView();
    this.appDescription.getEngine().loadContent("<body>" + application.getDescription() + "</body>");
    themeManager.bindWebEngineStylesheet(appDescription.getEngine().userStyleSheetLocationProperty());
    this.installers = new Label(tr("Installers"));
    this.installers.getStyleClass().add("descriptionTitle");
    this.scriptGrid = new GridPane();
    filteredScripts.addListener((InvalidationListener) change -> this.refreshScripts());
    this.refreshScripts();
    this.miniaturesPane = new HBox();
    this.miniaturesPane.getStyleClass().add("appPanelMiniaturesPane");
    this.miniaturesPaneWrapper = new ScrollPane(miniaturesPane);
    this.miniaturesPaneWrapper.getStyleClass().add("appPanelMiniaturesPaneWrapper");
    for (URI miniatureUri : application.getMiniatures()) {
        Region image = new Region();
        image.getStyleClass().add("appMiniature");
        image.setStyle(String.format("-fx-background-image: url(\"%s\");", miniatureUri.toString()));
        image.prefHeightProperty().bind(miniaturesPaneWrapper.heightProperty().multiply(0.8));
        image.prefWidthProperty().bind(image.prefHeightProperty().multiply(1.5));
        miniaturesPane.getChildren().add(image);
    }
    this.center = new VBox(appDescription, installers, scriptGrid, miniaturesPaneWrapper);
    VBox.setVgrow(appDescription, Priority.ALWAYS);
    this.setCenter(center);
}
Also used : Button(javafx.scene.control.Button) WebView(javafx.scene.web.WebView) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) javafx.scene.layout(javafx.scene.layout) ErrorMessage(org.phoenicis.javafx.views.common.ErrorMessage) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) InvalidationListener(javafx.beans.InvalidationListener) ApplicationDTO(org.phoenicis.repository.dto.ApplicationDTO) Consumer(java.util.function.Consumer) ScrollPane(javafx.scene.control.ScrollPane) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) DetailsView(org.phoenicis.javafx.views.common.widgets.lists.DetailsView) PhoenicisFilteredList(org.phoenicis.javafx.views.common.lists.PhoenicisFilteredList) URI(java.net.URI) Tooltip(javafx.scene.control.Tooltip) ThemeManager(org.phoenicis.javafx.views.common.ThemeManager) ScriptDTO(org.phoenicis.repository.dto.ScriptDTO) ScrollPane(javafx.scene.control.ScrollPane) Label(javafx.scene.control.Label) WebView(javafx.scene.web.WebView) URI(java.net.URI)

Aggregations

WebView (javafx.scene.web.WebView)50 Scene (javafx.scene.Scene)31 WebEngine (javafx.scene.web.WebEngine)15 BorderPane (javafx.scene.layout.BorderPane)10 Button (javafx.scene.control.Button)9 URL (java.net.URL)8 ObservableValue (javafx.beans.value.ObservableValue)7 Label (javafx.scene.control.Label)7 Tooltip (javafx.scene.control.Tooltip)7 StackPane (javafx.scene.layout.StackPane)6 VBox (javafx.scene.layout.VBox)6 Stage (javafx.stage.Stage)6 State (javafx.concurrent.Worker.State)5 JFXPanel (javafx.embed.swing.JFXPanel)5 ScrollPane (javafx.scene.control.ScrollPane)5 JFrame (javax.swing.JFrame)5 URI (java.net.URI)4 InvalidationListener (javafx.beans.InvalidationListener)4 FXCollections (javafx.collections.FXCollections)4 javafx.scene.layout (javafx.scene.layout)4