X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fdata%2FMediaList.java;fp=src%2Ftim%2Fprune%2Fdata%2FMediaList.java;h=cc30325f8cc12751e2943dae6da6540bba4e953f;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/data/MediaList.java b/src/tim/prune/data/MediaList.java new file mode 100644 index 0000000..cc30325 --- /dev/null +++ b/src/tim/prune/data/MediaList.java @@ -0,0 +1,253 @@ +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 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(MediaObject 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(MediaObject 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(MediaObject 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(MediaObject inMedia) + { + // Check if we need to check + final int num = getNumMedia(); + if (num <= 0 || inMedia == 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 (MediaObject 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 true if any of the media objects have Files + */ + public boolean hasMediaWithFile() + { + for (MediaObject m: _media) { + if (m.getFile() != null) { + return true; + } + } + return false; + } + + /** + * @return true if there are any modified media in the list + */ + public boolean hasModifiedMedia() + { + for (MediaObject m: _media) { + if (m.isModified()) { + return true; + } + } + return false; + } + + /** + * @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); + } + } +}