Changeset 11715
- Timestamp:
- 2006-04-26T16:55:49+12:00 (18 years ago)
- Location:
- branches/gsdl-2_70-distribution-branch/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gsdl-2_70-distribution-branch/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DisplayImages.java
r11572 r11715 12 12 * 13 13 * Retrieves images from the download thread, determines an appropriate position 14 * for thes eimages onscreen ensuring maximum whitespace coverage and minimal overlap14 * for thes images onscreen ensuring maximum whitespace coverage and minimal overlap 15 15 * when possible. Draws images using advanced image processing techniques when applicable, 16 16 * such as fading the edges of an image and discolouring backgrounds. Also re-uses images … … 19 19 public class DisplayImages extends Thread { 20 20 21 /** Decrements the alpha value between adjacent rows on the edge of an image<br>22 * Used to fade the edges faster than the rest of the image <br>23 * Only used when java2 parameter is true and advanced image processing24 * techniques may be applied */25 static final int FADEVALUE = 3;26 /** Defines the number of shades of white used to colour the backgrounds of white images <br>27 * These colours are used because when several white images appear in the collage28 * simultaneously it is difficult to distinguish their edges<br>29 * Only used when java2 parameter is true and advanced image processing30 * techniques may be applied */31 static final int NO_OF_COLORS = 7;32 21 33 22 /** Will fire a removal operation when 4 images in the collage overlap a single area */ … … 60 49 protected boolean is_java2_ = false; 61 50 62 /** Holds images currently on display in the applet */ 63 protected Vector inuse_ready_ = null; 64 51 65 52 /** Holds images currently on display in the applet */ 66 53 protected Vector inuse_ = null; 67 54 55 /** Holds images ready to be used */ 56 protected Vector inuse_ready_ = null; 57 68 58 /** Holds previously displayed images for re-use */ 69 59 protected Vector notinuse_ = null; … … 87 77 public static int [] [] used_space = null; 88 78 89 /** Defines the shades of white used to colour the backgrounds of white images <br> 90 * These colours are used because when several white images appear in the collage 91 * simultaneously it is difficult to distinguish their edges<br> 92 * Only used when java2 parameter is true and advanced image processing 93 * techniques may be applied */ 94 int colorMask [] = {0xF8FFFF, 0xFFF8FF, 0xFFFFF8, 0xF8F8FF, 0xFFF8F8, 0xF8FFF8, 0xFAFAFA}; 95 79 96 80 /** 97 81 * Starts the display images thread. Initialises variables using parameters and … … 114 98 115 99 inuse_ = new Vector(); 116 inuse_ready_ = new Vector();117 notinuse_ = new Vector();100 notinuse_ = new Vector(); 101 inuse_ready_ = new Vector(); 118 102 download_images_ = download_images; 119 103 // sets width and height … … 146 130 next_frame_ = new Thread(new Runnable(){ 147 131 public void run() { 148 try { 149 150 Thread curr_thread = Thread.currentThread(); 151 152 while (curr_thread == next_frame_) { 132 133 Thread curr_thread = Thread.currentThread(); 134 135 while (curr_thread == next_frame_) { 136 try { 137 Runtime rt = Runtime.getRuntime(); 138 //System.out.println("total: "+rt.totalMemory()); 139 //System.out.println("free: "+rt.freeMemory()); 140 rt.gc(); 141 //System.out.println("**************next frame..."); 153 142 next_frame(); 154 155 143 Thread.sleep(app_. refreshDelay_); 144 156 145 curr_thread = Thread.currentThread(); 146 } catch (Exception e) { 147 e.printStackTrace(); 148 break; 157 149 } 158 159 160 } catch (Exception e) { 161 e.printStackTrace(); 162 } 150 } 151 152 163 153 } 164 154 … … 166 156 }); 167 157 168 158 next_frame_.start(); 169 159 170 160 … … 175 165 * @param y the y co-ordinate of the mouse 176 166 * @return the image that the user has clicked on or null if the user has clicked whitespace */ 177 public synchronizedCollageImage clickedOnImage(int x, int y)167 public CollageImage clickedOnImage(int x, int y) 178 168 { 179 169 if (app_.verbosity() > 1) … … 182 172 } 183 173 184 int no_images = inuse_.size() - 1;174 185 175 // checks from last image down, as last images place will be at the top of the collage 186 for (int i= no_images; i >= 0; i--)176 for (int i= inuse_.size() - 1; i >= 0; i--) 187 177 { 188 178 CollageImage collage_image = (CollageImage)inuse_.elementAt(i); … … 211 201 public void display_collage() 212 202 { 213 214 // get the number of images currently in the collage 215 final int no_images = inuse_.size(); 216 217 203 218 204 // if there is nothing new to add 219 if (no_images==0) return; 220 205 if (inuse_.size()==0) return; 221 206 222 207 // otherwise need to re-generate images 223 208 if (app_.verbosity() >= 2) 224 {225 System.err.println("Regenerating images: " +no_images);226 }209 { 210 //system.err.println("Regenerating images"); 211 } 227 212 228 213 // get each image currently onscreen inturn 229 for (int i=0; i<inuse_.size(); i++) 230 { 231 CollageImage collage_image = (CollageImage)inuse_.elementAt(i); 232 233 Image image = collage_image.image_; 234 // images x and y dimensions 235 int image_x_dim = image.getWidth(app_); 236 int image_y_dim = image.getHeight(app_); 237 238 //int status = app_.checkImage(image,app_); 239 240 if ((image_x_dim>0) && (image_y_dim>0)) 214 for (int i=0; i<inuse_.size();) 241 215 { 216 CollageImage collage_image = (CollageImage)inuse_.elementAt(i); 217 218 if (!collage_image.isValid()){ 219 continue; 220 } 221 222 int[] pixels = null; 242 223 // the first time the image is painted, determine its position and size 243 224 if (collage_image.fresh == true) 244 225 { 245 // first time => randomly place doc 246 collage_image.setDimensions(image_x_dim,image_y_dim); 247 248 // places and sizes the image 249 MyAffineTransform af = new MyAffineTransform(image_x_dim,image_y_dim); 250 251 // sets location & size of collage image 252 collage_image.setAffineTransform(af, is_java2_); 253 254 if (is_java2_) { 255 collage_image.image_ 256 = restoreAlpha(collage_image.image_, 0, 0, 257 collage_image.image_x_dim_, collage_image.image_y_dim_); 258 259 } 260 261 226 collage_image.process(); 262 227 } 263 228 264 229 // advanced image processing may be used 265 230 if (is_java2_) 266 { 267 268 269 // conducts fading and colouring of image 270 Image img = handlepixels(collage_image.image_, 0, 0, collage_image.image_x_dim_, 271 collage_image.image_y_dim_, i, collage_image.fresh ); 272 collage_image.image_ = img; 231 { 232 // conducts fading and colouring of image 233 pixels = collage_image.handlepixels(inuse_.size()-i); 234 } 273 235 274 275 }276 277 236 if (collage_image.fresh) { 278 237 collage_image.fresh = false; 279 238 } 280 281 } 282 else { 283 if (app_.verbosity()>=3) { 284 System.err.println(" Image ["+i+"] not ready yet!"); 285 } 286 } 287 //finished_graphic_.drawImage(screen_buffer_,0,0,app_); 288 289 } 290 291 // draws the finished image onscreen 292 finished_graphic_.drawImage(screen_buffer_,0,0,app_); 293 remove_old_images(); 294 } 295 296 297 /** loops through removing oldest images and reduces number of images if excessive overlap is occuring */ 298 void remove_old_images() { 299 300 // loops through removing oldest images that have almost faded completely 301 // and restricting the size of a simple collage to 25 images 302 int i=0; 303 while (i<inuse_.size()) 304 { 305 CollageImage collage_image = (CollageImage)inuse_.elementAt(i); 306 307 // if we remove when images have faded too much 308 if (is_java2_) { 309 if (checkFaded(collage_image.image_, 0, 0, collage_image.image_x_dim_, collage_image.image_y_dim_) || overlap) 310 { 239 240 241 // if we remove when images have faded too much 242 if (is_java2_) { 243 if (collage_image.checkFaded(pixels)|| overlap) 244 { 245 overlap = false; 246 247 CollageImage removed_image = (CollageImage)inuse_.elementAt(i); 248 //System.out.println(removed_image.name_ + "is removed"); 249 inuse_.remove(i); 250 // indicates space for this image is no longer used 251 for (int n = removed_image.xl_; n < (removed_image.xl_ + removed_image.image_x_dim_); n++) 252 for (int m = removed_image.yt_; m < (removed_image.yt_ + removed_image.image_y_dim_); m++) 253 if(used_space[n][m] != 0) { 254 used_space[n][m]--; 255 if (used_space[n][m] > NO_IMAGES_OF_OVERLAP) 256 overlap = true; 257 } 258 259 // sets the image as fresh and adds it to the vector of images previously seen 260 removed_image.fresh = true; 261 notinuse_.addElement(removed_image); 262 } 263 else{ 264 i++; 265 } 266 } 267 else 268 if (inuse_.size() > 25 || overlap) { 311 269 overlap = false; 312 270 313 271 CollageImage removed_image = (CollageImage)inuse_.elementAt(i); 314 272 inuse_.remove(i); 315 316 // restores alpha channel to represent a solid image317 Image img = restoreAlpha(removed_image.image_, 0, 0, removed_image.image_x_dim_, removed_image.image_y_dim_);318 273 319 274 // indicates space for this image is no longer used … … 322 277 if(used_space[n][m] != 0) { 323 278 used_space[n][m]--; 324 325 279 if (used_space[n][m] > NO_IMAGES_OF_OVERLAP) 280 overlap = true; 326 281 } 327 282 328 283 // sets the image as fresh and adds it to the vector of images previously seen 329 removed_image.image_ = img;330 284 removed_image.fresh = true; 331 285 notinuse_.addElement(removed_image); 332 286 } 333 else { 334 i++; 335 } 336 } 337 // if we remove to prevent too many images being displayed simultaneously 338 else { 339 if (inuse_.size() > 25 || overlap) { 340 overlap = false; 341 342 CollageImage removed_image = (CollageImage)inuse_.elementAt(i); 343 inuse_.remove(i); 344 345 // indicates space for this image is no longer used 346 for (int n = removed_image.xl_; n < (removed_image.xl_ + removed_image.image_x_dim_); n++) 347 for (int m = removed_image.yt_; m < (removed_image.yt_ + removed_image.image_y_dim_); m++) 348 if(used_space[n][m] != 0) { 349 used_space[n][m]--; 350 if (used_space[n][m] > NO_IMAGES_OF_OVERLAP) 351 overlap = true; 352 } 353 354 // sets the image as fresh and adds it to the vector of images previously seen 355 removed_image.fresh = true; 356 notinuse_.addElement(removed_image); 357 } 358 else { 359 i++; 360 } 361 } 362 } 363 364 365 } 366 287 else{ 288 i++; 289 } 290 291 } 292 } 293 367 294 368 295 /** Alters the images currently on display in the applet <br> … … 379 306 { 380 307 double random = Math.random(); 381 382 383 if (inuse_ready_.size() > 0){308 309 310 if (inuse_ready_.size() > 0){ 384 311 int pos = (int) ((inuse_ready_.size() - 1) * random); 385 inuse_.addElement(inuse_ready_.remove(pos));386 }387 else if (notinuse_.size()>0)388 {389 int position = (int) ((notinuse_.size() - 1) * random);390 Image image;391 392 CollageImage collage_image = (CollageImage)notinuse_.elementAt(position);393 notinuse_.remove(position);394 inuse_.addElement(collage_image);395 396 if (app_.verbosity()>3)312 CollageImage collage_image = (CollageImage) inuse_ready_.remove(pos); 313 inuse_.addElement(collage_image); 314 } 315 else if (notinuse_.size()>0) 316 { 317 int position = (int) ((notinuse_.size() - 1) * random); 318 319 CollageImage collage_image = (CollageImage)notinuse_.elementAt(position); 320 notinuse_.remove(position); 321 inuse_.addElement(collage_image); 322 323 if (app_.verbosity()>3) 397 324 { 398 325 System.err.println("Re-using an image not on screen"); 399 326 } 400 } 401 // otherwise repaint the first image as the last image 402 // else if (inuse_.size() > 0){ 403 // CollageImage removed_image = (CollageImage)inuse_.elementAt(0); 404 405 // // empty the picture from the grid 406 // for (int n = removed_image.xl_; n < (removed_image.xl_ + removed_image.image_x_dim_); n++) 407 // for (int m = removed_image.yt_; m < (removed_image.yt_ + removed_image.image_y_dim_); m++) 408 // used_space[n][m]--; 409 410 // // reset the alpha and add it 411 // removed_image.fresh = true; 412 413 // if (is_java2_) { 414 // removed_image.image_ = restoreAlpha(removed_image.image_, 0, 0, 415 // removed_image.image_x_dim_, removed_image.image_y_dim_); 416 // } 417 418 // notinuse_.addElement(removed_image); 419 // inuse_.remove(0); 420 // if (app_.verbosity()>=4){ 421 // System.err.println("Removing oldest image"); 422 // } 423 // } 424 else{ 425 if (app_.verbosity()>=4) 426 System.err.println("No images in download area"); 427 } 428 display_collage(); 429 430 } 431 432 /** Adjusts the colour and alpha value of an individual pixel <br> 433 * If the image is being drawn for the first time, the RGB values are 434 * extracted. If the pixel is close to white (RGB > 250) then an offwhite 435 * colour is applied to this pixel. 436 * This is done because when several white images appear in the collage 437 * simultaneously it is difficult to distinguish their edges. <br> 438 * This function also fades the alpha value of the pixel as the image ages. 439 * The alpha value is more heavily decremented as pixels get closer to the 440 * edge of the image 441 * 442 * @param pixel the pixel to manipulate 443 * @param p the position of the image in collage (representative of age) 444 * @param fresh indicates whether or not the image is being drawn for the first time 445 * @param edge indicates whether or not this pixel is near the edge of the image 446 * @param fade the amount by which to fade this pixel 447 * @return the adjusted pixel as an int */ 448 public int handlesinglepixel(int pixel, int p, boolean fresh, boolean edge, int fade) { 449 450 int newpixel = 0; 451 452 //changes the colour of the picture, only when first drawn 453 //and only if the pixel is close to white 454 if (fresh) { 455 456 int red = (pixel >> 16) & 0xff; 457 int green = (pixel >> 8) & 0xff; 458 int blue = (pixel ) & 0xff; 459 460 if (red >= 250 && green >= 250 && blue >= 250) { 461 462 int c = colorMask[((int) (p%NO_OF_COLORS))]; 463 464 red = (c >> 16) & 0xff; 465 green = (c >> 8) & 0xff; 466 blue = (c) & 0xff; 467 } 468 469 newpixel |= (red << 16) & 0x00ff0000; 470 newpixel |= (green << 8) & 0x0000ff00; 471 newpixel |= blue & 0x000000ff; 472 } 473 474 else { 475 newpixel |= pixel & 0x00ffffff; 476 } 477 478 int alpha = (pixel >> 24) & 0xff; 479 480 if (edge) { 481 // fade the edges more... 482 alpha = fade; 483 } 484 else if (alpha > 10 && !fresh) { 485 alpha -= 10; 486 } 487 488 newpixel |= (alpha << 24) & 0xff000000; 489 490 return (newpixel); 491 } 492 493 /** Fades and colours the image on a pixel-by-pixel basis <br> 494 * First it grabs the pixels of the entire image and stores them in a 2D array. 495 * Then a bound is calculated to indicate the point from which edge 496 * fading should occur. The position of the bound will change in proportion 497 * to the age of the image so that older images have a larger faded edge. 498 * The area within the bounds, that forms the center of the image, is processed 499 * first and faded by a standard alpha value. Then each edge of the image 500 * is processed separately, creating a gradient fade from the true edge to the 501 * position of the bound. <br> 502 * The faded pixel array is then turned into a new image a returned. 503 * 504 * @param img the image that requires processing 505 * @param x the x co-ordinate of the image 506 * @param y the y co-ordinate of the image 507 * @param w the width of the image 508 * @param h the height of the image 509 * @param p the position of the image in the applet (indicates age) 510 * @param fresh whether the image is being processed for the first time */ 511 512 public Image handlepixels(Image img, int x, int y, int w, int h, int p, boolean fresh) { 513 514 // declare an array to hold the pixels 515 int[] pixels = new int[w * h]; 516 517 // get the pixels of the image into the pixels array 518 PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w); 519 try { 520 pg.grabPixels(); 521 522 } catch (InterruptedException e) { 523 System.err.println("interrupted waiting for pixels!"); 524 return img; 525 } 526 // check for any failures 527 if ((pg.getStatus() & ImageObserver.ABORT) != 0) { 528 System.err.println("image fetch aborted or errored"); 529 return img; 530 } 531 532 // calculates the bound from which fading should begin 533 double bound = (inuse_.size() - p) * 0.01; 534 if (w > h) 535 bound *= w; 536 else 537 bound *= h; 538 int upperboundheight = h - (int) bound; 539 int upperboundwidth = w - (int) bound; 540 int lowerbound = (int) bound; 541 542 // loop through every pixel in the picture and handle it 543 for (int j = lowerbound; j < upperboundheight; j++) { 544 for (int i = lowerbound; i < upperboundwidth; i++) { 545 // width and height: x+i y+j 546 pixels[j * w + i] = handlesinglepixel(pixels[j * w + i], p, fresh, false, 255); 547 } 548 } 549 550 int fade = 0; 551 int fader = 0; 552 int corealpha = (pixels[(h/2) * w + (w/2)] >> 24) & 0xff; 553 554 // top edge 555 for (int n = lowerbound; n >= 0; n--) { 556 fader = corealpha - fade; 557 if (fader < 0) 558 fader = 0; 559 560 for (int m = 0; m < w; m++) 561 pixels[n * w + m] = handlesinglepixel(pixels[n * w + m], p, fresh, true, fader); 562 563 fade+= FADEVALUE; 564 } 565 566 // bottom edge 567 fade = 0; 568 for (int n = upperboundheight; n < h; n++) { 569 fader = corealpha - fade; 570 if (fader < 0) 571 fader = 0; 572 for (int m = 0; m < w; m++) 573 pixels[n * w + m] = handlesinglepixel(pixels[n * w + m], p, fresh, true, fader); 574 575 fade += FADEVALUE; 576 } 577 578 // left edge 579 fade = 0; 580 for (int n = lowerbound; n >= 0; n--) { 581 fader = corealpha - fade; 582 if (fader < 0) 583 fader = 0; 584 for (int m = 0; m < h; m++) { 585 if ( m < lowerbound && n > m); 586 else if ( m > upperboundheight && n > (h - m)); 587 else 588 pixels[m * w + n] = handlesinglepixel(pixels[m * w + n], p, fresh, true, fader); 589 } 590 fade += FADEVALUE; 591 } 592 593 // right edge 594 fade = 0; 595 for (int n = upperboundwidth; n < w; n++) { 596 fader = corealpha - fade; 597 if (fader < 0) 598 fader = 0; 599 for (int m = 0; m < h; m++) { 600 if ( m < lowerbound && (w - n) > m); 601 else if ( m > upperboundheight && (w - n) > (h - m)); 602 else 603 pixels[m * w + n] = handlesinglepixel(pixels[m * w + n], p, fresh, true, fader); 604 } 605 606 fade += FADEVALUE; 607 } 608 609 // set the pixels of the whole picture to the pixels array 610 pg.setPixels(0, 0, w, h, pg.getColorModel(), pixels, 0, w); 611 612 // create the new image and return it 613 return( app_.createImage(new MemoryImageSource(w, h, pixels, 0, w)) ); 614 615 } 616 617 /** Resets the alpha channel of an image so that it appears solid 618 * 619 * @param img the image to restore 620 * @param x the x co-ordinate of the image 621 * @param y the y co-ordinate of the image 622 * @param w the width of the image 623 * @param h the height of the image */ 624 public Image restoreAlpha(Image img, int x, int y, int w, int h) { 625 626 // declare an array to hold the pixels 627 int[] pixels = new int[w * h]; 628 629 // get the pixels of the image into the pixels array 630 PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w); 631 632 try { 633 634 pg.grabPixels(); 635 636 } catch (InterruptedException e) { 637 System.err.println("interrupted waiting for pixels!"); 638 return img; 639 } 640 641 642 // check for any failures 643 if ((pg.getStatus() & ImageObserver.ABORT) != 0) { 644 System.err.println("image fetch aborted or errored"); 645 return img; 646 } 647 648 // loop through every pixel in the picture and handle it 649 for (int j = 0; j < h; j++) { 650 for (int i = 0; i < w; i++) { 651 pixels[j * w + i] |= (255 << 24) & 0xff000000; 652 } 653 } 654 655 // set the pixels of the whole picture to the pixels array 656 pg.setPixels(0, 0, w, h, pg.getColorModel(), pixels, 0, w); 657 658 // create the new image and return it 659 return( app_.createImage(new MemoryImageSource(w, h, pixels, 0, w)) ); 660 661 } 662 663 /** Checks whether an image has faded to the point where it must be removed 664 * from the collage. 665 * 666 * @param img the image to restore 667 * @param x the x co-ordinate of the image 668 * @param y the y co-ordinate of the image 669 * @param w the width of the image 670 * @param h the height of the image */ 671 public boolean checkFaded (Image img, int x, int y, int w, int h) { 672 if (w == 0 || h == 0) 673 return false; 674 675 // declare an array to hold the pixels 676 int[] pixels = new int[w * h]; 677 678 // get the pixels of the image into the pixels array 679 PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w); 680 try { 681 pg.grabPixels(); 682 683 } catch (InterruptedException e) { 684 System.err.println("interrupted waiting for pixels!"); 685 return false; 686 } 687 // check for any failures 688 if ((pg.getStatus() & ImageObserver.ABORT) != 0) { 689 System.err.println("image fetch aborted or errored"); 690 return false; 691 } 692 693 // get the alpha value of the middle pixel of the image 694 int corealpha = (pixels[(h/2) * w + (w/2)] >> 24) & 0xff; 695 696 if (corealpha < 2) 697 return true; 698 699 return false; 700 701 } 327 } 328 else{ 329 if (app_.verbosity()>=4) 330 System.err.println("No images in download area"); 331 } 332 333 display_collage(); 334 335 } 336 337 702 338 703 339 /** Paints the applet on the screen */ … … 725 361 if (collage_image.fresh) { 726 362 if (app_.verbosity()>=1) { 727 System.err.println("doing nothing... images in useis fresh.");363 System.err.println("doing nothing... "+ collage_image.name_ +" is fresh."); 728 364 } 729 365 } … … 742 378 // simple image collage 743 379 else 744 { 745 // add the image to the collage 380 { // add the image to the collage 746 381 747 382 screen_graphic_.drawImage(collage_image.image_, … … 779 414 780 415 while (curr_thread == this) { 781 CollageImage collage_image = download_images_.getCollageImage();782 if (collage_image !=null){783 inuse_ready_.addElement(collage_image);784 }785 else{786 break; 787 }788 curr_thread = Thread.currentThread();789 790 791 792 416 if (inuse_ready_.size() >= 1){ 417 Thread.sleep(1000); 418 continue; 419 } 420 CollageImage collage_image = download_images_.getCollageImage(); 421 422 if (collage_image !=null){ 423 inuse_ready_.addElement(collage_image); 424 } 425 curr_thread = Thread.currentThread(); 426 } 427 793 428 } catch (Exception e) { 794 //e.printStackTrace();429 e.printStackTrace(); 795 430 System.out.println("Display images thread is interrupted"); 796 431 } -
branches/gsdl-2_70-distribution-branch/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadUrls.java
r11563 r11715 65 65 int verbosity_ = 0; 66 66 67 protected boolean busy_ = false; 68 67 /** Records all images which have already been examined */ 68 Hashtable visited_images_ = null; 69 69 70 MediaTracker tracker; 70 71 … … 99 100 System.err.println("starting_url_ " + starting_url +"\n"+ 100 101 "href_musthave_ " + href_musthave +"\n"+ 101 "image_mustnothave_ " + image_mustnothave+"\n"+102 "image_mustnothave_ " + image_mustnothave+"\n"+ 102 103 "image_ignore_ "+ image_ignore+"\n"+ 103 104 "image_type_ "+ image_type+"\n"+ … … 110 111 } 111 112 112 public boolean getStatus(){ 113 return busy_; 114 115 } 116 113 117 114 /** Determines whether or not a url has already been examined 118 115 * … … 128 125 } 129 126 130 // if the url has been visited before, return true127 // if the url has been visited before, return true 131 128 if (visited_url_.containsKey(url_string)) 132 129 { … … 142 139 return false; 143 140 } 141 142 /** Determines whether or not an images or its screenview has been visited) 143 * has already been examined 144 * 145 * @param url_string the url to check 146 * @param img_name the image to check 147 * @return true if the url has been visited, false if not */ 148 public boolean image_visited(String url_string, String img_name) 149 { 150 String hash_dir = url_string.substring(0,url_string.lastIndexOf("/")); 151 152 if ( visited_images_.containsKey(hash_dir)){ 153 Hashtable hashed_images = (Hashtable)visited_images_.get(hash_dir); 154 155 if (img_name.startsWith("screenview")){ 156 return true; 157 } 158 159 if (hashed_images.containsKey(img_name)){ 160 return true; 161 } 162 163 Enumeration enu = hashed_images.keys(); 164 for(;enu.hasMoreElements();){ 165 String name = (String)enu.nextElement(); 166 if(name.startsWith("screenview")){ 167 return true; 168 } 169 } 170 171 hashed_images.put(img_name,"visited"); 172 } 173 else{ 174 Hashtable hashed_images = new Hashtable(); 175 hashed_images.put(img_name,"visited"); 176 visited_images_.put(hash_dir,hashed_images); 177 } 178 179 return false; 180 } 181 182 183 184 144 185 145 186 /** Restricts the type of images that can be included in the collage … … 325 366 // get the image from the url 326 367 if (verbosity_>=2) { 327 //System.err.println(" ****Downloading image URL: " + url.toString()); 328 } 368 System.err.println(" Downloading image URL: " + url.toString()); 369 } 370 371 if (image_visited(url.toString(),img_name)) return; 329 372 330 373 int size = download_images_.downloadImage(tracker,url, from_url, img_name); … … 354 397 public void rec_add_images(String new_url, int depth) 355 398 { 356 399 357 400 if (already_visited(new_url)) return; 358 401 … … 377 420 // get all the <code><img src=</code> links into a vector 378 421 Vector src_links = curl.getSrcLinks(); 379 422 423 380 424 if (verbosity_ >= 2) { 381 425 System.err.println(" Got src links... there are " + src_links.size() + " of them."); … … 386 430 URL url = (URL)src_links.get(i); 387 431 String url_string = url.toString(); 388 432 389 433 //System.err.println(" source links " + i + " [" + url_string +"]"); 390 434 … … 440 484 for (int i = 0; i < href_links.size(); i++) 441 485 { 486 442 487 URL url = (URL)href_links.get(i); 443 488 String url_string = url.toString(); 444 445 //System.err.println(" href links " + i + "[" + url_string +"]"); 446 489 //System.err.println(" href links " + i + "[" + url_string +"]"); 447 490 448 491 if (image_file_extension(url_string)) 449 492 { 450 493 451 494 if (filter_image(url_string)) 452 495 453 496 { 497 454 498 img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length()); 455 499 … … 471 515 if (filter_href(url_string,new_url,depth)) 472 516 { 517 473 518 rec_add_images(url_string,depth+1); 474 519 … … 493 538 public void externalLinks() { 494 539 external_links_ = null; 495 496 540 try { 497 541 498 if (starting_url_ .indexOf(document_root_) >= 0){542 if (starting_url_ == null || (document_root_ != null && starting_url_.indexOf(document_root_) >= 0) ){ 499 543 return; 500 544 } … … 510 554 // split the line of the space, first part is the image, second part the link 511 555 while (l != null) { 512 556 513 557 String tmp1 = new String(); 514 558 String tmp2 = new String(); … … 523 567 524 568 if (tmp2 != null) { 569 525 570 external_links_.put(tmp1, tmp2); 526 571 //System.err.println(tmp1 + " " + tmp2); … … 543 588 System.err.println("Starting download thread."); 544 589 visited_url_ = new Hashtable(); 545 590 visited_images_ = new Hashtable(); 591 546 592 rec_add_images(starting_url_,1); 547 593 download_images_.stopDownload();
Note:
See TracChangeset
for help on using the changeset viewer.