]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/load/PhotoMeasurer.java
Version 3, August 2007
[GpsPrune.git] / tim / prune / load / PhotoMeasurer.java
1 package tim.prune.load;
2
3 import tim.prune.data.Photo;
4 import tim.prune.data.PhotoList;
5
6 /**
7  * This class starts a new thread to preload image sizes
8  * TODO: # Cache small image thumbnails too?
9  */
10 public class PhotoMeasurer implements Runnable
11 {
12         /** PhotoList to loop through */
13         private PhotoList _photoList = null;
14
15
16         /**
17          * Constructor
18          * @param inPhotoList photo list to loop through
19          */
20         public PhotoMeasurer(PhotoList inPhotoList)
21         {
22                 _photoList = inPhotoList;
23         }
24
25
26         /**
27          * Start off the process to measure the photo sizes
28          */
29         public void measurePhotos()
30         {
31                 // check if any photos in list
32                 if (_photoList != null && _photoList.getNumPhotos() > 0)
33                 {
34                         // start new thread
35                         new Thread(this).start();
36                 }
37         }
38
39
40         /**
41          * Run method called in new thread
42          */
43         public void run()
44         {
45                 try
46                 {
47                         // loop over all photos in list
48                         for (int i=0; i<_photoList.getNumPhotos(); i++)
49                         {
50                                 Photo photo = _photoList.getPhoto(i);
51                                 if (photo != null)
52                                 {
53                                         // call get size method which will calculate it if necessary
54                                         photo.getSize();
55                                 }
56                         }
57                 }
58                 catch (ArrayIndexOutOfBoundsException obe) {} // ignore, must have been changed by other thread
59         }
60 }