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
11 public class Photo extends MediaFile
13 /** Size of original image */
14 private Dimension _size = null;
15 /** rotation flag (clockwise from 0 to 3) */
16 private int _rotation = 0;
17 // TODO: Need to store caption for image?
18 // thumbnail for image (from exif)
19 private byte[] _exifThumbnail = null;
23 * @param inFile File object for photo
25 public Photo(File inFile)
31 * Calculate the size of the image (slow)
33 private void calculateSize()
35 ImageIcon icon = new ImageIcon(_file.getAbsolutePath());
36 int width = icon.getIconWidth();
37 int height = icon.getIconHeight();
38 if (width > 0 && height > 0)
40 _size = new Dimension(width, height);
45 * @return size of image as Dimension object
47 public Dimension getSize()
56 * @return width of the image, if known
63 if (_size == null) {return -1;}
69 * @return height of the image, if known
71 public int getHeight()
76 if (_size == null) {return -1;}
82 * @return byte array of thumbnail data
84 public byte[] getExifThumbnail()
86 return _exifThumbnail;
90 * @param inBytes byte array from exif
92 public void setExifThumbnail(byte[] inBytes)
94 _exifThumbnail = inBytes;
98 * Delete the cached data when the Photo is no longer needed
100 public void resetCachedData()
103 // remove thumbnail too
107 * @param inRotation initial rotation value (from exif)
109 public void setRotation(int inRotation)
111 if (inRotation >= 0 && inRotation <= 3) {
112 _rotation = inRotation;
117 * Rotate the image by 90 degrees
118 * @param inRight true to rotate right, false for left
120 public void rotate(boolean inRight)
122 int dir = inRight?1:3;
123 _rotation = (_rotation + dir) % 4;
127 * @return rotation status
129 public int getRotationDegrees()
131 return _rotation * 90;