modules/graphics/src/main/java/javafx/css/Stylesheet.java
Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
*** 21,37 ****
* 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 com.sun.javafx.collections.TrackableObservableList;
- import com.sun.javafx.css.parser.CSSParser;
import javafx.collections.ListChangeListener.Change;
import javafx.collections.ObservableList;
! import javafx.css.StyleOrigin;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
--- 21,39 ----
* 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 javafx.css.StyleConverter.StringStore;
import javafx.collections.ListChangeListener.Change;
import javafx.collections.ObservableList;
!
! import com.sun.javafx.collections.TrackableObservableList;
! import com.sun.javafx.css.FontFaceImpl;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
*** 48,67 ****
* A stylesheet which can apply properties to a tree of objects. A stylesheet
* is a collection of zero or more {@link Rule Rules}, each of which is applied
* to each object in the tree. Typically the selector will examine the object to
* determine whether or not it is applicable, and if so it will apply certain
* property values to the object.
! * <p>
*/
public class Stylesheet {
/**
* Version number of binary CSS format. The value is incremented whenever the format of the
* binary stream changes. This number does not correlate with JavaFX versions.
* Version 5: persist @font-face
*/
! final static int BINARY_CSS_VERSION = 5;
private final String url;
/** The URL from which the stylesheet was loaded.
* @return The URL from which the stylesheet was loaded, or null if
* the stylesheet was created from an inline style.
--- 50,71 ----
* A stylesheet which can apply properties to a tree of objects. A stylesheet
* is a collection of zero or more {@link Rule Rules}, each of which is applied
* to each object in the tree. Typically the selector will examine the object to
* determine whether or not it is applicable, and if so it will apply certain
* property values to the object.
! *
! * @since 9
*/
public class Stylesheet {
/**
* Version number of binary CSS format. The value is incremented whenever the format of the
* binary stream changes. This number does not correlate with JavaFX versions.
* Version 5: persist @font-face
+ * Version 6: converter classes moved to public package
*/
! final static int BINARY_CSS_VERSION = 6;
private final String url;
/** The URL from which the stylesheet was loaded.
* @return The URL from which the stylesheet was loaded, or null if
* the stylesheet was created from an inline style.
*** 84,95 ****
}
/** All the rules contained in the stylesheet in the order they are in the file */
private final ObservableList<Rule> rules = new TrackableObservableList<Rule>() {
! @Override
! protected void onChanged(Change<Rule> c) {
c.reset();
while (c.next()) {
if (c.wasAdded()) {
for(Rule rule : c.getAddedSubList()) {
rule.setStylesheet(Stylesheet.this);
--- 88,98 ----
}
/** All the rules contained in the stylesheet in the order they are in the file */
private final ObservableList<Rule> rules = new TrackableObservableList<Rule>() {
! @Override protected void onChanged(Change<Rule> c) {
c.reset();
while (c.next()) {
if (c.wasAdded()) {
for(Rule rule : c.getAddedSubList()) {
rule.setStylesheet(Stylesheet.this);
*** 108,118 ****
/**
* Constructs a stylesheet with the base URI defaulting to the root
* path of the application.
*/
! public Stylesheet() {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// this.url = (cl != null) ? cl.getResource("") : null;
//
// RT-17344
--- 111,121 ----
/**
* Constructs a stylesheet with the base URI defaulting to the root
* path of the application.
*/
! Stylesheet() {
// ClassLoader cl = Thread.currentThread().getContextClassLoader();
// this.url = (cl != null) ? cl.getResource("") : null;
//
// RT-17344
*** 130,140 ****
/**
* Constructs a Stylesheet using the given URL as the base URI. The
* parameter may not be null.
* @param url
*/
! public Stylesheet(String url) {
this.url = url;
}
--- 133,143 ----
/**
* Constructs a Stylesheet using the given URL as the base URI. The
* parameter may not be null.
* @param url
*/
! Stylesheet(String url) {
this.url = url;
}
*** 200,210 ****
int nFontFaces = fontFaceList != null ? fontFaceList.size() : 0;
os.writeShort(nFontFaces);
for(int n=0; n<nFontFaces; n++) {
FontFace fontFace = fontFaceList.get(n);
! fontFace.writeBinary(os, stringStore);
}
}
// protected for unit testing
final void readBinary(int bssVersion, DataInputStream is, String[] strings)
--- 203,215 ----
int nFontFaces = fontFaceList != null ? fontFaceList.size() : 0;
os.writeShort(nFontFaces);
for(int n=0; n<nFontFaces; n++) {
FontFace fontFace = fontFaceList.get(n);
! if (fontFace instanceof FontFaceImpl) {
! ((FontFaceImpl)fontFace).writeBinary(os, stringStore);
! }
}
}
// protected for unit testing
final void readBinary(int bssVersion, DataInputStream is, String[] strings)
*** 222,232 ****
if (bssVersion >= 5) {
List<FontFace> fontFaceList = this.getFontFaces();
int nFontFaces = is.readShort();
for (int n=0; n<nFontFaces; n++) {
! FontFace fontFace = FontFace.readBinary(bssVersion, is, strings);
fontFaceList.add(fontFace);
}
}
}
--- 227,237 ----
if (bssVersion >= 5) {
List<FontFace> fontFaceList = this.getFontFaces();
int nFontFaces = is.readShort();
for (int n=0; n<nFontFaces; n++) {
! FontFace fontFace = FontFaceImpl.readBinary(bssVersion, is, strings);
fontFaceList.add(fontFace);
}
}
}
*** 308,318 ****
if (destination.exists() ? (destination.canWrite() == false) : (destination.createNewFile() == false)) {
throw new IllegalArgumentException("cannot write destination file");
}
URI sourceURI = source.toURI();
! Stylesheet stylesheet = new CSSParser().parse(sourceURI.toURL());
// first write all the css binary data into the buffer and collect strings on way
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
StringStore stringStore = new StringStore();
--- 313,323 ----
if (destination.exists() ? (destination.canWrite() == false) : (destination.createNewFile() == false)) {
throw new IllegalArgumentException("cannot write destination file");
}
URI sourceURI = source.toURI();
! Stylesheet stylesheet = new CssParser().parse(sourceURI.toURL());
// first write all the css binary data into the buffer and collect strings on way
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
StringStore stringStore = new StringStore();
*** 334,344 ****
os.flush();
os.close();
}
// Add the rules from the other stylesheet to this one
! public void importStylesheet(Stylesheet importedStylesheet) {
if (importedStylesheet == null) return;
List<Rule> rulesToImport = importedStylesheet.getRules();
if (rulesToImport == null || rulesToImport.isEmpty()) return;
--- 339,349 ----
os.flush();
os.close();
}
// Add the rules from the other stylesheet to this one
! void importStylesheet(Stylesheet importedStylesheet) {
if (importedStylesheet == null) return;
List<Rule> rulesToImport = importedStylesheet.getRules();
if (rulesToImport == null || rulesToImport.isEmpty()) return;