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 /** rotation flag (clockwise from 0 to 3) */
26 private int _rotation = 0;
27 // TODO: Need to store caption for image?
28 // thumbnail for image (from exif)
29 private byte[] _exifThumbnail = null;
33 /** Photo is not connected to any point */
35 /** Photo has been connected to a point since it was loaded */
37 /** Photo is connected to a point */
43 * @param inFile File object for photo
45 public Photo(File inFile)
52 * @return File object where photo resides
61 * Set the data point associated with the photo
62 * @param inPoint DataPoint with coordinates etc
64 public void setDataPoint(DataPoint inPoint)
67 // set status according to point
68 if (inPoint == null) {
69 setCurrentStatus(Status.NOT_CONNECTED);
72 setCurrentStatus(Status.CONNECTED);
77 * @return the DataPoint object
79 public DataPoint getDataPoint()
85 * @param inTimestamp Timestamp of photo
87 public void setTimestamp(Timestamp inTimestamp)
89 _timestamp = inTimestamp;
93 * @return timestamp of photo
95 public Timestamp getTimestamp()
101 * Calculate the size of the image (slow)
103 private void calculateSize()
105 ImageIcon icon = new ImageIcon(_file.getAbsolutePath());
106 int width = icon.getIconWidth();
107 int height = icon.getIconHeight();
108 if (width > 0 && height > 0)
110 _size = new Dimension(width, height);
115 * @return size of image as Dimension object
117 public Dimension getSize()
127 * @return width of the image, if known
129 public int getWidth()
134 if (_size == null) {return -1;}
140 * @return height of the image, if known
142 public int getHeight()
147 if (_size == null) {return -1;}
153 * @param inStatus status of photo when loaded
155 public void setOriginalStatus(Status inStatus)
157 _originalStatus = inStatus;
158 _currentStatus = inStatus;
162 * @return status of photo when it was loaded
164 public Status getOriginalStatus()
166 return _originalStatus;
170 * @return current status of photo
172 public Status getCurrentStatus()
174 return _currentStatus;
177 * @param inStatus current status of photo
179 public void setCurrentStatus(Status inStatus)
181 _currentStatus = inStatus;
185 * @return true if photo is connected to a point
187 public boolean isConnected()
189 return _currentStatus != Status.NOT_CONNECTED;
193 * @return byte array of thumbnail data
195 public byte[] getExifThumbnail()
197 return _exifThumbnail;
201 * @param inBytes byte array from exif
203 public void setExifThumbnail(byte[] inBytes)
205 _exifThumbnail = inBytes;
209 * Delete the cached data when the Photo is no longer needed
211 public void resetCachedData()
214 // remove thumbnail too
218 * Check if a Photo object refers to the same File as another
219 * @param inOther other Photo object
220 * @return true if the Files are the same
222 public boolean equals(Photo inOther)
224 return (inOther != null && inOther.getFile() != null && getFile() != null
225 && inOther.getFile().equals(getFile()));
229 * @param inRotation initial rotation value (from exif)
231 public void setRotation(int inRotation)
233 if (inRotation >= 0 && inRotation <= 3) {
234 _rotation = inRotation;
239 * Rotate the image by 90 degrees
240 * @param inRight true to rotate right, false for left
242 public void rotate(boolean inRight)
244 int dir = inRight?1:3;
245 _rotation = (_rotation + dir) % 4;
249 * @return rotation status
251 public int getRotationDegrees()
253 return _rotation * 90;