X-Git-Url: http://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FPhoto.java;h=0c5d9e51da160610757b299c7c6eee0924cebee5;hb=649c5da6ee1bbc590699e11a92316ece2ea8512d;hp=9eacac2706a87d1c2ef451c879ddc717b6c565d6;hpb=1ee49ae3c8ef3aa2e63eadd458531e5f8bd4f92c;p=GpsPrune.git diff --git a/tim/prune/data/Photo.java b/tim/prune/data/Photo.java index 9eacac2..0c5d9e5 100644 --- a/tim/prune/data/Photo.java +++ b/tim/prune/data/Photo.java @@ -8,95 +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; - } - - - /** - * @return File object where photo resides - */ - public File getFile() - { - 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); - } + super(inFile, null); } /** - * @return the DataPoint object + * 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 DataPoint getDataPoint() + public Photo(byte[] inData, String inName, String inUrl) { - 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); } /** @@ -104,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) @@ -118,8 +63,7 @@ public class Photo */ public Dimension getSize() { - if (_size == null) - { + if (_size == null) { calculateSize(); } return _size; @@ -130,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; } @@ -143,54 +83,10 @@ 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 - */ - public void setOriginalStatus(Status inStatus) - { - _originalStatus = inStatus; - _currentStatus = inStatus; - } - - /** - * @return status of photo when it was loaded - */ - public Status getOriginalStatus() - { - return _originalStatus; - } - - /** - * @return current status of photo - */ - public Status getCurrentStatus() - { - return _currentStatus; - } - /** - * @param inStatus current status of photo - */ - public void setCurrentStatus(Status inStatus) - { - _currentStatus = inStatus; - } - - /** - * @return true if photo is connected to a point - */ - public boolean isConnected() - { - return _currentStatus != Status.NOT_CONNECTED; - } - /** * @return byte array of thumbnail data */ @@ -216,17 +112,6 @@ public class Photo // remove thumbnail too } - /** - * 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())); - } - /** * @param inRotation initial rotation value (from exif) */ @@ -254,4 +139,30 @@ public class Photo { return _rotation * 90; } + + /** + * @return a new image icon for the whole image + */ + public ImageIcon createImageIcon() + { + 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; + } }