modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java

Print this page
rev 7080 : RT-37174: if ProgressIndicator is removed from scene and then later added back, re-initialize the ProgressIndicator.

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -37,10 +37,11 @@
 import javafx.beans.binding.BooleanExpression;
 import javafx.beans.property.BooleanProperty;
 import javafx.beans.property.DoubleProperty;
 import javafx.beans.property.IntegerProperty;
 import javafx.beans.property.ObjectProperty;
+import javafx.beans.value.ChangeListener;
 import javafx.beans.value.WritableValue;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.geometry.Bounds;
 import javafx.geometry.NodeOrientation;

@@ -104,11 +105,11 @@
         super(control, new ProgressIndicatorBehavior<ProgressIndicator>(control));
 
         this.control = control;
         this.control.indeterminateProperty().addListener(indeterminateListener);
         this.control.progressProperty().addListener(progressListener);
-
+        this.control.sceneProperty().addListener(sceneChangeListener);
         initialize();
     }
 
     private void initialize() {
         boolean isIndeterminate = control.isIndeterminate();

@@ -136,20 +137,21 @@
             getChildren().setAll(determinateIndicator);
         }
     }
 
     @Override public void dispose() {
-        super.dispose();
         if (spinner != null) {
             if (spinner.indeterminateTimeline != null) {
                 spinner.indeterminateTimeline.stop();
             }
             spinner = null;
         }
         control.indeterminateProperty().removeListener(indeterminateListener);
         control.progressProperty().removeListener(progressListener);
-        control = null;
+        control.sceneProperty().removeListener(sceneChangeListener);
+
+        super.dispose();
     }
 
     @Override protected void layoutChildren(final double x, final double y,
                                             final double w, final double h) {
         if (spinner != null && control.isIndeterminate()) {

@@ -170,15 +172,20 @@
     // Listen to ProgressIndicator indeterminateProperty
     private final InvalidationListener indeterminateListener = valueModel -> {
         initialize();
     };
 
-    private final InvalidationListener progressListener = new InvalidationListener() {
-        @Override public void invalidated(Observable valueModel) {
+    private final InvalidationListener progressListener = valueModel -> {
             if (determinateIndicator != null) {
                 determinateIndicator.updateProgress(((DoubleProperty)valueModel).doubleValue());
             }
+    };
+
+    private final ChangeListener<Scene> sceneChangeListener = (observable, oldValue, newValue) -> {
+        // if ProgressIndicator was removed from scene and then added back in...
+        if (oldValue == null) {
+            initialize();
         }
     };
 
     /***************************************************************************
      *                                                                         *