private void requestUpdate()

in kit/src/main/java/com/oracle/javafx/scenebuilder/kit/preview/PreviewWindowController.java [248:336]


    private void requestUpdate(long delay) {
        TimerTask timerTask = new TimerTask() {

            @Override
            public void run() {
            // JavaFX data should only be accessed on the JavaFX thread.
            // => we must wrap the code into a Runnable object and call the Platform.runLater
            Platform.runLater(() -> {
                final FXOMDocument fxomDocument = editorController.getFxomDocument();
                String themeStyleSheetString = null;
                if (fxomDocument != null) {
                    // We clone the FXOMDocument
                    FXOMDocument clone;

                    try {
                        clone = new FXOMDocument(fxomDocument.getFxmlText(false),
                                fxomDocument.getLocation(),
                                fxomDocument.getClassLoader(),
                                fxomDocument.getResources());
                        clone.setSampleDataEnabled(fxomDocument.isSampleDataEnabled());
                    } catch (IOException ex) {
                        throw new RuntimeException("Bug in PreviewWindowController::requestUpdate", ex); //NOI18N
                    }

                    Object sceneGraphRoot = clone.getDisplayNodeOrSceneGraphRoot();
                    themeStyleSheetString = editorControllerTheme.getStylesheetURL();

                    if (sceneGraphRoot instanceof Parent) {
                        ((Parent) sceneGraphRoot).setId(NID_PREVIEW_ROOT);
                        assert ((Parent) sceneGraphRoot).getScene() == null;

                        setRoot((Parent) updateAutoResizeTransform((Parent) sceneGraphRoot));

                        // Compute the proper styling
                        List<String> newStyleSheets1 = new ArrayList<>();
                        computeStyleSheets(newStyleSheets1, sceneGraphRoot, clone.getDisplayStylesheets());

                        // Clean all styling
                        ((Parent) sceneGraphRoot).getStylesheets().removeAll();

                        // Apply the new styling
                        ((Parent) sceneGraphRoot).getStylesheets().addAll(newStyleSheets1);
                    } else if (sceneGraphRoot instanceof Node) {
                        StackPane sp1 = new StackPane();
                        sp1.setId(NID_PREVIEW_ROOT);

                        // Compute the proper styling
                        List<String> newStyleSheets2 = new ArrayList<>();
                        computeStyleSheets(newStyleSheets2, sceneGraphRoot, clone.getDisplayStylesheets());

                        // Apply the new styling as a whole
                        sp1.getStylesheets().addAll(newStyleSheets2);

                        // With some 3D assets such as TuxRotation the
                        // rendering is wrong unless applyCSS is called.
                        ((Node) sceneGraphRoot).applyCss();
                        sp1.getChildren().add(updateAutoResizeTransform((Node) sceneGraphRoot));
                        setRoot(sp1);
                    } else {
                        setCameraType(CameraType.PARALLEL);
                        sizeChangedFromMenu = false;
                        StackPane sp2 = new StackPane(new Label(I18N.getString("preview.not.node")));
                        sp2.setId(NID_PREVIEW_ROOT);
                        sp2.setPrefSize(WIDTH_WHEN_EMPTY, HEIGHT_WHEN_EMPTY);
                        setRoot(sp2);
                    }
                } else {
                    setCameraType(CameraType.PARALLEL);
                    sizeChangedFromMenu = false;
                    StackPane sp3 = new StackPane(new Label(I18N.getString("preview.no.document")));
                    sp3.setId(NID_PREVIEW_ROOT);
                    sp3.setPrefSize(WIDTH_WHEN_EMPTY, HEIGHT_WHEN_EMPTY);
                    setRoot(sp3);
                }

                getScene().setRoot(getRoot());
                updateWindowSize();
                updateWindowTitle();
            });
            }
        };

        if (timer != null) {
            timer.cancel();
        }

        timer = new Timer(true);
        timer.schedule(timerTask, delay); // milliseconds
    }