apps/scenebuilder/SceneBuilderKit/src/com/oracle/javafx/scenebuilder/kit/util/CssInternal.java

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization


  42 import java.util.List;
  43 import java.util.Map;
  44 import java.util.Set;
  45 import java.util.TreeMap;
  46 import java.util.TreeSet;
  47 
  48 import javafx.beans.property.ReadOnlyProperty;
  49 import javafx.collections.FXCollections;
  50 import javafx.css.CssMetaData;
  51 import javafx.css.StyleOrigin;
  52 import javafx.css.Styleable;
  53 import javafx.css.StyleableProperty;
  54 import javafx.scene.Node;
  55 import javafx.scene.Parent;
  56 
  57 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
  58 import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform;
  59 import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform.Theme;
  60 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance;
  61 import com.oracle.javafx.scenebuilder.kit.metadata.property.ValuePropertyMetadata;
  62 import com.sun.javafx.css.CompoundSelector;
  63 import com.sun.javafx.css.Rule;
  64 import com.sun.javafx.css.Selector;
  65 import com.sun.javafx.css.SimpleSelector;
  66 import com.sun.javafx.css.Style;
  67 import com.sun.javafx.css.Stylesheet;
  68 import com.sun.javafx.css.parser.CSSParser;
  69 
  70 /**
  71  *
  72  * Utility classes using css internal classes (from com.sun package). Note that
  73  * the CSS Analyzer is also using extensively com.sun classes.
  74  *
  75  */
  76 public class CssInternal {
  77 
  78     private final static String[] themeUrls = {
  79         Deprecation.CASPIAN_EMBEDDED_HIGHCONTRAST_STYLESHEET,
  80         Deprecation.CASPIAN_EMBEDDED_QVGA_HIGHCONTRAST_STYLESHEET,
  81         Deprecation.CASPIAN_EMBEDDED_QVGA_STYLESHEET,
  82         Deprecation.CASPIAN_EMBEDDED_STYLESHEET,
  83         Deprecation.CASPIAN_HIGHCONTRAST_STYLESHEET,
  84         Deprecation.CASPIAN_STYLESHEET,
  85         Deprecation.MODENA_HIGHCONTRAST_BLACKONWHITE_STYLESHEET,
  86         Deprecation.MODENA_HIGHCONTRAST_WHITEONBLACK_STYLESHEET,
  87         Deprecation.MODENA_HIGHCONTRAST_YELLOWONBLACK_STYLESHEET,
  88         Deprecation.MODENA_STYLESHEET,


 220 
 221         if (fxObject instanceof Parent) {
 222             List<String> stylesheets = ((Parent) fxObject).getStylesheets();
 223             for (String stylesheet : stylesheets) {
 224                 try {
 225                     for (String styleClass : getStyleClasses(new URL(stylesheet))) {
 226                         classesMap.put(styleClass, stylesheet);
 227                     }
 228                 } catch (MalformedURLException ex) {
 229                     return classesMap;
 230                 }
 231             }
 232         }
 233         return classesMap;
 234     }
 235 
 236     private static Set<String> getStyleClasses(final URL url) {
 237         Set<String> styleClasses = new HashSet<>();
 238         Stylesheet s;
 239         try {
 240             s = new CSSParser().parse(url);
 241         } catch (IOException ex) {
 242             System.out.println("Warning: Invalid Stylesheet " + url); //NOI18N
 243             return styleClasses;
 244         }
 245         if (s == null) {
 246             // The parsed CSS file was empty. No parsing occured.
 247             return styleClasses;
 248         }
 249         for (Rule r : s.getRules()) {
 250             for (Selector ss : r.getSelectors()) {
 251                 if (ss instanceof SimpleSelector) {
 252                     SimpleSelector simple = (SimpleSelector) ss;
 253                     styleClasses.addAll(simple.getStyleClasses());
 254                 } else {
 255                     if (ss instanceof CompoundSelector) {
 256                         CompoundSelector cs = (CompoundSelector) ss;
 257                         for (Selector selector : cs.getSelectors()) {
 258                             if (selector instanceof SimpleSelector) {
 259                                 SimpleSelector simple = (SimpleSelector) selector;
 260                                 styleClasses.addAll(simple.getStyleClasses());




  42 import java.util.List;
  43 import java.util.Map;
  44 import java.util.Set;
  45 import java.util.TreeMap;
  46 import java.util.TreeSet;
  47 
  48 import javafx.beans.property.ReadOnlyProperty;
  49 import javafx.collections.FXCollections;
  50 import javafx.css.CssMetaData;
  51 import javafx.css.StyleOrigin;
  52 import javafx.css.Styleable;
  53 import javafx.css.StyleableProperty;
  54 import javafx.scene.Node;
  55 import javafx.scene.Parent;
  56 
  57 import com.oracle.javafx.scenebuilder.kit.editor.EditorController;
  58 import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform;
  59 import com.oracle.javafx.scenebuilder.kit.editor.EditorPlatform.Theme;
  60 import com.oracle.javafx.scenebuilder.kit.fxom.FXOMInstance;
  61 import com.oracle.javafx.scenebuilder.kit.metadata.property.ValuePropertyMetadata;
  62 import javafx.css.CompoundSelector;
  63 import javafx.css.Rule;
  64 import javafx.css.Selector;
  65 import javafx.css.SimpleSelector;
  66 import javafx.css.Style;
  67 import javafx.css.Stylesheet;
  68 import javafx.css.CssParser;
  69 
  70 /**
  71  *
  72  * Utility classes using css internal classes (from com.sun package). Note that
  73  * the CSS Analyzer is also using extensively com.sun classes.
  74  *
  75  */
  76 public class CssInternal {
  77 
  78     private final static String[] themeUrls = {
  79         Deprecation.CASPIAN_EMBEDDED_HIGHCONTRAST_STYLESHEET,
  80         Deprecation.CASPIAN_EMBEDDED_QVGA_HIGHCONTRAST_STYLESHEET,
  81         Deprecation.CASPIAN_EMBEDDED_QVGA_STYLESHEET,
  82         Deprecation.CASPIAN_EMBEDDED_STYLESHEET,
  83         Deprecation.CASPIAN_HIGHCONTRAST_STYLESHEET,
  84         Deprecation.CASPIAN_STYLESHEET,
  85         Deprecation.MODENA_HIGHCONTRAST_BLACKONWHITE_STYLESHEET,
  86         Deprecation.MODENA_HIGHCONTRAST_WHITEONBLACK_STYLESHEET,
  87         Deprecation.MODENA_HIGHCONTRAST_YELLOWONBLACK_STYLESHEET,
  88         Deprecation.MODENA_STYLESHEET,


 220 
 221         if (fxObject instanceof Parent) {
 222             List<String> stylesheets = ((Parent) fxObject).getStylesheets();
 223             for (String stylesheet : stylesheets) {
 224                 try {
 225                     for (String styleClass : getStyleClasses(new URL(stylesheet))) {
 226                         classesMap.put(styleClass, stylesheet);
 227                     }
 228                 } catch (MalformedURLException ex) {
 229                     return classesMap;
 230                 }
 231             }
 232         }
 233         return classesMap;
 234     }
 235 
 236     private static Set<String> getStyleClasses(final URL url) {
 237         Set<String> styleClasses = new HashSet<>();
 238         Stylesheet s;
 239         try {
 240             s = new CssParser().parse(url);
 241         } catch (IOException ex) {
 242             System.out.println("Warning: Invalid Stylesheet " + url); //NOI18N
 243             return styleClasses;
 244         }
 245         if (s == null) {
 246             // The parsed CSS file was empty. No parsing occured.
 247             return styleClasses;
 248         }
 249         for (Rule r : s.getRules()) {
 250             for (Selector ss : r.getSelectors()) {
 251                 if (ss instanceof SimpleSelector) {
 252                     SimpleSelector simple = (SimpleSelector) ss;
 253                     styleClasses.addAll(simple.getStyleClasses());
 254                 } else {
 255                     if (ss instanceof CompoundSelector) {
 256                         CompoundSelector cs = (CompoundSelector) ss;
 257                         for (Selector selector : cs.getSelectors()) {
 258                             if (selector instanceof SimpleSelector) {
 259                                 SimpleSelector simple = (SimpleSelector) selector;
 260                                 styleClasses.addAll(simple.getStyleClasses());