]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/data/Photo.java
3646cb5201ba706d3d2aae30fa021d8407a41adf
[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         // TODO: Need to store thumbnail for image?
27
28
29         /**
30          * Constructor
31          * @param inFile File object for photo
32          */
33         public Photo(File inFile)
34         {
35                 _file = inFile;
36         }
37
38
39         /**
40          * @return File object where photo resides
41          */
42         public File getFile()
43         {
44                 return _file;
45         }
46
47
48         /**
49          * Set the data point associated with the photo
50          * @param inPoint DataPoint with coordinates etc
51          */
52         public void setDataPoint(DataPoint inPoint)
53         {
54                 _dataPoint = inPoint;
55                 // set status according to point
56                 if (inPoint == null)
57                 {
58                         setCurrentStatus(PhotoStatus.NOT_CONNECTED);
59                 }
60                 else
61                 {
62                         setCurrentStatus(PhotoStatus.CONNECTED);
63                 }
64         }
65
66         /**
67          * @return the DataPoint object
68          */
69         public DataPoint getDataPoint()
70         {
71                 return _dataPoint;
72         }
73
74         /**
75          * @param inTimestamp Timestamp of photo
76          */
77         public void setTimestamp(Timestamp inTimestamp)
78         {
79                 _timestamp = inTimestamp;
80         }
81
82         /**
83          * @return timestamp of photo
84          */
85         public Timestamp getTimestamp()
86         {
87                 return _timestamp;
88         }
89
90         /**
91          * Calculate the size of the image (slow)
92          */
93         private void calculateSize()
94         {
95                 ImageIcon icon = new ImageIcon(_file.getAbsolutePath());
96                 int width = icon.getIconWidth();
97                 int height = icon.getIconHeight();
98                 if (width > 0 && height > 0)
99                 {
100                         _size = new Dimension(width, height);
101                 }
102         }
103
104         /**
105          * @return size of image as Dimension object
106          */
107         public Dimension getSize()
108         {
109                 if (_size == null)
110                 {
111                         calculateSize();
112                 }
113                 return _size;
114         }
115
116         /**
117          * @return width of the image, if known
118          */
119         public int getWidth()
120         {
121                 if (_size == null)
122                 {
123                         calculateSize();
124                         if (_size == null) {return -1;}
125                 }
126                 return _size.width;
127         }
128
129         /**
130          * @return height of the image, if known
131          */
132         public int getHeight()
133         {
134                 if (_size == null)
135                 {
136                         calculateSize();
137                         if (_size == null) {return -1;}
138                 }
139                 return _size.height;
140         }
141
142         /**
143          * @param inStatus status of photo when loaded
144          */
145         public void setOriginalStatus(byte inStatus)
146         {
147                 _originalStatus = inStatus;
148                 _currentStatus = inStatus;
149         }
150
151         /**
152          * @return status of photo when it was loaded
153          */
154         public byte getOriginalStatus()
155         {
156                 return _originalStatus;
157         }
158
159         /**
160          * @return current status of photo
161          */
162         public byte getCurrentStatus()
163         {
164                 return _currentStatus;
165         }
166         /**
167          * @param inStatus current status of photo
168          */
169         public void setCurrentStatus(byte inStatus)
170         {
171                 _currentStatus = inStatus;
172         }
173
174
175         /**
176          * Delete the cached data when the Photo is no longer needed
177          */
178         public void resetCachedData()
179         {
180                 _size = null;
181                 // remove thumbnail too
182         }
183
184         /**
185          * Check if a Photo object refers to the same File as another
186          * @param inOther other Photo object
187          * @return true if the Files are the same
188          */
189         public boolean equals(Photo inOther)
190         {
191                 return (inOther != null && inOther.getFile() != null && getFile() != null
192                         && inOther.getFile().equals(getFile()));
193         }
194 }