RFR: 8263095: Provide a way for a custom control to indicate that its userAgentStyleSheet has changed
Alessandro Parisi
alessandro.parisi406 at gmail.com
Wed Jul 7 17:43:42 UTC 2021
Sorry for the late reply, but I've been quite busy lately.
So, the code change that I suggested here #525
<https://github.com/openjdk/jfx/pull/525> is not only an improvement but
also a bug fix.
The improvement is that we can see this change as a little theming system
because if a control can provide an userAgentStylesheet depending on
certain conditions we can call this a theme system. This would be a good
improvement for devs like me who develop custom controls because as of now
the only way to provide such mechanism is to change the stylesheet list.
Let's say we have an enumerator for the style of a control and each enum
has the string url to the CSS file, the only way is to load the CSS and do
'control.getStylesheets().setAll(file)'
This, however, can cause nasty bugs and unexpected behaviors.
That's why I have overridden the 'invalidated()' method of the property, so
that when it changes, the control's style is re-computed correctly.
Regarding the 'StyleManager' the changes ensure that what's stored in
the 'weakRegionUserAgentStylesheetMap'
is the correct CSS file. In fact, using just the 'computeIfAbsent()' method
here Line 1667
<https://github.com/openjdk/jfx/pull/525/commits/3cffaccd7eaf11238e786e31f8c1b6fb16121471#diff-ca9344a33e4b346c9ac138a5e5d867acc3b0e53c761e8d207fd92026320792edR1667>
is not enough if the user agent changes.
The good thing about the user agent API change is that it is backward
compatible, libraries based on old JavaFX versions would still work because
as of now they override the 'getUserAgentStylesheet()' getter, and that
getter is still present but by default now returns the userAgenStylesheet
property value.
Let me know what do you think, I would really like to see this change
happen, implementing custom themes would be very easy
More information about the openjfx-dev
mailing list