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

Last change on this file since 5505 was 5505, checked in by bastiK, 12 years ago

add session support for geoimage layers (see #4029)

  • Property svn:eol-style set to native
File size: 4.9 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 public LatLon getExifCoor() {
83 return exifCoor;
84 }
85 public Double getExifImgDir() {
86 return exifImgDir;
87 }
88
89 public boolean hasThumbnail() {
90 return thumbnail != null;
91 }
92
93 /**
94 * setter methods
95 */
96 public void setPos(CachedLatLon pos) {
97 this.pos = pos;
98 }
99 public void setPos(LatLon pos) {
100 this.pos = new CachedLatLon(pos);
101 }
102 public void setSpeed(Double speed) {
103 this.speed = speed;
104 }
105 public void setElevation(Double elevation) {
106 this.elevation = elevation;
107 }
108 public void setFile(File file) {
109 this.file = file;
110 }
111 public void setExifOrientation(Integer exifOrientation) {
112 this.exifOrientation = exifOrientation;
113 }
114 public void setExifTime(Date exifTime) {
115 this.exifTime = exifTime;
116 }
117 public void setGpsTime(Date gpsTime) {
118 this.gpsTime = gpsTime;
119 }
120 public void setExifCoor(LatLon exifCoor) {
121 this.exifCoor = exifCoor;
122 }
123 public void setExifImgDir(double exifDir) {
124 this.exifImgDir = exifDir;
125 }
126
127 @Override
128 public ImageEntry clone() {
129 Object c;
130 try {
131 c = super.clone();
132 } catch (CloneNotSupportedException e) {
133 throw new RuntimeException();
134 }
135 return (ImageEntry) c;
136 }
137
138 public int compareTo(ImageEntry image) {
139 if (exifTime != null && image.exifTime != null)
140 return exifTime.compareTo(image.exifTime);
141 else if (exifTime == null && image.exifTime == null)
142 return 0;
143 else if (exifTime == null)
144 return -1;
145 else
146 return 1;
147 }
148
149 /**
150 * Make a fresh copy and save it in the temporary variable.
151 */
152 public void cleanTmp() {
153 tmp = clone();
154 tmp.setPos(null);
155 tmp.tmp = null;
156 }
157
158 /**
159 * Copy the values from the temporary variable to the main instance.
160 */
161 public void applyTmp() {
162 if (tmp != null) {
163 pos = tmp.pos;
164 speed = tmp.speed;
165 elevation = tmp.elevation;
166 gpsTime = tmp.gpsTime;
167 tmp = null;
168 }
169 }
170
171 /**
172 * If it has been tagged i.e. matched to a gpx track or retrieved lat/lon from exif
173 */
174 public boolean isTagged() {
175 return pos != null;
176 }
177
178 /**
179 * String representation. (only partial info)
180 */
181 @Override
182 public String toString() {
183 String result = file.getName()+": "+
184 "pos = "+pos+" | "+
185 "exifCoor = "+exifCoor+" | "+
186 (tmp == null ? " tmp==null" :
187 " [tmp] pos = "+tmp.pos+"");
188 return result;
189 }
190}
Note: See TracBrowser for help on using the repository browser.