modules/graphics/src/main/java/javafx/css/CompoundSelector.java
Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
*** 21,43 ****
* 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.PseudoClass;
! import javafx.css.Styleable;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
/**
* A compound selector which behaves according to the CSS standard. The selector is
* composed of one or more <code>Selectors</code>, along with an array of
* <code>CompoundSelectorRelationships</code> indicating the required relationship at each
* stage. There must be exactly one less <code>Combinator</code> than
--- 21,44 ----
* 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 com.sun.javafx.css.Combinator;
! import com.sun.javafx.css.PseudoClassState;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
+
/**
* A compound selector which behaves according to the CSS standard. The selector is
* composed of one or more <code>Selectors</code>, along with an array of
* <code>CompoundSelectorRelationships</code> indicating the required relationship at each
* stage. There must be exactly one less <code>Combinator</code> than
*** 56,67 ****
* <code>selector1 > selector2 selector3</code>. The greater-than (>)
* between selector1 and selector2 specifies a direct CHILD, whereas the
* whitespace between selector2 and selector3 corresponds to
* <code>Combinator.DESCENDANT</code>.
*
*/
-
final public class CompoundSelector extends Selector {
private final List<SimpleSelector> selectors;
/**
* The selectors that make up this compound selector
--- 57,68 ----
* <code>selector1 > selector2 selector3</code>. The greater-than (>)
* between selector1 and selector2 specifies a direct CHILD, whereas the
* whitespace between selector2 and selector3 corresponds to
* <code>Combinator.DESCENDANT</code>.
*
+ * @since 9
*/
final public class CompoundSelector extends Selector {
private final List<SimpleSelector> selectors;
/**
* The selectors that make up this compound selector
*** 70,106 ****
public List<SimpleSelector> getSelectors() {
return selectors;
}
private final List<Combinator> relationships;
/**
! * The relationships between the selectors
! * @return Immutable List<Combinator>
*/
! public List<Combinator> getRelationships() {
! return relationships;
! }
!
! public CompoundSelector(List<SimpleSelector> selectors, List<Combinator> relationships)
! {
this.selectors =
(selectors != null)
? Collections.unmodifiableList(selectors)
: Collections.EMPTY_LIST;
this.relationships =
(relationships != null)
? Collections.unmodifiableList(relationships)
: Collections.EMPTY_LIST;
}
! private CompoundSelector()
! {
this(null, null);
}
- Match createMatch() {
final PseudoClassState allPseudoClasses = new PseudoClassState();
int idCount = 0;
int styleClassCount = 0;
for(int n=0, nMax=selectors.size(); n<nMax; n++) {
--- 71,110 ----
public List<SimpleSelector> getSelectors() {
return selectors;
}
private final List<Combinator> relationships;
+ // /**
+ // * The relationships between the selectors
+ // * @return Immutable List<Combinator>
+ // */
+ // public List<Combinator> getRelationships() {
+ // return relationships;
+ // }
+
/**
! * Creates a <code>CompoundSelector</code> from a list of selectors and a
! * list of <code>Combinator</code> relationships. There must be exactly one
! * less <code>Combinator</code> than there are selectors.
*/
! CompoundSelector(List<SimpleSelector> selectors, List<Combinator> relationships) {
this.selectors =
(selectors != null)
? Collections.unmodifiableList(selectors)
: Collections.EMPTY_LIST;
this.relationships =
(relationships != null)
? Collections.unmodifiableList(relationships)
: Collections.EMPTY_LIST;
}
! private CompoundSelector() {
this(null, null);
}
+ @Override public Match createMatch() {
final PseudoClassState allPseudoClasses = new PseudoClassState();
int idCount = 0;
int styleClassCount = 0;
for(int n=0, nMax=selectors.size(); n<nMax; n++) {
*** 112,128 ****
}
return new Match(this, allPseudoClasses, idCount, styleClassCount);
}
! @Override
! public boolean applies(final Styleable styleable) {
return applies(styleable, selectors.size()-1, null, 0);
}
! @Override
! boolean applies(final Styleable styleable, Set<PseudoClass>[] triggerStates, int depth) {
assert (triggerStates == null || depth < triggerStates.length);
if (triggerStates != null && triggerStates.length <= depth) {
return false;
}
--- 116,130 ----
}
return new Match(this, allPseudoClasses, idCount, styleClassCount);
}
! @Override public boolean applies(final Styleable styleable) {
return applies(styleable, selectors.size()-1, null, 0);
}
! @Override public boolean applies(final Styleable styleable, Set<PseudoClass>[] triggerStates, int depth) {
assert (triggerStates == null || depth < triggerStates.length);
if (triggerStates != null && triggerStates.length <= depth) {
return false;
}
*** 198,209 ****
}
}
return false;
}
! @Override
! public boolean stateMatches(final Styleable styleable, Set<PseudoClass> states) {
return stateMatches(styleable, states, selectors.size()-1);
}
private boolean stateMatches(Styleable styleable, Set<PseudoClass> states, int index) {
// If the index is < 0 then we know we don't match
--- 200,210 ----
}
}
return false;
}
! @Override public boolean stateMatches(final Styleable styleable, Set<PseudoClass> states) {
return stateMatches(styleable, states, selectors.size()-1);
}
private boolean stateMatches(Styleable styleable, Set<PseudoClass> states, int index) {
// If the index is < 0 then we know we don't match
*** 252,274 ****
private int hash = -1;
/* Hash code is used in Style's hash code and Style's hash
code is used by StyleHelper */
! @Override
! public int hashCode() {
if (hash == -1) {
for (int i = 0, max=selectors.size(); i<max; i++)
hash = 31 * (hash + selectors.get(i).hashCode());
for (int i = 0, max=relationships.size(); i<max; i++)
hash = 31 * (hash + relationships.get(i).hashCode());
}
return hash;
}
! @Override
! public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
--- 253,273 ----
private int hash = -1;
/* Hash code is used in Style's hash code and Style's hash
code is used by StyleHelper */
! @Override public int hashCode() {
if (hash == -1) {
for (int i = 0, max=selectors.size(); i<max; i++)
hash = 31 * (hash + selectors.get(i).hashCode());
for (int i = 0, max=relationships.size(); i<max; i++)
hash = 31 * (hash + relationships.get(i).hashCode());
}
return hash;
}
! @Override public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
*** 295,315 ****
sbuf.append(selectors.get(n));
}
return sbuf.toString();
}
! public final void writeBinary(final DataOutputStream os, final StringStore stringStore)
throws IOException
{
super.writeBinary(os, stringStore);
os.writeShort(selectors.size());
for (int n=0; n< selectors.size(); n++) selectors.get(n).writeBinary(os,stringStore);
os.writeShort(relationships.size());
for (int n=0; n< relationships.size(); n++) os.writeByte(relationships.get(n).ordinal());
}
! public static CompoundSelector readBinary(int bssVersion, final DataInputStream is, final String[] strings)
throws IOException
{
final int nSelectors = is.readShort();
final List<SimpleSelector> selectors = new ArrayList<SimpleSelector>();
--- 294,314 ----
sbuf.append(selectors.get(n));
}
return sbuf.toString();
}
! @Override protected final void writeBinary(final DataOutputStream os, final StyleConverter.StringStore stringStore)
throws IOException
{
super.writeBinary(os, stringStore);
os.writeShort(selectors.size());
for (int n=0; n< selectors.size(); n++) selectors.get(n).writeBinary(os,stringStore);
os.writeShort(relationships.size());
for (int n=0; n< relationships.size(); n++) os.writeByte(relationships.get(n).ordinal());
}
! static CompoundSelector readBinary(int bssVersion, final DataInputStream is, final String[] strings)
throws IOException
{
final int nSelectors = is.readShort();
final List<SimpleSelector> selectors = new ArrayList<SimpleSelector>();