Changeset 11647 for trunk


Ignore:
Timestamp:
2006-04-12T09:31:03+12:00 (18 years ago)
Author:
shaoqun
Message:

add a new variable (url) to CollageImage class, so we known where the images was downloaded

Location:
trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/CollageImage.java

    r6816 r11647  
    44import java.awt.geom.*;
    55import java.io.*;
     6import java.net.*;
    67
    78/**
     
    2930    /** Indicates whether or not the image has been drawn on the applet previously */
    3031    boolean fresh       = true;
    31 
     32   
     33    URL url_ = null;     
     34 
    3235    /** Reflects the translation of the image from the origin to its position on the screen */
    3336    AffineTransform af_ = null;
     
    4649     *  @param from_url The source url for the image
    4750     *  @param name The file name of the image */
    48     public CollageImage(Image image, String from_url, String name)
     51    public CollageImage(Image image, URL url, String from_url, String name)
    4952    {
    5053    image_    = image;
    5154    from_url_ = from_url;
     55    url_ = url;
    5256    name_     = name;
    5357    }
  • trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadImages.java

    r11564 r11647  
    2424
    2525    Image image_;
    26     String url_;
     26    String urlString_;
    2727    String name_;
     28        URL url_;
    2829
    2930    /** Constructs a downloaded image structure from the given parameters
     
    3132     *  @param url the source url for this image
    3233     *  @param name the name of the image file */
    33     public ImageUrlTriple (Image image, String url, String name)
     34    public ImageUrlTriple (Image image, URL url, String urlString, String name)
    3435    {
    3536        image_ = image;
    3637        url_ = url;
     38            urlString_ = urlString;
    3739        name_ = name;
    3840    }
     
    4244    }
    4345
    44     String url() {
    45         return url_;
     46    String urlString() {
     47        return urlString_;
    4648    }
    4749
     
    5052    }
    5153
    52     }
    53 
     54    URL url(){
     55        return url_;
     56    }
     57
     58    }
    5459
    5560   
     
    6267    int num_of_downloads;
    6368    boolean stopDownload;
    64  
     69
    6570 
    6671
     
    9297
    9398    }
     99
    94100        Image image = Toolkit.getDefaultToolkit().getImage(url);
    95101
    96          tracker.addImage(image,num_of_downloads);
    97 
    98          try{
     102        tracker.addImage(image,num_of_downloads);
     103
     104        try{
    99105           System.out.println( "   downloading ...");
    100         tracker.waitForID(num_of_downloads);
     106          tracker.waitForID(num_of_downloads);
    101107                System.out.println(Thread.currentThread().getName() + " get!!!");
    102108           }
     
    105111         }
    106112     
    107     downloaded_image  = new ImageUrlTriple(image,urlString,name);
     113    downloaded_image  = new ImageUrlTriple(image,url,urlString,name);
    108114    num_of_downloads++;
    109115
     
    131137        }
    132138        catch(InterruptedException e){
     139        //e.printStackTrace(); 
    133140        return null;
    134141        }
     
    150157    private CollageImage process(ImageUrlTriple iutriple){
    151158            Image image     = iutriple.image();
    152         String from_url = iutriple.url();
     159        String from_url = iutriple.urlString();
    153160        String img_name = iutriple.name();
    154  
    155         CollageImage collage_image = new CollageImage(image,from_url,img_name);
     161        URL url =  iutriple.url();
     162       
     163        CollageImage collage_image = new CollageImage(image,url,from_url,img_name);
    156164
    157165        image = collage_image.image_;
     
    195203    // declare an array to hold the pixels
    196204    int[] pixels = new int[w * h];
    197 
     205   
    198206    // get the pixels of the image into the pixels array
    199207    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
    200 
     208       
    201209    try {
    202210        System.err.println("  grab pixels....");
    203211        pg.grabPixels();
    204         System.err.println("  got pixels!!!");
     212        System.err.println("  got pixels");
    205213    } catch (InterruptedException e) {
    206214        System.err.println("interrupted waiting for pixels!");
     
    216224
    217225    // loop through every pixel in the picture and handle it
    218     for (int j = 0; j < h; j++) {
    219         for (int i = 0; i < w; i++) {
    220         pixels[j * w + i] |= (255 << 24) & 0xff000000;
    221         }
    222     }
    223 
    224     // set the pixels of the whole picture to the pixels array
    225     pg.setPixels(0, 0, w, h, pg.getColorModel(), pixels, 0, w);
    226 
    227     // create the new image and return it
    228     return( app_.createImage(new MemoryImageSource(w, h, pixels, 0, w)) );
    229    
     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       
    230240    }
    231241
Note: See TracChangeset for help on using the changeset viewer.