]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/drew/jpeg/JpegData.java
Version 4, January 2008
[GpsPrune.git] / tim / prune / drew / jpeg / JpegData.java
1 package tim.prune.drew.jpeg;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 /**
7  * Class to hold the GPS data extracted from a Jpeg including position and time
8  * All contents are in Rational format
9  */
10 public class JpegData
11 {
12         private boolean _exifDataPresent = false;
13         private char _latitudeRef = '\0';
14         private char _longitudeRef = '\0';
15         private byte _altitudeRef = 0;
16         private Rational[] _latitude = null;
17         private Rational[] _longitude = null;
18         private Rational   _altitude = null;
19         private Rational[] _gpsTimestamp = null;
20         private Rational[] _gpsDatestamp = null;
21         private String _originalTimestamp = null;
22         private byte[] _thumbnail = null;
23         private ArrayList _errors = null;
24
25
26         /**
27          * Set the exif data present flag
28          */
29         public void setExifDataPresent()
30         {
31                 _exifDataPresent = true;
32         }
33         /**
34          * @return true if exif data found
35          */
36         public boolean getExifDataPresent()
37         {
38                 return _exifDataPresent;
39         }
40
41         /**
42          * Set the latitude reference (N/S)
43          * @param inChar character representing reference
44          */
45         public void setLatitudeRef(char inChar)
46         {
47                 _latitudeRef = inChar;
48         }
49
50         /**
51          * Set the latitude reference (N/S)
52          * @param inString string containing reference
53          */
54         public void setLatitudeRef(String inString)
55         {
56                 if (inString != null && inString.length() == 1)
57                         setLatitudeRef(inString.charAt(0));
58         }
59
60         /**
61          * Set the latitude
62          * @param inValues array of three Rationals for deg-min-sec
63          */
64         public void setLatitude(Rational[] inValues)
65         {
66                 if (inValues != null && inValues.length == 3)
67                         _latitude = inValues;
68         }
69
70         /**
71          * Set the longitude reference (E/W)
72          * @param inChar character representing reference
73          */
74         public void setLongitudeRef(char inChar)
75         {
76                 _longitudeRef = inChar;
77         }
78
79         /**
80          * Set the longitude reference (E/W)
81          * @param inString string containing reference
82          */
83         public void setLongitudeRef(String inString)
84         {
85                 if (inString != null && inString.length() == 1)
86                         setLongitudeRef(inString.charAt(0));
87         }
88
89         /**
90          * Set the longitude
91          * @param inValues array of three Rationals for deg-min-sec
92          */
93         public void setLongitude(Rational[] inValues)
94         {
95                 if (inValues != null && inValues.length == 3)
96                         _longitude = inValues;
97         }
98
99         /**
100          * Set the altitude reference (sea level / not)
101          * @param inByte byte representing reference
102          */
103         public void setAltitudeRef(byte inByte)
104         {
105                 _altitudeRef = inByte;
106         }
107
108         /**
109          * Set the altitude
110          * @param inRational Rational number representing altitude
111          */
112         public void setAltitude(Rational inRational)
113         {
114                 _altitude = inRational;
115         }
116
117         /**
118          * Set the Gps timestamp
119          * @param inValues array of Rationals holding timestamp
120          */
121         public void setGpsTimestamp(Rational[] inValues)
122         {
123                 _gpsTimestamp = inValues;
124         }
125
126         /**
127          * Set the Gps datestamp
128          * @param inValues array of Rationals holding datestamp
129          */
130         public void setGpsDatestamp(Rational[] inValues)
131         {
132                 _gpsDatestamp = inValues;
133         }
134
135         /**
136          * Set the original timestamp
137          * @param inStamp original timestamp of photo
138          */
139         public void setOriginalTimestamp(String inStamp)
140         {
141                 _originalTimestamp = inStamp;
142         }
143
144         /** @return latitude ref as char */
145         public char getLatitudeRef() { return _latitudeRef; }
146         /** @return latitude as array of 3 Rationals */
147         public Rational[] getLatitude() { return _latitude; }
148         /** @return longitude ref as char */
149         public char getLongitudeRef() { return _longitudeRef; }
150         /** @return longitude as array of 3 Rationals */
151         public Rational[] getLongitude() { return _longitude; }
152         /** @return altitude ref as byte (should be 0) */
153         public byte getAltitudeRef() { return _altitudeRef; }
154         /** @return altitude as Rational */
155         public Rational getAltitude() { return _altitude; }
156         /** @return Gps timestamp as array of 3 Rationals */
157         public Rational[] getGpsTimestamp() { return _gpsTimestamp; }
158         /** @return Gps datestamp as array of 3 Rationals */
159         public Rational[] getGpsDatestamp() { return _gpsDatestamp; }
160         /** @return original timestamp as string */
161         public String getOriginalTimestamp() { return _originalTimestamp; }
162
163         /**
164          * Set the thumbnail
165          * @param inBytes byte array containing thumbnail
166          */
167         public void setThumbnailImage(byte[] inBytes) {
168                 _thumbnail = inBytes;
169         }
170         /** @return thumbnail as byte array */
171         public byte[] getThumbnailImage() {
172                 return _thumbnail;
173         }
174
175         /**
176          * @return true if data looks valid, ie has at least lat and long
177          *  (altitude and timestamp optional).
178          */
179         public boolean isValid()
180         {
181                 return (_latitudeRef == 'N' || _latitudeRef == 'n' || _latitudeRef == 'S' || _latitudeRef == 's')
182                         && _latitude != null
183                         && (_longitudeRef == 'E' || _longitudeRef == 'e' || _longitudeRef == 'W' || _longitudeRef == 'w')
184                         && _longitude != null;
185         }
186
187         /**
188          * Add the given error message to the list of errors
189          * @param inError String containing error message
190          */
191         public void addError(String inError)
192         {
193                 if (_errors == null) _errors = new ArrayList();
194                 _errors.add(inError);
195         }
196
197         /**
198          * @return the number of errors, if any
199          */
200         public int getNumErrors()
201         {
202                 if (_errors == null) return 0;
203                 return _errors.size();
204         }
205
206         /**
207          * @return true if errors occurred
208          */
209         public boolean hasErrors()
210         {
211                 return getNumErrors() > 0;
212         }
213
214         /**
215          * @return all errors as a list
216          */
217         public List getErrors()
218         {
219                 return _errors;
220         }
221 }