X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FPhotoList.java;h=454055309285340476057efe4a51ad86a152ec74;hp=18ebe15d179d9f174d2d9ddc8dd1947098c9b10c;hb=f35b6d628f68e3b5ef19965ad8988d0dd1eb8efa;hpb=3745d70b1427bb8ac1a085e47cbdc566936784e1 diff --git a/tim/prune/data/PhotoList.java b/tim/prune/data/PhotoList.java index 18ebe15..4540553 100644 --- a/tim/prune/data/PhotoList.java +++ b/tim/prune/data/PhotoList.java @@ -3,17 +3,14 @@ package tim.prune.data; import java.util.ArrayList; /** - * Class to hold a list of Photos + * Class to hold a list of Photos, using the MediaList superclass */ -public class PhotoList +public class PhotoList extends MediaList { - private ArrayList _photos = null; - /** * Empty constructor */ - public PhotoList() - { + public PhotoList() { this(null); } @@ -21,236 +18,82 @@ public class PhotoList * Constructor * @param inList ArrayList containing Photo objects */ - private PhotoList(ArrayList inList) - { - _photos = inList; + private PhotoList(ArrayList inList) { + super(inList); } - /** - * @return the number of photos in the list + * @return clone of list contents */ - public int getNumPhotos() + public PhotoList cloneList() { - if (_photos == null) return 0; - return _photos.size(); + if (getNumMedia() == 0) return this; + ArrayList listCopy = new ArrayList(); + listCopy.addAll(_media); + return new PhotoList(listCopy); } + /** + * @return the number of photos in the list + */ + public int getNumPhotos() { + return getNumMedia(); + } /** * Add a Photo to the list * @param inPhoto Photo object to add */ - public void addPhoto(Photo inPhoto) - { - if (inPhoto != null) - { - // Make sure array is initialised - if (_photos == null) - { - _photos = new ArrayList(); - } - // Add the photo - _photos.add(inPhoto); - } + public void addPhoto(Photo inPhoto) { + addMedia(inPhoto); } - /** * 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) - { - // Make sure array is initialised - if (_photos == null) - { - _photos = new ArrayList(); - } - // Add the photo - _photos.add(inIndex, inPhoto); - } + public void addPhoto(Photo inPhoto, int inIndex) { + addMedia(inPhoto, inIndex); } - /** * 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); - } - } - - - /** - * Checks if the specified Photo is already in the list - * @param inPhoto Photo object to check - * @return true if it's already in the list - */ - public boolean contains(Photo inPhoto) - { - return (getPhotoIndex(inPhoto) > -1); + public void deletePhoto(int inIndex) { + deleteMedia(inIndex); } - /** * 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 - int numPhotos = getNumPhotos(); - if (numPhotos <= 0 || inPhoto == null || inPhoto.getFile() == null) - return -1; - // Loop around photos in list - Photo foundPhoto = null; - for (int i=0; i= getNumPhotos()) return null; - return _photos.get(inIndex); + public Photo getPhoto(int inIndex) { + return (Photo) getMedia(inIndex); } - - /** - * Crop the photo list to the specified size - * @param inIndex previous size - */ - public void cropTo(int inIndex) - { - if (inIndex <= 0) - { - // delete whole list - if (_photos != null) {_photos.clear();} - } - else - { - // delete photos to previous size - while (_photos.size() > inIndex) - { - _photos.remove(_photos.size()-1); - } - } - } - - - /** - * @return array of file names - */ - public String[] getNameList() - { - String[] names = new String[getNumPhotos()]; - 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 listCopy = new ArrayList(); - for (int i=0; i<_photos.size(); i++) { - listCopy.add(_photos.get(i)); - } - return new PhotoList(listCopy); - } - - - /** - * Restore contents from other PhotoList - * @param inOther PhotoList with cloned contents - */ - public void restore(PhotoList inOther) - { - if (inOther.getNumPhotos() == 0) - { - // List is empty - _photos = null; - } - else - { - // Clear array and copy over from other one - _photos.clear(); - _photos.addAll(inOther._photos); - } + public void removeCorrelatedPhotos() { + removeCorrelatedMedia(); } }