harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r562669 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/text/html/ test/api/java.injected/javax/swing/text/html/
Date Sat, 04 Aug 2007 07:10:49 GMT
Author: apetrenko
Date: Sat Aug  4 00:10:48 2007
New Revision: 562669

URL: http://svn.apache.org/viewvc?view=rev&rev=562669
Log:
Patch for HARMONY-4573 "[classlib][swing][html] Images are not displayed correctly repeatedly"

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/BackgroundImageLoader.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CSS.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewComponentFactory.java
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ImageViewTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/BackgroundImageLoader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/BackgroundImageLoader.java?view=diff&rev=562669&r1=562668&r2=562669
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/BackgroundImageLoader.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/BackgroundImageLoader.java
Sat Aug  4 00:10:48 2007
@@ -40,16 +40,26 @@
     private volatile boolean ready;
     private volatile boolean error;
 
-    BackgroundImageLoader(final URL url,
+    private boolean synchronous;
+    Object lock = new Object();
+
+    final Toolkit tk = Toolkit.getDefaultToolkit();
+
+    BackgroundImageLoader(final URL url, boolean synchronous,
                           final int desiredWidth, final int desiredHeight) {
         this.desiredWidth = desiredWidth;
         this.desiredHeight = desiredHeight;
 
+        this.synchronous = synchronous;
+
         error = url == null;
         if (!error) {
-            final Toolkit tk = Toolkit.getDefaultToolkit();
             image = tk.createImage(url);
-            tk.prepareImage(image, desiredWidth, desiredHeight, this);
+            if (synchronous){
+                waitForImage();
+            } else {
+                tk.prepareImage(image, desiredWidth, desiredHeight, this);
+            }
         } else {
             image = null;
         }
@@ -64,16 +74,22 @@
         if ((flags & HEIGHT) != 0) {
             imageHeight = desiredHeight == -1 ? height : desiredHeight;
         }
-        if ((flags & ALLBITS) != 0) {
+        if ((flags & (FRAMEBITS | ALLBITS)) != 0) {
             ready = true;
             onReady();
         }
         if ((flags & (ERROR | ABORT)) != 0) {
             error = true;
             onError();
-            return false;
         }
-        return width == -1 || height == -1 || !ready;
+
+        if (synchronous){
+            synchronized (lock){
+                lock.notify();
+            }
+        }
+
+        return (flags & ALLBITS) == 0;
     }
 
     public final Image getImage() {
@@ -97,11 +113,15 @@
     }
 
     public final void waitForImage() {
-        while (!ready && !error) {
-            try {
-                Thread.sleep(100);
-            } catch (InterruptedException e) {
-                e.printStackTrace();
+        synchronized (lock){
+            if (!tk.prepareImage(image, desiredWidth, desiredHeight, this)) {
+                while (!(error | ready)) {
+                    try {
+                        lock.wait(1000);
+                    } catch(InterruptedException e) {
+                        Thread.currentThread().interrupt();
+                    }
+                }
             }
         }
     }

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CSS.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CSS.java?view=diff&rev=562669&r1=562668&r2=562669
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CSS.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/CSS.java
Sat Aug  4 00:10:48 2007
@@ -528,7 +528,7 @@
             if (path != null && imageLoader == null) {
 
                 final URL url = HTML.resolveURL(path, base);
-                imageLoader = new BackgroundImageLoader(url, -1, -1) {
+                imageLoader = new BackgroundImageLoader(url, true, -1, -1) {
                     protected void onReady() {
                         super.onReady();
                         notifyViews();

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewComponentFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewComponentFactory.java?view=diff&rev=562669&r1=562668&r2=562669
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewComponentFactory.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/FormViewComponentFactory.java
Sat Aug  4 00:10:48 2007
@@ -86,7 +86,7 @@
                 if (url == null) {
                     icon = HTMLIconFactory.getLoadingFailedIcon();
                 } else {
-                    loader = new BackgroundImageLoader(url, -1, -1) {
+                    loader = new BackgroundImageLoader(url, true, -1, -1) {
                         protected void onReady() {
                             super.onReady();
                             view.preferenceChanged(view, true, true);

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java?view=diff&rev=562669&r1=562668&r2=562669
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/text/html/ImageView.java
Sat Aug  4 00:10:48 2007
@@ -53,9 +53,9 @@
 
     private BackgroundImageLoader loader;
     private String src;
-    private URL imageURL;
 
-    private boolean synchronous;
+    //TODO We can load images only synchronously yet
+    private boolean synchronous = true;
 
     private Color color;
 
@@ -67,15 +67,12 @@
     }
 
     public Image getImage() {
-        return loader.image;
+        return loader.getImage();
     }
 
     public URL getImageURL() {
-        if (imageURL == null) {
-            URL base = ((HTMLDocument)getDocument()).getBase();
-            imageURL = HTML.resolveURL(src, base);
-        }
-        return imageURL;
+        URL base = ((HTMLDocument)getDocument()).getBase();
+        return HTML.resolveURL(src, base);
     }
 
     public Icon getLoadingImageIcon() {
@@ -167,10 +164,8 @@
         if (!loader.isReady()) {
             if (!synchronous) {
                 getLoadingImageIcon().paintIcon(null, g, rc.x, rc.y);
-            } else {
-                loader.waitForImage();
+                return;
             }
-            return;
         }
 
         g.drawImage(getImage(), rc.x, rc.y, rc.width, rc.height, loader);
@@ -242,8 +237,7 @@
     }
 
     private void createImage(final int desiredWidth, final int desiredHeight) {
-        imageURL = null;
-        loader = new BackgroundImageLoader(getImageURL(),
+        loader = new BackgroundImageLoader(getImageURL(), synchronous,
                                            desiredWidth, desiredHeight) {
             protected void onReady() {
                 super.onReady();

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ImageViewTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ImageViewTest.java?view=diff&rev=562669&r1=562668&r2=562669
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ImageViewTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java.injected/javax/swing/text/html/ImageViewTest.java
Sat Aug  4 00:10:48 2007
@@ -263,17 +263,11 @@
         assertEquals(isHarmony() ? 18 : 38, icon.getIconHeight());
     }
 
-    public void testSetLoadsSynchronously() {
-        assertFalse(view.getLoadsSynchronously());
-
+    public void testSetGetLoadsSynchronously() {
         view.setLoadsSynchronously(true);
         assertTrue(view.getLoadsSynchronously());
 
         view.setLoadsSynchronously(false);
-        assertFalse(view.getLoadsSynchronously());
-    }
-
-    public void testGetLoadsSynchronously() {
         assertFalse(view.getLoadsSynchronously());
     }
 



Mime
View raw message