Changeset 7518 in josm
- Timestamp:
- 2014-09-10T02:29:55+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/GpxConstants.java
r6897 r7518 3 3 4 4 import java.util.Arrays; 5 import java.util.Collection; 5 6 import java.util.List; 6 7 … … 11 12 */ 12 13 public interface GpxConstants { 14 15 /** GPS name of the element. This field will be transferred to and from the GPS. 16 * GPX does not place restrictions on the length of this field or the characters contained in it. 17 * It is up to the receiving application to validate the field before sending it to the GPS. */ 18 public static final String GPX_NAME = "name"; 19 20 /** GPS element comment. Sent to GPS as comment. */ 21 public static final String GPX_CMT = "cmt"; 22 23 /** Text description of the element. Holds additional information about the element intended for the user, not the GPS. */ 24 public static final String GPX_DESC = "desc"; 25 26 /** Source of data. Included to give user some idea of reliability and accuracy of data. */ 27 public static final String GPX_SRC = "src"; 13 28 14 29 public static final String META_PREFIX = "meta."; … … 28 43 public static final String JOSM_EXTENSIONS_NAMESPACE_URI = Main.getXMLBase() + "/gpx-extensions-1.0"; 29 44 30 public static List<String> WPT_KEYS = Arrays.asList("ele", "time", "magvar", "geoidheight", 31 "name", "cmt", "desc", "src", META_LINKS, "sym", "number", "type", 32 "fix", "sat", "hdop", "vdop", "pdop", "ageofdgpsdata", "dgpsid", META_EXTENSIONS); 45 /** Elevation (in meters) of the point. */ 46 public static final String PT_ELE = "ele"; 33 47 48 /** Creation/modification timestamp for the point. 49 * Date and time in are in Univeral Coordinated Time (UTC), not local time! 50 * Conforms to ISO 8601 specification for date/time representation. 51 * Fractional seconds are allowed for millisecond timing in tracklogs. */ 52 public static final String PT_TIME = "time"; 53 54 /** Magnetic variation (in degrees) at the point. 0.0 <= value < 360.0 */ 55 public static final String PT_MAGVAR = "magvar"; 56 57 /** Height, in meters, of geoid (mean sea level) above WGS-84 earth ellipsoid. (NMEA GGA message) */ 58 public static final String PT_GEOIDHEIGHT = "geoidheight"; 59 60 /** Text of GPS symbol name. For interchange with other programs, use the exact spelling of the symbol on the GPS, if known. */ 61 public static final String PT_SYM = "sym"; 62 63 /** Type (textual classification) of element. */ 64 public static final String PT_TYPE = "type"; 65 66 /** Type of GPS fix. none means GPS had no fix. Value comes from list: {'none'|'2d'|'3d'|'dgps'|'pps'} */ 67 public static final String PT_FIX = "fix"; 68 69 /** Number of satellites used to calculate the GPS fix. (not number of satellites in view). */ 70 public static final String PT_SAT = "sat"; 71 72 /** Horizontal dilution of precision. */ 73 public static final String PT_HDOP = "hdop"; 74 75 /** Vertical dilution of precision. */ 76 public static final String PT_VDOP = "vdop"; 77 78 /** Position dilution of precision. */ 79 public static final String PT_PDOP = "pdop"; 80 81 /** Number of seconds since last DGPS update. */ 82 public static final String PT_AGEOFDGPSDATA = "ageofdgpsdata"; 83 84 /** Represents a differential GPS station. 0 <= value <= 1023 */ 85 public static final String PT_DGPSID = "dgpsid"; 86 87 /** 88 * Ordered list of all possible waypoint keys. 89 */ 90 public static List<String> WPT_KEYS = Arrays.asList(PT_ELE, PT_TIME, PT_MAGVAR, PT_GEOIDHEIGHT, 91 GPX_NAME, GPX_CMT, GPX_DESC, GPX_SRC, META_LINKS, PT_SYM, PT_TYPE, 92 PT_FIX, PT_SAT, PT_HDOP, PT_VDOP, PT_PDOP, PT_AGEOFDGPSDATA, PT_DGPSID, META_EXTENSIONS); 93 94 /** 95 * Ordered list of all possible route and track keys. 96 */ 97 public static List<String> RTE_TRK_KEYS = Arrays.asList( 98 GPX_NAME, GPX_CMT, GPX_DESC, GPX_SRC, META_LINKS, "number", PT_TYPE, META_EXTENSIONS); 99 100 /** 101 * Possible fix values. 102 */ 103 public static Collection<String> FIX_VALUES = Arrays.asList("none","2d","3d","dgps","pps"); 34 104 } -
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r7509 r7518 41 41 String k = ent.getKey(); 42 42 if (k.equals(META_LINKS) && attr.containsKey(META_LINKS)) { 43 @SuppressWarnings("unchecked") 44 Collection<GpxLink> my = (Collection<GpxLink>) attr.get(META_LINKS); 43 Collection<GpxLink> my = super.<GpxLink>getCollection(META_LINKS); 45 44 @SuppressWarnings("unchecked") 46 45 Collection<GpxLink> their = (Collection<GpxLink>) ent.getValue(); 47 46 my.addAll(their); 48 47 } else { 49 attr.put(k, ent.getValue());48 put(k, ent.getValue()); 50 49 } 51 50 } -
trunk/src/org/openstreetmap/josm/data/gpx/GpxLink.java
r6380 r7518 2 2 package org.openstreetmap.josm.data.gpx; 3 3 4 /** 5 * A link to an external resource (Web page, digital photo, video clip, etc) with additional information. 6 * @since 444 7 */ 4 8 public class GpxLink { 9 10 /** External resource URI */ 5 11 public String uri; 12 13 /** Text to display on the hyperlink */ 6 14 public String text; 15 16 /** Link type */ 7 17 public String type; 8 18 19 /** 20 * Constructs a new {@code GpxLink}. 21 * @param uri External resource URI 22 */ 9 23 public GpxLink(String uri) { 10 24 this.uri = uri; -
trunk/src/org/openstreetmap/josm/data/gpx/IWithAttributes.java
r6142 r7518 37 37 * @since 5502 38 38 */ 39 Collection<?> getCollection(String key);39 <T> Collection<T> getCollection(String key); 40 40 41 41 /** -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r7319 r7518 95 95 @Override 96 96 public String toString() { 97 return "WayPoint (" + (attr.containsKey( "name") ? attr.get("name") + ", " :"") + getCoor().toString() + ", " + attr + ")";97 return "WayPoint (" + (attr.containsKey(GPX_NAME) ? get(GPX_NAME) + ", " :"") + getCoor().toString() + ", " + attr + ")"; 98 98 } 99 99 … … 102 102 */ 103 103 public void setTime() { 104 if (attr.containsKey("time")) {104 if (attr.containsKey(PT_TIME)) { 105 105 try { 106 time = dateParser.get().parse( attr.get("time").toString()).getTime() / 1000.; /* ms => seconds */106 time = dateParser.get().parse(get(PT_TIME).toString()).getTime() / 1000.; /* ms => seconds */ 107 107 } catch(Exception e) { 108 108 time = 0; … … 123 123 public Object getTemplateValue(String name, boolean special) { 124 124 if (!special) 125 return attr.get(name);125 return get(name); 126 126 else 127 127 return null; -
trunk/src/org/openstreetmap/josm/data/gpx/WithAttributes.java
r7005 r7518 56 56 * @since 5502 57 57 */ 58 @SuppressWarnings("unchecked") 58 59 @Override 59 public Collection<?> getCollection(String key) {60 public <T> Collection<T> getCollection(String key) { 60 61 Object value = attr.get(key); 61 return (value instanceof Collection) ? (Collection< ?>)value : null;62 return (value instanceof Collection) ? (Collection<T>)value : null; 62 63 } 63 64 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r7402 r7518 64 64 65 65 public GpxLayer(GpxData d) { 66 super( (String) d.attr.get("name"));66 super(d.getString(GpxConstants.META_NAME)); 67 67 data = d; 68 68 drawHelper = new GpxDrawHelper(data); … … 124 124 125 125 if (data.attr.containsKey("name")) { 126 info.append(tr("Name: {0}", data. attr.get(GpxConstants.META_NAME))).append("<br>");126 info.append(tr("Name: {0}", data.get(GpxConstants.META_NAME))).append("<br>"); 127 127 } 128 128 129 129 if (data.attr.containsKey("desc")) { 130 info.append(tr("Description: {0}", data. attr.get(GpxConstants.META_DESC))).append("<br>");130 info.append(tr("Description: {0}", data.get(GpxConstants.META_DESC))).append("<br>"); 131 131 } 132 132 … … 141 141 for (GpxTrack trk : data.tracks) { 142 142 info.append("<tr><td>"); 143 if (trk.getAttributes().containsKey( "name")) {144 info.append(trk.get Attributes().get("name"));143 if (trk.getAttributes().containsKey(GpxConstants.GPX_NAME)) { 144 info.append(trk.get(GpxConstants.GPX_NAME)); 145 145 } 146 146 info.append("</td><td>"); 147 if (trk.getAttributes().containsKey( "desc")) {148 info.append(" ").append(trk.get Attributes().get("desc"));147 if (trk.getAttributes().containsKey(GpxConstants.GPX_DESC)) { 148 info.append(" ").append(trk.get(GpxConstants.GPX_DESC)); 149 149 } 150 150 info.append("</td><td>"); … … 154 154 info.append("</td><td>"); 155 155 if (trk.getAttributes().containsKey("url")) { 156 info.append(trk.get Attributes().get("url"));156 info.append(trk.get("url")); 157 157 } 158 158 info.append("</td></tr>"); … … 215 215 StringBuilder info = new StringBuilder().append("<html>"); 216 216 217 if (data.attr.containsKey( "name")) {218 info.append(tr("Name: {0}", data. attr.get(GpxConstants.META_NAME))).append("<br>");219 } 220 221 if (data.attr.containsKey( "desc")) {222 info.append(tr("Description: {0}", data. attr.get(GpxConstants.META_DESC))).append("<br>");217 if (data.attr.containsKey(GpxConstants.META_NAME)) { 218 info.append(tr("Name: {0}", data.get(GpxConstants.META_NAME))).append("<br>"); 219 } 220 221 if (data.attr.containsKey(GpxConstants.META_DESC)) { 222 info.append(tr("Description: {0}", data.get(GpxConstants.META_DESC))).append("<br>"); 223 223 } 224 224 -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r7414 r7518 51 51 import org.openstreetmap.josm.data.conflict.ConflictCollection; 52 52 import org.openstreetmap.josm.data.coor.LatLon; 53 import org.openstreetmap.josm.data.gpx.GpxConstants; 53 54 import org.openstreetmap.josm.data.gpx.GpxData; 55 import org.openstreetmap.josm.data.gpx.GpxLink; 54 56 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; 55 57 import org.openstreetmap.josm.data.gpx.WayPoint; … … 581 583 WayPoint wpt = new WayPoint(n.getCoor()); 582 584 if (!n.isTimestampEmpty()) { 583 wpt. attr.put("time", DateUtils.fromDate(n.getTimestamp()));585 wpt.put("time", DateUtils.fromDate(n.getTimestamp())); 584 586 wpt.setTime(); 585 587 } … … 600 602 } 601 603 WayPoint wpt = new WayPoint(n.getCoor()); 602 String name = n.get("name"); 603 if (name != null) { 604 wpt.attr.put("name", name); 605 } 604 605 // Position info 606 607 addDoubleIfPresent(wpt, n, GpxConstants.PT_ELE); 608 606 609 if (!n.isTimestampEmpty()) { 607 wpt. attr.put("time", DateUtils.fromDate(n.getTimestamp()));610 wpt.put("time", DateUtils.fromDate(n.getTimestamp())); 608 611 wpt.setTime(); 609 612 } 610 String desc = n.get("description"); 611 if (desc != null) { 612 wpt.attr.put("desc", desc); 613 } 613 614 addDoubleIfPresent(wpt, n, GpxConstants.PT_MAGVAR); 615 addDoubleIfPresent(wpt, n, GpxConstants.PT_GEOIDHEIGHT); 616 617 // Description info 618 619 addStringIfPresent(wpt, n, GpxConstants.GPX_NAME); 620 addStringIfPresent(wpt, n, GpxConstants.GPX_DESC, "description"); 621 addStringIfPresent(wpt, n, GpxConstants.GPX_CMT, "comment"); 622 addStringIfPresent(wpt, n, GpxConstants.GPX_SRC, "source", "source:position"); 623 624 Collection<GpxLink> links = new ArrayList<>(); 625 for (String key : new String[]{"link", "url", "website", "contact:website"}) { 626 String value = n.get(key); 627 if (value != null) { 628 links.add(new GpxLink(value)); 629 } 630 } 631 wpt.put(GpxConstants.META_LINKS, links); 632 633 addStringIfPresent(wpt, n, GpxConstants.PT_SYM, "wpt_symbol"); 634 addStringIfPresent(wpt, n, GpxConstants.PT_TYPE); 635 636 // Accuracy info 637 addStringIfPresent(wpt, n, GpxConstants.PT_FIX, "gps:fix"); 638 addIntegerIfPresent(wpt, n, GpxConstants.PT_SAT, "gps:sat"); 639 addDoubleIfPresent(wpt, n, GpxConstants.PT_HDOP, "gps:hdop"); 640 addDoubleIfPresent(wpt, n, GpxConstants.PT_VDOP, "gps:vdop"); 641 addDoubleIfPresent(wpt, n, GpxConstants.PT_PDOP, "gps:pdop"); 642 addDoubleIfPresent(wpt, n, GpxConstants.PT_AGEOFDGPSDATA, "gps:ageofdgpsdata"); 643 addIntegerIfPresent(wpt, n, GpxConstants.PT_DGPSID, "gps:dgpsid"); 614 644 615 645 gpxData.waypoints.add(wpt); 646 } 647 } 648 649 private static void addIntegerIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String ... osmKeys) { 650 ArrayList<String> possibleKeys = new ArrayList<>(Arrays.asList(osmKeys)); 651 possibleKeys.add(0, gpxKey); 652 for (String key : possibleKeys) { 653 String value = p.get(key); 654 if (value != null) { 655 try { 656 int i = Integer.parseInt(value); 657 // Sanity checks 658 if ((!GpxConstants.PT_SAT.equals(gpxKey) || i >= 0) && 659 (!GpxConstants.PT_DGPSID.equals(gpxKey) || (0 <= i && i <= 1023))) { 660 wpt.put(gpxKey, value); 661 break; 662 } 663 } catch (NumberFormatException e) { 664 if (Main.isTraceEnabled()) { 665 Main.trace(e.getMessage()); 666 } 667 } 668 } 669 } 670 } 671 672 private static void addDoubleIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String ... osmKeys) { 673 ArrayList<String> possibleKeys = new ArrayList<>(Arrays.asList(osmKeys)); 674 possibleKeys.add(0, gpxKey); 675 for (String key : possibleKeys) { 676 String value = p.get(key); 677 if (value != null) { 678 try { 679 double d = Double.parseDouble(value); 680 // Sanity checks 681 if (!GpxConstants.PT_MAGVAR.equals(gpxKey) || (0.0 <= d && d < 360.0)) { 682 wpt.put(gpxKey, value); 683 break; 684 } 685 } catch (NumberFormatException e) { 686 if (Main.isTraceEnabled()) { 687 Main.trace(e.getMessage()); 688 } 689 } 690 } 691 } 692 } 693 694 private static void addStringIfPresent(WayPoint wpt, OsmPrimitive p, String gpxKey, String ... osmKeys) { 695 ArrayList<String> possibleKeys = new ArrayList<>(Arrays.asList(osmKeys)); 696 possibleKeys.add(0, gpxKey); 697 for (String key : possibleKeys) { 698 String value = p.get(key); 699 if (value != null) { 700 // Sanity checks 701 if (!GpxConstants.PT_FIX.equals(gpxKey) || GpxConstants.FIX_VALUES.contains(value)) { 702 wpt.put(gpxKey, value); 703 break; 704 } 705 } 616 706 } 617 707 } -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java
r7320 r7518 63 63 import org.openstreetmap.josm.Main; 64 64 import org.openstreetmap.josm.actions.DiskAccessAction; 65 import org.openstreetmap.josm.data.gpx.GpxConstants; 65 66 import org.openstreetmap.josm.data.gpx.GpxData; 66 67 import org.openstreetmap.josm.data.gpx.GpxTrack; … … 1012 1013 for (GpxTrackSegment segment : trk.getSegments()) { 1013 1014 for (WayPoint curWp : segment.getWayPoints()) { 1014 String curDateWpStr = (String) curWp.attr.get("time");1015 String curDateWpStr = curWp.getString(GpxConstants.PT_TIME); 1015 1016 if (curDateWpStr == null) { 1016 1017 continue; … … 1136 1137 for (WayPoint curWp : segment.getWayPoints()) { 1137 1138 1138 String curWpTimeStr = (String) curWp.attr.get("time");1139 String curWpTimeStr = curWp.getString(GpxConstants.PT_TIME); 1139 1140 if (curWpTimeStr != null) { 1140 1141 … … 1163 1164 1164 1165 private static Double getElevation(WayPoint wp) { 1165 String value = (String) wp.attr.get("ele");1166 String value = wp.getString(GpxConstants.PT_ELE); 1166 1167 if (value != null) { 1167 1168 try { -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ChooseTrackVisibilityAction.java
r7005 r7518 32 32 33 33 import org.openstreetmap.josm.Main; 34 import org.openstreetmap.josm.data.gpx.GpxConstants; 34 35 import org.openstreetmap.josm.data.gpx.GpxTrack; 35 36 import org.openstreetmap.josm.gui.ExtendedDialog; … … 111 112 for (GpxTrack trk : layer.data.tracks) { 112 113 Map<String, Object> attr = trk.getAttributes(); 113 String name = (String) (attr.containsKey( "name") ? attr.get("name") : "");114 String desc = (String) (attr.containsKey( "desc") ? attr.get("desc") : "");114 String name = (String) (attr.containsKey(GpxConstants.GPX_NAME) ? attr.get(GpxConstants.GPX_NAME) : ""); 115 String desc = (String) (attr.containsKey(GpxConstants.GPX_DESC) ? attr.get(GpxConstants.GPX_DESC) : ""); 115 116 String time = GpxLayer.getTimespanForTrack(trk); 116 117 TrackLength length = new TrackLength(trk.length()); -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerAction.java
r7299 r7518 16 16 17 17 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.gpx.GpxConstants; 18 19 import org.openstreetmap.josm.data.gpx.GpxTrack; 19 20 import org.openstreetmap.josm.data.gpx.GpxTrackSegment; … … 53 54 for (WayPoint p : segment.getWayPoints()) { 54 55 Node n = new Node(p.getCoor()); 55 String timestr = p.getString( "time");56 String timestr = p.getString(GpxConstants.PT_TIME); 56 57 if (timestr != null) { 57 58 n.setTimestamp(DateUtils.fromString(timestr)); … … 68 69 Main.main.removeLayer(layer); 69 70 } 70 71 71 } -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/GpxDrawHelper.java
r7402 r7518 17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.data.coor.LatLon; 19 import org.openstreetmap.josm.data.gpx.GpxConstants; 19 20 import org.openstreetmap.josm.data.gpx.GpxData; 20 21 import org.openstreetmap.josm.data.gpx.WayPoint; … … 253 254 for (Collection<WayPoint> segment : data.getLinesIterable(null)) { 254 255 for (WayPoint trkPnt : segment) { 255 Object val = trkPnt. attr.get("hdop");256 Object val = trkPnt.get(GpxConstants.PT_HDOP); 256 257 if (val != null) { 257 258 double hdop = ((Float) val).doubleValue(); … … 304 305 305 306 if (colored == ColorMode.HDOP) { 306 Float hdop = (Float) trkPnt. attr.get("hdop");307 Float hdop = (Float) trkPnt.get(GpxConstants.PT_HDOP); 307 308 color = hdopScale.getColor(hdop); 308 309 } … … 446 447 447 448 448 if (hdopCircle && trkPnt. attr.get("hdop") != null) {449 if (hdopCircle && trkPnt.get(GpxConstants.PT_HDOP) != null) { 449 450 // hdop value 450 float hdop = (Float)trkPnt. attr.get("hdop");451 float hdop = (Float)trkPnt.get(GpxConstants.PT_HDOP); 451 452 if (hdop < 0) { 452 453 hdop = 0; -
trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java
r7509 r7518 21 21 import org.openstreetmap.josm.Main; 22 22 import org.openstreetmap.josm.actions.DiskAccessAction; 23 import org.openstreetmap.josm.data.gpx.GpxConstants; 23 24 import org.openstreetmap.josm.data.gpx.GpxData; 24 25 import org.openstreetmap.josm.data.gpx.GpxTrack; … … 184 185 WayPoint wc = new WayPoint(w.getCoor()); 185 186 wc.time = wNear.time; 186 if (w.attr.containsKey( "name")) {187 wc. attr.put("name", w.getString("name"));187 if (w.attr.containsKey(GpxConstants.GPX_NAME)) { 188 wc.put(GpxConstants.GPX_NAME, w.getString(GpxConstants.GPX_NAME)); 188 189 } 189 190 waypoints.add(wc); … … 200 201 for (GpxTrackSegment seg : track.getSegments()) { 201 202 for (WayPoint w : seg.getWayPoints()) { 202 if (w.attr.containsKey( "name") || w.attr.containsKey("desc")) {203 if (w.attr.containsKey(GpxConstants.GPX_NAME) || w.attr.containsKey(GpxConstants.GPX_DESC)) { 203 204 waypoints.add(w); 204 205 } … … 245 246 name = name.substring(0, dot); 246 247 } 247 wayPointFromTimeStamp. attr.put("name", name);248 wayPointFromTimeStamp.put(GpxConstants.GPX_NAME, name); 248 249 waypoints.add(wayPointFromTimeStamp); 249 250 } … … 259 260 for (WayPoint w : seg.getWayPoints()) { 260 261 WayPoint wStart = new WayPoint(w.getCoor()); 261 wStart. attr.put("name", "start");262 wStart.put(GpxConstants.GPX_NAME, "start"); 262 263 wStart.time = w.time; 263 264 waypoints.add(wStart); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/AudioMarker.java
r6830 r7518 87 87 GpxLink link = new GpxLink(audioUrl.toString()); 88 88 link.type = "audio"; 89 wpt. attr.put(GpxConstants.META_LINKS, Collections.singleton(link));89 wpt.put(GpxConstants.META_LINKS, Collections.singleton(link)); 90 90 wpt.addExtension("offset", Double.toString(offset)); 91 91 wpt.addExtension("sync-offset", Double.toString(syncOffset)); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarker.java
r6830 r7518 93 93 GpxLink link = new GpxLink(imageUrl.toString()); 94 94 link.type = "image"; 95 wpt. attr.put(GpxConstants.META_LINKS, Collections.singleton(link));95 wpt.put(GpxConstants.META_LINKS, Collections.singleton(link)); 96 96 return wpt; 97 97 } 98 99 98 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r7049 r7518 181 181 static { 182 182 Marker.markerProducers.add(new MarkerProducers() { 183 @SuppressWarnings("unchecked")184 183 @Override 185 184 public Marker createMarker(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time, double offset) { … … 187 186 // cheapest way to check whether "link" object exists and is a non-empty 188 187 // collection of GpxLink objects... 189 Collection<GpxLink> links = (Collection<GpxLink>)wpt.attr.get(GpxConstants.META_LINKS);188 Collection<GpxLink> links = wpt.<GpxLink>getCollection(GpxConstants.META_LINKS); 190 189 if (links != null) { 191 190 for (GpxLink oneLink : links ) { … … 210 209 String symbolName = wpt.getString("symbol"); 211 210 if (symbolName == null) { 212 symbolName = wpt.getString( "sym");211 symbolName = wpt.getString(GpxConstants.PT_SYM); 213 212 } 214 213 return new Marker(wpt.getCoor(), wpt, symbolName, parentLayer, time, offset); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r7326 r7518 94 94 if (firstTime < 0 && wpt_has_link) { 95 95 firstTime = time; 96 for (Object oneLink : wpt.getCollection(GpxConstants.META_LINKS)) { 97 if (oneLink instanceof GpxLink) { 98 lastLinkedFile = ((GpxLink)oneLink).uri; 99 break; 96 for (GpxLink oneLink : wpt.<GpxLink>getCollection(GpxConstants.META_LINKS)) { 97 lastLinkedFile = oneLink.uri; 98 break; 99 } 100 } 101 if (wpt_has_link) { 102 for (GpxLink oneLink : wpt.<GpxLink>getCollection(GpxConstants.META_LINKS)) { 103 String uri = oneLink.uri; 104 if (!uri.equals(lastLinkedFile)) { 105 firstTime = time; 100 106 } 101 } 102 } 103 if (wpt_has_link) { 104 for (Object oneLink : wpt.getCollection(GpxConstants.META_LINKS)) { 105 if (oneLink instanceof GpxLink) { 106 String uri = ((GpxLink)oneLink).uri; 107 if (!uri.equals(lastLinkedFile)) { 108 firstTime = time; 109 } 110 lastLinkedFile = uri; 111 break; 112 } 107 lastLinkedFile = uri; 108 break; 113 109 } 114 110 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/WebMarker.java
r6830 r7518 56 56 GpxLink link = new GpxLink(webUrl.toString()); 57 57 link.type = "web"; 58 wpt. attr.put(GpxConstants.META_LINKS, Collections.singleton(link));58 wpt.put(GpxConstants.META_LINKS, Collections.singleton(link)); 59 59 return wpt; 60 60 } -
trunk/src/org/openstreetmap/josm/io/GpxExporter.java
r7414 r7518 90 90 desc.setWrapStyleWord(true); 91 91 desc.setLineWrap(true); 92 desc.setText( (String) gpxData.attr.get(META_DESC));92 desc.setText(gpxData.getString(META_DESC)); 93 93 p.add(new JScrollPane(desc), GBC.eop().fill(GBC.BOTH)); 94 94 … … 120 120 p.add(new JLabel(tr("Keywords")), GBC.eol()); 121 121 JosmTextField keywords = new JosmTextField(); 122 keywords.setText( (String) gpxData.attr.get(META_KEYWORDS));122 keywords.setText(gpxData.getString(META_KEYWORDS)); 123 123 p.add(keywords, GBC.eop().fill(GBC.HORIZONTAL)); 124 124 … … 155 155 if (author.isSelected()) { 156 156 if (authorName.getText().length() > 0) { 157 gpxData. attr.put(META_AUTHOR_NAME, authorName.getText());158 gpxData. attr.put(META_COPYRIGHT_AUTHOR, authorName.getText());157 gpxData.put(META_AUTHOR_NAME, authorName.getText()); 158 gpxData.put(META_COPYRIGHT_AUTHOR, authorName.getText()); 159 159 } 160 160 if (email.getText().length() > 0) { 161 gpxData. attr.put(META_AUTHOR_EMAIL, email.getText());161 gpxData.put(META_AUTHOR_EMAIL, email.getText()); 162 162 } 163 163 if (copyright.getText().length() > 0) { 164 gpxData. attr.put(META_COPYRIGHT_LICENSE, copyright.getText());164 gpxData.put(META_COPYRIGHT_LICENSE, copyright.getText()); 165 165 } 166 166 if (copyrightYear.getText().length() > 0) { 167 gpxData. attr.put(META_COPYRIGHT_YEAR, copyrightYear.getText());167 gpxData.put(META_COPYRIGHT_YEAR, copyrightYear.getText()); 168 168 } 169 169 } … … 171 171 // add the description to the gpx data 172 172 if (desc.getText().length() > 0) { 173 gpxData. attr.put(META_DESC, desc.getText());173 gpxData.put(META_DESC, desc.getText()); 174 174 } 175 175 176 176 // add keywords to the gpx data 177 177 if (keywords.getText().length() > 0) { 178 gpxData. attr.put(META_KEYWORDS, keywords.getText());178 gpxData.put(META_KEYWORDS, keywords.getText()); 179 179 } 180 180 … … 201 201 if (enable) { 202 202 if (copyrightYear.getText().length()==0) { 203 String sCopyrightYear = (String) data.attr.get(META_COPYRIGHT_YEAR);203 String sCopyrightYear = data.getString(META_COPYRIGHT_YEAR); 204 204 if (sCopyrightYear == null) { 205 205 sCopyrightYear = Integer.toString(Calendar.getInstance().get(Calendar.YEAR)); … … 208 208 } 209 209 if (copyright.getText().length()==0) { 210 String sCopyright = (String) data.attr.get(META_COPYRIGHT_LICENSE);210 String sCopyright = data.getString(META_COPYRIGHT_LICENSE); 211 211 if (sCopyright == null) { 212 212 sCopyright = Main.pref.get("lastCopyright", "https://creativecommons.org/licenses/by-sa/2.5"); … … 247 247 emailLabel.setEnabled(b); 248 248 if (b) { 249 String sAuthorName = (String) data.attr.get(META_AUTHOR_NAME);249 String sAuthorName = data.getString(META_AUTHOR_NAME); 250 250 if (sAuthorName == null) { 251 251 sAuthorName = Main.pref.get("lastAuthorName"); 252 252 } 253 253 authorName.setText(sAuthorName); 254 String sEmail = (String) data.attr.get(META_AUTHOR_EMAIL);254 String sEmail = data.getString(META_AUTHOR_EMAIL); 255 255 if (sEmail == null) { 256 256 sEmail = Main.pref.get("lastAuthorEmail"); -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r7509 r7518 156 156 states.push(currentState); 157 157 currentState = State.copyright; 158 data. attr.put(META_COPYRIGHT_AUTHOR, atts.getValue("author"));158 data.put(META_COPYRIGHT_AUTHOR, atts.getValue("author")); 159 159 break; 160 160 case "link": … … 172 172 break; 173 173 case "email": 174 data. attr.put(META_AUTHOR_EMAIL, atts.getValue("id") + "@" + atts.getValue("domain"));174 data.put(META_AUTHOR_EMAIL, atts.getValue("id") + "@" + atts.getValue("domain")); 175 175 } 176 176 break; … … 275 275 switch (localName) { 276 276 case "name": 277 data. attr.put(META_NAME, accumulator.toString());277 data.put(META_NAME, accumulator.toString()); 278 278 break; 279 279 case "desc": 280 data. attr.put(META_DESC, accumulator.toString());280 data.put(META_DESC, accumulator.toString()); 281 281 break; 282 282 case "time": 283 data. attr.put(META_TIME, accumulator.toString());283 data.put(META_TIME, accumulator.toString()); 284 284 break; 285 285 case "keywords": 286 data. attr.put(META_KEYWORDS, accumulator.toString());286 data.put(META_KEYWORDS, accumulator.toString()); 287 287 break; 288 288 case "author": 289 289 if ("1.0".equals(version)) { 290 290 // author is a string in 1.0, but complex element in 1.1 291 data. attr.put(META_AUTHOR_NAME, accumulator.toString());291 data.put(META_AUTHOR_NAME, accumulator.toString()); 292 292 } 293 293 break; 294 294 case "email": 295 295 if ("1.0".equals(version)) { 296 data. attr.put(META_AUTHOR_EMAIL, accumulator.toString());296 data.put(META_AUTHOR_EMAIL, accumulator.toString()); 297 297 } 298 298 break; 299 299 case "url": 300 300 case "urlname": 301 data. attr.put(localName, accumulator.toString());301 data.put(localName, accumulator.toString()); 302 302 break; 303 303 case "metadata": … … 307 307 convertUrlToLink(data.attr); 308 308 if (currentExtensions != null && !currentExtensions.isEmpty()) { 309 data. attr.put(META_EXTENSIONS, currentExtensions);309 data.put(META_EXTENSIONS, currentExtensions); 310 310 } 311 311 currentState = states.pop(); … … 322 322 break; 323 323 case "name": 324 data. attr.put(META_AUTHOR_NAME, accumulator.toString());324 data.put(META_AUTHOR_NAME, accumulator.toString()); 325 325 break; 326 326 case "email": … … 328 328 break; 329 329 case "link": 330 data. attr.put(META_AUTHOR_LINK, currentLink);330 data.put(META_AUTHOR_LINK, currentLink); 331 331 break; 332 332 } … … 338 338 break; 339 339 case "year": 340 data. attr.put(META_COPYRIGHT_YEAR, accumulator.toString());340 data.put(META_COPYRIGHT_YEAR, accumulator.toString()); 341 341 break; 342 342 case "license": 343 data. attr.put(META_COPYRIGHT_LICENSE, accumulator.toString());343 data.put(META_COPYRIGHT_LICENSE, accumulator.toString()); 344 344 break; 345 345 } … … 361 361 } 362 362 if (currentState == State.author) { 363 data. attr.put(META_AUTHOR_LINK, currentLink);363 data.put(META_AUTHOR_LINK, currentLink); 364 364 } else if (currentState != State.link) { 365 365 Map<String, Object> attr = getAttr(); … … 381 381 case "url": 382 382 case "urlname": 383 currentWayPoint. attr.put(localName, accumulator.toString());383 currentWayPoint.put(localName, accumulator.toString()); 384 384 break; 385 385 case "hdop": … … 387 387 case "pdop": 388 388 try { 389 currentWayPoint. attr.put(localName, Float.parseFloat(accumulator.toString()));389 currentWayPoint.put(localName, Float.parseFloat(accumulator.toString())); 390 390 } catch(Exception e) { 391 currentWayPoint. attr.put(localName, new Float(0));391 currentWayPoint.put(localName, new Float(0)); 392 392 } 393 393 break; 394 394 case "time": 395 currentWayPoint. attr.put(localName, accumulator.toString());395 currentWayPoint.put(localName, accumulator.toString()); 396 396 currentWayPoint.setTime(); 397 397 break; 398 398 case "cmt": 399 399 case "desc": 400 currentWayPoint. attr.put(localName, accumulator.toString());400 currentWayPoint.put(localName, accumulator.toString()); 401 401 currentWayPoint.setTime(); 402 402 break; … … 415 415 convertUrlToLink(currentWayPoint.attr); 416 416 if (currentExtensions != null && !currentExtensions.isEmpty()) { 417 currentWayPoint. attr.put(META_EXTENSIONS, currentExtensions);417 currentWayPoint.put(META_EXTENSIONS, currentExtensions); 418 418 } 419 419 data.waypoints.add(currentWayPoint); … … 472 472 if (!states.empty()) 473 473 throw new SAXException(tr("Parse error: invalid document structure for GPX document.")); 474 Extensions metaExt = (Extensions) data. attr.get(META_EXTENSIONS);474 Extensions metaExt = (Extensions) data.get(META_EXTENSIONS); 475 475 if (metaExt != null && "true".equals(metaExt.get("from-server"))) { 476 476 data.fromServer = true; -
trunk/src/org/openstreetmap/josm/io/GpxWriter.java
r7082 r7518 10 10 import java.nio.charset.StandardCharsets; 11 11 import java.util.Collection; 12 import java.util.List; 12 13 import java.util.Map; 13 14 import java.util.Map.Entry; … … 32 33 public class GpxWriter extends XmlWriter implements GpxConstants { 33 34 35 /** 36 * Constructs a new {@code GpxWriter}. 37 * @param out The output writer 38 */ 34 39 public GpxWriter(PrintWriter out) { 35 40 super(out); 36 41 } 37 42 43 /** 44 * Constructs a new {@code GpxWriter}. 45 * @param out The output stream 46 */ 38 47 public GpxWriter(OutputStream out) { 39 48 super(new PrintWriter(new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8)))); … … 47 56 private static final int TRACK_POINT = 2; 48 57 58 /** 59 * Writes the given GPX data. 60 * @param data The data to write 61 */ 49 62 public void write(GpxData data) { 50 63 this.data = data; … … 80 93 } 81 94 82 private void writeAttr(IWithAttributes obj ) {83 for (String key : WPT_KEYS) {95 private void writeAttr(IWithAttributes obj, List<String> keys) { 96 for (String key : keys) { 84 97 if (key.equals(META_LINKS)) { 85 @SuppressWarnings("unchecked") 86 Collection<GpxLink> lValue = (Collection<GpxLink>) obj.getCollection(key); 98 Collection<GpxLink> lValue = obj.<GpxLink>getCollection(key); 87 99 if (lValue != null) { 88 100 for (GpxLink link : lValue) { … … 104 116 } 105 117 106 @SuppressWarnings("unchecked")107 118 private void writeMetaData() { 108 119 Map<String, Object> attr = data.attr; … … 111 122 // write the description 112 123 if (attr.containsKey(META_DESC)) { 113 simpleTag("desc", (String)attr.get(META_DESC));124 simpleTag("desc", data.getString(META_DESC)); 114 125 } 115 126 … … 119 130 openln("author"); 120 131 // write the name 121 simpleTag("name", (String) attr.get(META_AUTHOR_NAME));132 simpleTag("name", data.getString(META_AUTHOR_NAME)); 122 133 // write the email address 123 134 if (attr.containsKey(META_AUTHOR_EMAIL)) { 124 String[] tmp = ((String)attr.get(META_AUTHOR_EMAIL)).split("@");135 String[] tmp = data.getString(META_AUTHOR_EMAIL).split("@"); 125 136 if (tmp.length == 2) { 126 137 inline("email", "id=\"" + tmp[0] + "\" domain=\""+tmp[1]+"\""); … … 128 139 } 129 140 // write the author link 130 gpxLink((GpxLink) attr.get(META_AUTHOR_LINK));141 gpxLink((GpxLink) data.get(META_AUTHOR_LINK)); 131 142 closeln("author"); 132 143 } … … 135 146 if (attr.containsKey(META_COPYRIGHT_LICENSE) 136 147 || attr.containsKey(META_COPYRIGHT_YEAR)) { 137 openAtt("copyright", "author=\""+ attr.get(META_COPYRIGHT_AUTHOR) +"\"");148 openAtt("copyright", "author=\""+ data.get(META_COPYRIGHT_AUTHOR) +"\""); 138 149 if (attr.containsKey(META_COPYRIGHT_YEAR)) { 139 simpleTag("year", (String) attr.get(META_COPYRIGHT_YEAR));150 simpleTag("year", (String) data.get(META_COPYRIGHT_YEAR)); 140 151 } 141 152 if (attr.containsKey(META_COPYRIGHT_LICENSE)) { 142 simpleTag("license", encode((String) attr.get(META_COPYRIGHT_LICENSE)));153 simpleTag("license", encode((String) data.get(META_COPYRIGHT_LICENSE))); 143 154 } 144 155 closeln("copyright"); … … 147 158 // write links 148 159 if (attr.containsKey(META_LINKS)) { 149 for (GpxLink link : (Collection<GpxLink>) attr.get(META_LINKS)) {160 for (GpxLink link : data.<GpxLink>getCollection(META_LINKS)) { 150 161 gpxLink(link); 151 162 } … … 154 165 // write keywords 155 166 if (attr.containsKey(META_KEYWORDS)) { 156 simpleTag("keywords", (String)attr.get(META_KEYWORDS));167 simpleTag("keywords", data.getString(META_KEYWORDS)); 157 168 } 158 169 … … 182 193 for (GpxRoute rte : data.routes) { 183 194 openln("rte"); 184 writeAttr(rte );195 writeAttr(rte, RTE_TRK_KEYS); 185 196 for (WayPoint pnt : rte.routePoints) { 186 197 wayPoint(pnt, ROUTE_POINT); … … 193 204 for (GpxTrack trk : data.tracks) { 194 205 openln("trk"); 195 writeAttr(trk );206 writeAttr(trk, RTE_TRK_KEYS); 196 207 for (GpxTrackSegment seg : trk.getSegments()) { 197 208 openln("trkseg"); … … 284 295 } else { 285 296 openAtt(type, coordAttr); 286 writeAttr(pnt );297 writeAttr(pnt, WPT_KEYS); 287 298 closeln(type); 288 299 } -
trunk/src/org/openstreetmap/josm/io/NmeaReader.java
r7299 r7518 15 15 import org.openstreetmap.josm.Main; 16 16 import org.openstreetmap.josm.data.coor.LatLon; 17 import org.openstreetmap.josm.data.gpx.GpxConstants; 17 18 import org.openstreetmap.josm.data.gpx.GpxData; 18 19 import org.openstreetmap.josm.data.gpx.ImmutableGpxTrack; … … 287 288 // As this sentence has no complete time only use it 288 289 // if there is no time so far 289 currentwp. attr.put("time", DateUtils.fromDate(d));290 currentwp.put(GpxConstants.PT_TIME, DateUtils.fromDate(d)); 290 291 } 291 292 // elevation … … 299 300 // device sends nonstandard data. 300 301 if(!accu.isEmpty()) { // FIX ? same check 301 currentwp. attr.put("ele", accu);302 currentwp.put(GpxConstants.PT_ELE, accu); 302 303 } 303 304 } … … 308 309 if(!accu.isEmpty()) { 309 310 sat = Integer.parseInt(accu); 310 currentwp. attr.put("sat", accu);311 currentwp.put(GpxConstants.PT_SAT, accu); 311 312 } 312 313 // h-dilution 313 314 accu=e[GPGGA.HDOP.position]; 314 315 if(!accu.isEmpty()) { 315 currentwp. attr.put("hdop", Float.parseFloat(accu));316 currentwp.put(GpxConstants.PT_HDOP, Float.parseFloat(accu)); 316 317 } 317 318 // fix … … 321 322 switch(fixtype) { 322 323 case 0: 323 currentwp. attr.put("fix", "none");324 currentwp.put(GpxConstants.PT_FIX, "none"); 324 325 break; 325 326 case 1: 326 327 if(sat < 4) { 327 currentwp. attr.put("fix", "2d");328 currentwp.put(GpxConstants.PT_FIX, "2d"); 328 329 } else { 329 currentwp. attr.put("fix", "3d");330 currentwp.put(GpxConstants.PT_FIX, "3d"); 330 331 } 331 332 break; 332 333 case 2: 333 currentwp. attr.put("fix", "dgps");334 currentwp.put(GpxConstants.PT_FIX, "dgps"); 334 335 break; 335 336 default: … … 345 346 if(!accu.isEmpty()) { 346 347 Double.parseDouble(accu); 347 currentwp. attr.put("course", accu);348 currentwp.put("course", accu); 348 349 } 349 350 } … … 355 356 double speed = Double.parseDouble(accu); 356 357 speed /= 3.6; // speed in m/s 357 currentwp. attr.put("speed", Double.toString(speed));358 currentwp.put("speed", Double.toString(speed)); 358 359 } 359 360 } … … 362 363 accu=e[GPGSA.VDOP.position]; 363 364 if(!accu.isEmpty()) { 364 currentwp. attr.put("vdop", Float.parseFloat(accu));365 currentwp.put(GpxConstants.PT_VDOP, Float.parseFloat(accu)); 365 366 } 366 367 // hdop 367 368 accu=e[GPGSA.HDOP.position]; 368 369 if(!accu.isEmpty()) { 369 currentwp. attr.put("hdop", Float.parseFloat(accu));370 currentwp.put(GpxConstants.PT_HDOP, Float.parseFloat(accu)); 370 371 } 371 372 // pdop 372 373 accu=e[GPGSA.PDOP.position]; 373 374 if(!accu.isEmpty()) { 374 currentwp. attr.put("pdop", Float.parseFloat(accu));375 currentwp.put(GpxConstants.PT_PDOP, Float.parseFloat(accu)); 375 376 } 376 377 } … … 399 400 } 400 401 // time: this sentence has complete time so always use it. 401 currentwp. attr.put("time", DateUtils.fromDate(d));402 currentwp.put(GpxConstants.PT_TIME, DateUtils.fromDate(d)); 402 403 // speed 403 404 accu = e[GPRMC.SPEED.position]; … … 405 406 double speed = Double.parseDouble(accu); 406 407 speed *= 0.514444444; // to m/s 407 currentwp. attr.put("speed", Double.toString(speed));408 currentwp.put("speed", Double.toString(speed)); 408 409 } 409 410 // course … … 411 412 if(!accu.isEmpty() && !currentwp.attr.containsKey("course")) { 412 413 Double.parseDouble(accu); 413 currentwp. attr.put("course", accu);414 currentwp.put("course", accu); 414 415 } 415 416 -
trunk/src/org/openstreetmap/josm/io/session/MarkerSessionExporter.java
r7082 r7518 100 100 public void write(MarkerLayer layer) { 101 101 GpxData data = new GpxData(); 102 data. attr.put(GpxData.META_DESC, "exported JOSM marker layer");102 data.put(GpxData.META_DESC, "exported JOSM marker layer"); 103 103 for (Marker m : layer.data) { 104 104 data.waypoints.add(m.convertToWayPoint());
Note:
See TracChangeset
for help on using the changeset viewer.