APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.sun.javafx.css

public final Class StyleManager

extends Object
Class Inheritance
Imports
com.sun.javafx.scene.NodeHelper, .ParentHelper, com.sun.javafx.util.DataURI, javafx.application.Application, javafx.collections.FXCollections, .ListChangeListener.Change, .ObservableList, javafx.css.CssParser, .FontFace, .PseudoClass, .Rule, .Selector, .StyleOrigin, .Styleable, .StyleConverter, .Stylesheet, javafx.scene.Node, .Parent, .Scene, .SubScene, javafx.scene.image.Image, javafx.scene.layout.Region, javafx.scene.text.Font, javafx.stage.Window, com.sun.javafx.logging.PlatformLogger, .PlatformLogger.Level, java.io.ByteArrayInputStream, .FileNotFoundException, .IOException, .InputStream, java.lang.ref.Reference, .SoftReference, .WeakReference, java.lang.reflect.InvocationTargetException, .Method, java.net.MalformedURLException, .URI, .URISyntaxException, .URL, java.nio.charset.Charset, .IllegalCharsetNameException, .UnsupportedCharsetException, java.security.DigestInputStream, .MessageDigest, .NoSuchAlgorithmException, java.util.ArrayList, .Arrays, .Collections, .HashMap, .Iterator, .List, .Map, .Map.Entry, .Set, .WeakHashMap

Contains the stylesheet state for a single scene. This includes both the Stylesheets defined on the Scene itself as well as a map of stylesheets for "style"s defined on the Node itself. These containers are kept in the containerMap, key'd by the Scene to which they belong.

One of the key responsibilities of the StylesheetContainer is to create and maintain an admittedly elaborate series of caches so as to minimize the amount of time it takes to match a Node to its eventual StyleHelper, and to reuse the StyleHelper as much as possible.

Initially, the cache is empty. It is recreated whenever the userStylesheets on the container change, or whenever the userAgentStylesheet changes. The cache is built up as nodes are looked for, and thus there is some overhead associated with the first lookup but which is then not repeated for subsequent lookups.

The cache system used is a two level cache. The first level cache simply maps the classname/id/styleclass combination of the request node to a 2nd level cache. If the node has "styles" specified then we still use this 2nd level cache, but must combine its selectors with the selectors specified in "styles" and perform more work to cascade properly.

The 2nd level cache contains a data structure called the Cache. The Cache contains an ordered sequence of Rules, a Long, and a Map. The ordered sequence of selectors are the selectors that *may* match a node with the given classname, id, and style class. For example, selectors which may apply are any selector where the simple selector of the selector contains a reference to the id, style class, or classname of the Node, or a compound selector whose "descendant" part is a simple selector which contains a reference to the id, style class, or classname of the Node.

During lookup, we will iterate over all the potential selectors and discover if they apply to this particular node. If so, then we toggle a bit position in the Long corresponding to the position of the selector that matched. This long then becomes our key into the final map.

Once we have established our key, we will visit the map and look for an existing StyleHelper. If we find a StyleHelper, then we will return it. If not, then we will take the Rules that matched and construct a new StyleHelper from their various parts.

This system, while elaborate, also provides for numerous fast paths and sharing of data structures which should dramatically reduce the memory and runtime performance overhead associated with CSS by reducing the matching overhead and caching as much as possible. We make no attempt to use weak references here, so if memory issues result one work around would be to toggle the root user agent stylesheet or stylesheets on the scene to cause the cache to be flushed.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
StyleManager.Cache

Creates and caches maps of styles, reusing them as often as practical.

pack-priv static class
private static class
private static class
private static class
StyleManager.Key

The key used in the cacheMap of the StylesheetContainer

pack-priv static class
pack-priv static class

Field Summary

Modifier and TypeField and Description
public static final Map<Parent, StyleManager.CacheContainer>
cacheContainerMap

A map from a parent to its style cache.

private static List<String>
private static ObservableList<CssParser.ParseError>
public boolean
private final StyleManager.ImageCache
private StyleManager.Key
private static PlatformLogger
public final List<StyleManager.StylesheetContainer>
platformUserAgentStylesheetContainers

A list of user-agent stylesheet urls from calling setDefaultUserAgentStylesheet and addUserAgentStylesheet.

private static final String
private static final String
private static final Object
styleLock

Global lock object for the StyleManager.

public final Map<String, StyleManager.StylesheetContainer>
stylesheetContainerMap

A map from String => Stylesheet.

public final List<StyleManager.StylesheetContainer>
userAgentStylesheetContainers

A list of user-agent stylesheets from Scene or SubScene.

private final WeakHashMap<Region, String>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private boolean
private boolean
public void
addUserAgentStylesheet(String
The file URL, either relative or absolute, as a String.
fname
)

Add a user agent stylesheet, possibly overriding styles in the default user agent stylesheet.

public void
addUserAgentStylesheet(Scene
Only used in CssError for tracking back to the scene that loaded the stylesheet
scene
,
String
The file URL, either relative or absolute, as a String.
url
)

Add a user agent stylesheet, possibly overriding styles in the default user agent stylesheet.

public void
addUserAgentStylesheet(Scene
Only used in CssError for tracking back to the scene that loaded the stylesheet
scene
,
Stylesheet
The stylesheet to add as a user-agent stylesheet
ua_stylesheet
)

Add a user agent stylesheet, possibly overriding styles in the default user agent stylesheet.

pack-priv static byte[]
public static ObservableList<CssParser.ParseError>
errorsProperty()

Errors that may have occurred during css processing.

public StyleMap
findMatchingStyles(Node node, SubScene subScene, Set<PseudoClass>[] triggerStates)

Finds matching styles for this Node.

public void
forget(final Scene scene)

called from Window when the scene is closed.

public void
forget(Parent
The Parent being removed from the scene-graph
parent
)

Called from Parent's scenesChanged method when the Parent's scene is set to null.

public void
forget(final SubScene subScene)

called from Window when the scene is closed.

private List<StyleManager.StylesheetContainer>
private List<StyleManager.StylesheetContainer>
pack-priv StyleManager.CacheContainer
getCacheContainer(Styleable styleable, SubScene subScene)

public Image
public static ObservableList<CssParser.ParseError>
getErrors()

Errors that may have occurred during css processing.

public static StyleManager
getInstance()

Return the StyleManager instance.

private static PlatformLogger
public StyleCache
getSharedCache(Styleable styleable, SubScene subScene, StyleCache.Key key)

StyleHelper uses this cache but it lives here so it can be cleared when style-sheets change.

public StyleMap
getStyleMap(Styleable styleable, SubScene subScene, int smapId)

private static URL
getURL(final String str)

public static Stylesheet
loadStylesheet(final String fname)

private List<StyleManager.StylesheetContainer>
processStylesheets(List<String> stylesheets, Parent parent)

private void
public void
removeUserAgentStylesheet(String
The file URL, either relative or absolute, as a String.
url
)

Removes the specified stylesheet from the application default user agent stylesheet list.

public void
setDefaultUserAgentStylesheet(String
The file URL, either relative or absolute, as a String.
fname
)

Set the default user agent stylesheet.

public void
setDefaultUserAgentStylesheet(Scene
Only used in CssError for tracking back to the scene that loaded the stylesheet
scene
,
String
The file URL, either relative or absolute, as a String.
url
)

Set the default user agent stylesheet

public void
setDefaultUserAgentStylesheet(Stylesheet ua_stylesheet)

Set the user agent stylesheet.

public void
setUserAgentStylesheets(List<String>
The list of stylesheet URLs as Strings.
urls
)

Set a bunch of user agent stylesheets all at once.

private void
private void
public void
stylesheetsChanged(Scene scene, ListChangeListener.Change<String> c)

called from Scene's stylesheets property's onChanged method

public void
stylesheetsChanged(Parent parent, ListChangeListener.Change<String> c)

called from Parent's stylesheets property's onChanged method

private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait