load referenced images externally

2008-10-29 01:38
Submit by pandora808

diff for Kutil ImageLoader.java

--- ImageManager.java   (revision 34)
+++ ImageManager.java   (working copy)
@@ -37,6 +37,9 @@
 
        // Image cache
        private final Hashtable images = new Hashtable();
+
+    // external image loader - plugin type
+    private ExternalImageLoader externalLoader;
 
        /**
         * Retrieve an {@link Image} instance from the specified <code>path</code>.
@@ -75,6 +78,10 @@
                        }
                }
 
+        if (image == null && externalLoader != null) {
+            image = externalLoader.getImage(path);
+        }
+
                // Add image instance to cache
                if (image != null) {
                        images.put(path, image);
@@ -104,4 +111,10 @@
                System.gc();
        }
 
+    /**
+     * @param ExternalImageLoader to load images by abstracted means
+     */
+    public void setExternalLoader(ExternalImageLoader loader) {
+        this.externalLoader = loader;
+    }
 }

 

Additional file org.kalmeo.util.resource.ExternalImageLoader.java

package org.kalmeo.util.resource;

import javax.microedition.lcdui.Image;

/**
 * Be sure that if you use an ExternalImageLoader,
 * and your implementation can be a long or blocking
 * operation, that you should be properly threading
 * any event that would lead to your ExternalImageLoader
 * being used.  Like on loading or reloading stylesheets
 * or programatically creating Screens with images.
 *
 * @author pandora
 */
public interface ExternalImageLoader {

    public Image getImage(String path);
}

 


Tags: Popularity: 990