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
70 setCurrentStatus(Status.NOT_CONNECTED);
74 setCurrentStatus(Status.CONNECTED);
79 * @return the DataPoint object
81 public DataPoint getDataPoint()
87 * @param inTimestamp Timestamp of photo
89 public void setTimestamp(Timestamp inTimestamp)
91 _timestamp = inTimestamp;
95 * @return timestamp of photo
97 public Timestamp getTimestamp()
103 * Calculate the size of the image (slow)
105 private void calculateSize()
107 ImageIcon icon = new ImageIcon(_file.getAbsolutePath());
108 int width = icon.getIconWidth();
109 int height = icon.getIconHeight();
110 if (width > 0 && height > 0)
112 _size = new Dimension(width, height);
117 * @return size of image as Dimension object
119 public Dimension getSize()
129 * @return width of the image, if known
131 public int getWidth()
136 if (_size == null) {return -1;}
142 * @return height of the image, if known
144 public int getHeight()
149 if (_size == null) {return -1;}
155 * @param inStatus status of photo when loaded
157 public void setOriginalStatus(Status inStatus)
159 _originalStatus = inStatus;
160 _currentStatus = inStatus;
164 * @return status of photo when it was loaded
166 public Status getOriginalStatus()
168 return _originalStatus;
172 * @return current status of photo
174 public Status getCurrentStatus()
176 return _currentStatus;
179 * @param inStatus current status of photo
181 public void setCurrentStatus(Status inStatus)
183 _currentStatus = inStatus;
187 * @return true if photo is connected to a point
189 public boolean isConnected()
191 return _currentStatus != Status.NOT_CONNECTED;
195 * @return byte array of thumbnail data
197 public byte[] getExifThumbnail()
199 return _exifThumbnail;
203 * @param inBytes byte array from exif
205 public void setExifThumbnail(byte[] inBytes)
207 _exifThumbnail = inBytes;
211 * Delete the cached data when the Photo is no longer needed
213 public void resetCachedData()
216 // remove thumbnail too
220 * Check if a Photo object refers to the same File as another
221 * @param inOther other Photo object
222 * @return true if the Files are the same
224 public boolean equals(Photo inOther)
226 return (inOther != null && inOther.getFile() != null && getFile() != null
227 && inOther.getFile().equals(getFile()));
231 * @param inRotation initial rotation value (from exif)
233 public void setRotation(int inRotation)
235 if (inRotation >= 0 && inRotation <= 3) {
236 _rotation = inRotation;
241 * Rotate the image by 90 degrees
242 * @param inRight true to rotate right, false for left
244 public void rotate(boolean inRight)
246 int dir = inRight?1:3;
247 _rotation = (_rotation + dir) % 4;
251 * @return rotation status
253 public int getRotationDegrees()
255 return _rotation * 90;