changeset 4516:3aadad7d5904

RT-27791 :ProgressBar keeps animating when in ScrollPane and scrolled out of view
author mickf
date Thu, 01 Aug 2013 14:43:17 +0100
parents 4d59d24f0d8b
children 42157cdefd1a
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressBarSkin.java modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java
diffstat 2 files changed, 88 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressBarSkin.java	Thu Aug 01 14:39:44 2013 +0100
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressBarSkin.java	Thu Aug 01 14:43:17 2013 +0100
@@ -341,6 +341,46 @@
         }
     }
     
+    private boolean isVisibleInClip() {
+        Parent p1 = getSkinnable();
+
+        Bounds ourBounds1 = p1.localToScene(getSkinnable().getLayoutBounds());
+        while (p1 != null) {
+            Node clip = p1.getClip();
+            if (clip != null) {
+                Bounds clipBounds1 = p1.localToScene(clip.getLayoutBounds());
+                if (!ourBounds1.intersects(clipBounds1)) {
+                    return false;
+                }
+            }
+            p1 = p1.getParent();
+        }
+        return true;
+    }
+
+    /*
+    ** see if we're clipped...
+    */
+    private void pauseIfNotVisibleInClip() {
+        if (!isVisibleInClip()) {
+            indeterminateTimeline.pause();
+            
+            Thread t = new Thread(new Runnable() {
+                 @Override
+                     public void run() {
+                        while (!isVisibleInClip()) {
+                            try {
+                                Thread.sleep(500);
+                            }
+                            catch (Exception e) {};
+                        }
+                        indeterminateTimeline.play();
+                    }
+                });
+            t.start();
+        }
+    }
+
     private boolean isInvisibleOrDisconnected() {
         Scene s = getSkinnable().getScene();
         if (s == null) {
@@ -369,11 +409,15 @@
         return false;
     }
 
+
     private void stopIfNotNeeded() {
-        stopIfInvisibleOrDisconnected();
+        if (!stopIfInvisibleOrDisconnected()) {
+            pauseIfNotVisibleInClip();
+        }
     }
 
 
+
     private void createIndeterminateTimeline() {
         if (indeterminateTimeline != null) indeterminateTimeline.stop();
 
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java	Thu Aug 01 14:39:44 2013 +0100
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java	Thu Aug 01 14:43:17 2013 +0100
@@ -462,6 +462,46 @@
             rebuildTimeline();
         }
 
+    private boolean isVisibleInClip() {
+        Parent p1 = control;
+
+        Bounds ourBounds1 = p1.localToScene(control.getLayoutBounds());
+        while (p1 != null) {
+            Node clip = p1.getClip();
+            if (clip != null) {
+                Bounds clipBounds1 = p1.localToScene(clip.getLayoutBounds());
+                if (!ourBounds1.intersects(clipBounds1)) {
+                    return false;
+                }
+            }
+            p1 = p1.getParent();
+        }
+        return true;
+    }
+
+    /*
+    ** see if we're clipped...
+    */
+    private void pauseIfNotVisibleInClip() {
+        if (!isVisibleInClip()) {
+            indeterminateTimeline.pause();
+            
+            Thread t = new Thread(new Runnable() {
+                 @Override
+                     public void run() {
+                        while (!isVisibleInClip()) {
+                            try {
+                                Thread.sleep(500);
+                            }
+                            catch (Exception e) {};
+                        }
+                        indeterminateTimeline.play();
+                    }
+                });
+            t.start();
+        }
+    }
+
     private boolean isInvisibleOrDisconnected() {
         Scene s = control.getScene();
         if (s == null) {
@@ -492,7 +532,9 @@
 
 
         private void stopIfNotNeeded() {
-            stopIfInvisibleOrDisconnected();
+            if (!stopIfInvisibleOrDisconnected()) {
+                pauseIfNotVisibleInClip();
+            }
         }
 
         private void rebuildTimeline() {