Skip to content

Commit a08fa54

Browse files
author
nokutu
committed
Minor code enhances.
git-svn-id: http://svn.openstreetmap.org/applications/editors/josm/plugins/mapillary@31513 b9d5c4c9-76e1-0310-9c85-f3177eceb1e4
1 parent 57f4efb commit a08fa54

15 files changed

+503
-511
lines changed
Lines changed: 107 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.openstreetmap.josm.plugins.mapillary;
22

3-
import java.util.Date;
4-
import java.text.ParseException;
53
import java.text.SimpleDateFormat;
64
import java.util.Calendar;
5+
import java.util.Date;
76
import java.util.concurrent.locks.Lock;
87
import java.util.concurrent.locks.ReentrantLock;
98

@@ -24,7 +23,7 @@ public abstract class MapillaryAbstractImage {
2423
* {@link MapillaryAbstractImage#previous()} methods. Used when downloading
2524
* images to prevent concurrency problems.
2625
*/
27-
public static Lock LOCK = new ReentrantLock();
26+
public static final Lock LOCK = new ReentrantLock();
2827

2928
/** The time the image was captured, in Epoch format. */
3029
private long capturedAt;
@@ -34,8 +33,6 @@ public abstract class MapillaryAbstractImage {
3433
public final LatLon latLon;
3534
/** Direction of the picture. */
3635
public final double ca;
37-
/** If the image has been modified from its initial values. */
38-
public boolean isModified = false;
3936
/** Temporal position of the picture until it is uploaded. */
4037
public LatLon tempLatLon;
4138
/**
@@ -50,10 +47,11 @@ public abstract class MapillaryAbstractImage {
5047
* is stored here
5148
*/
5249
protected double movingCa;
50+
/** Whether the image must be drown in the map or not */
5351
private boolean visible;
5452

5553
/**
56-
* Main constructor of the class.
54+
* Creates a new object in the given position and with the given direction.
5755
*
5856
* @param lat
5957
* The latitude where the picture was taken.
@@ -72,87 +70,6 @@ public MapillaryAbstractImage(double lat, double lon, double ca) {
7270
this.visible = true;
7371
}
7472

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-
15673
/**
15774
* Returns the direction towards the image has been taken.
15875
*
@@ -163,12 +80,12 @@ public double getCa() {
16380
}
16481

16582
/**
166-
* Returns the last fixed direction of the object.
83+
* Returns the Epoch time when the image was captured.
16784
*
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.
16986
*/
170-
public double getTempCa() {
171-
return this.tempCa;
87+
public long getCapturedAt() {
88+
return this.capturedAt;
17289
}
17390

17491
/**
@@ -191,25 +108,6 @@ public String getDate() {
191108
return getDate(format);
192109
}
193110

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-
213111
/**
214112
* Returns the date the picture was taken in the given format.
215113
*
@@ -227,55 +125,76 @@ public String getDate(String format) {
227125
}
228126

229127
/**
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.
231130
*
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.
238132
*/
239-
public static long getEpoch(String date, String format) throws ParseException {
133+
public LatLon getLatLon() {
134+
return this.movingLatLon;
135+
}
240136

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+
}
244147

148+
return this.sequence;
245149
}
246150

247151
/**
248-
* Returns current time in Epoch format
152+
* Returns the last fixed direction of the object.
249153
*
250-
* @return The current date in Epoch format.
154+
* @return The last fixed direction of the object. 0 means north.
251155
*/
252-
protected static long currentTime() {
253-
Calendar cal = Calendar.getInstance();
254-
return cal.getTimeInMillis();
156+
public double getTempCa() {
157+
return this.tempCa;
255158
}
256159

257160
/**
258-
* Sets the MapillarySequence object which contains the MapillaryImage.
161+
* Returns the last fixed coordinates of the object.
259162
*
260-
* @param sequence
261-
* The MapillarySequence that contains the MapillaryImage.
163+
* @return A LatLon object containing.
262164
*/
263-
public void setSequence(MapillarySequence sequence) {
264-
this.sequence = sequence;
165+
public LatLon getTempLatLon() {
166+
return this.tempLatLon;
265167
}
266168

267169
/**
268-
* Returns the sequence which contains this image.
170+
* Returns whether the object has been modified or not.
269171
*
270-
* @return The MapillarySequence object that contains this MapillaryImage.
172+
* @return true if the object has been modified; false otherwise.
271173
*/
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+
}
277177

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);
279198
}
280199

281200
/**
@@ -314,4 +233,53 @@ public MapillaryAbstractImage previous() {
314233
}
315234

316235
}
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+
}
317285
}

src/org/openstreetmap/josm/plugins/mapillary/MapillaryData.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
package org.openstreetmap.josm.plugins.mapillary;
22

3+
import java.util.ArrayList;
4+
import java.util.List;
5+
import java.util.concurrent.CopyOnWriteArrayList;
6+
37
import org.openstreetmap.josm.Main;
48
import org.openstreetmap.josm.data.Bounds;
59
import org.openstreetmap.josm.plugins.mapillary.cache.CacheUtils;
610
import org.openstreetmap.josm.plugins.mapillary.gui.MapillaryMainDialog;
711

8-
import java.util.ArrayList;
9-
import java.util.List;
10-
import java.util.concurrent.CopyOnWriteArrayList;
11-
1212
/**
1313
* Database class for all the {@link MapillaryAbstractImage} objects.
1414
*
@@ -32,7 +32,7 @@ public class MapillaryData {
3232
public CopyOnWriteArrayList<Bounds> bounds;
3333

3434
/**
35-
* Main constructor.
35+
* Creates a new object and adds the initial set of listeners.
3636
*/
3737
protected MapillaryData() {
3838
this.images = new CopyOnWriteArrayList<>();
@@ -92,8 +92,8 @@ public synchronized void remove(MapillaryAbstractImage image) {
9292
* Removes a set of images from the database.
9393
*
9494
* @param images
95-
* A {@link List} of {@link MapillaryAbstractImage} objects that are going
96-
* to be removed.
95+
* A {@link List} of {@link MapillaryAbstractImage} objects that are
96+
* going to be removed.
9797
*/
9898
public synchronized void remove(List<MapillaryAbstractImage> images) {
9999
for (MapillaryAbstractImage img : images)
@@ -346,8 +346,8 @@ private void fireSelectedImageChanged(MapillaryAbstractImage oldImage,
346346
}
347347

348348
/**
349-
* Adds a {@link MapillaryImage} object to the list of selected images, (when ctrl +
350-
* click)
349+
* Adds a {@link MapillaryImage} object to the list of selected images, (when
350+
* ctrl + click)
351351
*
352352
* @param image
353353
* The {@link MapillaryImage} object to be added.

src/org/openstreetmap/josm/plugins/mapillary/MapillaryImportedImage.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public MapillaryImportedImage(double lat, double lon, double ca, File file,
5858
super(lat, lon, ca);
5959
this.file = file;
6060
try {
61-
this.datetimeOriginal = getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss");
61+
this.datetimeOriginal = MapillaryUtils.getEpoch(datetimeOriginal, "yyyy:MM:dd hh:mm:ss");
6262
} catch (ParseException e) {
6363
try {
64-
this.datetimeOriginal = getEpoch(datetimeOriginal,
64+
this.datetimeOriginal = MapillaryUtils.getEpoch(datetimeOriginal,
6565
"yyyy/MM/dd hh:mm:ss");
6666
} catch (ParseException e1) {
67-
this.datetimeOriginal = currentTime();
67+
this.datetimeOriginal = MapillaryUtils.currentTime();
6868
}
6969
}
7070
}

0 commit comments

Comments
 (0)