source: josm/trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageEntry.java@ 4932

Last change on this file since 4932 was 4241, checked in by bastiK, 13 years ago

applied #5605 - Geotagged image viewer should rotate images according to EXIF orientation tag (patch by m.zdila, some modifications)

  • Property svn:eol-style set to native
File size: 4.8 KB
Line 
1// License: GPL. See LICENSE file for details.
2// Copyright 2007 by Christian Gallioz (aka khris78)
3// Parts of code from Geotagged plugin (by Rob Neild)
4// and the core JOSM source code (by Immanuel Scholz and others)
5
6package org.openstreetmap.josm.gui.layer.geoimage;
7
8import java.awt.Image;
9import java.io.File;
10import java.util.Date;
11
12import org.openstreetmap.josm.data.coor.CachedLatLon;
13import org.openstreetmap.josm.data.coor.LatLon;
14
15/*
16 * Stores info about each image
17 */
18
19final public class ImageEntry implements Comparable<ImageEntry>, Cloneable {
20 private File file;
21 private Integer exifOrientation;
22 private LatLon exifCoor;
23 private Double exifImgDir;
24 private Date exifTime;
25 Image thumbnail;
26
27 /** The following values are computed from the correlation with the gpx track */
28 private CachedLatLon pos;
29 /** Speed in kilometer per second */
30 private Double speed;
31 /** Elevation (altitude) in meters */
32 private Double elevation;
33 /** The time after correlation with a gpx track */
34 private Date gpsTime;
35
36 /**
37 * When the corralation dialog is open, we like to show the image position
38 * for the current time offset on the map in real time.
39 * On the other hand, when the user aborts this operation, the old values
40 * should be restored. We have a temprary copy, that overrides
41 * the normal values if it is not null. (This may be not the most elegant
42 * solution for this, but it works.)
43 */
44 ImageEntry tmp;
45
46 /**
47 * getter methods that refer to the temporary value
48 */
49 public CachedLatLon getPos() {
50 if (tmp != null)
51 return tmp.pos;
52 return pos;
53 }
54 public Double getSpeed() {
55 if (tmp != null)
56 return tmp.speed;
57 return speed;
58 }
59 public Double getElevation() {
60 if (tmp != null)
61 return tmp.elevation;
62 return elevation;
63 }
64 public Date getGpsTime() {
65 if (tmp != null)
66 return tmp.gpsTime;
67 return gpsTime;
68 }
69
70 /**
71 * other getter methods
72 */
73 public File getFile() {
74 return file;
75 }
76 public Integer getExifOrientation() {
77 return exifOrientation;
78 }
79 public Date getExifTime() {
80 return exifTime;
81 }
82 LatLon getExifCoor() {
83 return exifCoor;
84 }
85 public Double getExifImgDir() {
86 return exifImgDir;
87 }
88
89 /**
90 * setter methods
91 */
92 public void setPos(CachedLatLon pos) {
93 this.pos = pos;
94 }
95 public void setPos(LatLon pos) {
96 this.pos = new CachedLatLon(pos);
97 }
98 public void setSpeed(Double speed) {
99 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}
Note: See TracBrowser for help on using the repository browser.