changeset 6569:eacaf885bab9

RT-34825: if spinEnabled is changed, rebuild the timeline.
author David Grieve<david.grieve@oracle.com>
date Fri, 28 Mar 2014 17:13:18 -0400
parents 4925e1655837
children a67e9552a5e5
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java
diffstat 1 files changed, 20 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java	Fri Mar 28 17:11:05 2014 -0400
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java	Fri Mar 28 17:13:18 2014 -0400
@@ -416,9 +416,6 @@
                     }
                 }
                 else if (isVisible) {
-                    indeterminateTimeline = new Timeline();
-                    indeterminateTimeline.setCycleCount(Timeline.INDEFINITE);
-                    indeterminateTimeline.setDelay(UNCLIPPED_DELAY);
                     rebuildTimeline();
                 }
             });
@@ -430,14 +427,10 @@
 
             pathsG = new IndicatorPaths();
             getChildren().add(pathsG);
-
-            indeterminateTimeline = new Timeline();
-            indeterminateTimeline.setCycleCount(Timeline.INDEFINITE);
-            indeterminateTimeline.setDelay(UNCLIPPED_DELAY);
+            rebuild();
 
             rebuildTimeline();
 
-            rebuild();
         }
 
         public void setFillOverride(Paint fillOverride) {
@@ -495,7 +488,15 @@
     }
 
         private void rebuildTimeline() {
-            if (indeterminateTimeline != null) {
+            if (spinEnabled) {
+                if (indeterminateTimeline == null) {
+                    indeterminateTimeline = new Timeline();
+                    indeterminateTimeline.setCycleCount(Timeline.INDEFINITE);
+                    indeterminateTimeline.setDelay(UNCLIPPED_DELAY);
+                } else {
+                    indeterminateTimeline.stop();
+                    indeterminateTimeline.getKeyFrames().clear();
+                }
                 final ObservableList<KeyFrame> keyFrames = FXCollections.<KeyFrame>observableArrayList();
                 keyFrames.add(
                   new KeyFrame(
@@ -523,10 +524,9 @@
                         }
                     }
                   ));
-                if(spinEnabled) {
-                    keyFrames.add(new KeyFrame(Duration.millis(1), new KeyValue(pathsG.rotateProperty(), 360)));
-                    keyFrames.add(new KeyFrame(Duration.millis(3900), new KeyValue(pathsG.rotateProperty(), 0)));
-                }
+
+                keyFrames.add(new KeyFrame(Duration.millis(1), new KeyValue(pathsG.rotateProperty(), 360)));
+                keyFrames.add(new KeyFrame(Duration.millis(3900), new KeyValue(pathsG.rotateProperty(), 0)));
 
                 for (int i = 100; i <= 3900; i += 100) {
                     keyFrames.add(
@@ -539,6 +539,12 @@
 
                 indeterminateTimeline.getKeyFrames().setAll(keyFrames);
                 indeterminateTimeline.playFromStart();
+            } else {
+                if (indeterminateTimeline != null) {
+                    indeterminateTimeline.stop();
+                    indeterminateTimeline.getKeyFrames().clear();
+                    indeterminateTimeline = null;
+                }
             }
         }
 
@@ -756,8 +762,7 @@
                     }
                 };
         private static final CssMetaData<ProgressIndicator,Boolean> SPIN_ENABLED =
-                new CssMetaData<ProgressIndicator,Boolean>("-fx-spin-enabled",
-                                                           BooleanConverter.getInstance(), Boolean.FALSE) {
+                new CssMetaData<ProgressIndicator,Boolean>("-fx-spin-enabled", BooleanConverter.getInstance(), Boolean.FALSE) {
 
                     @Override public boolean isSettable(ProgressIndicator node) {
                         final ProgressIndicatorSkin skin = (ProgressIndicatorSkin) node.getSkin();