1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 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<MediaObject> _media = null;
/**
* Empty constructor
*/
public MediaList() {
this(null);
}
/**
* Constructor
* @param inList ArrayList containing media objects
*/
protected MediaList(ArrayList<MediaObject> inList)
{
_media = inList;
if (_media == null) {
_media = new ArrayList<MediaObject>();
}
}
/**
* @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<num; i++)
{
MediaObject m = _media.get(i);
if (m != null && m.equals(inMedia)) {
return i;
}
}
// not found
return -1;
}
/**
* Get the media at the given index
* @param inIndex index number, starting at 0
* @return specified object
*/
public MediaObject getMedia(int inIndex)
{
if (inIndex < 0 || inIndex >= 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<num; i++) {
names[i] = getMedia(i).getName();
}
return names;
}
/**
* @return true if list contains correlated media
*/
public boolean hasCorrelatedMedia()
{
for (MediaObject m : _media) {
if (m.getDataPoint() != null) {
return true;
}
}
return false;
}
/**
* @return true if list contains uncorrelated media
*/
public boolean hasUncorrelatedMedia()
{
for (MediaObject m : _media) {
if (m.getDataPoint() == null && m.hasTimestamp()) {
return true;
}
}
return false;
}
/**
* Remove all correlated media from the list
*/
public void removeCorrelatedMedia()
{
if (getNumMedia() > 0)
{
// Construct new list to copy into
ArrayList<MediaObject> listCopy = new ArrayList<MediaObject>();
// 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);
}
}
}
|