Changeset 1169 in josm for trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
- Timestamp:
- 2008-12-23T15:07:05+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r1167 r1169 15 15 public class WayPoint extends WithAttributes implements Comparable<WayPoint> 16 16 { 17 18 19 20 21 22 17 public final LatLon latlon; 18 public final EastNorth eastNorth; 19 public double time; 20 public Color speedLineColor; 21 public boolean drawLine; 22 public int dir; 23 23 24 25 26 27 24 public WayPoint(LatLon ll) { 25 latlon = ll; 26 eastNorth = Main.proj.latlon2eastNorth(ll); 27 } 28 28 29 @Override 30 public String toString() { 31 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + latlon.toString() + ", " + attr + ")"; 32 } 33 34 /** 35 * Convert the time stamp of the waypoint into seconds from the epoch 36 */ 37 public final static SimpleDateFormat GPXTIMEFMT = 38 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); // ignore timezone 39 40 public void setTime() { 41 if (! attr.containsKey("time")) { 42 return; 43 } 44 Date d = GPXTIMEFMT.parse(attr.get("time").toString(), new ParsePosition(0)); 45 if (d != null /* parsing ok */) { 46 time = d.getTime() / 1000.0; /* ms => seconds */ 47 } 48 } 29 @Override 30 public String toString() { 31 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + latlon.toString() + ", " + attr + ")"; 32 } 49 33 50 /** 51 * Convert a time stamp of the waypoint from the <cmt> or <desc> field 52 * into seconds from the epoch. Handles the date format as it is used by 53 * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0). 54 * A value of <time> fields overwrites values set with by method. 55 * Does nothing if specified key does not exist or text cannot be parsed. 56 * 57 * @param key The key that contains the text to convert. 58 */ 59 public void setGarminCommentTime(String key) { 60 // do not overwrite time if already set 61 if (time != 0.0) { 62 return; 63 } 64 if (! attr.containsKey(key)) { 65 return; 66 } 67 // example date format "18-AUG-08 13:33:03" 68 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone 69 Date d = f.parse(attr.get(key).toString(), new ParsePosition(0)); 70 if (d != null /* parsing OK */) { 71 time = d.getTime() / 1000.0; /* ms => seconds */ 72 } 73 } 34 /** 35 * Convert the time stamp of the waypoint into seconds from the epoch 36 */ 37 public final static SimpleDateFormat GPXTIMEFMT = 38 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); // ignore timezone 74 39 75 public int compareTo(WayPoint w) 76 { 77 return Double.compare(time, w.time); 78 } 40 public void setTime() { 41 if (! attr.containsKey("time")) { 42 return; 43 } 44 Date d = GPXTIMEFMT.parse(attr.get("time").toString(), new ParsePosition(0)); 45 if (d != null /* parsing ok */) { 46 time = d.getTime() / 1000.0; /* ms => seconds */ 47 } 48 } 49 50 /** 51 * Convert a time stamp of the waypoint from the <cmt> or <desc> field 52 * into seconds from the epoch. Handles the date format as it is used by 53 * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0). 54 * A value of <time> fields overwrites values set with by method. 55 * Does nothing if specified key does not exist or text cannot be parsed. 56 * 57 * @param key The key that contains the text to convert. 58 */ 59 public void setGarminCommentTime(String key) { 60 // do not overwrite time if already set 61 if (time != 0.0) { 62 return; 63 } 64 if (! attr.containsKey(key)) { 65 return; 66 } 67 // example date format "18-AUG-08 13:33:03" 68 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone 69 Date d = f.parse(attr.get(key).toString(), new ParsePosition(0)); 70 if (d != null /* parsing OK */) { 71 time = d.getTime() / 1000.0; /* ms => seconds */ 72 } 73 } 74 75 public int compareTo(WayPoint w) 76 { 77 return Double.compare(time, w.time); 78 } 79 79 }
Note:
See TracChangeset
for help on using the changeset viewer.