Changeset 7334 for trunk


Ignore:
Timestamp:
2004-05-13T20:52:00+12:00 (20 years ago)
Author:
davidb
Message:

General improvements to the Collaging code, including
support options specified in Collasge classify line
in collectin configuration file control some of the
runtime aspects.

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

Legend:

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

    r6816 r7334  
    119119        value = peek_value;
    120120        peek_value = -1;
    121     } else {
     121    }
     122    else {
    122123        try {
    123124        value = input.read();
  • trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/Display.java

    r6816 r7334  
    2525    try {
    2626
    27         System.err.println("@@@DISPLAY");
     27        System.err.println("Started display thread.");
    2828
    2929        Thread curr_thread = Thread.currentThread();
     
    3636        }
    3737
    38         System.err.println("###DISPLAY");
     38        System.err.println("Stopped display thread.");
    3939       
    4040    } catch (Exception e) {
  • trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DisplayImages.java

    r6816 r7334  
    4040    /** Refers to download thread */
    4141    DownloadImages download_images_ = null;
     42
    4243    /** Refers to applet */
    4344    GsdlCollageApplet app_ = null;
     45
    4446    /** Applets width on screen */
    4547    public static int app_x_dim_  = 0;
     48
    4649    /** Applets height on screen */
    4750    public static int app_y_dim_  = 0;
    4851   
    4952    /** Background colour of the applet screen */
    50     Color bgcolor_        = null;
     53    protected Color bgcolor_        = null;
     54
    5155    /** Indicates whether java2 functionality should be used <br>
    5256     *  If true will allow advanced image processing techniques to occur,
     
    5458     *  If false, images will maintain an alpha value of 1 (appear solid),
    5559     *  newer images will simply be pasted on top of existing images <br> */
    56     boolean is_java2_     = false;
     60    protected boolean is_java2_     = false;
     61
    5762    /** Holds images currently on display in the applet */
    58     Vector inuse_    = null;
     63    protected Vector inuse_    = null;
     64
    5965    /** Holds previously displayed images for re-use */
    60     Vector notinuse_ = null;
     66    protected Vector notinuse_ = null;
    6167   
    62     Image      screen_buffer_  = null;
    63     Graphics screen_graphic_   = null;
    64     Image    finished_buffer_  = null;
    65     Graphics finished_graphic_ = null;
     68    protected Image    screen_buffer_    = null;
     69    protected Graphics screen_graphic_   = null;
     70    protected Image    finished_buffer_  = null;
     71    protected Graphics finished_graphic_ = null;
    6672
    6773    /** Used to determine where to place new images on the applet to optimize
     
    136142     *  @param y the y co-ordinate of the mouse
    137143     *  @return the image that the user has clicked on or null if the user has clicked whitespace */
    138     public CollageImage clickedOnImage(int x, int y)
     144 
     145   public synchronized CollageImage clickedOnImage(int x, int y)
    139146    {
    140147    if (app_.verbosity() > 1)
     
    195202        int image_y_dim = image.getHeight(app_);
    196203
     204        int status = app_.checkImage(image,app_);
     205
    197206        if ((image_x_dim>0) && (image_y_dim>0))
    198207        {
     
    210219           
    211220            if (is_java2_) {
    212                
    213                 collage_image.image_ = restoreAlpha(collage_image.image_, 0, 0,
    214                                 collage_image.image_x_dim_, collage_image.image_y_dim_);
     221                collage_image.image_
     222                = restoreAlpha(collage_image.image_, 0, 0,
     223                           collage_image.image_x_dim_, collage_image.image_y_dim_);
    215224            }
    216225           
     
    227236           
    228237        }
    229         if (collage_image.fresh)
    230                 collage_image.fresh = false;
     238        if (collage_image.fresh) {
     239            collage_image.fresh = false;
     240        }
    231241           
     242        }
     243        else {
     244        if (app_.verbosity()>=3) {
     245            System.err.println("  Image ["+i+"] not ready yet!");
     246        }
    232247        }
    233248        //finished_graphic_.drawImage(screen_buffer_,0,0,app_);
     
    241256
    242257    /** loops through removing oldest images and reduces number of images if excessive overlap is occuring */
    243     void remove_old_images() {
     258    synchronized void remove_old_images() {
    244259
    245260    // loops through removing oldest images that have almost faded completely
     
    318333     *  repaint it as the newest. <br>
    319334     *  Then the collage is asked to display and repaint with the new image set. */
    320     void next_frame()
     335
     336    synchronized void next_frame()
    321337    {
    322338    double random = Math.random();
     
    326342    {
    327343        int position = (int) ((download_images_.size() - 1) * random);
    328         Image image;
    329 
    330         // get the image and it's associated url
     344
     345        // get the image and its associated url (and remove from download area)
    331346        DownloadImages.ImageUrlTriple iutriple = download_images_.retrieve(position);
    332         image = iutriple.image();
     347        Image image    = iutriple.image();
    333348        String from_url = iutriple.url();
    334349        String img_name = iutriple.name();
    335        
     350
    336351        // prepare the image for collaging
    337         app_.prepareImage(image,app_);
     352        // app_.prepareImage(image,app_);
    338353        CollageImage collage_image = new CollageImage(image,from_url,img_name);
    339354       
     
    341356        inuse_.addElement(collage_image);       
    342357       
    343         if (app_.verbosity()>3)
     358        if (app_.verbosity()>=1)
    344359        {
    345         System.err.println("Using a downloaded image");
     360        System.err.println("Adding in a newly downloaded image");
     361        if (app_.verbosity()>=2)
     362            {
     363            System.err.println("  name="+img_name+", url="+from_url);
     364            }
     365
    346366        }
    347367    }
     
    362382    }
    363383    // otherwise repaint the first image as the last image
    364     else if (inuse_.size() > 0)
    365     {
     384    else if (inuse_.size() > 0){
    366385        CollageImage removed_image = (CollageImage)inuse_.elementAt(0);
    367386       
     
    370389        for (int m = removed_image.yt_; m < (removed_image.yt_ + removed_image.image_y_dim_); m++)
    371390            used_space[n][m]--;
    372 
     391       
    373392        // reset the alpha and add it
    374393        removed_image.fresh = true;
     
    378397                            removed_image.image_x_dim_, removed_image.image_y_dim_);
    379398        }
    380 
     399       
    381400        notinuse_.addElement(removed_image);
    382401        inuse_.removeElementAt(0);
    383402       
    384         if (app_.verbosity()>3)
    385         {
     403        if (app_.verbosity()>=4){
    386404        System.err.println("Removing oldest image");
    387405        }
    388406    }
    389     else
    390         {
    391         if (app_.verbosity()>3)
    392             System.err.println("no images in download area");
    393         }
     407    else{
     408        if (app_.verbosity()>=4)
     409        System.err.println("No images in download area");
     410    }
    394411   
    395412    display_collage();
    396413    }
    397 
     414   
    398415    /** Adjusts the colour and alpha value of an individual pixel <br>
    399416     *  If the image is being drawn for the first time, the RGB values are
     
    475492     *  @param p the position of the image in the applet (indicates age)
    476493     *  @param fresh whether the image is being processed for the first time */
    477     public Image handlepixels(Image img, int x, int y, int w, int h, int p, boolean fresh) {
     494
     495    public synchronized Image handlepixels(Image img, int x, int y, int w, int h, int p, boolean fresh) {
    478496   
    479497    // declare an array to hold the pixels
     
    666684    public synchronized void paint(Graphics g)
    667685    {
    668     //System.err.println("......" + is_java2_);
    669 
    670686    screen_graphic_.setColor(bgcolor_);
    671687    screen_graphic_.fillRect(0,0,app_x_dim_,app_y_dim_);
     
    678694        CollageImage collage_image = (CollageImage)inuse_.elementAt(i);
    679695        // don't paint new images yet
    680         if (collage_image.fresh)
    681             System.err.println("doing nothing... " + i + " " + n);
     696        if (collage_image.fresh) {
     697            if (app_.verbosity()>3) {
     698            System.err.println("doing nothing... image " + i + " of "+n+ " images in use is fresh.");
     699            }
     700        }
    682701
    683702        // advanced image processing may be used
    684         else if (is_java2_)
    685             {
     703        //      else if (is_java2_) {
     704        else if (false) {
    686705            // the alphacomposite controls the blending of these two images.
    687706            Graphics2D sg2d = (Graphics2D)screen_graphic_;
     
    695714        else
    696715            {
    697             // System.err.println("patu");
    698716            // add the image to the collage
    699717            screen_graphic_.drawImage(collage_image.image_,
  • trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadUrls.java

    r6816 r7334  
    55import java.net.*;
    66import java.util.*;
     7
     8// import javax.swing.ImageIcon; //****
     9
    710
    811/**
     
    1518 *  of downloading that occurs by restricting the number of downloaded images that are yet to
    1619 *  be displayed to 10, and the total number of downloads allowed is also restricted by
    17  *  the applet application (to prevent downloading occur infinitely). */
     20 *  the applet application (to prevent downloading occuring infinitely). */
     21
    1822public class DownloadUrls extends Thread {
    1923
     
    2529    /** The address from which the application should start looking for images */
    2630    String starting_url_  = null;
     31
     32    /** CHRIS - Holds the contents of the collection's assoc directory */
     33    //    File[] assocDir_ = null;
     34
    2735    /** Restricts links followed from the starting url to links that contain this string */
    2836    String href_musthave_ = null;
     
    5058    /** Determines whether there are still pages to examine and images to download */
    5159    boolean thread_running_ = true;
     60
     61    int verbosity_;
    5262
    5363    /** Constructor to initialise a download thread from which images are found,
     
    6474            DownloadImages download_images, String starting_url,
    6575            String href_musthave, String image_mustnothave,
    66             String image_ignore, String image_type)
     76            String image_ignore, String image_type, int verbosity)
    6777    {
    6878    super("DownloadUrls");
     
    7585    image_ignore_  = image_ignore;
    7686    image_type_    = image_type;
    77     }
     87   
     88    verbosity_ = verbosity;
     89    }
     90
     91   
    7892
    7993    /** Determines whether or not a url has already been examined
     
    93107    if (visited_url_.containsKey(url_string))
    94108    {
    95         if (app_.verbosity() > 3)
     109        if (verbosity_ > 3)
    96110        {
    97             System.err.println("Visited " + url_string + " Before!");
     111            System.err.println("Visited " + url_string + " before!");
    98112        }
    99113        return true;
     
    179193            }
    180194
    181             if (app_.verbosity() > 2) {
     195            if (verbosity_ > 2) {
    182196            System.err.println("src url = "+ url_string);
    183197            }
     
    205219    String original_href_musthave_ = href_musthave_;
    206220
    207     // checks the it does contain this content
     221    // checks that it does contain this content
    208222    if (href_musthave_ !=  null) {
    209223
     
    266280    /** Adds an image to the stored downloaded images as a triplet.
    267281     *  Ensures that the number of images downloaded but not displayed at
    268      *  anyone time is controlled by using a buffer. If the buffer is
     282     *  any one time is controlled by using a buffer. If the buffer is
    269283     *  full this function will wait until space becomes available before
    270284     *  continuing. It also restricts the
     
    288302       
    289303        // get the image from the url
     304        if (verbosity_>=2) {
     305        System.err.println("  Downloading image URL: " + url.toString());
     306        }
     307
     308        //ImageIcon image_icon = new ImageIcon(url);
     309        // Image image = image_icon.getImage();
     310
     311        // Image image = Toolkit.getDefaultToolkit().createImage(url);
     312        // Image image = app_.getImage(url);
    290313        Image image = Toolkit.getDefaultToolkit().getImage(url);
    291314
     315        //System.err.println("###DownloadingED image URL: " + url.toString());
     316
     317        boolean status = app_.prepareImage(image,app_);
     318        //System.err.println(" Prepare Image status = " + status);
     319
     320        Thread.sleep(100);
     321
    292322        // push image onto the downloaded images
     323        /* System.err.println("*** Pushing: name="+img_name
     324                   +" dimensions = "+image_icon.getIconWidth()+"x"+image_icon.getIconHeight());
     325        //                 +" dimensions = "+image.getWidth(app_)+"x"+image.getHeight(app_));
     326        */
     327
    293328        download_images_.push(image,from_url, img_name);
    294329       
    295330        // if have completed the maximum number of downloads for the
    296331        // application then stop
    297         if (download_images_.size() == app_.maxDownloads())
    298         {
    299             stop();
    300         }
     332        if (download_images_.size() == app_.maxDownloads()) {
     333        stop();
     334        }
    301335       
    302336    }
     
    329363    if (curl.connected_ok())
    330364    {
     365        if (verbosity_ >= 1) {
     366        System.err.print("Connected OK ... ");
     367        }
     368
    331369        // read the page
    332370        curl.readAll();
     371        if (verbosity_ >= 1) {
     372        System.err.println("URL read.");
     373        }
    333374
    334375        // get all the <code><img src=</code> links into a vector
    335376        Vector src_links = curl.getSrcLinks();
    336377       
     378        if (verbosity_ >= 2) {
     379        System.err.println("  Got src links... there are " + src_links.size() + " of them.");
     380        }
    337381        // process each of the image links according to the parameters given.
    338382        for (int i = 0; i < src_links.size(); i++)
     
    341385        String url_string  = url.toString();
    342386
     387        if (verbosity_ >= 3) {
     388            System.err.println("    Unfiltered: src_link[" + i + "] = " + url_string);
     389        }
     390
    343391        if (image_file_extension(url_string))
    344392            {
     
    347395                img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length());
    348396
    349                 if (external_links_ != null && ! external_links_.isEmpty()) {
     397                if (verbosity_ >= 2) {
     398                    System.err.println("    Filtered: src_link[" + i + "] = " + url_string);
     399                }
     400
     401                if ((external_links_ != null) && (!external_links_.isEmpty())) {
    350402                    String ext = (String) external_links_.get(img_name);
    351403                   
     
    378430                    img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length());
    379431
    380                     if (external_links_ != null && ! external_links_.isEmpty()) {
     432                    if ((external_links_ != null) && (!external_links_.isEmpty())) {
    381433                    String ext = (String) external_links_.get(img_name);
    382434
  • trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/GsdlCollageApplet.java

    r6816 r7334  
    2929     *  If false, images will maintain an alpha value of 1 (appear solid),
    3030     *  newer images will simply be pasted on top of existing images <br> */
    31     protected boolean is_java2_  = true;
     31    protected boolean isJava2_  = true;
    3232    /** Number of nested links to follow
    3333     *  When used with greenstone, controls to which level of the document links will be followed
     
    3535     *  while a depth of 2 will include sections within this document, 3 includes sections within
    3636     *  sections, and so on */
    37     protected int max_depth_     = 1;
    38     /** Maximum number of downloaded images to stored <br>
     37    protected int maxDepth_     = 3;
     38
     39    /** Maximum number of images to display on the canvas */
     40    protected int maxDisplay_ = 25;
     41
     42    /** Maximum number of downloaded images to store <br>
    3943     *  Prevents applet from using excessive amounts of bandwidth by downloading too many images simulataneously*/
    40     protected int max_downloads_ = Integer.MAX_VALUE;
     44    protected int maxDownloads_ = Integer.MAX_VALUE;
     45
    4146    /** Types of images permitted in the collage, for example gif, jpg, png... */
    42     protected String image_type;
     47    protected String imageType_ = ".jpg%.png";
     48
     49    /** Caption of the collage */
     50    protected String caption_ = "";
     51
    4352    /** Background color of applet screen */
    44     protected Color bgcolor_     = new Color(150, 193, 155);
     53    protected Color bgcolor_ = new Color(150, 193, 155);
    4554
    4655    /** Time lapse between repainting of the applet */
    47     protected int refresh_delay_ = 1500;
     56    protected int refreshDelay_ = 1500;
    4857   
    4958    /** Stores an image and url pair and provides associated methods */
     
    5665    protected Display display_ = null;
    5766
     67
     68    public static int app_x_dim_  = 0;
     69    public static int app_y_dim_  = 0;
     70
     71
    5872    /** Gets verbosity */
    5973    public int verbosity()    { return verbosity_; }
    6074    /** Gets maximum depth for nested links */
    61     public int maxDepth()     { return max_depth_; }
     75    public int maxDepth()     { return maxDepth_; }
     76
     77    /** Gets maximum number of images to display */
     78    public int maxDisplay() { return maxDisplay_;}
     79
    6280    /** Gets maximum number of images to store during downloading */
    63     public int maxDownloads() { return max_downloads_; }
     81    public int maxDownloads() { return maxDownloads_; }
    6482    /** Gets the refresh delay used between repaint */
    65     public int refreshDelay() { return refresh_delay_; }
     83    public int refreshDelay() { return refreshDelay_; }
    6684
    6785    /** Gets parameters from the applet code and stores locally<br>
     
    7492     * Then starts downloading and displaying images */
    7593    public void init()
    76     {
     94    {       
     95    if (verbosity_ >= 4) {
     96        System.err.println("Attempting to retrieve parameters...");
     97    }
    7798
    7899    // gets the parameters specified
     
    81102    String max_depth_param      = getParameter("maxDepth");
    82103    String max_downloads_param  = getParameter("maxDownloads");
     104    String max_display_param    = getParameter("maxDisplay");
    83105    String refresh_delay_param  = getParameter("refreshDelay");
    84106    String image_type_param     = getParameter("imageType");
    85107    String bgcolor_param        = getParameter("bgcolor");
    86 
    87     if (bgcolor_param != null) {
    88         String [] c = bgcolor_param.split(",");
    89         if (c.length == 3)
    90         bgcolor_ = new Color(Integer.parseInt(c[0]), Integer.parseInt(c[1]), Integer.parseInt(c[2]));
    91     }
    92 
    93     if (image_type_param != null) {
    94         image_type = image_type_param;
    95     }
    96 
    97     if (verbosity_param!=null)
    98     {
     108    String caption_param        = getParameter("caption");
     109
     110    // Check it isn't null
     111    if ((verbosity_param!=null) && (!verbosity_param.startsWith("_"))) {
    99112        verbosity_  = Integer.parseInt(verbosity_param);
    100113    }
    101 
    102     if (is_java2_param == null || is_java2_param.equals("auto"))
    103     {
     114    else {
     115        verbosity_ = 2;
     116    }
     117
     118    if (verbosity_ >= 4) {
     119        System.err.println("Got parameters.");
     120    }
     121
     122    if (caption_param != null && !caption_param.startsWith("_")) {
     123        caption_ = caption_param;
     124    }
     125    else {
     126        if (verbosity_ >= 4) {
     127        System.err.println("No Caption: setting to a space.");
     128        }
     129        caption_ = " ";
     130    }
     131
     132    if ((bgcolor_param != null) && (!bgcolor_param.startsWith("_"))) {
     133        if (bgcolor_param.startsWith("#")) {
     134        bgcolor_ = Color.decode(bgcolor_param);   
     135        }
     136        else {
     137        String [] c = bgcolor_param.split(",");
     138        if (c.length == 3)
     139            bgcolor_ = new Color(Integer.parseInt(c[0]), Integer.parseInt(c[1]), Integer.parseInt(c[2]));
     140        }
     141        if (verbosity_ >= 4){
     142        System.err.println("Set BG to be " + bgcolor_.toString());
     143        }
     144    }
     145    else {
     146        if (verbosity_ >= 4) {
     147        System.err.println("No BG: setting to NZDL green.");
     148        }     
     149        bgcolor_ = new Color(150, 193, 155);
     150    }
     151
     152    if ((image_type_param != null) && (!image_type_param.startsWith("_"))) {
     153        imageType_ = image_type_param;
     154    }
     155
     156    if (is_java2_param == null || is_java2_param.equals("auto")) {
    104157        String version = System.getProperty("java.version");
    105158        version = version.substring(0, version.lastIndexOf("."));
    106         System.err.println("VERSION:" + version);
     159        System.err.println("VERSION: " + version);
    107160        float ver = (new Float(version)).floatValue();
    108         is_java2_ = (ver >= 1.2) ? true : false;
     161        isJava2_ = (ver >= 1.2) ? true : false;
    109162    }
    110163    else {
    111         is_java2_ = (is_java2_param.equals("true")) ? true : false;
    112     }
    113 
    114     if (max_depth_param!=null)
    115     {
    116         max_depth_ = Integer.parseInt(max_depth_param);
    117     }
    118     if (max_downloads_param!=null)
    119     {
    120         max_downloads_ = Integer.parseInt(max_downloads_param);
    121     }
    122 
    123     if (refresh_delay_param!=null)
    124     {
    125         refresh_delay_ = Integer.parseInt(refresh_delay_param);
     164        isJava2_ = (is_java2_param.equals("true")) ? true : false;
     165    }
     166
     167    if (max_depth_param != null) {
     168        System.err.println("maxDepth = " + max_depth_param);
     169        maxDepth_ = Integer.parseInt(max_depth_param);
     170    }
     171
     172    if (max_downloads_param!=null) {
     173        maxDownloads_ = Integer.parseInt(max_downloads_param);
     174    }
     175
     176    if (max_display_param!=null) {
     177        maxDisplay_ = Integer.parseInt(max_display_param);
     178    }
     179
     180    if (refresh_delay_param!=null) {
     181        refreshDelay_ = Integer.parseInt(refresh_delay_param);
    126182    }
    127183
     
    145201    }
    146202
     203    /* 
    147204    // creates a class to store the image and it's associated url
    148205    download_images_ = new DownloadImages(verbosity_);
     
    150207    download_thread_ = new DownloadUrls(this, download_images_,
    151208                        image_url, href_musthave, image_mustnothave,
    152                         image_ignore, image_type);
     209                        image_ignore, imageType_, verbosity_);
    153210    // starts the display image thread with the currently downloaded images
    154     display_thread_ = new DisplayImages(this,download_images_,is_java2_, bgcolor_);
    155     display_ = new Display(this);
     211    display_thread_ = new DisplayImages(this,download_images_, isJava2_, bgcolor_);
     212
     213    */
     214
     215
     216
     217    // creates initial screen
     218    app_x_dim_ = getWidth();
     219    app_y_dim_ = getHeight();
     220
     221    // display_ = new Display(this);
    156222    }
    157223
     
    165231    if (cimage != null)
    166232    {
    167         //System.err.println("Click on image: from url = " + cimage.from_url_);
     233        System.err.println("Click on image: from url = " + cimage.from_url_);
    168234        try {
    169235        // displays the associated url in a new window
     
    182248    public void start()
    183249    {
    184     download_thread_.start();
    185     display_thread_.start();
    186     display_.start();
     250    // download_thread_.start();
     251    // display_thread_.start();
     252    // display_.start();
    187253    }
    188254
     
    190256    public void stop()
    191257    {
    192     download_thread_.stop();
    193     display_thread_.stop();
    194     display_.stop();
     258    // download_thread_.stop();
     259    // display_thread_.stop();
     260    // display_.stop();
    195261
    196262    download_thread_ = null;
     
    202268    public void destroyed()
    203269    {
    204     download_thread_ = null;
    205     display_thread_ = null;
    206     display_ = null;
     270    // download_thread_ = null;
     271    // display_thread_ = null;
     272    // display_ = null;
    207273    }
    208274
     
    216282    /** Repaints the applet using the paint method of the thread that is currently displaying images */
    217283    public void paint(Graphics g) {
    218     if (display_thread_!=null)
    219     {
    220         //display_thread_.display_collage();
    221         display_thread_.paint(g);
    222     }
    223     else
    224     {
    225         System.err.println("Applet still trying to paint!!");
    226     }
     284
     285    System.err.println("Paint called!");
     286    g.setColor(bgcolor_);
     287    g.fillRect(0,0,app_x_dim_,app_y_dim_);
     288    g.fillRect(0,0,100,200);
     289
    227290    }
    228291
Note: See TracChangeset for help on using the changeset viewer.