kit/src/main/java/com/oracle/javafx/scenebuilder/kit/preview/PreviewWindowController.java
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());
                      BindingExpressionDisabler.disable(clone);
                    } 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
  }
/**
   * We use the provided delay before refreshing the content of the preview. If further modification
   * is brought to the layout before expiration of it we restart the timer. The idea is to lower the
   * resources used to refresh the preview window content. The delay is expressed in milliseconds.
   * In some cases it is wise to used delay = 0, e.g. when opening the window.
   */
We use the provided delay before refreshing the content of the preview. If further modification
is brought to the layout before expiration of it we restart the timer. The idea is to lower the
resources used to refresh the preview window content. The delay is expressed in milliseconds.
In some cases it is wise to used delay = 0, e.g. when opening the window.
We use the provided delay before refreshing the content of the preview . If further modification is brought to the layout before expiration of it we restart the timer . The idea is to lower the resources used to refresh the preview window content . The delay is expressed in milliseconds . In some cases it is wise to used delay = 0 e . g . when opening the window .
private void requestUpdate(long delay) {
    TimerTask timerTask =
        new TimerTask() {
          @Override
          public void run() {
            Platform.runLater(
                () -> {
                  final FXOMDocument fxomDocument = editorController.getFxomDocument();
                  String themeStyleSheetString = null;
                  if (fxomDocument != null) {
                    FXOMDocument clone;
                    try {
                      clone =
                          new FXOMDocument(
                              fxomDocument.getFxmlText(false),
                              fxomDocument.getLocation(),
                              fxomDocument.getClassLoader(),
                              fxomDocument.getResources());
                      clone.setSampleDataEnabled(fxomDocument.isSampleDataEnabled());
                      BindingExpressionDisabler.disable(clone);
                    } catch (IOException ex) {
                      throw new RuntimeException(
                          "Bug in PreviewWindowController::requestUpdate", ex); 
                    }
                    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));
                      List<String> newStyleSheets1 = new ArrayList<>();
                      computeStyleSheets(
                          newStyleSheets1, sceneGraphRoot, clone.getDisplayStylesheets());
                      ((Parent) sceneGraphRoot).getStylesheets().removeAll();
                      ((Parent) sceneGraphRoot).getStylesheets().addAll(newStyleSheets1);
                    } else if (sceneGraphRoot instanceof Node) {
                      StackPane sp1 = new StackPane();
                      sp1.setId(NID_PREVIEW_ROOT);
                      List<String> newStyleSheets2 = new ArrayList<>();
                      computeStyleSheets(
                          newStyleSheets2, sceneGraphRoot, clone.getDisplayStylesheets());
                       as a whole
                      sp1.getStylesheets().addAll(newStyleSheets2);
                      ((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); 
  }
private void requestUpdate ( long delay ) { TimerTask timerTask = new TimerTask ( ) { @ Override public void run ( ) { Platform . runLater ( ( ) -> { final FXOMDocument fxomDocument = editorController . getFxomDocument ( ) ; String themeStyleSheetString = null ; if ( fxomDocument != null ) { FXOMDocument clone ; try { clone = new FXOMDocument ( fxomDocument . getFxmlText ( false ) , fxomDocument . getLocation ( ) , fxomDocument . getClassLoader ( ) , fxomDocument . getResources ( ) ) ; clone . setSampleDataEnabled ( fxomDocument . isSampleDataEnabled ( ) ) ; BindingExpressionDisabler . disable ( clone ) ; } catch ( IOException ex ) { throw new RuntimeException ( "Bug in PreviewWindowController::requestUpdate" , ex ) ; } 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 ) ) ; List < String > newStyleSheets1 = new ArrayList < > ( ) ; computeStyleSheets ( newStyleSheets1 , sceneGraphRoot , clone . getDisplayStylesheets ( ) ) ; ( ( Parent ) sceneGraphRoot ) . getStylesheets ( ) . removeAll ( ) ; ( ( Parent ) sceneGraphRoot ) . getStylesheets ( ) . addAll ( newStyleSheets1 ) ; } else if ( sceneGraphRoot instanceof Node ) { StackPane sp1 = new StackPane ( ) ; sp1 . setId ( NID_PREVIEW_ROOT ) ; List < String > newStyleSheets2 = new ArrayList < > ( ) ; computeStyleSheets ( newStyleSheets2 , sceneGraphRoot , clone . getDisplayStylesheets ( ) ) ; sp1 . getStylesheets ( ) . addAll ( newStyleSheets2 ) ; ( ( 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 ) ; }
We use the provided delay before refreshing the content of the preview.
We use the provided delay before refreshing the content of the preview .
// JavaFX data should only be accessed on the JavaFX thread. // => we must wrap the code into a Runnable object and call the Platform.runLater // We clone the FXOMDocument // NOI18N // Compute the proper styling // Clean all styling // Apply the new styling // Compute the proper styling // Apply the new styling as a whole // With some 3D assets such as TuxRotation the // rendering is wrong unless applyCSS is called. // milliseconds