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

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

fixed #1642. patch by xeen

  • Property svn:eol-style set to native
File size: 2.8 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 customColoring;
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 public final static SimpleDateFormat GPXTIMEFMT2 =
40 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ignore timezone
41
42 public void setTime() {
43 if (! attr.containsKey("time")) {
44 return;
45 }
46 Date d = GPXTIMEFMT.parse(attr.get("time").toString(), new ParsePosition(0));
47 if (d == null) {
48 d = GPXTIMEFMT2.parse(attr.get("time").toString(), new ParsePosition(0));
49 }
50 if (d != null /* parsing ok */) {
51 time = d.getTime() / 1000.0; /* ms => seconds */
52 }
53 }
54
55 /**
56 * Convert a time stamp of the waypoint from the <cmt> or <desc> field
57 * into seconds from the epoch. Handles the date format as it is used by
58 * Garmin handhelds. Does not overwrite an existing timestamp (!= 0.0).
59 * A value of <time> fields overwrites values set with by method.
60 * Does nothing if specified key does not exist or text cannot be parsed.
61 *
62 * @param key The key that contains the text to convert.
63 */
64 public void setGarminCommentTime(String key) {
65 // do not overwrite time if already set
66 if (time != 0.0) {
67 return;
68 }
69 if (! attr.containsKey(key)) {
70 return;
71 }
72 // example date format "18-AUG-08 13:33:03"
73 SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yy HH:mm:ss"); // Garmin wpts have no timezone
74 Date d = f.parse(attr.get(key).toString(), new ParsePosition(0));
75 if (d != null /* parsing OK */) {
76 time = d.getTime() / 1000.0; /* ms => seconds */
77 }
78 }
79
80 public int compareTo(WayPoint w)
81 {
82 return Double.compare(time, w.time);
83 }
84}
Note: See TracBrowser for help on using the repository browser.