public final class StyleManager
extends java.lang.Object
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 who's "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.
Modifier and Type | Class and Description |
---|---|
private static class |
StyleManager.Cache
Creates and caches maps of styles, reusing them as often as practical.
|
(package private) static class |
StyleManager.CacheContainer |
private static class |
StyleManager.InstanceHolder |
private static class |
StyleManager.Key
The key used in the cacheMap of the StylesheetContainer
|
(package private) static class |
StyleManager.RefList<K> |
(package private) static class |
StyleManager.StylesheetContainer |
Modifier and Type | Field and Description |
---|---|
(package private) static java.util.Map<Parent,StyleManager.CacheContainer> |
cacheContainerMap
A map from a parent to its style cache.
|
private static java.util.List<java.lang.String> |
cacheMapKey |
private static ObservableList<CssError> |
errors |
(package private) boolean |
hasDefaultUserAgentStylesheet |
private java.util.Map<java.lang.String,Image> |
imageCache |
private StyleManager.Key |
key |
private static sun.util.logging.PlatformLogger |
LOGGER |
(package private) java.util.List<StyleManager.StylesheetContainer> |
platformUserAgentStylesheetContainers
A list of user-agent stylesheet urls from calling setDefaultUserAgentStylesheet and
addUserAgentStylesheet.
|
private static java.lang.String |
skinPrefix |
private static java.lang.String |
skinUtilsClassName |
private static java.lang.Object |
styleLock
Global lock object for the StyleManager.
|
(package private) java.util.Map<java.lang.String,StyleManager.StylesheetContainer> |
stylesheetContainerMap
A map from String => Stylesheet.
|
(package private) java.util.List<StyleManager.StylesheetContainer> |
userAgentStylesheetContainers
A list of user-agent stylesheets from Scene or SubScene.
|
Modifier | Constructor and Description |
---|---|
private |
StyleManager() |
Modifier and Type | Method and Description |
---|---|
private boolean |
_addUserAgentStylesheet(java.lang.String fname) |
private boolean |
_setDefaultUserAgentStylesheet(java.lang.String fname) |
void |
addUserAgentStylesheet(Scene scene,
java.lang.String url)
Add a user agent stylesheet, possibly overriding styles in the default
user agent stylesheet.
|
void |
addUserAgentStylesheet(Scene scene,
Stylesheet ua_stylesheet)
Add a user agent stylesheet, possibly overriding styles in the default
user agent stylesheet.
|
void |
addUserAgentStylesheet(java.lang.String fname)
Add a user agent stylesheet, possibly overriding styles in the default
user agent stylesheet.
|
(package private) static byte[] |
calculateCheckSum(java.lang.String fname) |
private void |
cleanUpImageCache(java.lang.String imgFname) |
static ObservableList<CssError> |
errorsProperty()
Errors that may have occurred during css processing.
|
StyleMap |
findMatchingStyles(Node node,
SubScene subScene,
java.util.Set<PseudoClass>[] triggerStates)
Finds matching styles for this Node.
|
void |
forget(Parent parent)
Called from Parent's scenesChanged method when the Parent's scene is set to null.
|
void |
forget(Scene scene)
called from Window when the scene is closed.
|
void |
forget(SubScene subScene)
called from Window when the scene is closed.
|
private java.util.List<StyleManager.StylesheetContainer> |
gatherParentStylesheets(Parent parent) |
private java.util.List<StyleManager.StylesheetContainer> |
gatherSceneStylesheets(Scene scene) |
(package private) StyleManager.CacheContainer |
getCacheContainer(Styleable styleable,
SubScene subScene) |
Image |
getCachedImage(java.lang.String url) |
static ObservableList<CssError> |
getErrors()
Errors that may have occurred during css processing.
|
static StyleManager |
getInstance()
Return the StyleManager instance.
|
private static sun.util.logging.PlatformLogger |
getLogger() |
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.
|
StyleMap |
getStyleMap(Styleable styleable,
SubScene subScene,
int smapId) |
private static java.net.URL |
getURL(java.lang.String str) |
static Stylesheet |
loadStylesheet(java.lang.String fname) |
private static Stylesheet |
loadStylesheetUnPrivileged(java.lang.String fname) |
private java.util.List<StyleManager.StylesheetContainer> |
processStylesheets(java.util.List<java.lang.String> stylesheets,
Parent parent) |
private void |
removeStylesheetContainer(StyleManager.StylesheetContainer stylesheetContainer) |
void |
removeUserAgentStylesheet(java.lang.String url)
Removes the specified stylesheet from the application default user agent
stylesheet list.
|
void |
setDefaultUserAgentStylesheet(Scene scene,
java.lang.String url)
Set the default user agent stylesheet
|
void |
setDefaultUserAgentStylesheet(java.lang.String fname)
Set the default user agent stylesheet.
|
void |
setDefaultUserAgentStylesheet(Stylesheet ua_stylesheet)
Set the user agent stylesheet.
|
void |
setUserAgentStylesheets(java.util.List<java.lang.String> urls)
Set a bunch of user agent stylesheets all at once.
|
private void |
stylesheetRemoved(Parent parent,
java.lang.String fname) |
private void |
stylesheetRemoved(Scene scene,
java.lang.String fname) |
void |
stylesheetsChanged(Parent parent,
ListChangeListener.Change<java.lang.String> c)
called from Parent's stylesheets property's onChanged method
|
void |
stylesheetsChanged(Scene scene,
ListChangeListener.Change<java.lang.String> c)
called from Scene's stylesheets property's onChanged method
|
private void |
userAgentStylesheetsChanged() |
private static final java.lang.Object styleLock
private static sun.util.logging.PlatformLogger LOGGER
static final java.util.Map<Parent,StyleManager.CacheContainer> cacheContainerMap
final java.util.List<StyleManager.StylesheetContainer> userAgentStylesheetContainers
final java.util.List<StyleManager.StylesheetContainer> platformUserAgentStylesheetContainers
boolean hasDefaultUserAgentStylesheet
final java.util.Map<java.lang.String,StyleManager.StylesheetContainer> stylesheetContainerMap
private final java.util.Map<java.lang.String,Image> imageCache
private static final java.lang.String skinPrefix
private static final java.lang.String skinUtilsClassName
private StyleManager.Key key
private static ObservableList<CssError> errors
private static java.util.List<java.lang.String> cacheMapKey
private static sun.util.logging.PlatformLogger getLogger()
public static StyleManager getInstance()
StyleManager.CacheContainer getCacheContainer(Styleable styleable, SubScene subScene)
public StyleCache getSharedCache(Styleable styleable, SubScene subScene, StyleCache.Key key)
public void forget(Scene scene)
public void stylesheetsChanged(Scene scene, ListChangeListener.Change<java.lang.String> c)
private void stylesheetRemoved(Scene scene, java.lang.String fname)
public void forget(Parent parent)
parent
- The Parent being removed from the scene-graphpublic void stylesheetsChanged(Parent parent, ListChangeListener.Change<java.lang.String> c)
private void stylesheetRemoved(Parent parent, java.lang.String fname)
public void forget(SubScene subScene)
private void removeStylesheetContainer(StyleManager.StylesheetContainer stylesheetContainer)
public Image getCachedImage(java.lang.String url)
private void cleanUpImageCache(java.lang.String imgFname)
private static java.net.URL getURL(java.lang.String str)
static byte[] calculateCheckSum(java.lang.String fname)
public static Stylesheet loadStylesheet(java.lang.String fname)
private static Stylesheet loadStylesheetUnPrivileged(java.lang.String fname)
public void setUserAgentStylesheets(java.util.List<java.lang.String> urls)
urls
- The list of stylesheet URLs as Strings.public void addUserAgentStylesheet(java.lang.String fname)
fname
- The file URL, either relative or absolute, as a String.public void addUserAgentStylesheet(Scene scene, java.lang.String url)
scene
- Only used in CssError for tracking back to the scene that loaded the stylesheeturl
- The file URL, either relative or absolute, as a String.private boolean _addUserAgentStylesheet(java.lang.String fname)
public void addUserAgentStylesheet(Scene scene, Stylesheet ua_stylesheet)
scene
- Only used in CssError for tracking back to the scene that loaded the stylesheetua_stylesheet
- The stylesheet to add as a user-agent stylesheetpublic void setDefaultUserAgentStylesheet(java.lang.String fname)
fname
- The file URL, either relative or absolute, as a String.public void setDefaultUserAgentStylesheet(Scene scene, java.lang.String url)
scene
- Only used in CssError for tracking back to the scene that loaded the stylesheeturl
- The file URL, either relative or absolute, as a String.private boolean _setDefaultUserAgentStylesheet(java.lang.String fname)
public void removeUserAgentStylesheet(java.lang.String url)
url
- The file URL, either relative or absolute, as a String.public void setDefaultUserAgentStylesheet(Stylesheet ua_stylesheet)
private void userAgentStylesheetsChanged()
private java.util.List<StyleManager.StylesheetContainer> processStylesheets(java.util.List<java.lang.String> stylesheets, Parent parent)
private java.util.List<StyleManager.StylesheetContainer> gatherParentStylesheets(Parent parent)
private java.util.List<StyleManager.StylesheetContainer> gatherSceneStylesheets(Scene scene)
public StyleMap findMatchingStyles(Node node, SubScene subScene, java.util.Set<PseudoClass>[] triggerStates)
public static ObservableList<CssError> errorsProperty()
public static ObservableList<CssError> getErrors()