Example usage for javafx.embed.swing JFXPanel setScene

List of usage examples for javafx.embed.swing JFXPanel setScene

Introduction

In this page you can find the example usage for javafx.embed.swing JFXPanel setScene.

Prototype

public void setScene(final Scene newScene) 

Source Link

Document

Attaches a Scene object to display in this JFXPanel .

Usage

From source file:Main.java

private static void initFX(JFXPanel fxPanel) {
    final Group rootGroup = new Group();
    final Scene scene = new Scene(rootGroup, 800, 400, Color.BEIGE);

    fxPanel.setScene(scene);
}

From source file:tw.edu.sju.ee.eea.module.iepe.project.window.IepeRealtimeSpectrumElement.java

private void initFX(JFXPanel fxPanel) {
    // This method is invoked on the JavaFX thread
    Scene scene = createScene();//from   w  w  w  .j a v a2 s.  c o  m
    fxPanel.setScene(scene);

    //-- Prepare Executor Services
    executor = Executors.newCachedThreadPool();
    addToQueue = new AddToQueue();
    executor.execute(addToQueue);
    //-- Prepare Timeline
    prepareTimeline();
}

From source file:gui.accessories.GraphPopup.java

private void initFX(JFXPanel fxPanel) {
    // This method is invoked on the JavaFX thread
    Stage window = new Stage();
    window.initModality(Modality.APPLICATION_MODAL);
    window.setTitle(labels.getString("PONTOS.VITORIA"));
    window.setMinWidth(500);//from  w w w  .j a  v  a2  s.co  m

    Chart chart = createStackedBarChart();
    chart.setAnimated(true);
    Scene scene = new Scene(chart);

    //show and tell
    window.setScene(scene);
    window.showAndWait();

    fxPanel.setScene(scene);
}

From source file:eu.ggnet.dwoss.redtape.document.DocumentUpdateView.java

private void initFxComponents() {
    final JFXPanel jfxp = new JFXPanel();
    positionPanelFx.add(jfxp, BorderLayout.CENTER);

    Platform.runLater(() -> {//from   www . ja  v a2s .co  m
        BorderPane pane = new BorderPane();
        Scene scene = new Scene(pane, Color.ALICEBLUE);

        positionsFxList = new ListView<>();
        positionsFxList.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
        positionsFxList.setCellFactory(new PositionListCell.Factory());
        positionsFxList.setItems(positions);
        positionsFxList.setOnMouseClicked((mouseEvent) -> {
            if (mouseEvent.getButton().equals(MouseButton.PRIMARY) && mouseEvent.getClickCount() == 2) {
                if (isChangeAllowed()) {
                    controller.editPosition(positionsFxList.getSelectionModel().getSelectedItem());
                    positionsFxList.refresh();
                } else {
                    Alert.show("nderung an Positionen ist nicht erlaubt.");
                }
            }
        });

        pane.setCenter(positionsFxList);
        jfxp.setScene(scene);
    });
}

From source file:org.wandora.application.gui.topicpanels.webview.WebViewPanel.java

private void initFX(final JFXPanel fxPanel) {
    Group group = new Group();
    Scene scene = new Scene(group);
    fxPanel.setScene(scene);

    webView = new WebView();

    if (javaFXVersionInt >= 8) {
        webView.setScaleX(1.0);//from   www .  j av  a2  s .  c om
        webView.setScaleY(1.0);
        //webView.setFitToHeight(false);
        //webView.setFitToWidth(false);
        //webView.setZoom(javafx.stage.Screen.getPrimary().getDpi() / 96);
    }

    group.getChildren().add(webView);

    int w = this.getWidth();
    int h = this.getHeight() - 34;

    webView.setMinSize(w, h);
    webView.setMaxSize(w, h);
    webView.setPrefSize(w, h);

    // Obtain the webEngine to navigate
    webEngine = webView.getEngine();

    webEngine.locationProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue,
                final String newValue) {
            if (newValue.endsWith(".pdf")) {
                try {
                    int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(),
                            "Open PDF document in external application?",
                            "Open PDF document in external application?", WandoraOptionPane.YES_NO_OPTION);
                    if (a == WandoraOptionPane.YES_OPTION) {
                        Desktop dt = Desktop.getDesktop();
                        dt.browse(new URI(newValue));
                    }
                } catch (Exception e) {
                }
            } else {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        urlTextField.setText(newValue);
                    }
                });
            }
        }
    });
    webEngine.titleProperty().addListener(new ChangeListener<String>() {
        @Override
        public void changed(ObservableValue<? extends String> observable, String oldValue,
                final String newValue) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    title = newValue;
                }
            });
        }
    });
    webEngine.setOnAlert(new EventHandler<WebEvent<java.lang.String>>() {
        @Override
        public void handle(WebEvent<String> t) {
            if (t != null) {
                String str = t.getData();
                if (str != null && str.length() > 0) {
                    WandoraOptionPane.showMessageDialog(Wandora.getWandora(), str, "Javascript Alert",
                            WandoraOptionPane.PLAIN_MESSAGE);
                }
            }
        }
    });
    webEngine.setConfirmHandler(new Callback<String, Boolean>() {
        @Override
        public Boolean call(String msg) {
            int a = WandoraOptionPane.showConfirmDialog(Wandora.getWandora(), msg, "Javascript Alert",
                    WandoraOptionPane.YES_NO_OPTION);
            return (a == WandoraOptionPane.YES_OPTION);
        }
    });
    webEngine.setPromptHandler(new Callback<PromptData, String>() {
        @Override
        public String call(PromptData data) {
            String a = WandoraOptionPane.showInputDialog(Wandora.getWandora(), data.getMessage(),
                    data.getDefaultValue(), "Javascript Alert", WandoraOptionPane.QUESTION_MESSAGE);
            return a;
        }
    });

    webEngine.setCreatePopupHandler(new Callback<PopupFeatures, WebEngine>() {
        @Override
        public WebEngine call(PopupFeatures features) {
            if (informPopupBlocking) {
                WandoraOptionPane.showMessageDialog(Wandora.getWandora(),
                        "A javascript popup has been blocked. Wandora doesn't allow javascript popups in Webview topic panel.",
                        "Javascript popup blocked", WandoraOptionPane.PLAIN_MESSAGE);
            }
            informPopupBlocking = false;
            return null;
        }
    });
    webEngine.setOnVisibilityChanged(new EventHandler<WebEvent<Boolean>>() {
        @Override
        public void handle(WebEvent<Boolean> t) {
            if (t != null) {
                Boolean b = t.getData();
                if (informVisibilityChanges) {
                    WandoraOptionPane.showMessageDialog(Wandora.getWandora(),
                            "A browser window visibility change has been blocked. Wandora doesn't allow visibility changes of windows in Webview topic panel.",
                            "Javascript visibility chnage blocked", WandoraOptionPane.PLAIN_MESSAGE);
                    informVisibilityChanges = false;
                }
            }
        }
    });
    webEngine.getLoadWorker().stateProperty().addListener(new ChangeListener<State>() {
        @Override
        public void changed(ObservableValue ov, State oldState, State newState) {
            if (newState == Worker.State.SCHEDULED) {
                //System.out.println("Scheduled!");
                startLoadingAnimation();
            }
            if (newState == Worker.State.SUCCEEDED) {
                Document doc = webEngine.getDocument();
                try {
                    Transformer transformer = TransformerFactory.newInstance().newTransformer();
                    //transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
                    transformer.setOutputProperty(OutputKeys.METHOD, "xml");
                    transformer.setOutputProperty(OutputKeys.INDENT, "yes");
                    transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
                    transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");

                    // transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(System.out, "UTF-8")));

                    StringWriter stringWriter = new StringWriter();
                    transformer.transform(new DOMSource(doc), new StreamResult(stringWriter));
                    webSource = stringWriter.toString();
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                stopLoadingAnimation();
            } else if (newState == Worker.State.CANCELLED) {
                //System.out.println("Cancelled!");
                stopLoadingAnimation();
            } else if (newState == Worker.State.FAILED) {
                webEngine.loadContent(failedToOpenMessage);
                stopLoadingAnimation();
            }
        }
    });

}

From source file:utybo.branchingstorytree.swing.visuals.NodePanel.java

public NodePanel(BranchingStory story, StoryPanel parent, final IMGClient imageClient) {
    OpenBSTGUI.getInstance().addDarkModeCallback(callback);
    callback.accept(OpenBSTGUI.getInstance().isDark());
    this.parent = parent;
    this.imageClient = imageClient;
    setLayout(new BorderLayout());

    JFXPanel panel = new JFXPanel();
    add(panel, BorderLayout.CENTER);

    CountDownLatch cdl = new CountDownLatch(1);
    Platform.runLater(() -> {//from   w w  w.  ja  v a  2 s .co  m
        try {
            view = new WebView();
            view.getEngine().setOnAlert(e -> SwingUtilities
                    .invokeLater(() -> Messagers.showMessage(OpenBSTGUI.getInstance(), e.getData())));
            view.getEngine().getLoadWorker().stateProperty().addListener((obs, oldState, newState) -> {
                if (newState == State.SUCCEEDED) {
                    Document doc = view.getEngine().getDocument();
                    NodeList nl = doc.getElementsByTagName("a");
                    for (int i = 0; i < nl.getLength(); i++) {
                        Node n = nl.item(i);
                        HTMLAnchorElement a = (HTMLAnchorElement) n;
                        if (a.getHref() != null) {
                            ((EventTarget) a).addEventListener("click", ev -> {
                                if (!hrefEnabled) {
                                    ev.preventDefault();
                                }
                            }, false);
                        }
                    }
                }
            });
            Scene sc = new Scene(view);
            try {
                view.getEngine()
                        .loadContent(IOUtils
                                .toString(
                                        NodePanel.class.getResourceAsStream(
                                                "/utybo/branchingstorytree/swing/html/error.html"),
                                        StandardCharsets.UTF_8)
                                .replace("$MSG", Lang.get("story.problem")).replace("$STYLE", FONT_UBUNTU));
            } catch (IOException e) {
                OpenBST.LOG.warn("Error on trying to load error HTML file", e);
            }
            panel.setScene(sc);
        } finally {
            cdl.countDown();
        }
    });
    try {
        cdl.await();
    } catch (InterruptedException e) {
        OpenBST.LOG.warn("Synchronization failed", e);
    }
}