Index: branches/gsdl-2_70-distribution-branch/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadImages.java
===================================================================
--- branches/gsdl-2_70-distribution-branch/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadImages.java	(revision 11713)
+++ branches/gsdl-2_70-distribution-branch/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadImages.java	(revision 11714)
@@ -24,6 +24,7 @@
 
 	Image image_;
-	String url_;
+	String urlString_;
 	String name_;
+        URL url_;
 
 	/** Constructs a downloaded image structure from the given parameters
@@ -31,8 +32,9 @@
 	 *  @param url the source url for this image
 	 *  @param name the name of the image file */
-	public ImageUrlTriple (Image image, String url, String name)
+	public ImageUrlTriple (Image image, URL url, String urlString, String name)
 	{
 	    image_ = image;
 	    url_ = url;
+            urlString_ = urlString; 
 	    name_ = name;
 	}
@@ -42,6 +44,6 @@
 	}
 
-	String url() {
-	    return url_;
+	String urlString() {
+	    return urlString_;
 	}
 
@@ -50,6 +52,9 @@
 	}
 
+	URL url(){
+	    return url_;
+	}
+
     }
-
 
    
@@ -60,8 +65,8 @@
     GsdlCollageApplet app_ = null;
     boolean isJava2_;
-    int num_of_downloads;
+    int num_of_downloads = 1;
     boolean stopDownload;
- 
-  
+
+    MediaTracker tracker_;
 
     /** Initialises an empty vector to store downloaded images in and sets
@@ -74,5 +79,4 @@
     }
 
-
     /** Push a new image into the vector of downloaded images
      *  @param image the graphical image to add
@@ -81,4 +85,6 @@
     public  synchronized int downloadImage(MediaTracker tracker, URL url, String urlString, String name)
     {
+	
+	tracker_= tracker;
 
 	while (downloaded_image != null ){
@@ -92,31 +98,25 @@
 
 	}
-	    Image image = Toolkit.getDefaultToolkit().getImage(url);
+      
+	Image image = Toolkit.getDefaultToolkit().getImage(url);
+	tracker_.addImage(image,num_of_downloads);
 
-	     tracker.addImage(image,num_of_downloads);
+	try{
+	    tracker_.waitForID(num_of_downloads);
+	}
+	catch (InterruptedException e){
+	    notify();
+	    return num_of_downloads;
+	}
+	
 
-	     try{
-	       System.out.println( "   downloading ..."); 
-		 tracker.waitForID(num_of_downloads);
-                System.out.println(Thread.currentThread().getName() + " get!!!"); 
-	       }
-	       catch (InterruptedException e){
-	        return 0;
-	     }
-     
-	downloaded_image  = new ImageUrlTriple(image,urlString,name);
-	num_of_downloads++;
+	downloaded_image  = new ImageUrlTriple(image,url,urlString,name);
 
-	if (num_of_downloads == app_.maxDownloads()){
-	    stopDownload = true;
-            System.out.println("num_of_downloads "+num_of_downloads);
-
-	}	
-	//System.out.println("num_of_downloads "+num_of_downloads +" ");
 	notify();
        
 	return num_of_downloads ;
     }
-
+ 
+ 
     /** Remove the image from the specified position in the array of downloaded images
      *  @return an ImageUrlTriple containing the image, url and image name */
@@ -125,5 +125,5 @@
 	if (stopDownload)  return null;   
 
-	while (downloaded_image == null && !stopDownload){
+	while (downloaded_image == null){
 	    System.out.println(Thread.currentThread().getName() + " wait to get Collage image...");
 	    try{
@@ -131,14 +131,29 @@
 	    }
 	    catch(InterruptedException e){
+		//e.printStackTrace();
+		downloaded_image = null;
+		notify();
 		return null;
 	    }
 	}
-
-	collage_image = process(downloaded_image);
-	downloaded_image = null;
-       
-        notify();
-	System.out.println(Thread.currentThread().getName() + " get Collage image!!!");
-        return collage_image;
+         
+      	if (tracker_.statusID(num_of_downloads, false) == MediaTracker.COMPLETE){
+	    collage_image = new CollageImage(app_,isJava2_,downloaded_image);
+	    downloaded_image = null; 
+	    num_of_downloads++;
+	    notify();
+	    return collage_image;
+	}
+	else{
+	    if ((tracker_.statusAll(false) & MediaTracker.ERRORED) != 0){
+		//System.out.println(downloaded_image.name_);
+		downloaded_image = null;
+		num_of_downloads++;
+		notify();
+		return null;
+	    }
+	}
+	
+	return null;
 
     }
@@ -148,86 +163,4 @@
     }
 
-    private CollageImage process(ImageUrlTriple iutriple){
-            Image image     = iutriple.image();
-	    String from_url = iutriple.url();
-	    String img_name = iutriple.name();
  
-	    CollageImage collage_image = new CollageImage(image,from_url,img_name);
-
-	    image = collage_image.image_;
-	    // images x and y dimensions
-	    int image_x_dim = image.getWidth(app_);
-	    int image_y_dim = image.getHeight(app_);
-
-	    if ((image_x_dim>0) && (image_y_dim>0))
-	    {
-		collage_image.setDimensions(image_x_dim,image_y_dim);
-		
-		// places and sizes the image
-		MyAffineTransform af = new MyAffineTransform(image_x_dim,image_y_dim);
-		
-		// sets location & size of collage image
-		collage_image.setAffineTransform(af, isJava2_);
-		
-		 if (isJava2_ ) {
-		    collage_image.image_ 
-			= restoreAlpha(collage_image.image_, 0, 0, 
-				       collage_image.image_x_dim_, collage_image.image_y_dim_); 
-		    
-		}
-			
-			
-	    }
-	 
-	    collage_image.fresh = false;
-	    return collage_image;
-    }
-
-  /** Resets the alpha channel of an image so that it appears solid
-     *
-     *  @param img the image to restore
-     *  @param x the x co-ordinate of the image
-     *  @param y the y co-ordinate of the image
-     *  @param w the width of the image
-     *  @param h the height of the image */
-    public Image restoreAlpha(Image img, int x, int y, int w, int h) {
-      
-	// declare an array to hold the pixels
-	int[] pixels = new int[w * h];
-
-	// get the pixels of the image into the pixels array
-	PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
-
-	try {
-	    System.err.println("  grab pixels....");
-	    pg.grabPixels();
-	    System.err.println("  got pixels!!!");
-	} catch (InterruptedException e) {
-	    System.err.println("interrupted waiting for pixels!");
-	    return img;
-	}
-
-      
-	// check for any failures
-	if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
-	    System.err.println(" image fetch aborted or errored");
-	    return img;
-	}
-
-	// loop through every pixel in the picture and handle it
-	for (int j = 0; j < h; j++) {
-	    for (int i = 0; i < w; i++) {
-		pixels[j * w + i] |= (255 << 24) & 0xff000000;
-	    }
-	}
-
-	// set the pixels of the whole picture to the pixels array
-	pg.setPixels(0, 0, w, h, pg.getColorModel(), pixels, 0, w);
-
-	// create the new image and return it
-	return( app_.createImage(new MemoryImageSource(w, h, pixels, 0, w)) );
-    
-    }
-
-
 }
