X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=tim%2Fprune%2Fdata%2FPhoto.java;h=0c5d9e51da160610757b299c7c6eee0924cebee5;hp=c9046743a704ca2629e8341ebef1d4497f878384;hb=649c5da6ee1bbc590699e11a92316ece2ea8512d;hpb=eebbb64b5d63f9eea43a0dff908c30361a376768 diff --git a/tim/prune/data/Photo.java b/tim/prune/data/Photo.java index c904674..0c5d9e5 100644 --- a/tim/prune/data/Photo.java +++ b/tim/prune/data/Photo.java @@ -8,14 +8,16 @@ import javax.swing.ImageIcon; /** * Class to represent a photo and link to DataPoint */ -public class Photo extends MediaFile +public class Photo extends MediaObject { /** 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) + /** Bearing, if any */ + private double _bearing = -1.0; + /** thumbnail for image (from exif) */ private byte[] _exifThumbnail = null; /** @@ -27,12 +29,27 @@ public class Photo extends MediaFile super(inFile, null); } + /** + * 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 Photo(byte[] inData, String inName, String inUrl) + { + super(inData, inName, inUrl); + } + /** * Calculate the size of the image (slow) */ 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) @@ -57,11 +74,7 @@ public class Photo extends MediaFile */ public int getWidth() { - if (_size == null) - { - calculateSize(); - if (_size == null) {return -1;} - } + if (getSize() == null) {return -1;} return _size.width; } @@ -70,11 +83,7 @@ public class Photo extends MediaFile */ public int getHeight() { - if (_size == null) - { - calculateSize(); - if (_size == null) {return -1;} - } + if (getSize() == null) {return -1;} return _size.height; } @@ -130,4 +139,30 @@ public class Photo extends MediaFile { 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; + } }