1 package tim.prune.data;
3 import java.awt.Dimension;
6 import javax.swing.ImageIcon;
9 * Class to represent a photo and link to DataPoint
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 Status _originalStatus = Status.NOT_CONNECTED;
23 /** Current photo status */
24 private Status _currentStatus = Status.NOT_CONNECTED;
25 // TODO: Need to store caption for image?
26 // thumbnail for image (from exif)
27 private byte[] _exifThumbnail = null;
31 /** Photo is not connected to any point */
33 /** Photo has been connected to a point since it was loaded */
35 /** Photo is connected to a point */
42 * @param inFile File object for photo
44 public Photo(File inFile)
51 * @return File object where photo resides
60 * Set the data point associated with the photo
61 * @param inPoint DataPoint with coordinates etc
63 public void setDataPoint(DataPoint inPoint)
66 // set status according to point
69 setCurrentStatus(Status.NOT_CONNECTED);
73 setCurrentStatus(Status.CONNECTED);
78 * @return the DataPoint object
80 public DataPoint getDataPoint()
86 * @param inTimestamp Timestamp of photo
88 public void setTimestamp(Timestamp inTimestamp)
90 _timestamp = inTimestamp;
94 * @return timestamp of photo
96 public Timestamp getTimestamp()
102 * Calculate the size of the image (slow)
104 private void calculateSize()
106 ImageIcon icon = new ImageIcon(_file.getAbsolutePath());
107 int width = icon.getIconWidth();
108 int height = icon.getIconHeight();
109 if (width > 0 && height > 0)
111 _size = new Dimension(width, height);
116 * @return size of image as Dimension object
118 public Dimension getSize()
128 * @return width of the image, if known
130 public int getWidth()
135 if (_size == null) {return -1;}
141 * @return height of the image, if known
143 public int getHeight()
148 if (_size == null) {return -1;}
154 * @param inStatus status of photo when loaded
156 public void setOriginalStatus(Status inStatus)
158 _originalStatus = inStatus;
159 _currentStatus = inStatus;
163 * @return status of photo when it was loaded
165 public Status getOriginalStatus()
167 return _originalStatus;
171 * @return current status of photo
173 public Status getCurrentStatus()
175 return _currentStatus;
178 * @param inStatus current status of photo
180 public void setCurrentStatus(Status inStatus)
182 _currentStatus = inStatus;
186 * @return true if photo is connected to a point
188 public boolean isConnected()
190 return _currentStatus != Status.NOT_CONNECTED;
194 * @return byte array of thumbnail data
196 public byte[] getExifThumbnail()
198 return _exifThumbnail;
202 * @param inBytes byte array from exif
204 public void setExifThumbnail(byte[] inBytes)
206 _exifThumbnail = inBytes;
210 * Delete the cached data when the Photo is no longer needed
212 public void resetCachedData()
215 // remove thumbnail too
219 * Check if a Photo object refers to the same File as another
220 * @param inOther other Photo object
221 * @return true if the Files are the same
223 public boolean equals(Photo inOther)
225 return (inOther != null && inOther.getFile() != null && getFile() != null
226 && inOther.getFile().equals(getFile()));