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 // TODO: Need to store thumbnail for image?
31 * @param inFile File object for photo
33 public Photo(File inFile)
40 * @return File object where photo resides
49 * Set the data point associated with the photo
50 * @param inPoint DataPoint with coordinates etc
52 public void setDataPoint(DataPoint inPoint)
55 // set status according to point
58 setCurrentStatus(PhotoStatus.NOT_CONNECTED);
62 setCurrentStatus(PhotoStatus.CONNECTED);
67 * @return the DataPoint object
69 public DataPoint getDataPoint()
75 * @param inTimestamp Timestamp of photo
77 public void setTimestamp(Timestamp inTimestamp)
79 _timestamp = inTimestamp;
83 * @return timestamp of photo
85 public Timestamp getTimestamp()
91 * Calculate the size of the image (slow)
93 private void calculateSize()
95 ImageIcon icon = new ImageIcon(_file.getAbsolutePath());
96 int width = icon.getIconWidth();
97 int height = icon.getIconHeight();
98 if (width > 0 && height > 0)
100 _size = new Dimension(width, height);
105 * @return size of image as Dimension object
107 public Dimension getSize()
117 * @return width of the image, if known
119 public int getWidth()
124 if (_size == null) {return -1;}
130 * @return height of the image, if known
132 public int getHeight()
137 if (_size == null) {return -1;}
143 * @param inStatus status of photo when loaded
145 public void setOriginalStatus(byte inStatus)
147 _originalStatus = inStatus;
148 _currentStatus = inStatus;
152 * @return status of photo when it was loaded
154 public byte getOriginalStatus()
156 return _originalStatus;
160 * @return current status of photo
162 public byte getCurrentStatus()
164 return _currentStatus;
167 * @param inStatus current status of photo
169 public void setCurrentStatus(byte inStatus)
171 _currentStatus = inStatus;
176 * Delete the cached data when the Photo is no longer needed
178 public void resetCachedData()
181 // remove thumbnail too
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
189 public boolean equals(Photo inOther)
191 return (inOther != null && inOther.getFile() != null && getFile() != null
192 && inOther.getFile().equals(getFile()));