Changeset 11693
- Timestamp:
- 2006-04-26T09:17:30+12:00 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadImages.java
r11647 r11693 65 65 GsdlCollageApplet app_ = null; 66 66 boolean isJava2_; 67 int num_of_downloads ;67 int num_of_downloads = 1; 68 68 boolean stopDownload; 69 69 70 70 MediaTracker tracker_; 71 71 72 72 /** Initialises an empty vector to store downloaded images in and sets … … 79 79 } 80 80 81 82 81 /** Push a new image into the vector of downloaded images 83 82 * @param image the graphical image to add … … 86 85 public synchronized int downloadImage(MediaTracker tracker, URL url, String urlString, String name) 87 86 { 87 88 tracker_= tracker; 88 89 89 90 while (downloaded_image != null ){ … … 97 98 98 99 } 100 101 Image image = Toolkit.getDefaultToolkit().getImage(url); 102 tracker_.addImage(image,num_of_downloads); 99 103 100 Image image = Toolkit.getDefaultToolkit().getImage(url); 104 try{ 105 tracker_.waitForID(num_of_downloads); 106 } 107 catch (InterruptedException e){ 108 notify(); 109 return num_of_downloads; 110 } 111 101 112 102 tracker.addImage(image,num_of_downloads);113 downloaded_image = new ImageUrlTriple(image,url,urlString,name); 103 114 104 try{105 System.out.println( " downloading ...");106 tracker.waitForID(num_of_downloads);107 System.out.println(Thread.currentThread().getName() + " get!!!");108 }109 catch (InterruptedException e){110 return 0;111 }112 113 downloaded_image = new ImageUrlTriple(image,url,urlString,name);114 num_of_downloads++;115 116 if (num_of_downloads == app_.maxDownloads()){117 stopDownload = true;118 System.out.println("num_of_downloads "+num_of_downloads);119 120 }121 //System.out.println("num_of_downloads "+num_of_downloads +" ");122 115 notify(); 123 116 124 117 return num_of_downloads ; 125 118 } 126 119 120 127 121 /** Remove the image from the specified position in the array of downloaded images 128 122 * @return an ImageUrlTriple containing the image, url and image name */ … … 131 125 if (stopDownload) return null; 132 126 133 while (downloaded_image == null && !stopDownload){127 while (downloaded_image == null){ 134 128 System.out.println(Thread.currentThread().getName() + " wait to get Collage image..."); 135 129 try{ … … 137 131 } 138 132 catch(InterruptedException e){ 139 //e.printStackTrace(); 133 //e.printStackTrace(); 134 downloaded_image = null; 135 notify(); 140 136 return null; 141 137 } 142 138 } 143 144 collage_image = process(downloaded_image); 145 downloaded_image = null; 146 147 notify(); 148 System.out.println(Thread.currentThread().getName() + " get Collage image!!!"); 149 return collage_image; 139 140 if (tracker_.statusID(num_of_downloads, false) == MediaTracker.COMPLETE){ 141 collage_image = new CollageImage(app_,isJava2_,downloaded_image); 142 downloaded_image = null; 143 num_of_downloads++; 144 notify(); 145 return collage_image; 146 } 147 else{ 148 if ((tracker_.statusAll(false) & MediaTracker.ERRORED) != 0){ 149 //System.out.println(downloaded_image.name_); 150 downloaded_image = null; 151 num_of_downloads++; 152 notify(); 153 return null; 154 } 155 } 156 157 return null; 150 158 151 159 } … … 155 163 } 156 164 157 private CollageImage process(ImageUrlTriple iutriple){ 158 Image image = iutriple.image(); 159 String from_url = iutriple.urlString(); 160 String img_name = iutriple.name(); 161 URL url = iutriple.url(); 162 163 CollageImage collage_image = new CollageImage(image,url,from_url,img_name); 164 165 image = collage_image.image_; 166 // images x and y dimensions 167 int image_x_dim = image.getWidth(app_); 168 int image_y_dim = image.getHeight(app_); 169 170 if ((image_x_dim>0) && (image_y_dim>0)) 171 { 172 collage_image.setDimensions(image_x_dim,image_y_dim); 173 174 // places and sizes the image 175 MyAffineTransform af = new MyAffineTransform(image_x_dim,image_y_dim); 176 177 // sets location & size of collage image 178 collage_image.setAffineTransform(af, isJava2_); 179 180 if (isJava2_ ) { 181 collage_image.image_ 182 = restoreAlpha(collage_image.image_, 0, 0, 183 collage_image.image_x_dim_, collage_image.image_y_dim_); 184 185 } 186 187 188 } 189 190 collage_image.fresh = false; 191 return collage_image; 192 } 193 194 /** Resets the alpha channel of an image so that it appears solid 195 * 196 * @param img the image to restore 197 * @param x the x co-ordinate of the image 198 * @param y the y co-ordinate of the image 199 * @param w the width of the image 200 * @param h the height of the image */ 201 public Image restoreAlpha(Image img, int x, int y, int w, int h) { 202 203 // declare an array to hold the pixels 204 int[] pixels = new int[w * h]; 205 206 // get the pixels of the image into the pixels array 207 PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w); 208 209 try { 210 System.err.println(" grab pixels...."); 211 pg.grabPixels(); 212 System.err.println(" got pixels"); 213 } catch (InterruptedException e) { 214 System.err.println("interrupted waiting for pixels!"); 215 return img; 216 } 217 218 219 // check for any failures 220 if ((pg.getStatus() & ImageObserver.ABORT) != 0) { 221 System.err.println(" image fetch aborted or errored"); 222 return img; 223 } 224 225 // loop through every pixel in the picture and handle it 226 for (int j = 0; j < h; j++) { 227 for (int i = 0; i < w; i++) { 228 pixels[j * w + i] |= (255 << 24) & 0xff000000; 229 } 230 } 231 232 // set the pixels of the whole picture to the pixels array 233 pg.setPixels(0, 0, w, h, pg.getColorModel(), pixels, 0, w); 234 // create the new image and return it 235 return( app_.createImage(new MemoryImageSource(w, h, pixels, 0, w)) ); 236 237 238 239 240 } 241 242 165 243 166 }
Note:
See TracChangeset
for help on using the changeset viewer.