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 MediaObject
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 /** Bearing, if any */
19 private double _bearing = -1.0;
20 /** thumbnail for image (from exif) */
21 private byte[] _exifThumbnail = null;
25 * @param inFile File object for photo
27 public Photo(File inFile)
33 * Constructor using data, eg from zip file or URL
34 * @param inData data as byte array
35 * @param inName name of file from which it came
36 * @param inUrl url from which it came (or null)
38 public Photo(byte[] inData, String inName, String inUrl)
40 super(inData, inName, inUrl);
44 * Calculate the size of the image (slow)
46 private void calculateSize()
48 ImageIcon icon = null;
50 icon = new ImageIcon(_file.getAbsolutePath());
52 icon = new ImageIcon(_data);
53 int width = icon.getIconWidth();
54 int height = icon.getIconHeight();
55 if (width > 0 && height > 0)
57 _size = new Dimension(width, height);
62 * @return size of image as Dimension object
64 public Dimension getSize()
73 * @return width of the image, if known
77 if (getSize() == null) {return -1;}
82 * @return height of the image, if known
84 public int getHeight()
86 if (getSize() == null) {return -1;}
91 * @return byte array of thumbnail data
93 public byte[] getExifThumbnail()
95 return _exifThumbnail;
99 * @param inBytes byte array from exif
101 public void setExifThumbnail(byte[] inBytes)
103 _exifThumbnail = inBytes;
107 * Delete the cached data when the Photo is no longer needed
109 public void resetCachedData()
112 // remove thumbnail too
116 * @param inRotation initial rotation value (from exif)
118 public void setRotation(int inRotation)
120 if (inRotation >= 0 && inRotation <= 3) {
121 _rotation = inRotation;
126 * Rotate the image by 90 degrees
127 * @param inRight true to rotate right, false for left
129 public void rotate(boolean inRight)
131 int dir = inRight?1:3;
132 _rotation = (_rotation + dir) % 4;
136 * @return rotation status
138 public int getRotationDegrees()
140 return _rotation * 90;
144 * @return a new image icon for the whole image
146 public ImageIcon createImageIcon()
149 return new ImageIcon(_file.getAbsolutePath());
152 return new ImageIcon(_data);
158 * @param inValue bearing in degrees, 0 to 360
160 public void setBearing(double inValue) {
164 /** @return bearing in degrees */
165 public double getBearing() {