]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/Photo.java
Version 4, January 2008
[GpsPrune.git] / tim / prune / data / Photo.java
1 package tim.prune.data;
2
3 import java.awt.Dimension;
4 import java.io.File;
5
6 import javax.swing.ImageIcon;
7
8 /**
9  * Class to represent a photo and link to DataPoint
10  */
11 public class Photo
12 {
13         /** File where photo is stored */
14         private File _file = null;
15         /** Timestamp, if any */
16         private Timestamp _timestamp = null;
17         /** Associated DataPoint if correlated */
18         private DataPoint _dataPoint = null;
19         /** Size of original image */
20         private Dimension _size = null;
21         /** Status of photo when loaded */
22         private byte _originalStatus = PhotoStatus.NOT_CONNECTED;
23         /** Current photo status */
24         private byte _currentStatus = PhotoStatus.NOT_CONNECTED;
25         // TODO: Need to store caption for image?
26         // thumbnail for image (from exif)
27         private byte[] _exifThumbnail = null;
28
29
30         /**
31          * Constructor
32          * @param inFile File object for photo
33          */
34         public Photo(File inFile)
35         {
36                 _file = inFile;
37         }
38
39
40         /**
41          * @return File object where photo resides
42          */
43         public File getFile()
44         {
45                 return _file;
46         }
47
48
49         /**
50          * Set the data point associated with the photo
51          * @param inPoint DataPoint with coordinates etc
52          */
53         public void setDataPoint(DataPoint inPoint)
54         {
55                 _dataPoint = inPoint;
56                 // set status according to point
57                 if (inPoint == null)
58                 {
59                         setCurrentStatus(PhotoStatus.NOT_CONNECTED);
60                 }
61                 else
62                 {
63                         setCurrentStatus(PhotoStatus.CONNECTED);
64                 }
65         }
66
67         /**
68          * @return the DataPoint object
69          */
70         public DataPoint getDataPoint()
71         {
72                 return _dataPoint;
73         }
74
75         /**
76          * @param inTimestamp Timestamp of photo
77          */
78         public void setTimestamp(Timestamp inTimestamp)
79         {
80                 _timestamp = inTimestamp;
81         }
82
83         /**
84          * @return timestamp of photo
85          */
86         public Timestamp getTimestamp()
87         {
88                 return _timestamp;
89         }
90
91         /**
92          * Calculate the size of the image (slow)
93          */
94         private void calculateSize()
95         {
96                 ImageIcon icon = new ImageIcon(_file.getAbsolutePath());
97                 int width = icon.getIconWidth();
98                 int height = icon.getIconHeight();
99                 if (width > 0 && height > 0)
100                 {
101                         _size = new Dimension(width, height);
102                 }
103         }
104
105         /**
106          * @return size of image as Dimension object
107          */
108         public Dimension getSize()
109         {
110                 if (_size == null)
111                 {
112                         calculateSize();
113                 }
114                 return _size;
115         }
116
117         /**
118          * @return width of the image, if known
119          */
120         public int getWidth()
121         {
122                 if (_size == null)
123                 {
124                         calculateSize();
125                         if (_size == null) {return -1;}
126                 }
127                 return _size.width;
128         }
129
130         /**
131          * @return height of the image, if known
132          */
133         public int getHeight()
134         {
135                 if (_size == null)
136                 {
137                         calculateSize();
138                         if (_size == null) {return -1;}
139                 }
140                 return _size.height;
141         }
142
143         /**
144          * @param inStatus status of photo when loaded
145          */
146         public void setOriginalStatus(byte inStatus)
147         {
148                 _originalStatus = inStatus;
149                 _currentStatus = inStatus;
150         }
151
152         /**
153          * @return status of photo when it was loaded
154          */
155         public byte getOriginalStatus()
156         {
157                 return _originalStatus;
158         }
159
160         /**
161          * @return current status of photo
162          */
163         public byte getCurrentStatus()
164         {
165                 return _currentStatus;
166         }
167         /**
168          * @param inStatus current status of photo
169          */
170         public void setCurrentStatus(byte inStatus)
171         {
172                 _currentStatus = inStatus;
173         }
174
175         /**
176          * @return byte array of thumbnail data
177          */
178         public byte[] getExifThumbnail()
179         {
180                 return _exifThumbnail;
181         }
182
183         /**
184          * @param inBytes byte array from exif
185          */
186         public void setExifThumbnail(byte[] inBytes)
187         {
188                 _exifThumbnail = inBytes;
189         }
190
191         /**
192          * Delete the cached data when the Photo is no longer needed
193          */
194         public void resetCachedData()
195         {
196                 _size = null;
197                 // remove thumbnail too
198         }
199
200         /**
201          * Check if a Photo object refers to the same File as another
202          * @param inOther other Photo object
203          * @return true if the Files are the same
204          */
205         public boolean equals(Photo inOther)
206         {
207                 return (inOther != null && inOther.getFile() != null && getFile() != null
208                         && inOther.getFile().equals(getFile()));
209         }
210 }