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() {
+ this(null);
+ }
/**
- * @return the number of photos in the list
+ * Constructor
+ * @param inList ArrayList containing Photo objects
*/
- public int getNumPhotos()
+ private PhotoList(ArrayList<MediaObject> inList) {
+ super(inList);
+ }
+
+ /**
+ * @return clone of list contents
+ */
+ public PhotoList cloneList()
{
- if (_photos == null) return 0;
- return _photos.size();
+ if (getNumMedia() == 0) return this;
+ ArrayList<MediaObject> listCopy = new ArrayList<MediaObject>();
+ listCopy.addAll(_media);
+ return new PhotoList(listCopy);
}
+ /**
+ * @return the number of photos in the list
+ */
+ public int getNumPhotos() {
+ return getNumMedia();
+ }
/**
- * 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)
- {
- _photos = new ArrayList();
- }
- // Add the photo
- if (inPhoto != null)
- {
- _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) {
+ addMedia(inPhoto, 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
+ * Remove the selected photo from the list
+ * @param inIndex index number to remove
*/
- public boolean contains(Photo inPhoto)
- {
- // Check if we need to check
- if (getNumPhotos() <= 0 || inPhoto == null || inPhoto.getFile() == null)
- return false;
- // Loop around photos in list
- for (int i=0; i<getNumPhotos(); i++)
- {
- if (getPhoto(i) != null && getPhoto(i).equals(inPhoto))
- {
- return true;
- }
- }
- // not found
- return false;
+ 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) {
+ return getMediaIndex(inPhoto);
+ }
/**
* Get the Photo at the given index
* @param inIndex index number, starting at 0
* @return specified Photo object
*/
- public Photo getPhoto(int inIndex)
- {
- if (inIndex < 0 || inIndex >= getNumPhotos()) return null;
- return (Photo) _photos.get(inIndex);
+ public Photo getPhoto(int inIndex) {
+ return (Photo) getMedia(inIndex);
}
-
/**
- * Crop the photo list to the specified size
- * @param inIndex previous size
+ * @return true if photo list contains correlated photos
*/
- public void cropTo(int inIndex)
- {
- if (inIndex <= 0)
- {
- // delete whole list
- _photos.clear();
- }
- else
- {
- // delete photos to previous size
- while (_photos.size() > inIndex)
- {
- _photos.remove(_photos.size()-1);
- }
- }
+ public boolean hasCorrelatedPhotos() {
+ return hasCorrelatedMedia();
}
/**
- * @return array of file names
+ * Remove all correlated photos from the list
*/
- public String[] getNameList()
- {
- String[] names = new String[getNumPhotos()];
- for (int i=0; i<getNumPhotos(); i++)
- {
- names[i] = getPhoto(i).getFile().getName();
- }
- return names;
+ public void removeCorrelatedPhotos() {
+ removeCorrelatedMedia();
}
}