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 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;
32 * @param inFile File object for photo
34 public Photo(File inFile)
41 * @return File object where photo resides
50 * Set the data point associated with the photo
51 * @param inPoint DataPoint with coordinates etc
53 public void setDataPoint(DataPoint inPoint)
56 // set status according to point
59 setCurrentStatus(PhotoStatus.NOT_CONNECTED);
63 setCurrentStatus(PhotoStatus.CONNECTED);
68 * @return the DataPoint object
70 public DataPoint getDataPoint()
76 * @param inTimestamp Timestamp of photo
78 public void setTimestamp(Timestamp inTimestamp)
80 _timestamp = inTimestamp;
84 * @return timestamp of photo
86 public Timestamp getTimestamp()
92 * Calculate the size of the image (slow)
94 private void calculateSize()
96 ImageIcon icon = new ImageIcon(_file.getAbsolutePath());
97 int width = icon.getIconWidth();
98 int height = icon.getIconHeight();
99 if (width > 0 && height > 0)
101 _size = new Dimension(width, height);
106 * @return size of image as Dimension object
108 public Dimension getSize()
118 * @return width of the image, if known
120 public int getWidth()
125 if (_size == null) {return -1;}
131 * @return height of the image, if known
133 public int getHeight()
138 if (_size == null) {return -1;}
144 * @param inStatus status of photo when loaded
146 public void setOriginalStatus(byte inStatus)
148 _originalStatus = inStatus;
149 _currentStatus = inStatus;
153 * @return status of photo when it was loaded
155 public byte getOriginalStatus()
157 return _originalStatus;
161 * @return current status of photo
163 public byte getCurrentStatus()
165 return _currentStatus;
168 * @param inStatus current status of photo
170 public void setCurrentStatus(byte inStatus)
172 _currentStatus = inStatus;
176 * @return byte array of thumbnail data
178 public byte[] getExifThumbnail()
180 return _exifThumbnail;
184 * @param inBytes byte array from exif
186 public void setExifThumbnail(byte[] inBytes)
188 _exifThumbnail = inBytes;
192 * Delete the cached data when the Photo is no longer needed
194 public void resetCachedData()
197 // remove thumbnail too
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
205 public boolean equals(Photo inOther)
207 return (inOther != null && inOther.getFile() != null && getFile() != null
208 && inOther.getFile().equals(getFile()));