]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/MediaFile.java
Version 12.1, December 2010
[GpsPrune.git] / tim / prune / data / MediaFile.java
1 package tim.prune.data;
2
3 import java.io.File;
4
5 /**
6  * Class to represent a general media file for correlation.
7  * Subclasses are currently Photo and AudioFile
8  */
9 public abstract class MediaFile
10 {
11         /** File where media is stored */
12         protected File _file = null;
13         /** Timestamp, if any */
14         protected Timestamp _timestamp = null;
15         /** Associated DataPoint if correlated */
16         protected DataPoint _dataPoint = null;
17         /** Status when loaded */
18         private Status _originalStatus = Status.NOT_CONNECTED;
19         /** Current status */
20         private Status _currentStatus = Status.NOT_CONNECTED;
21
22         /** Connection status */
23         public enum Status {
24                 /** Media is not connected to any point */
25                 NOT_CONNECTED,
26                 /** Media has been connected to a point since it was loaded */
27                 TAGGED,
28                 /** Media is connected to a point */
29                 CONNECTED
30         };
31
32
33         /**
34          * Constructor
35          * @param inFile file object
36          * @param inStamp timestamp object
37          */
38         public MediaFile(File inFile, Timestamp inStamp)
39         {
40                 _file = inFile;
41                 _timestamp = inStamp;
42         }
43
44         /**
45          * @return the file object
46          */
47         public File getFile() {
48                 return _file;
49         }
50
51         /**
52          * @return the timestamp object
53          */
54         public Timestamp getTimestamp() {
55                 return _timestamp;
56         }
57
58         /**
59          * @param inTimestamp Timestamp object
60          */
61         public void setTimestamp(Timestamp inTimestamp) {
62                 _timestamp = inTimestamp;
63         }
64
65         /**
66          * @return true if details are valid (might not have timestamp)
67          */
68         public boolean isValid() {
69                 return _file != null && _file.exists() && _file.canRead();
70         }
71
72         /**
73          * @return true if file has timestamp
74          */
75         public boolean hasTimestamp() {
76                  return _timestamp != null && _timestamp.isValid();
77         }
78
79         /**
80          * Check if this object refers to the same File as another
81          * @param inOther other MediaFile object
82          * @return true if the Files are the same
83          */
84         public boolean equals(MediaFile inOther)
85         {
86                 return (inOther != null && inOther.getFile() != null && getFile() != null
87                         && inOther.getFile().equals(getFile()));
88         }
89
90         /**
91          * Set the data point associated with the photo
92          * @param inPoint DataPoint with coordinates etc
93          */
94         public void setDataPoint(DataPoint inPoint)
95         {
96                 _dataPoint = inPoint;
97                 // set status according to point
98                 if (inPoint == null) {
99                         setCurrentStatus(Status.NOT_CONNECTED);
100                 }
101                 else {
102                         setCurrentStatus(Status.CONNECTED);
103                 }
104         }
105
106         /**
107          * @return the DataPoint object
108          */
109         public DataPoint getDataPoint() {
110                 return _dataPoint;
111         }
112
113         /**
114          * @param inStatus status of file when loaded
115          */
116         public void setOriginalStatus(Status inStatus)
117         {
118                 _originalStatus = inStatus;
119                 _currentStatus = inStatus;
120         }
121
122         /**
123          * @return status of file when it was loaded
124          */
125         public Status getOriginalStatus()
126         {
127                 return _originalStatus;
128         }
129
130         /**
131          * @return current status
132          */
133         public Status getCurrentStatus()
134         {
135                 return _currentStatus;
136         }
137         /**
138          * @param inStatus current status
139          */
140         public void setCurrentStatus(Status inStatus)
141         {
142                 _currentStatus = inStatus;
143         }
144
145         /**
146          * @return true if file is connected to a point
147          */
148         public boolean isConnected()
149         {
150                 return _currentStatus != Status.NOT_CONNECTED;
151         }
152
153         /**
154          * Reset any cached data held by the media file (eg thumbnail)
155          */
156         public void resetCachedData() {}
157 }