changeset 1764:d24b55c7fb6a

RT-30871: Indeterminate progress bar causes memory leak Reviewed-by: mickf,vkarnauk
author anashaty
date Wed, 22 Jan 2014 17:08:12 +0400
parents 3d32d956a1a2
children 6a0d5584a605
files javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ProgressBarSkin.java javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java
diffstat 2 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ProgressBarSkin.java	Tue Jan 28 08:49:32 2014 -0800
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ProgressBarSkin.java	Wed Jan 22 17:08:12 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, 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
@@ -33,6 +33,8 @@
 import javafx.animation.Timeline;
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
+import javafx.beans.binding.Bindings;
+import javafx.beans.binding.BooleanBinding;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.event.ActionEvent;
@@ -196,6 +198,8 @@
     private Timeline indeterminateTimeline;
     private boolean timelineNulled = false;
 
+    private BooleanBinding windowIsShowingBinding;
+
     /***************************************************************************
      *                                                                         *
      * Constructors                                                            *
@@ -212,6 +216,8 @@
         };
         control.indeterminateProperty().addListener(indeterminateListener);
 
+        windowIsShowingBinding = Bindings.selectBoolean(getSkinnable().sceneProperty(), "window", "showing");
+
         InvalidationListener visibilityListener = new InvalidationListener() {
             @Override public void invalidated(Observable valueModel) {
                 if (getSkinnable().isIndeterminate() && timelineNulled && indeterminateTimeline == null) {
@@ -220,7 +226,8 @@
                 }
                 
                 if (indeterminateTimeline != null) {
-                    if (getSkinnable().isVisible() && getSkinnable().getScene() != null) {
+                    if (getSkinnable().isVisible() && getSkinnable().getScene() != null
+                            && windowIsShowingBinding.get()) {
                         indeterminateTimeline.play();
                     }
                     else {
@@ -233,6 +240,7 @@
         };
         control.visibleProperty().addListener(visibilityListener);
         control.parentProperty().addListener(visibilityListener);
+        windowIsShowingBinding.addListener(visibilityListener);
 
         InvalidationListener sceneListener = new InvalidationListener() {
             @Override public void invalidated(Observable valueModel) {
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java	Tue Jan 28 08:49:32 2014 -0800
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ProgressIndicatorSkin.java	Wed Jan 22 17:08:12 2014 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2013, 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
@@ -28,6 +28,8 @@
 import javafx.animation.Timeline;
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
+import javafx.beans.binding.Bindings;
+import javafx.beans.binding.BooleanBinding;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.event.ActionEvent;
@@ -89,6 +91,8 @@
     private DeterminateIndicator determinateIndicator;
     private boolean timelineNulled = false;
 
+    private BooleanBinding windowIsShowingBinding;
+
     /***************************************************************************
      *                                                                         *
      * Constructors                                                            *
@@ -105,6 +109,8 @@
         };
         control.indeterminateProperty().addListener(indeterminateListener);
 
+        windowIsShowingBinding = Bindings.selectBoolean(getSkinnable().sceneProperty(), "window", "showing");
+
         InvalidationListener visibilityListener = new InvalidationListener() {
             @Override public void invalidated(Observable valueModel) {
                 if (getSkinnable().isIndeterminate() && timelineNulled && spinner == null) {
@@ -114,7 +120,8 @@
                 }
                 
                 if (spinner != null) {
-                    if (getSkinnable().isVisible() && getSkinnable().getScene() != null) {
+                    if (getSkinnable().isVisible() && getSkinnable().getScene() != null &&
+                            windowIsShowingBinding.get()) {
                         spinner.indeterminateTimeline.play();
                     }
                     else {
@@ -128,6 +135,7 @@
         };
         control.visibleProperty().addListener(visibilityListener);
         control.parentProperty().addListener(visibilityListener);
+        windowIsShowingBinding.addListener(visibilityListener);
 
         InvalidationListener sceneListener = new InvalidationListener() {
             @Override public void invalidated(Observable valueModel) {