]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/drew/jpeg/JpegData.java
Version 2, March 2007
[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[] _timestamp = null;
20         private Rational[] _datestamp = null;
21         private ArrayList _errors = null;
22
23
24         /**
25          * Set the exif data present flag
26          */
27         public void setExifDataPresent()
28         {
29                 _exifDataPresent = true;
30         }
31         /**
32          * @return true if exif data found
33          */
34         public boolean getExifDataPresent()
35         {
36                 return _exifDataPresent;
37         }
38
39         /**
40          * Set the latitude reference (N/S)
41          * @param inChar character representing reference
42          */
43         public void setLatitudeRef(char inChar)
44         {
45                 _latitudeRef = inChar;
46         }
47
48         /**
49          * Set the latitude reference (N/S)
50          * @param inString string containing reference
51          */
52         public void setLatitudeRef(String inString)
53         {
54                 if (inString != null && inString.length() == 1)
55                         setLatitudeRef(inString.charAt(0));
56         }
57
58         /**
59          * Set the latitude
60          * @param inValues array of three Rationals for deg-min-sec
61          */
62         public void setLatitude(Rational[] inValues)
63         {
64                 if (inValues != null && inValues.length == 3)
65                         _latitude = inValues;
66         }
67
68         /**
69          * Set the longitude reference (E/W)
70          * @param inChar character representing reference
71          */
72         public void setLongitudeRef(char inChar)
73         {
74                 _longitudeRef = inChar;
75         }
76
77         /**
78          * Set the longitude reference (E/W)
79          * @param inString string containing reference
80          */
81         public void setLongitudeRef(String inString)
82         {
83                 if (inString != null && inString.length() == 1)
84                         setLongitudeRef(inString.charAt(0));
85         }
86
87         /**
88          * Set the longitude
89          * @param inValues array of three Rationals for deg-min-sec
90          */
91         public void setLongitude(Rational[] inValues)
92         {
93                 if (inValues != null && inValues.length == 3)
94                         _longitude = inValues;
95         }
96
97         /**
98          * Set the altitude reference (sea level / not)
99          * @param inByte byte representing reference
100          */
101         public void setAltitudeRef(byte inByte)
102         {
103                 _altitudeRef = inByte;
104         }
105
106         /**
107          * Set the altitude
108          * @param inRational Rational number representing altitude
109          */
110         public void setAltitude(Rational inRational)
111         {
112                 _altitude = inRational;
113         }
114
115         /**
116          * Set the timestamp
117          * @param inValues array of Rationals holding timestamp
118          */
119         public void setTimestamp(Rational[] inValues)
120         {
121                 _timestamp = inValues;
122         }
123
124         /**
125          * Set the datestamp
126          * @param inValues array of Rationals holding datestamp
127          */
128         public void setDatestamp(Rational[] inValues)
129         {
130                 _datestamp = inValues;
131         }
132
133         /** @return latitude ref as char */
134         public char getLatitudeRef() { return _latitudeRef; }
135         /** @return latitude as array of 3 Rationals */
136         public Rational[] getLatitude() { return _latitude; }
137         /** @return longitude ref as char */
138         public char getLongitudeRef() { return _longitudeRef; }
139         /** @return longitude as array of 3 Rationals */
140         public Rational[] getLongitude() { return _longitude; }
141         /** @return altitude ref as byte (should be 0) */
142         public byte getAltitudeRef() { return _altitudeRef; }
143         /** @return altitude as Rational */
144         public Rational getAltitude() { return _altitude; }
145         /** @return timestamp as array of 3 Rationals */
146         public Rational[] getTimestamp() { return _timestamp; }
147         /** @return timestamp as array of 3 Rationals */
148         public Rational[] getDatestamp() { return _datestamp; }
149
150         /**
151          * @return true if data looks valid, ie has at least lat and long
152          *  (altitude and timestamp optional).
153          */
154         public boolean isValid()
155         {
156                 return (_latitudeRef == 'N' || _latitudeRef == 'n' || _latitudeRef == 'S' || _latitudeRef == 's')
157                         && _latitude != null
158                         && (_longitudeRef == 'E' || _longitudeRef == 'e' || _longitudeRef == 'W' || _longitudeRef == 'w')
159                         && _longitude != null;
160         }
161
162         /**
163          * Add the given error message to the list of errors
164          * @param inError String containing error message
165          */
166         public void addError(String inError)
167         {
168                 if (_errors == null) _errors = new ArrayList();
169                 _errors.add(inError);
170         }
171
172         /**
173          * @return the number of errors, if any
174          */
175         public int getNumErrors()
176         {
177                 if (_errors == null) return 0;
178                 return _errors.size();
179         }
180
181         /**
182          * @return true if errors occurred
183          */
184         public boolean hasErrors()
185         {
186                 return getNumErrors() > 0;
187         }
188
189         /**
190          * @return all errors as a list
191          */
192         public List getErrors()
193         {
194                 return _errors;
195         }
196 }