- Timestamp:
- 2004-05-13T20:52:00+12:00 (20 years ago)
- 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 119 119 value = peek_value; 120 120 peek_value = -1; 121 } else { 121 } 122 else { 122 123 try { 123 124 value = input.read(); -
trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/Display.java
r6816 r7334 25 25 try { 26 26 27 System.err.println(" @@@DISPLAY");27 System.err.println("Started display thread."); 28 28 29 29 Thread curr_thread = Thread.currentThread(); … … 36 36 } 37 37 38 System.err.println(" ###DISPLAY");38 System.err.println("Stopped display thread."); 39 39 40 40 } catch (Exception e) { -
trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DisplayImages.java
r6816 r7334 40 40 /** Refers to download thread */ 41 41 DownloadImages download_images_ = null; 42 42 43 /** Refers to applet */ 43 44 GsdlCollageApplet app_ = null; 45 44 46 /** Applets width on screen */ 45 47 public static int app_x_dim_ = 0; 48 46 49 /** Applets height on screen */ 47 50 public static int app_y_dim_ = 0; 48 51 49 52 /** Background colour of the applet screen */ 50 Color bgcolor_ = null; 53 protected Color bgcolor_ = null; 54 51 55 /** Indicates whether java2 functionality should be used <br> 52 56 * If true will allow advanced image processing techniques to occur, … … 54 58 * If false, images will maintain an alpha value of 1 (appear solid), 55 59 * newer images will simply be pasted on top of existing images <br> */ 56 boolean is_java2_ = false; 60 protected boolean is_java2_ = false; 61 57 62 /** Holds images currently on display in the applet */ 58 Vector inuse_ = null; 63 protected Vector inuse_ = null; 64 59 65 /** Holds previously displayed images for re-use */ 60 Vector notinuse_ = null;66 protected Vector notinuse_ = null; 61 67 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; 66 72 67 73 /** Used to determine where to place new images on the applet to optimize … … 136 142 * @param y the y co-ordinate of the mouse 137 143 * @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) 139 146 { 140 147 if (app_.verbosity() > 1) … … 195 202 int image_y_dim = image.getHeight(app_); 196 203 204 int status = app_.checkImage(image,app_); 205 197 206 if ((image_x_dim>0) && (image_y_dim>0)) 198 207 { … … 210 219 211 220 if (is_java2_) { 212 213 collage_image.image_= restoreAlpha(collage_image.image_, 0, 0,214 221 collage_image.image_ 222 = restoreAlpha(collage_image.image_, 0, 0, 223 collage_image.image_x_dim_, collage_image.image_y_dim_); 215 224 } 216 225 … … 227 236 228 237 } 229 if (collage_image.fresh) 230 collage_image.fresh = false; 238 if (collage_image.fresh) { 239 collage_image.fresh = false; 240 } 231 241 242 } 243 else { 244 if (app_.verbosity()>=3) { 245 System.err.println(" Image ["+i+"] not ready yet!"); 246 } 232 247 } 233 248 //finished_graphic_.drawImage(screen_buffer_,0,0,app_); … … 241 256 242 257 /** 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() { 244 259 245 260 // loops through removing oldest images that have almost faded completely … … 318 333 * repaint it as the newest. <br> 319 334 * Then the collage is asked to display and repaint with the new image set. */ 320 void next_frame() 335 336 synchronized void next_frame() 321 337 { 322 338 double random = Math.random(); … … 326 342 { 327 343 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) 331 346 DownloadImages.ImageUrlTriple iutriple = download_images_.retrieve(position); 332 image= iutriple.image();347 Image image = iutriple.image(); 333 348 String from_url = iutriple.url(); 334 349 String img_name = iutriple.name(); 335 350 336 351 // prepare the image for collaging 337 app_.prepareImage(image,app_);352 // app_.prepareImage(image,app_); 338 353 CollageImage collage_image = new CollageImage(image,from_url,img_name); 339 354 … … 341 356 inuse_.addElement(collage_image); 342 357 343 if (app_.verbosity()> 3)358 if (app_.verbosity()>=1) 344 359 { 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 346 366 } 347 367 } … … 362 382 } 363 383 // otherwise repaint the first image as the last image 364 else if (inuse_.size() > 0) 365 { 384 else if (inuse_.size() > 0){ 366 385 CollageImage removed_image = (CollageImage)inuse_.elementAt(0); 367 386 … … 370 389 for (int m = removed_image.yt_; m < (removed_image.yt_ + removed_image.image_y_dim_); m++) 371 390 used_space[n][m]--; 372 391 373 392 // reset the alpha and add it 374 393 removed_image.fresh = true; … … 378 397 removed_image.image_x_dim_, removed_image.image_y_dim_); 379 398 } 380 399 381 400 notinuse_.addElement(removed_image); 382 401 inuse_.removeElementAt(0); 383 402 384 if (app_.verbosity()>3) 385 { 403 if (app_.verbosity()>=4){ 386 404 System.err.println("Removing oldest image"); 387 405 } 388 406 } 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 } 394 411 395 412 display_collage(); 396 413 } 397 414 398 415 /** Adjusts the colour and alpha value of an individual pixel <br> 399 416 * If the image is being drawn for the first time, the RGB values are … … 475 492 * @param p the position of the image in the applet (indicates age) 476 493 * @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) { 478 496 479 497 // declare an array to hold the pixels … … 666 684 public synchronized void paint(Graphics g) 667 685 { 668 //System.err.println("......" + is_java2_);669 670 686 screen_graphic_.setColor(bgcolor_); 671 687 screen_graphic_.fillRect(0,0,app_x_dim_,app_y_dim_); … … 678 694 CollageImage collage_image = (CollageImage)inuse_.elementAt(i); 679 695 // 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 } 682 701 683 702 // advanced image processing may be used 684 else if (is_java2_)685 703 // else if (is_java2_) { 704 else if (false) { 686 705 // the alphacomposite controls the blending of these two images. 687 706 Graphics2D sg2d = (Graphics2D)screen_graphic_; … … 695 714 else 696 715 { 697 // System.err.println("patu");698 716 // add the image to the collage 699 717 screen_graphic_.drawImage(collage_image.image_, -
trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/DownloadUrls.java
r6816 r7334 5 5 import java.net.*; 6 6 import java.util.*; 7 8 // import javax.swing.ImageIcon; //**** 9 7 10 8 11 /** … … 15 18 * of downloading that occurs by restricting the number of downloaded images that are yet to 16 19 * 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 18 22 public class DownloadUrls extends Thread { 19 23 … … 25 29 /** The address from which the application should start looking for images */ 26 30 String starting_url_ = null; 31 32 /** CHRIS - Holds the contents of the collection's assoc directory */ 33 // File[] assocDir_ = null; 34 27 35 /** Restricts links followed from the starting url to links that contain this string */ 28 36 String href_musthave_ = null; … … 50 58 /** Determines whether there are still pages to examine and images to download */ 51 59 boolean thread_running_ = true; 60 61 int verbosity_; 52 62 53 63 /** Constructor to initialise a download thread from which images are found, … … 64 74 DownloadImages download_images, String starting_url, 65 75 String href_musthave, String image_mustnothave, 66 String image_ignore, String image_type )76 String image_ignore, String image_type, int verbosity) 67 77 { 68 78 super("DownloadUrls"); … … 75 85 image_ignore_ = image_ignore; 76 86 image_type_ = image_type; 77 } 87 88 verbosity_ = verbosity; 89 } 90 91 78 92 79 93 /** Determines whether or not a url has already been examined … … 93 107 if (visited_url_.containsKey(url_string)) 94 108 { 95 if ( app_.verbosity()> 3)109 if (verbosity_ > 3) 96 110 { 97 System.err.println("Visited " + url_string + " Before!");111 System.err.println("Visited " + url_string + " before!"); 98 112 } 99 113 return true; … … 179 193 } 180 194 181 if ( app_.verbosity()> 2) {195 if (verbosity_ > 2) { 182 196 System.err.println("src url = "+ url_string); 183 197 } … … 205 219 String original_href_musthave_ = href_musthave_; 206 220 207 // checks th eit does contain this content221 // checks that it does contain this content 208 222 if (href_musthave_ != null) { 209 223 … … 266 280 /** Adds an image to the stored downloaded images as a triplet. 267 281 * Ensures that the number of images downloaded but not displayed at 268 * any one time is controlled by using a buffer. If the buffer is282 * any one time is controlled by using a buffer. If the buffer is 269 283 * full this function will wait until space becomes available before 270 284 * continuing. It also restricts the … … 288 302 289 303 // 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); 290 313 Image image = Toolkit.getDefaultToolkit().getImage(url); 291 314 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 292 322 // 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 293 328 download_images_.push(image,from_url, img_name); 294 329 295 330 // if have completed the maximum number of downloads for the 296 331 // application then stop 297 if (download_images_.size() == app_.maxDownloads()) 298 { 299 stop(); 300 } 332 if (download_images_.size() == app_.maxDownloads()) { 333 stop(); 334 } 301 335 302 336 } … … 329 363 if (curl.connected_ok()) 330 364 { 365 if (verbosity_ >= 1) { 366 System.err.print("Connected OK ... "); 367 } 368 331 369 // read the page 332 370 curl.readAll(); 371 if (verbosity_ >= 1) { 372 System.err.println("URL read."); 373 } 333 374 334 375 // get all the <code><img src=</code> links into a vector 335 376 Vector src_links = curl.getSrcLinks(); 336 377 378 if (verbosity_ >= 2) { 379 System.err.println(" Got src links... there are " + src_links.size() + " of them."); 380 } 337 381 // process each of the image links according to the parameters given. 338 382 for (int i = 0; i < src_links.size(); i++) … … 341 385 String url_string = url.toString(); 342 386 387 if (verbosity_ >= 3) { 388 System.err.println(" Unfiltered: src_link[" + i + "] = " + url_string); 389 } 390 343 391 if (image_file_extension(url_string)) 344 392 { … … 347 395 img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length()); 348 396 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())) { 350 402 String ext = (String) external_links_.get(img_name); 351 403 … … 378 430 img_name = url_string.substring(url_string.lastIndexOf("/") + 1, url_string.length()); 379 431 380 if ( external_links_ != null && ! external_links_.isEmpty()) {432 if ((external_links_ != null) && (!external_links_.isEmpty())) { 381 433 String ext = (String) external_links_.get(img_name); 382 434 -
trunk/gsdl/src/java/org/nzdl/gsdl/GsdlCollageApplet/GsdlCollageApplet.java
r6816 r7334 29 29 * If false, images will maintain an alpha value of 1 (appear solid), 30 30 * newer images will simply be pasted on top of existing images <br> */ 31 protected boolean is _java2_ = true;31 protected boolean isJava2_ = true; 32 32 /** Number of nested links to follow 33 33 * When used with greenstone, controls to which level of the document links will be followed … … 35 35 * while a depth of 2 will include sections within this document, 3 includes sections within 36 36 * 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> 39 43 * 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 41 46 /** 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 43 52 /** Background color of applet screen */ 44 protected Color bgcolor_ 53 protected Color bgcolor_ = new Color(150, 193, 155); 45 54 46 55 /** Time lapse between repainting of the applet */ 47 protected int refresh _delay_ = 1500;56 protected int refreshDelay_ = 1500; 48 57 49 58 /** Stores an image and url pair and provides associated methods */ … … 56 65 protected Display display_ = null; 57 66 67 68 public static int app_x_dim_ = 0; 69 public static int app_y_dim_ = 0; 70 71 58 72 /** Gets verbosity */ 59 73 public int verbosity() { return verbosity_; } 60 74 /** 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 62 80 /** Gets maximum number of images to store during downloading */ 63 public int maxDownloads() { return max _downloads_; }81 public int maxDownloads() { return maxDownloads_; } 64 82 /** Gets the refresh delay used between repaint */ 65 public int refreshDelay() { return refresh _delay_; }83 public int refreshDelay() { return refreshDelay_; } 66 84 67 85 /** Gets parameters from the applet code and stores locally<br> … … 74 92 * Then starts downloading and displaying images */ 75 93 public void init() 76 { 94 { 95 if (verbosity_ >= 4) { 96 System.err.println("Attempting to retrieve parameters..."); 97 } 77 98 78 99 // gets the parameters specified … … 81 102 String max_depth_param = getParameter("maxDepth"); 82 103 String max_downloads_param = getParameter("maxDownloads"); 104 String max_display_param = getParameter("maxDisplay"); 83 105 String refresh_delay_param = getParameter("refreshDelay"); 84 106 String image_type_param = getParameter("imageType"); 85 107 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("_"))) { 99 112 verbosity_ = Integer.parseInt(verbosity_param); 100 113 } 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")) { 104 157 String version = System.getProperty("java.version"); 105 158 version = version.substring(0, version.lastIndexOf(".")); 106 System.err.println("VERSION: " + version);159 System.err.println("VERSION: " + version); 107 160 float ver = (new Float(version)).floatValue(); 108 is _java2_ = (ver >= 1.2) ? true : false;161 isJava2_ = (ver >= 1.2) ? true : false; 109 162 } 110 163 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); 126 182 } 127 183 … … 145 201 } 146 202 203 /* 147 204 // creates a class to store the image and it's associated url 148 205 download_images_ = new DownloadImages(verbosity_); … … 150 207 download_thread_ = new DownloadUrls(this, download_images_, 151 208 image_url, href_musthave, image_mustnothave, 152 image_ignore, image _type);209 image_ignore, imageType_, verbosity_); 153 210 // 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); 156 222 } 157 223 … … 165 231 if (cimage != null) 166 232 { 167 //System.err.println("Click on image: from url = " + cimage.from_url_);233 System.err.println("Click on image: from url = " + cimage.from_url_); 168 234 try { 169 235 // displays the associated url in a new window … … 182 248 public void start() 183 249 { 184 download_thread_.start();185 display_thread_.start();186 display_.start();250 // download_thread_.start(); 251 // display_thread_.start(); 252 // display_.start(); 187 253 } 188 254 … … 190 256 public void stop() 191 257 { 192 download_thread_.stop();193 display_thread_.stop();194 display_.stop();258 // download_thread_.stop(); 259 // display_thread_.stop(); 260 // display_.stop(); 195 261 196 262 download_thread_ = null; … … 202 268 public void destroyed() 203 269 { 204 download_thread_ = null;205 display_thread_ = null;206 display_ = null;270 // download_thread_ = null; 271 // display_thread_ = null; 272 // display_ = null; 207 273 } 208 274 … … 216 282 /** Repaints the applet using the paint method of the thread that is currently displaying images */ 217 283 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 227 290 } 228 291
Note:
See TracChangeset
for help on using the changeset viewer.