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

Print this page

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

    *** 1078,1088 ****
              @Override
              protected void onChanged(Change<String> c) {
                  final Scene scene = getScene();
                  if (scene != null) {

    !                 scene.styleManager.parentStylesheetsChanged(Parent.this, c);
                      // RT-9784 - if stylesheet is removed, reset styled properties to
                      // their initial value.
                      while(c.next()) {
                          if (c.wasRemoved() == false) continue;
                          impl_cssResetInitialValues();
    --- 1078,1090 ----
              @Override
              protected void onChanged(Change<String> c) {
                  final Scene scene = getScene();
                  if (scene != null) {

    !                 StyleManager sm = getStyleManager();
    !                 if (sm != null) sm.stylesheetsChanged(c);
    !
                      // RT-9784 - if stylesheet is removed, reset styled properties to
                      // their initial value.
                      while(c.next()) {
                          if (c.wasRemoved() == false) continue;
                          impl_cssResetInitialValues();
    *** 1102,1111 ****
    --- 1104,1136 ----
           *
           * @return the list of stylesheets to use with this Parent
           */
          public final ObservableList<String> getStylesheets() { return stylesheets; }

    +     private StyleManager styleManager;
    +     private StyleManager getStyleManager() {
    +
    +         final Scene scene = getScene();
    +         final boolean hasStylesheets = (getStylesheets().isEmpty() == false);
    +
    +         if (hasStylesheets == false || scene == null) {
    +
    +             styleManager = null;
    +
    +         } else if (styleManager == null) {
    +
    +             Parent parent = getParent();
    +             StyleManager sm = null;
    +             while (parent != null && (sm = parent.styleManager) == null) {
    +                 parent = parent.getParent();
    +             }
    +             if (sm == null) sm = scene.styleManager;
    +             styleManager = StyleManager.createStyleManager(this, sm);
    +         }
    +
    +         return styleManager;
    +     }
          /**
           * This method recurses up the parent chain until parent is null. As the
           * stack unwinds, if the Parent has stylesheets, they are added to the
           * list.
           *
    *** 1144,1163 ****
          /**
           * @treatAsPrivate implementation detail
           * @deprecated This is an internal API that is not intended for use and will be removed in the next version
           */
          @Deprecated
    !     @Override public void impl_processCSS(boolean reapply) {
              // Determine whether we will need to reapply from here on down
              boolean flag = reapply || cssFlag == CSSFlags.REAPPLY;
              // Let the super implementation handle CSS for this node
    !         super.impl_processCSS(flag);
              // For each child, process CSS
              for (int i=0, max=children.size(); i<max; i++) {
                  final Node kid = children.get(i);
                  if (kid != null) {
    !                 kid.impl_processCSS(flag);
                  }
              }
          }

          /**
    --- 1169,1193 ----
          /**
           * @treatAsPrivate implementation detail
           * @deprecated This is an internal API that is not intended for use and will be removed in the next version
           */
          @Deprecated
    !     @Override public void impl_processCSS(StyleManager styleManager, boolean reapply) {
    !
    !         final StyleManager parentStyleManager = getStyleManager();
    !         final StyleManager relevantStyleManager =
    !                 parentStyleManager != null ? parentStyleManager : styleManager;
    !
              // Determine whether we will need to reapply from here on down
              boolean flag = reapply || cssFlag == CSSFlags.REAPPLY;
              // Let the super implementation handle CSS for this node
    !         super.impl_processCSS(relevantStyleManager, flag);
              // For each child, process CSS
              for (int i=0, max=children.size(); i<max; i++) {
                  final Node kid = children.get(i);
                  if (kid != null) {
    !                 kid.impl_processCSS(relevantStyleManager, flag);
                  }
              }
          }

          /**
    *** 1187,1197 ****

          /**
           * Constructs a new {@code Parent}.
           */
    !     protected Parent() { }

          /**
           * @treatAsPrivate implementation detail
           * @deprecated This is an internal API that is not intended for use and will be removed in the next version
           */
    --- 1217,1228 ----

          /**
           * Constructs a new {@code Parent}.
           */
    !     protected Parent() {
    !     }

          /**
           * @treatAsPrivate implementation detail
           * @deprecated This is an internal API that is not intended for use and will be removed in the next version
           */