]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/PhotoList.java
Version 2, March 2007
[GpsPrune.git] / tim / prune / data / PhotoList.java
1 package tim.prune.data;
2
3 import java.util.ArrayList;
4
5 /**
6  * Class to hold a list of Photos
7  */
8 public class PhotoList
9 {
10         private ArrayList _photos = null;
11
12         /**
13          * @return the number of photos in the list
14          */
15         public int getNumPhotos()
16         {
17                 if (_photos == null) return 0;
18                 return _photos.size();
19         }
20
21
22         /**
23          * Add a List of Photos
24          * @param inList List containing Photo objects
25          */
26         public void addPhoto(Photo inPhoto)
27         {
28                 // Make sure array is initialised
29                 if (_photos == null)
30                 {
31                         _photos = new ArrayList();
32                 }
33                 // Add the photo
34                 if (inPhoto != null)
35                 {
36                         _photos.add(inPhoto);
37                 }
38         }
39
40
41         /**
42          * Checks if the specified Photo is already in the list
43          * @param inPhoto Photo object to check
44          * @return true if it's already in the list
45          */
46         public boolean contains(Photo inPhoto)
47         {
48                 // Check if we need to check
49                 if (getNumPhotos() <= 0 || inPhoto == null || inPhoto.getFile() == null)
50                         return false;
51                 // Loop around photos in list
52                 for (int i=0; i<getNumPhotos(); i++)
53                 {
54                         if (getPhoto(i) != null && getPhoto(i).equals(inPhoto))
55                         {
56                                 return true;
57                         }
58                 }
59                 // not found
60                 return false;
61         }
62
63
64         /**
65          * Get the Photo at the given index
66          * @param inIndex index number, starting at 0
67          * @return specified Photo object
68          */
69         public Photo getPhoto(int inIndex)
70         {
71                 if (inIndex < 0 || inIndex >= getNumPhotos()) return null;
72                 return (Photo) _photos.get(inIndex);
73         }
74
75
76         /**
77          * Crop the photo list to the specified size
78          * @param inIndex previous size
79          */
80         public void cropTo(int inIndex)
81         {
82                 if (inIndex <= 0)
83                 {
84                         // delete whole list
85                         _photos.clear();
86                 }
87                 else
88                 {
89                         // delete photos to previous size
90                         while (_photos.size() > inIndex)
91                         {
92                                 _photos.remove(_photos.size()-1);
93                         }
94                 }
95         }
96
97         /**
98          * @return array of file names
99          */
100         public String[] getNameList()
101         {
102                 String[] names = new String[getNumPhotos()];
103                 for (int i=0; i<getNumPhotos(); i++)
104                 {
105                         names[i] = getPhoto(i).getFile().getName();
106                 }
107                 return names;
108         }
109 }