X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;ds=sidebyside;f=tim%2Fprune%2Fdata%2FMediaList.java;fp=tim%2Fprune%2Fdata%2FMediaList.java;h=3fc87fe81a8dc936e5651dd541794f98927e068f;hb=f35b6d628f68e3b5ef19965ad8988d0dd1eb8efa;hp=0000000000000000000000000000000000000000;hpb=3745d70b1427bb8ac1a085e47cbdc566936784e1;p=GpsPrune.git diff --git a/tim/prune/data/MediaList.java b/tim/prune/data/MediaList.java new file mode 100644 index 0000000..3fc87fe --- /dev/null +++ b/tim/prune/data/MediaList.java @@ -0,0 +1,227 @@ +package tim.prune.data; + +import java.util.ArrayList; + +/** + * Class to hold a list of Media, either Photos or Audio files + */ +public abstract class MediaList +{ + /** list of media file objects */ + protected ArrayList _media = null; + + + /** + * Empty constructor + */ + public MediaList() { + this(null); + } + + /** + * Constructor + * @param inList ArrayList containing media objects + */ + protected MediaList(ArrayList inList) + { + _media = inList; + if (_media == null) { + _media = new ArrayList(); + } + } + + /** + * @return the number of media in the list + */ + public int getNumMedia() { + return _media.size(); + } + + /** + * Add an object to the list + * @param inObject object to add + */ + public void addMedia(MediaFile inObject) + { + if (inObject != null) { + _media.add(inObject); + } + } + + /** + * Add an object to the list at a specified index (used for undo) + * @param inObject object to add + * @param inIndex index at which to add + */ + public void addMedia(MediaFile inObject, int inIndex) + { + if (inObject != null) { + _media.add(inIndex, inObject); + } + } + + + /** + * Remove the selected media from the list + * @param inIndex index number to remove + */ + public void deleteMedia(int inIndex) + { + // Maybe throw exception if this fails? + _media.remove(inIndex); + } + + + /** + * Checks if the specified object is already in the list + * @param inMedia media object to check + * @return true if it's already in the list + */ + public boolean contains(MediaFile inMedia) { + return (getMediaIndex(inMedia) > -1); + } + + + /** + * Get the index of the given media + * @param inMedia object to check + * @return index of this object in the list, or -1 if not found + */ + public int getMediaIndex(MediaFile inMedia) + { + // Check if we need to check + final int num = getNumMedia(); + if (num <= 0 || inMedia == null || inMedia.getFile() == null) + return -1; + // Loop over list + for (int i=0; i= getNumMedia()) return null; + return _media.get(inIndex); + } + + + /** + * Crop the list to the specified size + * @param inIndex previous size + */ + public void cropTo(int inIndex) + { + if (inIndex <= 0) + { + // delete whole list + _media.clear(); + } + else + { + // delete to previous size + while (_media.size() > inIndex) { + _media.remove(_media.size()-1); + } + } + } + + + /** + * @return array of file names + */ + public String[] getNameList() + { + final int num = getNumMedia(); + String[] names = new String[num]; + for (int i=0; i 0) + { + // Construct new list to copy into + ArrayList listCopy = new ArrayList(); + // Loop over list + for (MediaFile m : _media) + { + // Copy media if it has no point + if (m != null) + { + if (m.getDataPoint() == null) + listCopy.add(m); + else + m.resetCachedData(); + } + } + // Switch reference to new list + _media = listCopy; + } + } + + /** + * @return clone of list contents + */ + public abstract MediaList cloneList(); + + /** + * Restore contents from other MediaList + * @param inOther MediaList with cloned contents + */ + public void restore(MediaList inOther) + { + _media.clear(); + if (inOther != null && inOther.getNumMedia() > 0) + { + // Copy contents from other list + _media.addAll(inOther._media); + } + } +}