1 package tim.prune.data;
3 import java.util.ArrayList;
6 * Class to hold a list of Photos
10 private ArrayList<Photo> _photos = null;
22 * @param inList ArrayList containing Photo objects
24 private PhotoList(ArrayList<Photo> inList)
31 * @return the number of photos in the list
33 public int getNumPhotos()
35 if (_photos == null) return 0;
36 return _photos.size();
41 * Add a Photo to the list
42 * @param inPhoto Photo object to add
44 public void addPhoto(Photo inPhoto)
48 // Make sure array is initialised
51 _photos = new ArrayList<Photo>();
60 * Add a Photo to the list
61 * @param inPhoto Photo object to add
62 * @param inIndex index at which to add photo
64 public void addPhoto(Photo inPhoto, int inIndex)
68 // Make sure array is initialised
71 _photos = new ArrayList<Photo>();
74 _photos.add(inIndex, inPhoto);
80 * Remove the selected photo from the list
81 * @param inIndex index number to remove
83 public void deletePhoto(int inIndex)
85 // Maybe throw exception if this fails?
88 _photos.remove(inIndex);
94 * Checks if the specified Photo is already in the list
95 * @param inPhoto Photo object to check
96 * @return true if it's already in the list
98 public boolean contains(Photo inPhoto)
100 return (getPhotoIndex(inPhoto) > -1);
105 * Get the index of the given Photo
106 * @param inPhoto Photo object to check
107 * @return index of this Photo in the list, or -1 if not found
109 public int getPhotoIndex(Photo inPhoto)
111 // Check if we need to check
112 int numPhotos = getNumPhotos();
113 if (numPhotos <= 0 || inPhoto == null || inPhoto.getFile() == null)
115 // Loop around photos in list
116 Photo foundPhoto = null;
117 for (int i=0; i<numPhotos; i++)
119 foundPhoto = getPhoto(i);
120 if (foundPhoto != null && foundPhoto.equals(inPhoto))
131 * Get the Photo at the given index
132 * @param inIndex index number, starting at 0
133 * @return specified Photo object
135 public Photo getPhoto(int inIndex)
137 if (inIndex < 0 || inIndex >= getNumPhotos()) return null;
138 return _photos.get(inIndex);
143 * Crop the photo list to the specified size
144 * @param inIndex previous size
146 public void cropTo(int inIndex)
151 if (_photos != null) {_photos.clear();}
155 // delete photos to previous size
156 while (_photos.size() > inIndex)
158 _photos.remove(_photos.size()-1);
165 * @return array of file names
167 public String[] getNameList()
169 String[] names = new String[getNumPhotos()];
170 for (int i=0; i<getNumPhotos(); i++)
172 names[i] = getPhoto(i).getFile().getName();
179 * @return true if photo list contains correlated photos
181 public boolean hasCorrelatedPhotos()
183 int numPhotos = getNumPhotos();
184 boolean hasCorrelated = false;
185 // Loop over photos in list
186 for (int i=0; i<numPhotos && !hasCorrelated; i++)
188 if (getPhoto(i).getDataPoint() != null)
189 hasCorrelated = true;
191 return hasCorrelated;
196 * Remove all correlated photos from the list
198 public void removeCorrelatedPhotos()
200 int numPhotos = getNumPhotos();
203 // Construct new list to copy into
204 ArrayList<Photo> listCopy = new ArrayList<Photo>();
205 // Loop over photos in list
206 for (int i=0; i<numPhotos; i++)
208 // Copy photo if it has no point
209 Photo photo = getPhoto(i);
212 if (photo.getDataPoint() == null)
215 photo.resetCachedData();
218 // Switch reference to new list
225 * @return clone of photo list contents
227 public PhotoList cloneList()
229 if (_photos == null) return this;
230 ArrayList<Photo> listCopy = new ArrayList<Photo>();
231 for (int i=0; i<_photos.size(); i++) {
232 listCopy.add(_photos.get(i));
234 return new PhotoList(listCopy);
239 * Restore contents from other PhotoList
240 * @param inOther PhotoList with cloned contents
242 public void restore(PhotoList inOther)
244 if (inOther.getNumPhotos() == 0)
251 // Clear array and copy over from other one
253 _photos.addAll(inOther._photos);