source: josm/trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java@ 1169

Last change on this file since 1169 was 1169, checked in by stoecker, 15 years ago

removed usage of tab stops

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1//License: GPLv2 or later
2//Copyright 2007 by Raphael Mack and others
3
4package org.openstreetmap.josm.data.gpx;
5
6import java.text.ParsePosition;
7import java.text.SimpleDateFormat;
8import java.util.Date;
9import java.awt.Color;
10
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.coor.EastNorth;
13import org.openstreetmap.josm.data.coor.LatLon;
14
15public class WayPoint extends WithAttributes implements Comparable<WayPoint>
16{
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
24 public WayPoint(LatLon ll) {
25 latlon = ll;
26 eastNorth = Main.proj.latlon2eastNorth(ll);
27 }
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 }
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}
Note: See TracBrowser for help on using the repository browser.