X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FPhoto.java;h=0c5d9e51da160610757b299c7c6eee0924cebee5;hb=649c5da6ee1bbc590699e11a92316ece2ea8512d;hp=3646cb5201ba706d3d2aae30fa021d8407a41adf;hpb=5625a1abadb5f2ca5f017fe7dbda1d5141cb637b;p=GpsPrune.git diff --git a/tim/prune/data/Photo.java b/tim/prune/data/Photo.java index 3646cb5..0c5d9e5 100644 --- a/tim/prune/data/Photo.java +++ b/tim/prune/data/Photo.java @@ -8,23 +8,17 @@ import javax.swing.ImageIcon; /** * Class to represent a photo and link to DataPoint */ -public class Photo +public class Photo extends MediaObject { - /** File where photo is stored */ - private File _file = null; - /** Timestamp, if any */ - private Timestamp _timestamp = null; - /** Associated DataPoint if correlated */ - private DataPoint _dataPoint = null; /** Size of original image */ private Dimension _size = null; - /** Status of photo when loaded */ - private byte _originalStatus = PhotoStatus.NOT_CONNECTED; - /** Current photo status */ - private byte _currentStatus = PhotoStatus.NOT_CONNECTED; + /** rotation flag (clockwise from 0 to 3) */ + private int _rotation = 0; // TODO: Need to store caption for image? - // TODO: Need to store thumbnail for image? - + /** Bearing, if any */ + private double _bearing = -1.0; + /** thumbnail for image (from exif) */ + private byte[] _exifThumbnail = null; /** * Constructor @@ -32,59 +26,18 @@ public class Photo */ public Photo(File inFile) { - _file = inFile; + super(inFile, null); } - /** - * @return File object where photo resides + * Constructor using data, eg from zip file or URL + * @param inData data as byte array + * @param inName name of file from which it came + * @param inUrl url from which it came (or null) */ - public File getFile() + public Photo(byte[] inData, String inName, String inUrl) { - return _file; - } - - - /** - * Set the data point associated with the photo - * @param inPoint DataPoint with coordinates etc - */ - public void setDataPoint(DataPoint inPoint) - { - _dataPoint = inPoint; - // set status according to point - if (inPoint == null) - { - setCurrentStatus(PhotoStatus.NOT_CONNECTED); - } - else - { - setCurrentStatus(PhotoStatus.CONNECTED); - } - } - - /** - * @return the DataPoint object - */ - public DataPoint getDataPoint() - { - return _dataPoint; - } - - /** - * @param inTimestamp Timestamp of photo - */ - public void setTimestamp(Timestamp inTimestamp) - { - _timestamp = inTimestamp; - } - - /** - * @return timestamp of photo - */ - public Timestamp getTimestamp() - { - return _timestamp; + super(inData, inName, inUrl); } /** @@ -92,7 +45,11 @@ public class Photo */ private void calculateSize() { - ImageIcon icon = new ImageIcon(_file.getAbsolutePath()); + ImageIcon icon = null; + if (_file != null) + icon = new ImageIcon(_file.getAbsolutePath()); + else + icon = new ImageIcon(_data); int width = icon.getIconWidth(); int height = icon.getIconHeight(); if (width > 0 && height > 0) @@ -106,8 +63,7 @@ public class Photo */ public Dimension getSize() { - if (_size == null) - { + if (_size == null) { calculateSize(); } return _size; @@ -118,11 +74,7 @@ public class Photo */ public int getWidth() { - if (_size == null) - { - calculateSize(); - if (_size == null) {return -1;} - } + if (getSize() == null) {return -1;} return _size.width; } @@ -131,64 +83,86 @@ public class Photo */ public int getHeight() { - if (_size == null) - { - calculateSize(); - if (_size == null) {return -1;} - } + if (getSize() == null) {return -1;} return _size.height; } /** - * @param inStatus status of photo when loaded + * @return byte array of thumbnail data */ - public void setOriginalStatus(byte inStatus) + public byte[] getExifThumbnail() { - _originalStatus = inStatus; - _currentStatus = inStatus; + return _exifThumbnail; } /** - * @return status of photo when it was loaded + * @param inBytes byte array from exif */ - public byte getOriginalStatus() + public void setExifThumbnail(byte[] inBytes) { - return _originalStatus; + _exifThumbnail = inBytes; } /** - * @return current status of photo + * Delete the cached data when the Photo is no longer needed */ - public byte getCurrentStatus() + public void resetCachedData() { - return _currentStatus; + _size = null; + // remove thumbnail too } + /** - * @param inStatus current status of photo + * @param inRotation initial rotation value (from exif) */ - public void setCurrentStatus(byte inStatus) + public void setRotation(int inRotation) { - _currentStatus = inStatus; + if (inRotation >= 0 && inRotation <= 3) { + _rotation = inRotation; + } } + /** + * Rotate the image by 90 degrees + * @param inRight true to rotate right, false for left + */ + public void rotate(boolean inRight) + { + int dir = inRight?1:3; + _rotation = (_rotation + dir) % 4; + } /** - * Delete the cached data when the Photo is no longer needed + * @return rotation status */ - public void resetCachedData() + public int getRotationDegrees() { - _size = null; - // remove thumbnail too + return _rotation * 90; } /** - * 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 a new image icon for the whole image */ - public boolean equals(Photo inOther) + public ImageIcon createImageIcon() { - return (inOther != null && inOther.getFile() != null && getFile() != null - && inOther.getFile().equals(getFile())); + if (_file != null) { + return new ImageIcon(_file.getAbsolutePath()); + } + if (_data != null) { + return new ImageIcon(_data); + } + return null; + } + + /** + * @param inValue bearing in degrees, 0 to 360 + */ + public void setBearing(double inValue) { + _bearing = inValue; + } + + /** @return bearing in degrees */ + public double getBearing() { + return _bearing; } }