changeset 4938:5707c927c106

[TEST ONLY] RT-31865 caused failures in RegionCSSTest. Need to register images with stub toolkit
author David Grieve<david.grieve@oracle.com>
date Thu, 05 Sep 2013 20:03:22 -0400
parents 5c3ec77e5d2a
children fa70a7506503
files modules/graphics/src/main/java/com/sun/javafx/css/StyleManager.java modules/graphics/src/main/java/javafx/scene/layout/Background.java modules/graphics/src/main/java/javafx/scene/layout/BackgroundConverter.java modules/graphics/src/test/java/javafx/scene/layout/RegionCSSTest.java
diffstat 4 files changed, 74 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/modules/graphics/src/main/java/com/sun/javafx/css/StyleManager.java	Thu Sep 05 17:02:27 2013 -0400
+++ b/modules/graphics/src/main/java/com/sun/javafx/css/StyleManager.java	Thu Sep 05 20:03:22 2013 -0400
@@ -686,16 +686,18 @@
                 image = new Image(url);
 
                 // RT-31865
-                if (image.isError() == false) {
-                    imageCache.put(url, image);
-                } else {
-                    imageCache.put(url, null);
+                if (image.isError()) {
+
                     final PlatformLogger logger = getLogger();
                     if (logger != null && logger.isLoggable(Level.WARNING)) {
                         logger.warning("Error loading image: " + url);
                     }
+
+                    image = null;
                 }
 
+                imageCache.put(url, image);
+
             } catch (IllegalArgumentException iae) {
                 // url was empty!
                 final PlatformLogger logger = getLogger();
--- a/modules/graphics/src/main/java/javafx/scene/layout/Background.java	Thu Sep 05 17:02:27 2013 -0400
+++ b/modules/graphics/src/main/java/javafx/scene/layout/Background.java	Thu Sep 05 20:03:22 2013 -0400
@@ -506,12 +506,16 @@
         for (BackgroundImage bi : images) {
             if (bi.opaque == null) {
                 // If the image is not yet loaded, just skip it
-                final com.sun.prism.Image platformImage = (com.sun.prism.Image) acc.getImageProperty(bi.image).get();
+                // Note: Unit test wants this to be com.sun.javafx.tk.PlatformImage, not com.sun.prism.Image
+                final com.sun.javafx.tk.PlatformImage platformImage = acc.getImageProperty(bi.image).get();
                 if (platformImage == null) continue;
 
                 // The image has been loaded, so update the opaque flag
-                assert platformImage != null;
-                bi.opaque = platformImage.isOpaque();
+                if (platformImage instanceof com.sun.prism.Image) {
+                    bi.opaque = ((com.sun.prism.Image)platformImage).isOpaque();
+                } else {
+                    continue;
+                }
             }
 
             // At this point we know that we're processing an image which has already been resolved
--- a/modules/graphics/src/main/java/javafx/scene/layout/BackgroundConverter.java	Thu Sep 05 17:02:27 2013 -0400
+++ b/modules/graphics/src/main/java/javafx/scene/layout/BackgroundConverter.java	Thu Sep 05 20:03:22 2013 -0400
@@ -109,6 +109,8 @@
                 if (imageUrls[i] == null) continue;
 
                 final Image image = StyleManager.getInstance().getCachedImage(imageUrls[i]);
+                if (image == null) continue;
+
                 final RepeatStruct repeat = (repeats.length > 0) ?
                         repeats[i <= lastRepeatIndex ? i : lastRepeatIndex] : null; // min
                 final BackgroundPosition position = (positions.length > 0) ?
--- a/modules/graphics/src/test/java/javafx/scene/layout/RegionCSSTest.java	Thu Sep 05 17:02:27 2013 -0400
+++ b/modules/graphics/src/test/java/javafx/scene/layout/RegionCSSTest.java	Thu Sep 05 20:03:22 2013 -0400
@@ -25,6 +25,10 @@
 
 package javafx.scene.layout;
 
+import com.sun.javafx.pgstub.StubImageLoaderFactory;
+import com.sun.javafx.pgstub.StubPlatformImageInfo;
+import com.sun.javafx.pgstub.StubToolkit;
+import com.sun.javafx.tk.Toolkit;
 import javafx.geometry.Insets;
 import javafx.geometry.Side;
 import javafx.scene.Scene;
@@ -33,6 +37,11 @@
 import org.junit.Ignore;
 import org.junit.Test;
 
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+
 import static javafx.scene.layout.BackgroundSize.*;
 import static org.junit.Assert.*;
 
@@ -59,10 +68,60 @@
     private void processCSS() {
         scene.getRoot().impl_processCSS(true);
     }
+
+    private static void installImage(final String str) {
+
+        if (str == null || str.trim().isEmpty()) return;
+
+        URL imageUrl = null;
+
+        try {
+
+            URI uri =  new URI(str.trim());
+
+            // if url doesn't have a scheme
+            if (uri.isAbsolute() == false) {
+
+                final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
+                final String path = uri.getPath();
+
+                URL resource = null;
+
+                if (path.startsWith("/")) {
+                    resource = contextClassLoader.getResource(path.substring(1));
+                } else {
+                    resource = contextClassLoader.getResource(path);
+                }
+
+                imageUrl = resource;
+
+            } else {
+                // else, url does have a scheme
+                imageUrl = uri.toURL();
+            }
+
+        } catch (MalformedURLException malf) {
+
+        } catch (URISyntaxException urise) {
+        }
+
+        if (imageUrl != null) {
+
+            StubImageLoaderFactory imageLoaderFactory =
+                    ((StubToolkit) Toolkit.getToolkit()).getImageLoaderFactory();
+
+            imageLoaderFactory.registerImage(
+                    imageUrl.toExternalForm(), new StubPlatformImageInfo(100, 100));
+        }
+
+    }
     
     @Before public void setUp() {
         region = new Region();
         scene = new Scene(region);
+
+        installImage("javafx/scene/layout/red.png");
+        installImage("javafx/scene/layout/center-btn.png");
     }
 
     /**************************************************************************