Re: Reloading stylesheets

2013-12-12 Thread Jerome Cambon


This is also impacting Scene Builder.

I have filed a Jira with a test case:
https://javafx-jira.kenai.com/browse/RT-34863

Jerome

On 12/11/13 6:19 PM, David Grieve wrote:

There is clearly a bug there somewhere. Would you mind filing an issue on 
javafx-jira.kenai.com?

On Dec 11, 2013, at 11:51 AM, ngalarn...@abinitio.com wrote:


Hi David,

I have stylesheet SWITCHING working fine. I can switch between 2 different
stylesheets on disk without tearing down  rebuilding my Scene. To do this
I simply do:
scene.stylesheets.clear()
scene.stylesheets.add(differentStylesheet)
and the changes show up immediately (I'm assuming those 2 lines cause a
.css recalculation  a pulse).

I would like to get stylesheet RELOADING to work in my JavaFX 8 app. By
this I mean picking up changes in a single .css file. This would allow the
developers to tweak the stylesheet  reload to see the effects
immediately.

Unfortunately, it feels like the Filename of the stylesheet is the Key in
a cache that isn't getting cleared by my code above. Nothing visible
happens when I do:
scene.stylesheets.clear()
scene.stylesheets.add(sameStylesheet)

Given your description below, my impression is that RELOADING should also
work...

Thank you for any suggestions,

Neil




From:   David Grieve david.gri...@oracle.com
To: Werner Lehmann lehm...@media-interactive.de
Cc: openjfx-dev@openjdk.java.net
Date:   12/10/2013 11:10 AM
Subject:Re: Reloading stylesheets
Sent by:openjfx-dev-boun...@openjdk.java.net



The way it works in 8.0 is that there is a cache of loaded stylesheets.
When a scene or parent adds a stylesheet, the stylesheet is added to the
cache. Any other scene or parent that uses the same stylesheet will get
the one from cache. If a scene or parent later removes the stylesheet, the
stylesheet is removed from the cache and the css style cache for any scene
or parent that referenced that stylesheet is cleared (since the set of
styles may have changed). Any scene or parent that referenced the now
removed stylesheet is told to reapply its styles. Since the stylesheet is
no longer in cache, it will be re-parsed (or reloaded if there is a binary
version of the stylesheet) when it is called for by a scene or parent.

The way it worked in 2.x was an abomination.

On Dec 10, 2013, at 10:30 AM, Werner Lehmann
lehm...@media-interactive.de wrote:


Interesting. Assuming the stylesheets are still cached, how would it

know when to reload and not use the cached sheet? Or has sheet processing
been optimized so much that caching is not necessary anymore...

On 10.12.2013 16:15, Tom Schindl wrote:

No on FX8 you need to remove and readd them! So the only thing

different

is that you omit the reload-call on FX8.





NOTICE from Ab Initio: This email (including any attachments) may contain
information that is subject to confidentiality obligations or is legally
privileged, and sender does not waive confidentiality or privilege. If
received in error, please notify the sender, delete this email, and make
no further use, disclosure, or distribution.




Re: Reloading stylesheets

2013-12-11 Thread ngalarneau
Hi David,

I have stylesheet SWITCHING working fine. I can switch between 2 different 
stylesheets on disk without tearing down  rebuilding my Scene. To do this 
I simply do:
scene.stylesheets.clear()
scene.stylesheets.add(differentStylesheet)
and the changes show up immediately (I'm assuming those 2 lines cause a 
.css recalculation  a pulse).

I would like to get stylesheet RELOADING to work in my JavaFX 8 app. By 
this I mean picking up changes in a single .css file. This would allow the 
developers to tweak the stylesheet  reload to see the effects 
immediately.

Unfortunately, it feels like the Filename of the stylesheet is the Key in 
a cache that isn't getting cleared by my code above. Nothing visible 
happens when I do:
scene.stylesheets.clear()
scene.stylesheets.add(sameStylesheet)

Given your description below, my impression is that RELOADING should also 
work...

Thank you for any suggestions,

Neil




From:   David Grieve david.gri...@oracle.com
To: Werner Lehmann lehm...@media-interactive.de
Cc: openjfx-dev@openjdk.java.net
Date:   12/10/2013 11:10 AM
Subject:Re: Reloading stylesheets
Sent by:openjfx-dev-boun...@openjdk.java.net



The way it works in 8.0 is that there is a cache of loaded stylesheets. 
When a scene or parent adds a stylesheet, the stylesheet is added to the 
cache. Any other scene or parent that uses the same stylesheet will get 
the one from cache. If a scene or parent later removes the stylesheet, the 
stylesheet is removed from the cache and the css style cache for any scene 
or parent that referenced that stylesheet is cleared (since the set of 
styles may have changed). Any scene or parent that referenced the now 
removed stylesheet is told to reapply its styles. Since the stylesheet is 
no longer in cache, it will be re-parsed (or reloaded if there is a binary 
version of the stylesheet) when it is called for by a scene or parent.

The way it worked in 2.x was an abomination.

On Dec 10, 2013, at 10:30 AM, Werner Lehmann 
lehm...@media-interactive.de wrote:

 Interesting. Assuming the stylesheets are still cached, how would it 
know when to reload and not use the cached sheet? Or has sheet processing 
been optimized so much that caching is not necessary anymore...
 
 On 10.12.2013 16:15, Tom Schindl wrote:
 No on FX8 you need to remove and readd them! So the only thing 
different
 is that you omit the reload-call on FX8.




 
NOTICE from Ab Initio: This email (including any attachments) may contain 
information that is subject to confidentiality obligations or is legally 
privileged, and sender does not waive confidentiality or privilege. If 
received in error, please notify the sender, delete this email, and make 
no further use, disclosure, or distribution. 


Re: Reloading stylesheets

2013-12-11 Thread David Grieve
There is clearly a bug there somewhere. Would you mind filing an issue on 
javafx-jira.kenai.com?

On Dec 11, 2013, at 11:51 AM, ngalarn...@abinitio.com wrote:

 Hi David,
 
 I have stylesheet SWITCHING working fine. I can switch between 2 different 
 stylesheets on disk without tearing down  rebuilding my Scene. To do this 
 I simply do:
scene.stylesheets.clear()
scene.stylesheets.add(differentStylesheet)
 and the changes show up immediately (I'm assuming those 2 lines cause a 
 .css recalculation  a pulse).
 
 I would like to get stylesheet RELOADING to work in my JavaFX 8 app. By 
 this I mean picking up changes in a single .css file. This would allow the 
 developers to tweak the stylesheet  reload to see the effects 
 immediately.
 
 Unfortunately, it feels like the Filename of the stylesheet is the Key in 
 a cache that isn't getting cleared by my code above. Nothing visible 
 happens when I do:
scene.stylesheets.clear()
scene.stylesheets.add(sameStylesheet)
 
 Given your description below, my impression is that RELOADING should also 
 work...
 
 Thank you for any suggestions,
 
 Neil
 
 
 
 
 From:   David Grieve david.gri...@oracle.com
 To: Werner Lehmann lehm...@media-interactive.de
 Cc: openjfx-dev@openjdk.java.net
 Date:   12/10/2013 11:10 AM
 Subject:Re: Reloading stylesheets
 Sent by:openjfx-dev-boun...@openjdk.java.net
 
 
 
 The way it works in 8.0 is that there is a cache of loaded stylesheets. 
 When a scene or parent adds a stylesheet, the stylesheet is added to the 
 cache. Any other scene or parent that uses the same stylesheet will get 
 the one from cache. If a scene or parent later removes the stylesheet, the 
 stylesheet is removed from the cache and the css style cache for any scene 
 or parent that referenced that stylesheet is cleared (since the set of 
 styles may have changed). Any scene or parent that referenced the now 
 removed stylesheet is told to reapply its styles. Since the stylesheet is 
 no longer in cache, it will be re-parsed (or reloaded if there is a binary 
 version of the stylesheet) when it is called for by a scene or parent.
 
 The way it worked in 2.x was an abomination.
 
 On Dec 10, 2013, at 10:30 AM, Werner Lehmann 
 lehm...@media-interactive.de wrote:
 
 Interesting. Assuming the stylesheets are still cached, how would it 
 know when to reload and not use the cached sheet? Or has sheet processing 
 been optimized so much that caching is not necessary anymore...
 
 On 10.12.2013 16:15, Tom Schindl wrote:
 No on FX8 you need to remove and readd them! So the only thing 
 different
 is that you omit the reload-call on FX8.
 
 
 
 
 
 NOTICE from Ab Initio: This email (including any attachments) may contain 
 information that is subject to confidentiality obligations or is legally 
 privileged, and sender does not waive confidentiality or privilege. If 
 received in error, please notify the sender, delete this email, and make 
 no further use, disclosure, or distribution. 



Re: Reloading stylesheets

2013-12-10 Thread Tom Schindl
That doesn't work in 2.x because the CSS is cached on a scene base! A
trick that could work is to load the CSS with an URL like this like:

my.css?timestamp=123456789

but I have not tried that and don't know if this would work.

Tom

On 10.12.13 13:41, Scott Palmer wrote:
 Have you tried simply removing and re-adding the stylesheet to the scene?
 
 Scott
 
 
 On Tue, Dec 10, 2013 at 7:21 AM, Werner Lehmann 
 lehm...@media-interactive.de wrote:
 
 Hi,

 is there a way to reload previously loaded stylesheets (in FX2)?

 Currently I have to restart the application each time I am changing the
 css. It would be nice to just close and reopen that window instead to see
 the new styles. I'd like to unload css automatically when closing a window
 - in debug mode - in order to avoid the application restart.

 Or, even better, define a hotkey to update css immediately. Much like
 shift+ctrl+8 for ScenicView (only works in FX2 as far as I know).

 Rgds
 Werner




Re: Reloading stylesheets

2013-12-10 Thread Scott Palmer
Hmm.. I'll have to take a look at what I was doing, because I had something
that appeared to work with 2.x and I'm pretty sure I wasn't using internal
APIs.  Perhaps it was only working by chance.

Scott


On Tue, Dec 10, 2013 at 7:46 AM, Tom Schindl tom.schi...@bestsolution.atwrote:

 That doesn't work in 2.x because the CSS is cached on a scene base! A
 trick that could work is to load the CSS with an URL like this like:

 my.css?timestamp=123456789

 but I have not tried that and don't know if this would work.

 Tom

 On 10.12.13 13:41, Scott Palmer wrote:
  Have you tried simply removing and re-adding the stylesheet to the scene?
 
  Scott
 
 
  On Tue, Dec 10, 2013 at 7:21 AM, Werner Lehmann 
  lehm...@media-interactive.de wrote:
 
  Hi,
 
  is there a way to reload previously loaded stylesheets (in FX2)?
 
  Currently I have to restart the application each time I am changing the
  css. It would be nice to just close and reopen that window instead to
 see
  the new styles. I'd like to unload css automatically when closing a
 window
  - in debug mode - in order to avoid the application restart.
 
  Or, even better, define a hotkey to update css immediately. Much like
  shift+ctrl+8 for ScenicView (only works in FX2 as far as I know).
 
  Rgds
  Werner
 




Re: Reloading stylesheets

2013-12-10 Thread Werner Lehmann

Thanks, Tom. Somehow it does not work for me. Any idea?

Basically this is what I am doing:

Parent root = ...
root.getStyleSheets().add(...stylesheets...)
Scene scene = new Scene(root)
StyleManager.getInstance().reloadStylesheets(scene)

Then I show the scene in a JFXPanel, change and save the stylesheet in 
Eclipse, and reopen the window which repeats all of the above. But the 
css changes are not reflected until I restart the application.


On 10.12.2013 13:30, Tom Schindl wrote:

com.sun.javafx.css.StyleManager.getInstance().reloadStylesheets(scene);


Re: Reloading stylesheets

2013-12-10 Thread Werner Lehmann
Got it. The key was to move the stylesheets from the root node to the 
scene before reloading them:


scene.styleSheets.clear
scene.styleSheets.addAll(root.styleSheets)
root.styleSheets.clear
styleManager.reload(scene)

The hotkey also works now: shift+ctrl+7 reloads CSS while the scene is 
visible. This works by using a custom scene, overriding 
impl_processKeyEvent. Even better would be automatic change-detection 
(in debug mode only) but I don't have time to do this now. Previously 
you said that reloading is not needed on FX8... does this work out of 
the box then?


Werner

On 10.12.2013 14:10, Tom Schindl wrote:

My code does:


// Force CSS-Reloading
if( isJavaFX2() ) {
   ReflectiveInvoke.onStyleManagerClass(scene);
}

scene.getStylesheets().clear(); 
scene.getStylesheets().addAll(contentData.cssFiles);


A difference I see is that your stylesheets are on the Root-Container
whereas mine are directly on the Scene.

Tom


Re: Reloading stylesheets

2013-12-10 Thread Tom Schindl
No on FX8 you need to remove and readd them! So the only thing different
is that you omit the reload-call on FX8.

Tom

On 10.12.13 16:10, Werner Lehmann wrote:
 Got it. The key was to move the stylesheets from the root node to the
 scene before reloading them:
 
 scene.styleSheets.clear
 scene.styleSheets.addAll(root.styleSheets)
 root.styleSheets.clear
 styleManager.reload(scene)
 
 The hotkey also works now: shift+ctrl+7 reloads CSS while the scene is
 visible. This works by using a custom scene, overriding
 impl_processKeyEvent. Even better would be automatic change-detection
 (in debug mode only) but I don't have time to do this now. Previously
 you said that reloading is not needed on FX8... does this work out of
 the box then?
 
 Werner
 
 On 10.12.2013 14:10, Tom Schindl wrote:
 My code does:

 // Force CSS-Reloading
 if( isJavaFX2() ) {
ReflectiveInvoke.onStyleManagerClass(scene);
 }

 scene.getStylesheets().clear();   
 scene.getStylesheets().addAll(contentData.cssFiles);

 A difference I see is that your stylesheets are on the Root-Container
 whereas mine are directly on the Scene.

 Tom



Re: Reloading stylesheets

2013-12-10 Thread Werner Lehmann
Interesting. Assuming the stylesheets are still cached, how would it 
know when to reload and not use the cached sheet? Or has sheet 
processing been optimized so much that caching is not necessary anymore...


On 10.12.2013 16:15, Tom Schindl wrote:

No on FX8 you need to remove and readd them! So the only thing different
is that you omit the reload-call on FX8.


Re: Reloading stylesheets

2013-12-10 Thread David Grieve
The way it works in 8.0 is that there is a cache of loaded stylesheets. When a 
scene or parent adds a stylesheet, the stylesheet is added to the cache. Any 
other scene or parent that uses the same stylesheet will get the one from 
cache. If a scene or parent later removes the stylesheet, the stylesheet is 
removed from the cache and the css style cache for any scene or parent that 
referenced that stylesheet is cleared (since the set of styles may have 
changed). Any scene or parent that referenced the now removed stylesheet is 
told to reapply its styles. Since the stylesheet is no longer in cache, it will 
be re-parsed (or reloaded if there is a binary version of the stylesheet) when 
it is called for by a scene or parent.

The way it worked in 2.x was an abomination.

On Dec 10, 2013, at 10:30 AM, Werner Lehmann lehm...@media-interactive.de 
wrote:

 Interesting. Assuming the stylesheets are still cached, how would it know 
 when to reload and not use the cached sheet? Or has sheet processing been 
 optimized so much that caching is not necessary anymore...
 
 On 10.12.2013 16:15, Tom Schindl wrote:
 No on FX8 you need to remove and readd them! So the only thing different
 is that you omit the reload-call on FX8.



Re: Reloading stylesheets

2013-12-10 Thread Werner Lehmann

Makes sense. Thanks!

On 10.12.2013 17:09, David Grieve wrote:

The way it works in 8.0 is that there is a cache of loaded stylesheets. [...]


RE: Reloading stylesheets

2013-12-10 Thread John Smith
 And in general if there were some performance guidelines for JavaFX that 
 would be really helpful.  

There is an open-jfx wiki page for JavaFX Performance Tips and Tricks, you 
could check that and see if it is helpful (if it's not maybe you could edit it 
and add a new section on performance issues you would like to see discussed or 
documented):
  https://wiki.openjdk.java.net/display/OpenJFX/Performance+Tips+and+Tricks

There are some JavaOne presentations on Performance topic:
  http://www.youtube.com/watch?feature=player_embeddedv=ddJpDi5SWFc
  http://parleys.com/play/514892290364bc17fc56c3c5/chapter26/about

John

-Original Message-
From: openjfx-dev-boun...@openjdk.java.net 
[mailto:openjfx-dev-boun...@openjdk.java.net] On Behalf Of Mark Fortner
Sent: Tuesday, December 10, 2013 9:39 AM
To: openjfx-dev@openjdk.java.net
Subject: Fwd: Reloading stylesheets

It would be nice if there were some documentation for how to get around the 
memory leak in stylesheets in 7x (since most of us won't be upgrading to 8 
until it's actually released).  And in general if there were some performance 
guidelines for JavaFX that would be really helpful.  There was some mention of 
when (and when not) to use *Platform.runLater*.  Avoiding memory leaks in 
multi-threaded code, guidelines for threadpool tuning so that apps stay 
responsive, etc.  The Best 
Practiceshttp://docs.oracle.com/javafx/2/best_practices/jfxpub-best_practices.htm
document
provides a start but more details would be useful.


Cheers,

Mark



-- Forwarded message --
From: Werner Lehmann lehm...@media-interactive.de
Date: Tue, Dec 10, 2013 at 9:03 AM
Subject: Re: Reloading stylesheets
To:
Cc: openjfx-dev@openjdk.java.net openjfx-dev@openjdk.java.net


Makes sense. Thanks!

On 10.12.2013 17:09, David Grieve wrote:

 The way it works in 8.0 is that there is a cache of loaded stylesheets.
 [...]