X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FPhoto.java;h=0c5d9e51da160610757b299c7c6eee0924cebee5;hb=649c5da6ee1bbc590699e11a92316ece2ea8512d;hp=4fdb61261b64dbc21beb3ed060b28894903e479d;hpb=112bb0c9b46894adca9a33ed8c99ea712b253185;p=GpsPrune.git diff --git a/tim/prune/data/Photo.java b/tim/prune/data/Photo.java index 4fdb612..0c5d9e5 100644 --- a/tim/prune/data/Photo.java +++ b/tim/prune/data/Photo.java @@ -8,94 +8,36 @@ 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 Status _originalStatus = Status.NOT_CONNECTED; - /** Current photo status */ - private Status _currentStatus = Status.NOT_CONNECTED; + /** rotation flag (clockwise from 0 to 3) */ + private int _rotation = 0; // TODO: Need to store caption for image? - // thumbnail for image (from exif) + /** Bearing, if any */ + private double _bearing = -1.0; + /** thumbnail for image (from exif) */ private byte[] _exifThumbnail = null; - /** Photo status */ - public enum Status { - /** Photo is not connected to any point */ - NOT_CONNECTED, - /** Photo has been connected to a point since it was loaded */ - TAGGED, - /** Photo is connected to a point */ - CONNECTED - }; - - /** * Constructor * @param inFile File object for 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(Status.NOT_CONNECTED); - } - else - { - setCurrentStatus(Status.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); } /** @@ -103,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) @@ -117,8 +63,7 @@ public class Photo */ public Dimension getSize() { - if (_size == null) - { + if (_size == null) { calculateSize(); } return _size; @@ -129,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; } @@ -142,87 +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(Status 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 Status 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 Status 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(Status inStatus) + public void setRotation(int inRotation) { - _currentStatus = inStatus; + if (inRotation >= 0 && inRotation <= 3) { + _rotation = inRotation; + } } /** - * @return true if photo is connected to a point + * Rotate the image by 90 degrees + * @param inRight true to rotate right, false for left */ - public boolean isConnected() + public void rotate(boolean inRight) { - return _currentStatus != Status.NOT_CONNECTED; + int dir = inRight?1:3; + _rotation = (_rotation + dir) % 4; } /** - * @return byte array of thumbnail data + * @return rotation status */ - public byte[] getExifThumbnail() + public int getRotationDegrees() { - return _exifThumbnail; + return _rotation * 90; } /** - * @param inBytes byte array from exif + * @return a new image icon for the whole image */ - public void setExifThumbnail(byte[] inBytes) + public ImageIcon createImageIcon() { - _exifThumbnail = inBytes; + if (_file != null) { + return new ImageIcon(_file.getAbsolutePath()); + } + if (_data != null) { + return new ImageIcon(_data); + } + return null; } /** - * Delete the cached data when the Photo is no longer needed + * @param inValue bearing in degrees, 0 to 360 */ - public void resetCachedData() - { - _size = null; - // remove thumbnail too + public void setBearing(double inValue) { + _bearing = inValue; } - /** - * 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 - */ - public boolean equals(Photo inOther) - { - return (inOther != null && inOther.getFile() != null && getFile() != null - && inOther.getFile().equals(getFile())); + /** @return bearing in degrees */ + public double getBearing() { + return _bearing; } }