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 true if details are valid (might not have timestamp)
111 public boolean isValid()
113 return ((_file != null && _file.exists() && _file.canRead())
114 || (_data != null && _data.length > 0));
118 * @return true if file has timestamp
120 public boolean hasTimestamp() {
121 return _timestamp != null && _timestamp.isValid();
125 * Check if this object refers to the same object as another
126 * @param inOther other MediaObject
127 * @return true if the objects are the same
129 public boolean equals(MediaObject inOther)
133 // compare file objects
134 return (inOther != null && inOther.getFile() != null && getFile() != null
135 && inOther.getFile().equals(getFile()));
137 // compare data arrays
138 return (inOther != null && _name != null && inOther._name != null && _name.equals(inOther._name)
139 && _data != null && inOther._data != null && _data.length == inOther._data.length);
143 * Set the data point associated with the photo
144 * @param inPoint DataPoint with coordinates etc
146 public void setDataPoint(DataPoint inPoint)
148 _dataPoint = inPoint;
149 // set status according to point
150 if (inPoint == null) {
151 setCurrentStatus(Status.NOT_CONNECTED);
154 setCurrentStatus(Status.CONNECTED);
159 * @return the DataPoint object
161 public DataPoint getDataPoint() {
166 * @param inStatus status of file when loaded
168 public void setOriginalStatus(Status inStatus)
170 _originalStatus = inStatus;
171 _currentStatus = inStatus;
175 * @return status of file when it was loaded
177 public Status getOriginalStatus()
179 return _originalStatus;
183 * @return current status
185 public Status getCurrentStatus()
187 return _currentStatus;
190 * @param inStatus current status
192 public void setCurrentStatus(Status inStatus)
194 _currentStatus = inStatus;
198 * @return true if this object is connected to a point
200 public boolean isConnected()
202 return _currentStatus != Status.NOT_CONNECTED;
206 * Reset any cached data (eg thumbnail)
208 public void resetCachedData() {}