]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/data/Photo.java
Version 13, August 2011
[GpsPrune.git] / tim / prune / data / Photo.java
index 2f230cc45dae35db740159724b7bd989002dbfae..0c5d9e51da160610757b299c7c6eee0924cebee5 100644 (file)
@@ -8,84 +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 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?
-       // thumbnail for image (from exif)
+       /** Bearing, if any */
+       private double _bearing = -1.0;
+       /** thumbnail for image (from exif) */
        private byte[] _exifThumbnail = null;
 
-
        /**
         * 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(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;
+               super(inFile, null);
        }
 
        /**
-        * @return timestamp of photo
+        * 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 Timestamp getTimestamp()
+       public Photo(byte[] inData, String inName, String inUrl)
        {
-               return _timestamp;
+               super(inData, inName, inUrl);
        }
 
        /**
@@ -93,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)
@@ -107,8 +63,7 @@ public class Photo
         */
        public Dimension getSize()
        {
-               if (_size == null)
-               {
+               if (_size == null) {
                        calculateSize();
                }
                return _size;
@@ -119,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;
        }
 
@@ -132,79 +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;
+               }
        }
 
        /**
-        * @return byte array of thumbnail data
+        * Rotate the image by 90 degrees
+        * @param inRight true to rotate right, false for left
         */
-       public byte[] getExifThumbnail()
+       public void rotate(boolean inRight)
        {
-               return _exifThumbnail;
+               int dir = inRight?1:3;
+               _rotation = (_rotation + dir) % 4;
        }
 
        /**
-        * @param inBytes byte array from exif
+        * @return rotation status
         */
-       public void setExifThumbnail(byte[] inBytes)
+       public int getRotationDegrees()
        {
-               _exifThumbnail = inBytes;
+               return _rotation * 90;
        }
 
        /**
-        * Delete the cached data when the Photo is no longer needed
+        * @return a new image icon for the whole image
         */
-       public void resetCachedData()
+       public ImageIcon createImageIcon()
        {
-               _size = null;
-               // remove thumbnail too
+               if (_file != null) {
+                       return new ImageIcon(_file.getAbsolutePath());
+               }
+               if (_data != null) {
+                       return new ImageIcon(_data);
+               }
+               return null;
        }
 
        /**
-        * 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
+        * @param inValue bearing in degrees, 0 to 360
         */
-       public boolean equals(Photo inOther)
-       {
-               return (inOther != null && inOther.getFile() != null && getFile() != null
-                       && inOther.getFile().equals(getFile()));
+       public void setBearing(double inValue) {
+               _bearing = inValue;
+       }
+
+       /** @return bearing in degrees */
+       public double getBearing() {
+               return _bearing;
        }
 }