changeset 9246:51fa62819979

8135310: Remove CascadingStyle class from public API
author jgiles
date Thu, 10 Sep 2015 18:22:42 +1200
parents 5023330f0526
children 1f4cc95ea5eb
files modules/graphics/src/main/java/com/sun/javafx/css/CascadingStyle.java modules/graphics/src/main/java/com/sun/javafx/css/StyleMap.java modules/graphics/src/main/java/javafx/css/CascadingStyle.java modules/graphics/src/main/java/javafx/css/Declaration.java modules/graphics/src/main/java/javafx/css/Match.java modules/graphics/src/main/java/javafx/scene/CssStyleHelper.java modules/graphics/src/test/java/com/sun/javafx/css/StyleManagerTest.java modules/graphics/src/test/java/javafx/css/CssMetaDataTest.java modules/graphics/src/test/java/javafx/css/Node_cssStyleMap_Test.java
diffstat 9 files changed, 198 insertions(+), 190 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/modules/graphics/src/main/java/com/sun/javafx/css/CascadingStyle.java	Thu Sep 10 18:22:42 2015 +1200
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.javafx.css;
+
+import javafx.css.Declaration;
+import javafx.css.Match;
+import javafx.css.ParsedValue;
+import javafx.css.PseudoClass;
+import javafx.css.Rule;
+import javafx.css.Selector;
+import javafx.css.Style;
+import javafx.css.StyleOrigin;
+
+import java.util.Set;
+
+/** A marriage of pseudo-classes (potentially empty) to property and value
+ *
+ * @since 9
+ */
+public class CascadingStyle implements Comparable<CascadingStyle> {
+
+    /** */
+    private final Style style;
+    public Style getStyle() {
+        return style;
+    }
+    
+    /** State variables, like &quot;hover&quot; or &quot;pressed&quot; */
+    private final Set<PseudoClass> pseudoClasses;
+
+    /* specificity of the selector that matched */
+    private final int specificity;
+    
+    /* order in which this style appeared in the stylesheet */
+    private final int ordinal;
+    
+    /*
+     * True if the property is -fx-skin. We want the skin property to
+     * sort less than all other properties.
+     */
+    private final boolean skinProp;
+
+    public CascadingStyle(final Style style, Set<PseudoClass> pseudoClasses,
+            final int specificity, final int ordinal) {
+        this.style = style;
+        this.pseudoClasses = pseudoClasses;
+        this.specificity = specificity;
+        this.ordinal = ordinal;
+        this.skinProp = "-fx-skin".equals(style.getDeclaration().getProperty());
+    }
+        
+    public CascadingStyle(final Declaration decl, final Match match, final int ordinal) {
+        this(new Style(match.getSelector(), decl), 
+             match.getPseudoClasses(), 
+             match.getSpecificity(), 
+             ordinal);
+    }
+
+    // Wrapper to make StyleHelper's life a little easier
+    public String getProperty() {
+        return style.getDeclaration().getProperty();
+    }
+    
+    // Wrapper to make StyleHelper's life a little easier
+    public Selector getSelector() {
+        return style.getSelector();
+    }
+    
+    // Wrapper to make StyleHelper's life a little easier
+    public Rule getRule() {
+        return style.getDeclaration().getRule();
+    }
+    
+    // Wrapper to make StyleHelper's life a little easier
+    public StyleOrigin getOrigin() {
+        return getRule().getOrigin();
+    }
+    
+    // Wrapper to make StyleHelper's life a little easier
+    public ParsedValue getParsedValue() {
+        return style.getDeclaration().getParsedValue();
+    }
+    
+    @Override public String toString() { return getProperty(); }
+
+    /**
+     * When testing equality against another Style, we only care about
+     * the property and pseudo-classes. In other words, we only care about
+     * where the style is applied, not what is applied.
+     */
+    @Override public boolean equals(Object obj) {
+        if (obj == null) {
+            return false;
+        }
+        if (getClass() != obj.getClass()) {
+            return false;
+        }
+        CascadingStyle other = (CascadingStyle)obj;
+
+        final String property = getProperty();
+        final String otherProperty = other.getProperty();
+        if (property == null ? otherProperty != null : !property.equals(otherProperty)) {
+            return false;
+        }
+        
+        // does [foo bar bang] contain all of [foo bar]?
+        if (pseudoClasses == null ? other.pseudoClasses != null : !pseudoClasses.containsAll(other.pseudoClasses)) {
+            return false;            
+        }
+        
+        return true;
+
+    }
+
+    /*
+     * Hash on property and pseudoclasses since
+     * obj1.hashCode() should equal obj2.hashCode() if obj1.equals(obj2)
+     */
+    @Override public int hashCode() {
+        int hash = 7;
+        final String property = getProperty();
+        hash = 47 * hash + (property != null ? property.hashCode() : 0);
+        hash = 47 * hash + (pseudoClasses != null ? pseudoClasses.hashCode() : 0);
+        return hash;
+    }
+
+    /**
+     * Implementation of Comparable such that more specific styles get
+     * sorted before less specific ones.
+     */
+    @Override public int compareTo(CascadingStyle other) {
+
+        //
+        // Important styles take the cake
+        // Importance being equal, then specificity is considered
+        // Specificity being equal, then the order of declaration decides.
+        //
+        
+        final Declaration decl = style.getDeclaration();
+        final boolean important = decl != null ? decl.isImportant() : false;
+        final Rule rule = decl != null ? decl.getRule() : null;
+        final StyleOrigin source = rule != null ? rule.getOrigin() : null;
+        
+        final Declaration otherDecl = other.style.getDeclaration();
+        final boolean otherImportant = otherDecl != null ? otherDecl.isImportant() : false;
+        final Rule otherRule = otherDecl != null ? otherDecl.getRule() : null;
+        final StyleOrigin otherSource = otherRule != null ? otherRule.getOrigin() : null;
+
+        int c = 0;
+
+        if (this.skinProp && !other.skinProp) {
+            c = 1;
+        } else if (important != otherImportant) {
+            c = important ? -1 : 1;
+        } else if (source != otherSource) {
+            if (source == null) c = -1;
+            else if (otherSource == null) c = 1;
+            else c = otherSource.compareTo(source);
+        } else {
+            c = other.specificity - this.specificity;
+        };
+
+        if (c == 0) c = other.ordinal - this.ordinal;
+        return c;
+    }
+
+}
+
--- a/modules/graphics/src/main/java/com/sun/javafx/css/StyleMap.java	Thu Sep 10 11:21:20 2015 +1200
+++ b/modules/graphics/src/main/java/com/sun/javafx/css/StyleMap.java	Thu Sep 10 18:22:42 2015 +1200
@@ -32,12 +32,10 @@
 import java.util.List;
 import java.util.Map;
 
-import javafx.css.CascadingStyle;
 import javafx.css.Declaration;
 import javafx.css.Match;
 import javafx.css.Rule;
 import javafx.css.Selector;
-import javafx.css.Style;
 
 
 /**
--- a/modules/graphics/src/main/java/javafx/css/CascadingStyle.java	Thu Sep 10 11:21:20 2015 +1200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,182 +0,0 @@
-/*
- * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package javafx.css;
-
-import java.util.Set;
-
-/** A marriage of pseudo-classes (potentially empty) to property and value
- *
- * @since 9
- */
-public class CascadingStyle implements Comparable<CascadingStyle> {
-
-    /** */
-    private final Style style;
-    public Style getStyle() {
-        return style;
-    }
-    
-    /** State variables, like &quot;hover&quot; or &quot;pressed&quot; */
-    private final Set<PseudoClass> pseudoClasses;
-
-    /* specificity of the selector that matched */
-    private final int specificity;
-    
-    /* order in which this style appeared in the stylesheet */
-    private final int ordinal;
-    
-    /*
-     * True if the property is -fx-skin. We want the skin property to
-     * sort less than all other properties.
-     */
-    private final boolean skinProp;
-
-    public CascadingStyle(final Style style, Set<PseudoClass> pseudoClasses,
-            final int specificity, final int ordinal) {
-        this.style = style;
-        this.pseudoClasses = pseudoClasses;
-        this.specificity = specificity;
-        this.ordinal = ordinal;
-        this.skinProp = "-fx-skin".equals(style.getDeclaration().getProperty());
-    }
-        
-    public CascadingStyle(final Declaration decl, final Match match, final int ordinal) {
-        this(new Style(match.getSelector(), decl), 
-             match.getPseudoClasses(), 
-             match.getSpecificity(), 
-             ordinal);
-    }
-
-    // Wrapper to make StyleHelper's life a little easier
-    public String getProperty() {
-        return style.getDeclaration().getProperty();
-    }
-    
-    // Wrapper to make StyleHelper's life a little easier
-    public Selector getSelector() {
-        return style.getSelector();
-    }
-    
-    // Wrapper to make StyleHelper's life a little easier
-    public Rule getRule() {
-        return style.getDeclaration().getRule();
-    }
-    
-    // Wrapper to make StyleHelper's life a little easier
-    public StyleOrigin getOrigin() {
-        return getRule().getOrigin();
-    }
-    
-    // Wrapper to make StyleHelper's life a little easier
-    public ParsedValue getParsedValue() {
-        return style.getDeclaration().getParsedValue();
-    }
-    
-    @Override public String toString() { return getProperty(); }
-
-    /**
-     * When testing equality against another Style, we only care about
-     * the property and pseudo-classes. In other words, we only care about
-     * where the style is applied, not what is applied.
-     */
-    @Override public boolean equals(Object obj) {
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        CascadingStyle other = (CascadingStyle)obj;
-
-        final String property = getProperty();
-        final String otherProperty = other.getProperty();
-        if (property == null ? otherProperty != null : !property.equals(otherProperty)) {
-            return false;
-        }
-        
-        // does [foo bar bang] contain all of [foo bar]?
-        if (pseudoClasses == null ? other.pseudoClasses != null : !pseudoClasses.containsAll(other.pseudoClasses)) {
-            return false;            
-        }
-        
-        return true;
-
-    }
-
-    /*
-     * Hash on property and pseudoclasses since
-     * obj1.hashCode() should equal obj2.hashCode() if obj1.equals(obj2)
-     */
-    @Override public int hashCode() {
-        int hash = 7;
-        final String property = getProperty();
-        hash = 47 * hash + (property != null ? property.hashCode() : 0);
-        hash = 47 * hash + (pseudoClasses != null ? pseudoClasses.hashCode() : 0);
-        return hash;
-    }
-
-    /**
-     * Implementation of Comparable such that more specific styles get
-     * sorted before less specific ones.
-     */
-    @Override public int compareTo(CascadingStyle other) {
-
-        //
-        // Important styles take the cake
-        // Importance being equal, then specificity is considered
-        // Specificity being equal, then the order of declaration decides.
-        //
-        
-        final Declaration decl = style.getDeclaration();
-        final boolean important = decl != null ? decl.isImportant() : false;
-        final Rule rule = decl != null ? decl.getRule() : null;
-        final StyleOrigin source = rule != null ? rule.getOrigin() : null;
-        
-        final Declaration otherDecl = other.style.getDeclaration();
-        final boolean otherImportant = otherDecl != null ? otherDecl.isImportant() : false;
-        final Rule otherRule = otherDecl != null ? otherDecl.getRule() : null;
-        final StyleOrigin otherSource = otherRule != null ? otherRule.getOrigin() : null;
-
-        int c = 0;
-
-        if (this.skinProp && !other.skinProp) {
-            c = 1;
-        } else if (important != otherImportant) {
-            c = important ? -1 : 1;
-        } else if (source != otherSource) {
-            if (source == null) c = -1;
-            else if (otherSource == null) c = 1;
-            else c = otherSource.compareTo(source);
-        } else {
-            c = other.specificity - this.specificity;
-        };
-
-        if (c == 0) c = other.ordinal - this.ordinal;
-        return c;
-    }
-
-}
-
--- a/modules/graphics/src/main/java/javafx/css/Declaration.java	Thu Sep 10 11:21:20 2015 +1200
+++ b/modules/graphics/src/main/java/javafx/css/Declaration.java	Thu Sep 10 18:22:42 2015 +1200
@@ -70,7 +70,7 @@
         return rule;
     }
     
-    boolean isImportant() {
+    public final boolean isImportant() {
         return important;
     }
 
--- a/modules/graphics/src/main/java/javafx/css/Match.java	Thu Sep 10 11:21:20 2015 +1200
+++ b/modules/graphics/src/main/java/javafx/css/Match.java	Thu Sep 10 18:22:42 2015 +1200
@@ -65,15 +65,15 @@
         specificity = (idCount << 8) | (styleClassCount << 4) | nPseudoClasses;
     }
         
-    Selector getSelector() {
+    public Selector getSelector() {
         return selector;
     }
 
-    PseudoClassState getPseudoClasses() {
+    public PseudoClassState getPseudoClasses() {
         return pseudoClasses;
     }
 
-    int getSpecificity() {
+    public int getSpecificity() {
         return specificity;
     }
 
--- a/modules/graphics/src/main/java/javafx/scene/CssStyleHelper.java	Thu Sep 10 11:21:20 2015 +1200
+++ b/modules/graphics/src/main/java/javafx/scene/CssStyleHelper.java	Thu Sep 10 18:22:42 2015 +1200
@@ -37,7 +37,7 @@
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleObjectProperty;
 import javafx.beans.value.WritableValue;
-import javafx.css.CascadingStyle;
+import com.sun.javafx.css.CascadingStyle;
 import javafx.css.CssMetaData;
 import javafx.css.CssParser;
 import javafx.css.FontCssMetaData;
--- a/modules/graphics/src/test/java/com/sun/javafx/css/StyleManagerTest.java	Thu Sep 10 11:21:20 2015 +1200
+++ b/modules/graphics/src/test/java/com/sun/javafx/css/StyleManagerTest.java	Thu Sep 10 18:22:42 2015 +1200
@@ -25,7 +25,6 @@
 
 package com.sun.javafx.css;
 
-import javafx.css.CascadingStyle;
 import javafx.css.CssParser;
 import javafx.css.StyleOrigin;
 import javafx.css.StyleableProperty;
--- a/modules/graphics/src/test/java/javafx/css/CssMetaDataTest.java	Thu Sep 10 11:21:20 2015 +1200
+++ b/modules/graphics/src/test/java/javafx/css/CssMetaDataTest.java	Thu Sep 10 18:22:42 2015 +1200
@@ -36,6 +36,7 @@
 import java.util.List;
 import java.util.Set;
 
+import com.sun.javafx.css.CascadingStyle;
 import com.sun.javafx.css.ParsedValueImpl;
 import com.sun.javafx.css.PseudoClassState;
 import com.sun.javafx.css.StyleManager;
--- a/modules/graphics/src/test/java/javafx/css/Node_cssStyleMap_Test.java	Thu Sep 10 11:21:20 2015 +1200
+++ b/modules/graphics/src/test/java/javafx/css/Node_cssStyleMap_Test.java	Thu Sep 10 18:22:42 2015 +1200
@@ -25,6 +25,7 @@
 
 package javafx.css;
 
+import com.sun.javafx.css.CascadingStyle;
 import com.sun.javafx.css.ParsedValueImpl;
 import com.sun.javafx.css.StyleManager;
 import javafx.css.converter.FontConverter;