1 package tim.prune.data;
6 * Class to represent a general media object for correlation.
7 * Subclasses are currently Photo and AudioClip
9 public abstract class MediaObject
11 /** File where media is stored (if any) */
12 protected File _file = null;
14 protected String _name = null;
15 /** Cached data if downloaded */
16 protected byte[] _data = null;
17 /** URL if media came from net */
18 protected String _url = null;
19 /** Timestamp, if any */
20 protected Timestamp _timestamp = null;
21 /** Associated DataPoint if correlated */
22 protected DataPoint _dataPoint = null;
23 /** Status when loaded */
24 private Status _originalStatus = Status.NOT_CONNECTED;
26 private Status _currentStatus = Status.NOT_CONNECTED;
28 /** Connection status */
31 /** Media is not connected to any point */
33 /** Media has been connected to a point since it was loaded */
35 /** Media is connected to a point */
42 * @param inFile file object
43 * @param inStamp timestamp object
45 public MediaObject(File inFile, Timestamp inStamp)
48 _name = inFile.getName();
54 * Constructor for byte arrays
55 * @param inData byte array containing data
56 * @param inName name of object
57 * @param inUrl source url of object or null
59 public MediaObject(byte[] inData, String inName, String inUrl)
69 * @return the file object
71 public File getFile() {
75 /** @return media name */
76 public String getName() {
81 * @return the timestamp object
83 public Timestamp getTimestamp() {
88 * @param inTimestamp Timestamp object
90 public void setTimestamp(Timestamp inTimestamp) {
91 _timestamp = inTimestamp;
95 * @return byte data of media
97 public byte[] getByteData() {
102 * @return source Url (or null)
104 public String getUrl() {
109 * @return the full path to the media, either filename or url
111 public String getFullPath()
113 if (_file != null) return _file.getAbsolutePath();
118 * @return true if details are valid (might not have timestamp)
120 public boolean isValid()
122 return ((_file != null && _file.exists() && _file.canRead())
123 || (_data != null && _data.length > 0));
127 * @return true if file has timestamp
129 public boolean hasTimestamp() {
130 return _timestamp != null && _timestamp.isValid();
134 * Check if this object refers to the same object as another
135 * @param inOther other MediaObject
136 * @return true if the objects are the same
138 public boolean equals(MediaObject inOther)
142 // compare file objects
143 return (inOther != null && inOther.getFile() != null && getFile() != null
144 && inOther.getFile().equals(getFile()));
146 // compare data arrays
147 return (inOther != null && _name != null && inOther._name != null && _name.equals(inOther._name)
148 && _data != null && inOther._data != null && _data.length == inOther._data.length);
152 * Set the data point associated with the photo
153 * @param inPoint DataPoint with coordinates etc
155 public void setDataPoint(DataPoint inPoint)
157 _dataPoint = inPoint;
158 // set status according to point
159 if (inPoint == null) {
160 setCurrentStatus(Status.NOT_CONNECTED);
163 setCurrentStatus(Status.CONNECTED);
168 * @return the DataPoint object
170 public DataPoint getDataPoint() {
175 * @param inStatus status of file when loaded
177 public void setOriginalStatus(Status inStatus)
179 _originalStatus = inStatus;
180 _currentStatus = inStatus;
184 * @return status of file when it was loaded
186 public Status getOriginalStatus()
188 return _originalStatus;
192 * @return current status
194 public Status getCurrentStatus()
196 return _currentStatus;
199 * @param inStatus current status
201 public void setCurrentStatus(Status inStatus)
203 _currentStatus = inStatus;
207 * @return true if this object is connected to a point
209 public boolean isConnected()
211 return _currentStatus != Status.NOT_CONNECTED;
215 * @return true if status has changed since load
217 public boolean isModified()
219 return _currentStatus != _originalStatus;
223 * Reset any cached data (eg thumbnail)
225 public void resetCachedData() {}