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

Print this page

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

    1063
    1064     /***********************************************************************
    1065      *                                                                     *
    1066      *                         Stylesheet Handling                         *
    1067      *                                                                     *
    1068      **********************************************************************/
    1069
    1070
    1071     /**
    1072      * A ObservableList of string URLs linking to the stylesheets to use with this scene's
    1073      * contents. For additional information about using CSS with the
    1074      * scene graph, see the <a href="doc-files/cssref.html">CSS Reference
    1075      * Guide</a>.
    1076      */
    1077     private final ObservableList<String> stylesheets = new TrackableObservableList<String>() {
    1078         @Override
    1079         protected void onChanged(Change<String> c) {
    1080             final Scene scene = getScene();
    1081             if (scene != null) {
    1082
    1083                 scene.styleManager.parentStylesheetsChanged(Parent.this, c);

    1084                 // RT-9784 - if stylesheet is removed, reset styled properties to
    1085                 // their initial value.
    1086                 while(c.next()) {
    1087                     if (c.wasRemoved() == false) continue;
    1088                     impl_cssResetInitialValues();
    1089                     break; // no point in resetting more than once...
    1090                 }
    1091
    1092                 impl_reapplyCSS();
    1093             }
    1094         }
    1095     };
    1096
    1097     /**
    1098      * Gets an observable list of string URLs linking to the stylesheets to use
    1099      * with this Parent's contents. For additional information about using CSS
    1100      * with the scene graph, see the <a href="doc-files/cssref.html">CSS Reference
    1101      * Guide</a>.
    1102      *
    1103      * @return the list of stylesheets to use with this Parent
    1104      */
    1105     public final ObservableList<String> getStylesheets() { return stylesheets; }
    1106

    1107     /**
    1108      * This method recurses up the parent chain until parent is null. As the
    1109      * stack unwinds, if the Parent has stylesheets, they are added to the
    1110      * list.
    1111      *
    1112      * It is possible to override this method to stop the recursion. This allows
    1113      * a Parent to have a set of stylesheets distinct from its Parent.
    1114      *
    1115      * @treatAsPrivate implementation detail
    1116      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    1117      */
    1118     @Deprecated // SB-dependency: RT-21247 has been filed to track this
    1119     public /* Do not make this final! */ List<String> impl_getAllParentStylesheets() {
    1120
    1121         List<String> list = null;
    1122         final Parent myParent = getParent();
    1123         if (myParent != null) {
    1124
    1125             //
    1126             // recurse so that stylesheets of Parents closest to the root are
    1129             // a higer ordinal in the cascade.
    1130             //
    1131             list = myParent.impl_getAllParentStylesheets();
    1132         }
    1133
    1134         if (stylesheets != null && stylesheets.isEmpty() == false) {
    1135             if (list == null) list = new ArrayList<String>(stylesheets.size());
    1136             for (int n=0,nMax=stylesheets.size(); n<nMax; n++)
    1137                 list.add(stylesheets.get(n));
    1138         }
    1139
    1140         return list;
    1141
    1142     }
    1143
    1144     /**
    1145      * @treatAsPrivate implementation detail
    1146      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    1147      */
    1148     @Deprecated
    1149     @Override public void impl_processCSS(boolean reapply) {

    1150         // Determine whether we will need to reapply from here on down
    1151         boolean flag = reapply || cssFlag == CSSFlags.REAPPLY;
    1152         // Let the super implementation handle CSS for this node
    1153         super.impl_processCSS(flag);
    1154         // For each child, process CSS
    1155         for (int i=0, max=children.size(); i<max; i++) {
    1156             final Node kid = children.get(i);
    1157             if (kid != null) {
    1158                 kid.impl_processCSS(flag);
    1159             }
    1160         }
    1161     }
    1162
    1163     /**
    1164      * @treatAsPrivate implementation detail
    1165      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    1166      */
    1167     @Deprecated
    1168     @Override public void impl_cssResetInitialValues() {
    1169         // RT-9784
    1170         super.impl_cssResetInitialValues();
    1171
    1172         for (int i=0, max=children.size(); i<max; i++) {
    1173             final Node kid = children.get(i);
    1174             if (kid != null) {
    1175                 kid.impl_cssResetInitialValues();
    1176             }
    1177         }
    1178     }
    1179
    1180
    1181     /***********************************************************************
    1182      *                               Misc                                  *
    1183      *                                                                     *
    1184      *  Initialization and other functions                                 *
    1185      *                                                                     *
    1186      **********************************************************************/
    1187
    1188
    1189     /**
    1190      * Constructs a new {@code Parent}.
    1191      */
    1192     protected Parent() { }

    1193
    1194     /**
    1195      * @treatAsPrivate implementation detail
    1196      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    1197      */
    1198     @Deprecated
    1199     protected @Override PGNode impl_createPGNode() {
    1200         return Toolkit.getToolkit().createPGGroup();
    1201     }
    1202
    1203     PGGroup getPGGroup() {
    1204         return ((PGGroup) impl_getPGNode());
    1205     }
    1206
    1207
    1208     /***************************************************************************
    1209      *                                                                         *
    1210      *                         Bounds Computations                             *
    1211      *                                                                         *
    1212      *  This code originated in GroupBoundsHelper (part of javafx-sg-common)   *
    1063
    1064     /***********************************************************************
    1065      *                                                                     *
    1066      *                         Stylesheet Handling                         *
    1067      *                                                                     *
    1068      **********************************************************************/
    1069
    1070
    1071     /**
    1072      * A ObservableList of string URLs linking to the stylesheets to use with this scene's
    1073      * contents. For additional information about using CSS with the
    1074      * scene graph, see the <a href="doc-files/cssref.html">CSS Reference
    1075      * Guide</a>.
    1076      */
    1077     private final ObservableList<String> stylesheets = new TrackableObservableList<String>() {
    1078         @Override
    1079         protected void onChanged(Change<String> c) {
    1080             final Scene scene = getScene();
    1081             if (scene != null) {
    1082
    1083                 StyleManager sm = getStyleManager();
    1084                 if (sm != null) sm.stylesheetsChanged(c);
    1085
    1086                 // RT-9784 - if stylesheet is removed, reset styled properties to
    1087                 // their initial value.
    1088                 while(c.next()) {
    1089                     if (c.wasRemoved() == false) continue;
    1090                     impl_cssResetInitialValues();
    1091                     break; // no point in resetting more than once...
    1092                 }
    1093
    1094                 impl_reapplyCSS();
    1095             }
    1096         }
    1097     };
    1098
    1099     /**
    1100      * Gets an observable list of string URLs linking to the stylesheets to use
    1101      * with this Parent's contents. For additional information about using CSS
    1102      * with the scene graph, see the <a href="doc-files/cssref.html">CSS Reference
    1103      * Guide</a>.
    1104      *
    1105      * @return the list of stylesheets to use with this Parent
    1106      */
    1107     public final ObservableList<String> getStylesheets() { return stylesheets; }
    1108
    1109     private StyleManager styleManager;
    1110     private StyleManager getStyleManager() {
    1111
    1112         final Scene scene = getScene();
    1113         final boolean hasStylesheets = (getStylesheets().isEmpty() == false);
    1114
    1115         if (hasStylesheets == false || scene == null) {
    1116
    1117             styleManager = null;
    1118
    1119         } else if (styleManager == null) {
    1120
    1121             Parent parent = getParent();
    1122             StyleManager sm = null;
    1123             while (parent != null && (sm = parent.styleManager) == null) {
    1124                 parent = parent.getParent();
    1125             }
    1126             if (sm == null) sm = scene.styleManager;
    1127             styleManager = StyleManager.createStyleManager(this, sm);
    1128         }
    1129
    1130         return styleManager;
    1131     }
    1132     /**
    1133      * This method recurses up the parent chain until parent is null. As the
    1134      * stack unwinds, if the Parent has stylesheets, they are added to the
    1135      * list.
    1136      *
    1137      * It is possible to override this method to stop the recursion. This allows
    1138      * a Parent to have a set of stylesheets distinct from its Parent.
    1139      *
    1140      * @treatAsPrivate implementation detail
    1141      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    1142      */
    1143     @Deprecated // SB-dependency: RT-21247 has been filed to track this
    1144     public /* Do not make this final! */ List<String> impl_getAllParentStylesheets() {
    1145
    1146         List<String> list = null;
    1147         final Parent myParent = getParent();
    1148         if (myParent != null) {
    1149
    1150             //
    1151             // recurse so that stylesheets of Parents closest to the root are
    1154             // a higer ordinal in the cascade.
    1155             //
    1156             list = myParent.impl_getAllParentStylesheets();
    1157         }
    1158
    1159         if (stylesheets != null && stylesheets.isEmpty() == false) {
    1160             if (list == null) list = new ArrayList<String>(stylesheets.size());
    1161             for (int n=0,nMax=stylesheets.size(); n<nMax; n++)
    1162                 list.add(stylesheets.get(n));
    1163         }
    1164
    1165         return list;
    1166
    1167     }
    1168
    1169     /**
    1170      * @treatAsPrivate implementation detail
    1171      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    1172      */
    1173     @Deprecated
    1174     @Override public void impl_processCSS(StyleManager styleManager, boolean reapply) {
    1175
    1176         final StyleManager parentStyleManager = getStyleManager();
    1177         final StyleManager relevantStyleManager =
    1178                 parentStyleManager != null ? parentStyleManager : styleManager;
    1179
    1180         // Determine whether we will need to reapply from here on down
    1181         boolean flag = reapply || cssFlag == CSSFlags.REAPPLY;
    1182         // Let the super implementation handle CSS for this node
    1183         super.impl_processCSS(relevantStyleManager, flag);
    1184         // For each child, process CSS
    1185         for (int i=0, max=children.size(); i<max; i++) {
    1186             final Node kid = children.get(i);
    1187             if (kid != null) {
    1188                 kid.impl_processCSS(relevantStyleManager, flag);
    1189             }
    1190         }
    1191     }
    1192
    1193     /**
    1194      * @treatAsPrivate implementation detail
    1195      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    1196      */
    1197     @Deprecated
    1198     @Override public void impl_cssResetInitialValues() {
    1199         // RT-9784
    1200         super.impl_cssResetInitialValues();
    1201
    1202         for (int i=0, max=children.size(); i<max; i++) {
    1203             final Node kid = children.get(i);
    1204             if (kid != null) {
    1205                 kid.impl_cssResetInitialValues();
    1206             }
    1207         }
    1208     }
    1209
    1210
    1211     /***********************************************************************
    1212      *                               Misc                                  *
    1213      *                                                                     *
    1214      *  Initialization and other functions                                 *
    1215      *                                                                     *
    1216      **********************************************************************/
    1217
    1218
    1219     /**
    1220      * Constructs a new {@code Parent}.
    1221      */
    1222     protected Parent() {
    1223     }
    1224
    1225     /**
    1226      * @treatAsPrivate implementation detail
    1227      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
    1228      */
    1229     @Deprecated
    1230     protected @Override PGNode impl_createPGNode() {
    1231         return Toolkit.getToolkit().createPGGroup();
    1232     }
    1233
    1234     PGGroup getPGGroup() {
    1235         return ((PGGroup) impl_getPGNode());
    1236     }
    1237
    1238
    1239     /***************************************************************************
    1240      *                                                                         *
    1241      *                         Bounds Computations                             *
    1242      *                                                                         *
    1243      *  This code originated in GroupBoundsHelper (part of javafx-sg-common)   *