X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FPhoto.java;h=c9046743a704ca2629e8341ebef1d4497f878384;hb=f35b6d628f68e3b5ef19965ad8988d0dd1eb8efa;hp=52743f7a34659d40bd6aebb46b85759b0b524902;hpb=23959e65a6a0d581e657b07186d18b7a1ac5afeb;p=GpsPrune.git diff --git a/tim/prune/data/Photo.java b/tim/prune/data/Photo.java index 52743f7..c904674 100644 --- a/tim/prune/data/Photo.java +++ b/tim/prune/data/Photo.java @@ -1,17 +1,22 @@ package tim.prune.data; +import java.awt.Dimension; import java.io.File; +import javax.swing.ImageIcon; + /** * Class to represent a photo and link to DataPoint */ -public class Photo +public class Photo extends MediaFile { - /** File where photo is stored */ - private File _file = null; - /** Associated DataPoint if correlated */ - private DataPoint _dataPoint = null; - + /** Size of original image */ + private Dimension _size = null; + /** rotation flag (clockwise from 0 to 3) */ + private int _rotation = 0; + // TODO: Need to store caption for image? + // thumbnail for image (from exif) + private byte[] _exifThumbnail = null; /** * Constructor @@ -19,45 +24,110 @@ public class Photo */ public Photo(File inFile) { - _file = inFile; - // TODO: Cache photo file contents to allow thumbnail preview + super(inFile, null); + } + + /** + * Calculate the size of the image (slow) + */ + private void calculateSize() + { + ImageIcon icon = new ImageIcon(_file.getAbsolutePath()); + int width = icon.getIconWidth(); + int height = icon.getIconHeight(); + if (width > 0 && height > 0) + { + _size = new Dimension(width, height); + } + } + + /** + * @return size of image as Dimension object + */ + public Dimension getSize() + { + if (_size == null) { + calculateSize(); + } + return _size; + } + + /** + * @return width of the image, if known + */ + public int getWidth() + { + if (_size == null) + { + calculateSize(); + if (_size == null) {return -1;} + } + return _size.width; } + /** + * @return height of the image, if known + */ + public int getHeight() + { + if (_size == null) + { + calculateSize(); + if (_size == null) {return -1;} + } + return _size.height; + } /** - * @return File object where photo resides + * @return byte array of thumbnail data */ - public File getFile() + public byte[] getExifThumbnail() { - return _file; + return _exifThumbnail; } + /** + * @param inBytes byte array from exif + */ + public void setExifThumbnail(byte[] inBytes) + { + _exifThumbnail = inBytes; + } + + /** + * Delete the cached data when the Photo is no longer needed + */ + public void resetCachedData() + { + _size = null; + // remove thumbnail too + } /** - * Set the data point associated with the photo - * @param inPoint DataPoint with coordinates etc + * @param inRotation initial rotation value (from exif) */ - public void setDataPoint(DataPoint inPoint) + public void setRotation(int inRotation) { - _dataPoint = inPoint; + if (inRotation >= 0 && inRotation <= 3) { + _rotation = inRotation; + } } /** - * @return the DataPoint object + * Rotate the image by 90 degrees + * @param inRight true to rotate right, false for left */ - public DataPoint getDataPoint() + public void rotate(boolean inRight) { - return _dataPoint; + int dir = inRight?1:3; + _rotation = (_rotation + dir) % 4; } /** - * Check if a Photo object refers to the same File as another - * @param inOther other Photo object - * @return true if the Files are the same + * @return rotation status */ - public boolean equals(Photo inOther) + public int getRotationDegrees() { - return (inOther != null && inOther.getFile() != null && getFile() != null - && inOther.getFile().equals(getFile())); + return _rotation * 90; } }