## javafx-ui-common/src/javafx/scene/Scene.java

Print this page

    rev 1582 : RT-22121: Have StyleManager for Parent, also

     268      * <p>
     269      * The depthBuffer flag is a conditional feature and its default value is
     270      * false. See
     271      * {@link javafx.application.ConditionalFeature#SCENE3D ConditionalFeature.SCENE3D}
     272      * for more information.
     273      *
     274      * @throws IllegalStateException if this constructor is called on a thread
     275      * other than the JavaFX Application Thread.
     276      * @throws NullPointerException if root is null
     277      *
     278      * @see javafx.scene.Node#setDepthTest(DepthTest)
     279      */
     280     public Scene(Parent root, @Default("-1") double width, @Default("-1") double height, boolean depthBuffer) {
     281         this(root, width, height, Color.WHITE, depthBuffer);
     282     }
     283
     284     private Scene(Parent root, double width, double height,
     285             @Default("javafx.scene.paint.Color.WHITE") Paint fill,
     286             boolean depthBuffer) {
     287         Toolkit.getToolkit().checkFxUserThread();
     288         styleManager = new StyleManager(this);
     289         setRoot(root);
     290         init(width, height, depthBuffer);
     291         setFill(fill);
     292     }
     293
     294     static {
     295             PerformanceTracker.setSceneAccessor(new PerformanceTracker.SceneAccessor() {
     296                 public void setPerfTracker(Scene scene, PerformanceTracker tracker) {
     297                     synchronized (trackerMonitor) {
     298                         scene.tracker = tracker;
     299                     }
     300                 }
     301                 public PerformanceTracker getPerfTracker(Scene scene) {
     302                     synchronized (trackerMonitor) {
     303                         return scene.tracker;
     304                     }
     305                 }
     306             });
     307             FXRobotHelper.setSceneAccessor(new FXRobotHelper.FXRobotSceneAccessor() {
     308                 public void processKeyEvent(Scene scene, KeyEvent keyEvent) {
     424         //
     425         // RT-17547: when the tree is synchronized, the dirty bits are
     426         // are cleared but the cssFlag might still be something other than
     427         // clean.
     428         //
     429         // Before RT-17547, the code checked the dirty bit. But this is
     430         // superfluous since the dirty bit will be set if the flag is not clean,
     431         // but the flag will never be anything other than clean if the dirty
     432         // bit is not set. The dirty bit is still needed, however, since setting
     433         // it ensures a pulse if no other dirty bits have been set.
     434         //
     435         // For the purpose of showing the change, the dirty bit
     436         // check code was commented out and not removed.
     437         //
     438 //        if (sceneRoot.impl_isDirty(com.sun.javafx.scene.DirtyBits.NODE_CSS)) {
     439         if (sceneRoot.cssFlag != CSSFlags.CLEAN) {
     440             // The dirty bit isn't checked but we must ensure it is cleared.
     441             // The cssFlag is set to clean in either Node.processCSS or
     442             // Node.impl_processCSS(boolean)
     443             sceneRoot.impl_clearDirty(com.sun.javafx.scene.DirtyBits.NODE_CSS);
     444             sceneRoot.processCSS();
     445         }
     446     }
     447
     448     /**
     449      * List of dirty layout roots.
     450      * When a parent is either marked as a layout root or is unmanaged and it
     451      * has its needsLayout flag set to true, then that node is added to this set
     452      * so that it can be laid out on the next pulse without requiring its
     453      * ancestors to be laid out.
     454      */
     455     private Set<Parent> dirtyLayoutRootsA = new LinkedHashSet<Parent>(10);
     456     private Set<Parent> dirtyLayoutRootsB = new LinkedHashSet<Parent>(10);
     457     private Set<Parent> dirtyLayoutRoots = dirtyLayoutRootsA;
     458
     459     /**
     460      * Add the specified parent to this scene's dirty layout list.
     461      * @treatAsPrivate implementation detail
     462      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
     463      */
     464     @Deprecated
    1362      * If more than one node matches the specified selector, this function
    1363      * returns the first of them.
    1364      * If no nodes are found with this id, then null is returned.
    1365      *
    1366      * @param selector The css selector to look up
    1367      * @return the {@code Node} in the scene which matches the CSS {@code selector},
    1368      * or {@code null} if none is found.
    1369      */
    1370      public Node lookup(String selector) {
    1371          return getRoot().lookup(selector);
    1372      }
    1373     /**
    1374      * A ObservableList of string URLs linking to the stylesheets to use with this scene's
    1375      * contents. For additional information about using CSS with the
    1376      * scene graph, see the <a href="doc-files/cssref.html">CSS Reference
    1377      * Guide</a>.
    1378      */
    1379     private final ObservableList<String> stylesheets  = new TrackableObservableList<String>() {
    1380         @Override
    1381         protected void onChanged(Change<String> c) {
    1382             styleManager.updateStylesheets();
    1383             // RT-9784 - if stylesheet is removed, reset styled properties to
    1384             // their initial value.
    1385             while(c.next()) {
    1386                 if (c.wasRemoved() == false) continue;
    1387                 getRoot().impl_cssResetInitialValues();
    1388                 break; // no point in resetting more than once...
    1389         }
    1390             c.reset();
    1391             getRoot().impl_reapplyCSS();
    1392         }
    1393     };
    1394
    1395     /**
    1396      * Gets an observable list of string URLs linking to the stylesheets to use
    1397      * with this scene's contents. For additional information about using CSS
    1398      * with the scene graph, see the <a href="doc-files/cssref.html">CSS Reference
    1399      * Guide</a>.
    1400      *
    1401      * @return the list of stylesheets to use with this scene
    1402      */
     268      * <p>
     269      * The depthBuffer flag is a conditional feature and its default value is
     270      * false. See
     271      * {@link javafx.application.ConditionalFeature#SCENE3D ConditionalFeature.SCENE3D}
     272      * for more information.
     273      *
     274      * @throws IllegalStateException if this constructor is called on a thread
     275      * other than the JavaFX Application Thread.
     276      * @throws NullPointerException if root is null
     277      *
     278      * @see javafx.scene.Node#setDepthTest(DepthTest)
     279      */
     280     public Scene(Parent root, @Default("-1") double width, @Default("-1") double height, boolean depthBuffer) {
     281         this(root, width, height, Color.WHITE, depthBuffer);
     282     }
     283
     284     private Scene(Parent root, double width, double height,
     285             @Default("javafx.scene.paint.Color.WHITE") Paint fill,
     286             boolean depthBuffer) {
     287         Toolkit.getToolkit().checkFxUserThread();
     288         styleManager = StyleManager.createStyleManager(this);
     289         setRoot(root);
     290         init(width, height, depthBuffer);
     291         setFill(fill);
     292     }
     293
     294     static {
     295             PerformanceTracker.setSceneAccessor(new PerformanceTracker.SceneAccessor() {
     296                 public void setPerfTracker(Scene scene, PerformanceTracker tracker) {
     297                     synchronized (trackerMonitor) {
     298                         scene.tracker = tracker;
     299                     }
     300                 }
     301                 public PerformanceTracker getPerfTracker(Scene scene) {
     302                     synchronized (trackerMonitor) {
     303                         return scene.tracker;
     304                     }
     305                 }
     306             });
     307             FXRobotHelper.setSceneAccessor(new FXRobotHelper.FXRobotSceneAccessor() {
     308                 public void processKeyEvent(Scene scene, KeyEvent keyEvent) {
     424         //
     425         // RT-17547: when the tree is synchronized, the dirty bits are
     426         // are cleared but the cssFlag might still be something other than
     427         // clean.
     428         //
     429         // Before RT-17547, the code checked the dirty bit. But this is
     430         // superfluous since the dirty bit will be set if the flag is not clean,
     431         // but the flag will never be anything other than clean if the dirty
     432         // bit is not set. The dirty bit is still needed, however, since setting
     433         // it ensures a pulse if no other dirty bits have been set.
     434         //
     435         // For the purpose of showing the change, the dirty bit
     436         // check code was commented out and not removed.
     437         //
     438 //        if (sceneRoot.impl_isDirty(com.sun.javafx.scene.DirtyBits.NODE_CSS)) {
     439         if (sceneRoot.cssFlag != CSSFlags.CLEAN) {
     440             // The dirty bit isn't checked but we must ensure it is cleared.
     441             // The cssFlag is set to clean in either Node.processCSS or
     442             // Node.impl_processCSS(boolean)
     443             sceneRoot.impl_clearDirty(com.sun.javafx.scene.DirtyBits.NODE_CSS);
     444             sceneRoot.processCSS(styleManager);
     445         }
     446     }
     447
     448     /**
     449      * List of dirty layout roots.
     450      * When a parent is either marked as a layout root or is unmanaged and it
     451      * has its needsLayout flag set to true, then that node is added to this set
     452      * so that it can be laid out on the next pulse without requiring its
     453      * ancestors to be laid out.
     454      */
     455     private Set<Parent> dirtyLayoutRootsA = new LinkedHashSet<Parent>(10);
     456     private Set<Parent> dirtyLayoutRootsB = new LinkedHashSet<Parent>(10);
     457     private Set<Parent> dirtyLayoutRoots = dirtyLayoutRootsA;
     458
     459     /**
     460      * Add the specified parent to this scene's dirty layout list.
     461      * @treatAsPrivate implementation detail
     462      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
     463      */
     464     @Deprecated
    1362      * If more than one node matches the specified selector, this function
    1363      * returns the first of them.
    1364      * If no nodes are found with this id, then null is returned.
    1365      *
    1366      * @param selector The css selector to look up
    1367      * @return the {@code Node} in the scene which matches the CSS {@code selector},
    1368      * or {@code null} if none is found.
    1369      */
    1370      public Node lookup(String selector) {
    1371          return getRoot().lookup(selector);
    1372      }
    1373     /**
    1374      * A ObservableList of string URLs linking to the stylesheets to use with this scene's
    1375      * contents. For additional information about using CSS with the
    1376      * scene graph, see the <a href="doc-files/cssref.html">CSS Reference
    1377      * Guide</a>.
    1378      */
    1379     private final ObservableList<String> stylesheets  = new TrackableObservableList<String>() {
    1380         @Override
    1381         protected void onChanged(Change<String> c) {
    1382             styleManager.stylesheetsChanged(c);
    1383             // RT-9784 - if stylesheet is removed, reset styled properties to
    1384             // their initial value.
    1385             while(c.next()) {
    1386                 if (c.wasRemoved() == false) continue;
    1387                 getRoot().impl_cssResetInitialValues();
    1388                 break; // no point in resetting more than once...
    1389         }
    1390             c.reset();
    1391             getRoot().impl_reapplyCSS();
    1392         }
    1393     };
    1394
    1395     /**
    1396      * Gets an observable list of string URLs linking to the stylesheets to use
    1397      * with this scene's contents. For additional information about using CSS
    1398      * with the scene graph, see the <a href="doc-files/cssref.html">CSS Reference
    1399      * Guide</a>.
    1400      *
    1401      * @return the list of stylesheets to use with this scene
    1402      */