modules/graphics/src/main/java/com/sun/javafx/css/StyleManager.java

Print this page




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.css;
  27 

  28 import javafx.css.Styleable;
  29 import java.io.FileNotFoundException;
  30 import java.io.FilePermission;
  31 import java.io.IOException;
  32 import java.io.InputStream;
  33 import java.lang.ref.Reference;
  34 import java.lang.ref.WeakReference;
  35 import java.net.MalformedURLException;
  36 import java.net.URI;
  37 import java.net.URISyntaxException;
  38 import java.net.URL;
  39 import java.security.AccessControlContext;
  40 import java.security.AccessController;
  41 import java.security.DigestInputStream;
  42 import java.security.MessageDigest;
  43 import java.security.NoSuchAlgorithmException;
  44 import java.security.PermissionCollection;
  45 import java.security.PrivilegedAction;
  46 import java.security.PrivilegedActionException;
  47 import java.security.PrivilegedExceptionAction;


1252 
1253         final Stylesheet ua_stylesheet = loadStylesheet(fname);
1254         final StylesheetContainer sc = new StylesheetContainer(fname, ua_stylesheet);
1255         if (platformUserAgentStylesheetContainers.size() == 0) {
1256             platformUserAgentStylesheetContainers.add(sc);
1257         } else if (hasDefaultUserAgentStylesheet) {
1258             platformUserAgentStylesheetContainers.set(0,sc);
1259         } else {
1260             platformUserAgentStylesheetContainers.add(0,sc);
1261         }
1262         hasDefaultUserAgentStylesheet = true;
1263 
1264         if (ua_stylesheet != null) {
1265             ua_stylesheet.setOrigin(StyleOrigin.USER_AGENT);
1266         }
1267         userAgentStylesheetsChanged();
1268 
1269         // RT-20643
1270         CssError.setCurrentScene(null);
1271 



































1272     }
1273 
1274     /**
1275      * Set the user agent stylesheet. This is the base default stylesheet for
1276      * the platform
1277      */
1278     public void setDefaultUserAgentStylesheet(Stylesheet ua_stylesheet) {
1279 
1280         if (ua_stylesheet == null ) {
1281             throw new IllegalArgumentException("null arg ua_stylesheet");
1282         }
1283 
1284         // null url is ok, just means that it is a stylesheet not loaded from a file
1285         String url = ua_stylesheet.getUrl();
1286         final String fname = url != null ? url.trim() : "";
1287 
1288         // if we already have this stylesheet, make sure it is the first element
1289         for (int n=0, nMax= platformUserAgentStylesheetContainers.size(); n < nMax; n++) {
1290             StylesheetContainer container = platformUserAgentStylesheetContainers.get(n);
1291             if (fname.equals(container.fname)) {




   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.javafx.css;
  27 
  28 import javafx.application.Application;
  29 import javafx.css.Styleable;
  30 import java.io.FileNotFoundException;
  31 import java.io.FilePermission;
  32 import java.io.IOException;
  33 import java.io.InputStream;
  34 import java.lang.ref.Reference;
  35 import java.lang.ref.WeakReference;
  36 import java.net.MalformedURLException;
  37 import java.net.URI;
  38 import java.net.URISyntaxException;
  39 import java.net.URL;
  40 import java.security.AccessControlContext;
  41 import java.security.AccessController;
  42 import java.security.DigestInputStream;
  43 import java.security.MessageDigest;
  44 import java.security.NoSuchAlgorithmException;
  45 import java.security.PermissionCollection;
  46 import java.security.PrivilegedAction;
  47 import java.security.PrivilegedActionException;
  48 import java.security.PrivilegedExceptionAction;


1253 
1254         final Stylesheet ua_stylesheet = loadStylesheet(fname);
1255         final StylesheetContainer sc = new StylesheetContainer(fname, ua_stylesheet);
1256         if (platformUserAgentStylesheetContainers.size() == 0) {
1257             platformUserAgentStylesheetContainers.add(sc);
1258         } else if (hasDefaultUserAgentStylesheet) {
1259             platformUserAgentStylesheetContainers.set(0,sc);
1260         } else {
1261             platformUserAgentStylesheetContainers.add(0,sc);
1262         }
1263         hasDefaultUserAgentStylesheet = true;
1264 
1265         if (ua_stylesheet != null) {
1266             ua_stylesheet.setOrigin(StyleOrigin.USER_AGENT);
1267         }
1268         userAgentStylesheetsChanged();
1269 
1270         // RT-20643
1271         CssError.setCurrentScene(null);
1272 
1273     }
1274     
1275     /**
1276      * Removes the specified stylesheet from the application default user agent
1277      * stylesheet list.
1278      * @param url  The file URL, either relative or absolute, as a String.
1279      */
1280     public void removeUserAgentStylesheet(String url) {
1281         if (url == null ) {
1282             throw new IllegalArgumentException("null arg url");
1283         }
1284  
1285         final String fname = url.trim();
1286         if (fname.isEmpty()) {
1287             return;
1288         }
1289  
1290         // if we already have this stylesheet, remove it!
1291         boolean removed = false;
1292         for (int n = platformUserAgentStylesheetContainers.size() - 1; n >= 0; n--) {
1293             // don't remove the platform default user agent stylesheet
1294             if (fname.equals(Application.getUserAgentStylesheet())) {
1295                 continue;
1296             }
1297  
1298             StylesheetContainer container = platformUserAgentStylesheetContainers.get(n);
1299             if (fname.equals(container.fname)) {
1300                 platformUserAgentStylesheetContainers.remove(n);
1301                 removed = true;
1302             }
1303         }
1304  
1305         if (removed) {
1306             userAgentStylesheetsChanged();
1307         }
1308     }
1309 
1310     /**
1311      * Set the user agent stylesheet. This is the base default stylesheet for
1312      * the platform
1313      */
1314     public void setDefaultUserAgentStylesheet(Stylesheet ua_stylesheet) {
1315 
1316         if (ua_stylesheet == null ) {
1317             throw new IllegalArgumentException("null arg ua_stylesheet");
1318         }
1319 
1320         // null url is ok, just means that it is a stylesheet not loaded from a file
1321         String url = ua_stylesheet.getUrl();
1322         final String fname = url != null ? url.trim() : "";
1323 
1324         // if we already have this stylesheet, make sure it is the first element
1325         for (int n=0, nMax= platformUserAgentStylesheetContainers.size(); n < nMax; n++) {
1326             StylesheetContainer container = platformUserAgentStylesheetContainers.get(n);
1327             if (fname.equals(container.fname)) {