1
1
package org .openstreetmap .josm .plugins .mapillary ;
2
2
3
- import java .util .Date ;
4
- import java .text .ParseException ;
5
3
import java .text .SimpleDateFormat ;
6
4
import java .util .Calendar ;
5
+ import java .util .Date ;
7
6
import java .util .concurrent .locks .Lock ;
8
7
import java .util .concurrent .locks .ReentrantLock ;
9
8
@@ -24,7 +23,7 @@ public abstract class MapillaryAbstractImage {
24
23
* {@link MapillaryAbstractImage#previous()} methods. Used when downloading
25
24
* images to prevent concurrency problems.
26
25
*/
27
- public static Lock LOCK = new ReentrantLock ();
26
+ public static final Lock LOCK = new ReentrantLock ();
28
27
29
28
/** The time the image was captured, in Epoch format. */
30
29
private long capturedAt ;
@@ -34,8 +33,6 @@ public abstract class MapillaryAbstractImage {
34
33
public final LatLon latLon ;
35
34
/** Direction of the picture. */
36
35
public final double ca ;
37
- /** If the image has been modified from its initial values. */
38
- public boolean isModified = false ;
39
36
/** Temporal position of the picture until it is uploaded. */
40
37
public LatLon tempLatLon ;
41
38
/**
@@ -50,10 +47,11 @@ public abstract class MapillaryAbstractImage {
50
47
* is stored here
51
48
*/
52
49
protected double movingCa ;
50
+ /** Whether the image must be drown in the map or not */
53
51
private boolean visible ;
54
52
55
53
/**
56
- * Main constructor of the class .
54
+ * Creates a new object in the given position and with the given direction .
57
55
*
58
56
* @param lat
59
57
* The latitude where the picture was taken.
@@ -72,87 +70,6 @@ public MapillaryAbstractImage(double lat, double lon, double ca) {
72
70
this .visible = true ;
73
71
}
74
72
75
- /**
76
- * Returns whether the object has been modified or not.
77
- *
78
- * @return true if the object has been modified; false otherwise.
79
- */
80
- public boolean isModified () {
81
- return this .isModified ;
82
- }
83
-
84
- /**
85
- * Returns a LatLon object containing the current coordinates of the object.
86
- * When you are dragging the image this changes.
87
- *
88
- * @return The LatLon object with the position of the object.
89
- */
90
- public LatLon getLatLon () {
91
- return this .movingLatLon ;
92
- }
93
-
94
- /**
95
- * Returns whether the image is visible on the map or not.
96
- *
97
- * @return True if the image is visible; false otherwise.
98
- */
99
- public boolean isVisible () {
100
- return this .visible ;
101
- }
102
-
103
- /**
104
- * Set's whether the image should be visible on the map or not.
105
- *
106
- * @param visible
107
- * true if the image is set to be visible; false otherwise.
108
- */
109
- public void setVisible (boolean visible ) {
110
- this .visible = visible ;
111
- }
112
-
113
- /**
114
- * Returns the last fixed coordinates of the object.
115
- *
116
- * @return A LatLon object containing.
117
- */
118
- public LatLon getTempLatLon () {
119
- return this .tempLatLon ;
120
- }
121
-
122
- /**
123
- * Moves the image temporally to another position
124
- *
125
- * @param x
126
- * The movement of the image in longitude units.
127
- * @param y
128
- * The movement of the image in latitude units.
129
- */
130
- public void move (double x , double y ) {
131
- this .movingLatLon = new LatLon (this .tempLatLon .getY () + y ,
132
- this .tempLatLon .getX () + x );
133
- this .isModified = true ;
134
- }
135
-
136
- /**
137
- * Turns the image direction.
138
- *
139
- * @param ca
140
- * The angle the image is moving.
141
- */
142
- public void turn (double ca ) {
143
- this .movingCa = this .tempCa + ca ;
144
- this .isModified = true ;
145
- }
146
-
147
- /**
148
- * Called when the mouse button is released, meaning that the picture has
149
- * stopped being dragged.
150
- */
151
- public void stopMoving () {
152
- this .tempLatLon = this .movingLatLon ;
153
- this .tempCa = this .movingCa ;
154
- }
155
-
156
73
/**
157
74
* Returns the direction towards the image has been taken.
158
75
*
@@ -163,12 +80,12 @@ public double getCa() {
163
80
}
164
81
165
82
/**
166
- * Returns the last fixed direction of the object .
83
+ * Returns the Epoch time when the image was captured .
167
84
*
168
- * @return The last fixed direction of the object. 0 means north .
85
+ * @return The long containing the Epoch time when the image was captured .
169
86
*/
170
- public double getTempCa () {
171
- return this .tempCa ;
87
+ public long getCapturedAt () {
88
+ return this .capturedAt ;
172
89
}
173
90
174
91
/**
@@ -191,25 +108,6 @@ public String getDate() {
191
108
return getDate (format );
192
109
}
193
110
194
- /**
195
- * Sets the Epoch time when the picture was captured.
196
- *
197
- * @param capturedAt
198
- * Epoch time when the image was captured.
199
- */
200
- public void setCapturedAt (long capturedAt ) {
201
- this .capturedAt = capturedAt ;
202
- }
203
-
204
- /**
205
- * Returns the Epoch time when the image was captured.
206
- *
207
- * @return The long containing the Epoch time when the image was captured.
208
- */
209
- public long getCapturedAt () {
210
- return this .capturedAt ;
211
- }
212
-
213
111
/**
214
112
* Returns the date the picture was taken in the given format.
215
113
*
@@ -227,55 +125,76 @@ public String getDate(String format) {
227
125
}
228
126
229
127
/**
230
- * Parses a string with a given format and returns the Epoch time.
128
+ * Returns a LatLon object containing the current coordinates of the object.
129
+ * When you are dragging the image this changes.
231
130
*
232
- * @param date
233
- * The string containing the date.
234
- * @param format
235
- * The format of the date.
236
- * @return The date in Epoch format.
237
- * @throws ParseException
131
+ * @return The LatLon object with the position of the object.
238
132
*/
239
- public static long getEpoch (String date , String format ) throws ParseException {
133
+ public LatLon getLatLon () {
134
+ return this .movingLatLon ;
135
+ }
240
136
241
- SimpleDateFormat formatter = new SimpleDateFormat (format );
242
- Date dateTime = formatter .parse (date );
243
- return dateTime .getTime ();
137
+ /**
138
+ * Returns the sequence which contains this image.
139
+ *
140
+ * @return The MapillarySequence object that contains this MapillaryImage.
141
+ */
142
+ public MapillarySequence getSequence () {
143
+ if (this .sequence == null ) {
144
+ this .sequence = new MapillarySequence ();
145
+ this .sequence .add (this );
146
+ }
244
147
148
+ return this .sequence ;
245
149
}
246
150
247
151
/**
248
- * Returns current time in Epoch format
152
+ * Returns the last fixed direction of the object.
249
153
*
250
- * @return The current date in Epoch format .
154
+ * @return The last fixed direction of the object. 0 means north .
251
155
*/
252
- protected static long currentTime () {
253
- Calendar cal = Calendar .getInstance ();
254
- return cal .getTimeInMillis ();
156
+ public double getTempCa () {
157
+ return this .tempCa ;
255
158
}
256
159
257
160
/**
258
- * Sets the MapillarySequence object which contains the MapillaryImage .
161
+ * Returns the last fixed coordinates of the object .
259
162
*
260
- * @param sequence
261
- * The MapillarySequence that contains the MapillaryImage.
163
+ * @return A LatLon object containing.
262
164
*/
263
- public void setSequence ( MapillarySequence sequence ) {
264
- this .sequence = sequence ;
165
+ public LatLon getTempLatLon ( ) {
166
+ return this .tempLatLon ;
265
167
}
266
168
267
169
/**
268
- * Returns the sequence which contains this image .
170
+ * Returns whether the object has been modified or not .
269
171
*
270
- * @return The MapillarySequence object that contains this MapillaryImage .
172
+ * @return true if the object has been modified; false otherwise .
271
173
*/
272
- public MapillarySequence getSequence () {
273
- if (this .sequence == null ) {
274
- this .sequence = new MapillarySequence ();
275
- this .sequence .add (this );
276
- }
174
+ public boolean isModified () {
175
+ return (this .getLatLon () != this .latLon || this .getCa () != this .ca );
176
+ }
277
177
278
- return this .sequence ;
178
+ /**
179
+ * Returns whether the image is visible on the map or not.
180
+ *
181
+ * @return True if the image is visible; false otherwise.
182
+ */
183
+ public boolean isVisible () {
184
+ return this .visible ;
185
+ }
186
+
187
+ /**
188
+ * Moves the image temporally to another position
189
+ *
190
+ * @param x
191
+ * The movement of the image in longitude units.
192
+ * @param y
193
+ * The movement of the image in latitude units.
194
+ */
195
+ public void move (double x , double y ) {
196
+ this .movingLatLon = new LatLon (this .tempLatLon .getY () + y ,
197
+ this .tempLatLon .getX () + x );
279
198
}
280
199
281
200
/**
@@ -314,4 +233,53 @@ public MapillaryAbstractImage previous() {
314
233
}
315
234
316
235
}
236
+
237
+ /**
238
+ * Sets the Epoch time when the picture was captured.
239
+ *
240
+ * @param capturedAt
241
+ * Epoch time when the image was captured.
242
+ */
243
+ public void setCapturedAt (long capturedAt ) {
244
+ this .capturedAt = capturedAt ;
245
+ }
246
+
247
+ /**
248
+ * Sets the MapillarySequence object which contains the MapillaryImage.
249
+ *
250
+ * @param sequence
251
+ * The MapillarySequence that contains the MapillaryImage.
252
+ */
253
+ public void setSequence (MapillarySequence sequence ) {
254
+ this .sequence = sequence ;
255
+ }
256
+
257
+ /**
258
+ * Set's whether the image should be visible on the map or not.
259
+ *
260
+ * @param visible
261
+ * true if the image is set to be visible; false otherwise.
262
+ */
263
+ public void setVisible (boolean visible ) {
264
+ this .visible = visible ;
265
+ }
266
+
267
+ /**
268
+ * Called when the mouse button is released, meaning that the picture has
269
+ * stopped being dragged, so the temporal values are saved.
270
+ */
271
+ public void stopMoving () {
272
+ this .tempLatLon = this .movingLatLon ;
273
+ this .tempCa = this .movingCa ;
274
+ }
275
+
276
+ /**
277
+ * Turns the image direction.
278
+ *
279
+ * @param ca
280
+ * The angle the image is moving.
281
+ */
282
+ public void turn (double ca ) {
283
+ this .movingCa = this .tempCa + ca ;
284
+ }
317
285
}
0 commit comments