001 // License: GPL. See LICENSE file for details. 002 // Copyright 2007 by Christian Gallioz (aka khris78) 003 // Parts of code from Geotagged plugin (by Rob Neild) 004 // and the core JOSM source code (by Immanuel Scholz and others) 005 006 package org.openstreetmap.josm.gui.layer.geoimage; 007 008 import java.awt.Image; 009 import java.io.File; 010 import java.util.Date; 011 012 import org.openstreetmap.josm.data.coor.CachedLatLon; 013 import org.openstreetmap.josm.data.coor.LatLon; 014 015 /* 016 * Stores info about each image 017 */ 018 019 final public class ImageEntry implements Comparable<ImageEntry>, Cloneable { 020 private File file; 021 private Integer exifOrientation; 022 private LatLon exifCoor; 023 private Double exifImgDir; 024 private Date exifTime; 025 Image thumbnail; 026 027 /** The following values are computed from the correlation with the gpx track */ 028 private CachedLatLon pos; 029 /** Speed in kilometer per second */ 030 private Double speed; 031 /** Elevation (altitude) in meters */ 032 private Double elevation; 033 /** The time after correlation with a gpx track */ 034 private Date gpsTime; 035 036 /** 037 * When the corralation dialog is open, we like to show the image position 038 * for the current time offset on the map in real time. 039 * On the other hand, when the user aborts this operation, the old values 040 * should be restored. We have a temprary copy, that overrides 041 * the normal values if it is not null. (This may be not the most elegant 042 * solution for this, but it works.) 043 */ 044 ImageEntry tmp; 045 046 /** 047 * getter methods that refer to the temporary value 048 */ 049 public CachedLatLon getPos() { 050 if (tmp != null) 051 return tmp.pos; 052 return pos; 053 } 054 public Double getSpeed() { 055 if (tmp != null) 056 return tmp.speed; 057 return speed; 058 } 059 public Double getElevation() { 060 if (tmp != null) 061 return tmp.elevation; 062 return elevation; 063 } 064 public Date getGpsTime() { 065 if (tmp != null) 066 return tmp.gpsTime; 067 return gpsTime; 068 } 069 070 /** 071 * other getter methods 072 */ 073 public File getFile() { 074 return file; 075 } 076 public Integer getExifOrientation() { 077 return exifOrientation; 078 } 079 public Date getExifTime() { 080 return exifTime; 081 } 082 LatLon getExifCoor() { 083 return exifCoor; 084 } 085 public Double getExifImgDir() { 086 return exifImgDir; 087 } 088 089 /** 090 * setter methods 091 */ 092 public void setPos(CachedLatLon pos) { 093 this.pos = pos; 094 } 095 public void setPos(LatLon pos) { 096 this.pos = new CachedLatLon(pos); 097 } 098 public void setSpeed(Double speed) { 099 this.speed = speed; 100 } 101 public void setElevation(Double elevation) { 102 this.elevation = elevation; 103 } 104 void setFile(File file) { 105 this.file = file; 106 } 107 void setExifOrientation(Integer exifOrientation) { 108 this.exifOrientation = exifOrientation; 109 } 110 void setExifTime(Date exifTime) { 111 this.exifTime = exifTime; 112 } 113 void setGpsTime(Date gpsTime) { 114 this.gpsTime = gpsTime; 115 } 116 void setExifCoor(LatLon exifCoor) { 117 this.exifCoor = exifCoor; 118 } 119 void setExifImgDir(double exifDir) { 120 this.exifImgDir = exifDir; 121 } 122 123 @Override 124 public ImageEntry clone() { 125 Object c; 126 try { 127 c = super.clone(); 128 } catch (CloneNotSupportedException e) { 129 throw new RuntimeException(); 130 } 131 return (ImageEntry) c; 132 } 133 134 public int compareTo(ImageEntry image) { 135 if (exifTime != null && image.exifTime != null) 136 return exifTime.compareTo(image.exifTime); 137 else if (exifTime == null && image.exifTime == null) 138 return 0; 139 else if (exifTime == null) 140 return -1; 141 else 142 return 1; 143 } 144 145 /** 146 * Make a fresh copy and save it in the temporary variable. 147 */ 148 public void cleanTmp() { 149 tmp = clone(); 150 tmp.setPos(null); 151 tmp.tmp = null; 152 } 153 154 /** 155 * Copy the values from the temporary variable to the main instance. 156 */ 157 public void applyTmp() { 158 if (tmp != null) { 159 pos = tmp.pos; 160 speed = tmp.speed; 161 elevation = tmp.elevation; 162 gpsTime = tmp.gpsTime; 163 tmp = null; 164 } 165 } 166 167 /** 168 * If it has been tagged i.e. matched to a gpx track or retrieved lat/lon from exif 169 */ 170 public boolean isTagged() { 171 return pos != null; 172 } 173 174 /** 175 * String representation. (only partial info) 176 */ 177 @Override 178 public String toString() { 179 String result = file.getName()+": "+ 180 "pos = "+pos+" | "+ 181 "exifCoor = "+exifCoor+" | "+ 182 (tmp == null ? " tmp==null" : 183 " [tmp] pos = "+tmp.pos+""); 184 return result; 185 } 186 }