changeset 6168:cbe1008fbea3

Fix RT-25249: ImageInput effect not updated when WritableImage is updated Reviewed by Felipe and Chien
author flar <James.Graham@oracle.com>
date Wed, 22 Jan 2014 11:25:49 -0800
parents 2e23e1f2b922
children f7e4bebcf795
files modules/graphics/src/main/java/javafx/scene/effect/ImageInput.java
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/javafx/scene/effect/ImageInput.java	Wed Jan 22 13:04:02 2014 -0500
+++ b/modules/graphics/src/main/java/javafx/scene/effect/ImageInput.java	Wed Jan 22 11:25:49 2014 -0800
@@ -25,6 +25,7 @@
 
 package javafx.scene.effect;
 
+import javafx.beans.Observable;
 import javafx.beans.property.DoubleProperty;
 import javafx.beans.property.DoublePropertyBase;
 import javafx.beans.property.ObjectProperty;
@@ -32,6 +33,7 @@
 import javafx.scene.Node;
 import javafx.scene.image.Image;
 
+import com.sun.javafx.beans.event.AbstractNotifyListener;
 import com.sun.javafx.effect.EffectDirtyBits;
 import com.sun.javafx.geom.BaseBounds;
 import com.sun.javafx.geom.RectBounds;
@@ -91,12 +93,40 @@
         return source == null ? null : source.get();
     }
 
+    private final AbstractNotifyListener platformImageChangeListener =
+        new AbstractNotifyListener() {
+            @Override
+            public void invalidated(Observable valueModel) {
+                markDirty(EffectDirtyBits.EFFECT_DIRTY);
+                effectBoundsChanged();
+            }
+        };
+    private Image oldImage;
     public final ObjectProperty<Image> sourceProperty() {
         if (source == null) {
             source = new ObjectPropertyBase<Image>() {
 
+                private boolean needsListeners = false;
+
                 @Override
                 public void invalidated() {
+                    Image _image = get();
+
+                    Toolkit.ImageAccessor accessor = Toolkit.getImageAccessor();
+
+                    if (needsListeners) {
+                        accessor.getImageProperty(oldImage).
+                                removeListener(platformImageChangeListener.getWeakListener());
+                    }
+
+                    needsListeners = _image != null && (accessor.isAnimation(_image) ||
+                                                        _image.getProgress() < 1);
+                    oldImage = _image;
+
+                    if (needsListeners) {
+                        accessor.getImageProperty(_image).
+                                addListener(platformImageChangeListener.getWeakListener());
+                    }
                     markDirty(EffectDirtyBits.EFFECT_DIRTY);
                     effectBoundsChanged();
                 }