X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FPhotoList.java;h=b7c044da5ad2295b2bd98d677fc1c1a84d1aca2d;hp=ac10edfafd8d3335dd87f50fb48c4b0e46f0637a;hb=5625a1abadb5f2ca5f017fe7dbda1d5141cb637b;hpb=23959e65a6a0d581e657b07186d18b7a1ac5afeb diff --git a/tim/prune/data/PhotoList.java b/tim/prune/data/PhotoList.java index ac10edf..b7c044d 100644 --- a/tim/prune/data/PhotoList.java +++ b/tim/prune/data/PhotoList.java @@ -9,6 +9,24 @@ public class PhotoList { private ArrayList _photos = null; + /** + * Empty constructor + */ + public PhotoList() + { + this(null); + } + + /** + * Constructor + * @param inList ArrayList containing Photo objects + */ + private PhotoList(ArrayList inList) + { + _photos = inList; + } + + /** * @return the number of photos in the list */ @@ -20,20 +38,54 @@ public class PhotoList /** - * Add a List of Photos - * @param inList List containing Photo objects + * Add a Photo to the list + * @param inPhoto Photo object to add */ public void addPhoto(Photo inPhoto) { - // Make sure array is initialised - if (_photos == null) + if (inPhoto != null) { - _photos = new ArrayList(); + // Make sure array is initialised + if (_photos == null) + { + _photos = new ArrayList(); + } + // Add the photo + _photos.add(inPhoto); } - // Add the photo + } + + + /** + * Add a Photo to the list + * @param inPhoto Photo object to add + * @param inIndex index at which to add photo + */ + public void addPhoto(Photo inPhoto, int inIndex) + { if (inPhoto != null) { - _photos.add(inPhoto); + // Make sure array is initialised + if (_photos == null) + { + _photos = new ArrayList(); + } + // Add the photo + _photos.add(inIndex, inPhoto); + } + } + + + /** + * Remove the selected photo from the list + * @param inIndex index number to remove + */ + public void deletePhoto(int inIndex) + { + // Maybe throw exception if this fails? + if (_photos != null) + { + _photos.remove(inIndex); } } @@ -44,20 +96,34 @@ public class PhotoList * @return true if it's already in the list */ public boolean contains(Photo inPhoto) + { + return (getPhotoIndex(inPhoto) > -1); + } + + + /** + * Get the index of the given Photo + * @param inPhoto Photo object to check + * @return index of this Photo in the list, or -1 if not found + */ + public int getPhotoIndex(Photo inPhoto) { // Check if we need to check - if (getNumPhotos() <= 0 || inPhoto == null || inPhoto.getFile() == null) - return false; + int numPhotos = getNumPhotos(); + if (numPhotos <= 0 || inPhoto == null || inPhoto.getFile() == null) + return -1; // Loop around photos in list - for (int i=0; i 0) + { + // Construct new list to copy into + ArrayList listCopy = new ArrayList(); + // Loop over photos in list + for (int i=0; i