Dear JOSM developers,
since introduction of "identifiable" tracks in API, I find it very useful
to see which track I am looking at in the editor. Therefore, written the
attached patch.
Please consider including it into JOSM, if it doesn't have any problems.
--
Totus tuus, Glebius.
GLEB-RIPE
Index: gui/layer/GpxLayer.java
===
--- gui/layer/GpxLayer.java (revision 2144)
+++ gui/layer/GpxLayer.java (working copy)
@@ -329,10 +329,6 @@
public String getToolTipText() {
StringBuilder info = new StringBuilder().append("");
-info.append(trn("{0} track, ", "{0} tracks, ", data.tracks.size(), data.tracks.size())).append(
-trn("{0} route, ", "{0} routes, ", data.routes.size(), data.routes.size())).append(
-trn("{0} waypoint", "{0} waypoints", data.waypoints.size(), data.waypoints.size())).append("");
-
if (data.attr.containsKey("name")) {
info.append(tr("Name: {0}", data.attr.get(GpxData.META_NAME))).append("");
}
@@ -342,15 +338,28 @@
}
if (data.tracks.size() > 0) {
-boolean first = true;
-WayPoint earliest = null, latest = null;
+ info.append(""
+ + trn("{0} track", "{0} tracks", data.tracks.size(), data.tracks.size())
+ + "" + tr("Name") + ""
+ + tr("Description") + "" + tr("Timespan")
+ + "" + tr("Length") + "" + tr("URL")
+ + "");
for (GpxTrack trk : data.tracks) {
+ WayPoint earliest = null, latest = null;
+
+ info.append("");
+ if (trk.attr.containsKey("name"))
+ info.append(trk.attr.get("name"));
+ info.append("");
+ if (trk.attr.containsKey("desc"))
+ info.append(" ").append(trk.attr.get("desc"));
+ info.append("");
+
for (Collection seg : trk.trackSegs) {
for (WayPoint pnt : seg) {
-if (first) {
+if (latest == null) {
latest = earliest = pnt;
-first = false;
} else {
if (pnt.compareTo(earliest) < 0) {
earliest = pnt;
@@ -360,19 +369,33 @@
}
}
}
-}
-if (earliest != null && latest != null) {
-DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
-info.append(tr("Timespan: ") + df.format(new Date((long) (earliest.time * 1000))) + " - "
+
+ if (earliest != null && latest != null) {
+ DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT);
+ info.append(df.format(new Date((long) (earliest.time * 1000))) + " - "
+ df.format(new Date((long) (latest.time * 1000;
-int diff = (int) (latest.time - earliest.time);
-info.append(" (" + (diff / 3600) + ":" + ((diff % 3600) / 60) + ")");
-info.append("");
+ int diff = (int) (latest.time - earliest.time);
+ info.append(" (" + (diff / 3600) + ":" + ((diff % 3600) / 60) + ")");
+ }
+
+ info.append("");
+ info.append(new DecimalFormat("#0.00").format(trk.length() / 1000) + "km");
+ info.append("");
+ if (trk.attr.containsKey("url"))
+ info.append(trk.attr.get("url"));
+ info.append("");
}
+
+ info.append("");
+
}
+
info.append(tr("Length: ") + new DecimalFormat("#0.00").format(data.length() / 1000) + "km");
info.append("");
+ info.append(trn("{0} route, ", "{0} routes, ", data.routes.size(), data.routes.size())).append(
+trn("{0} waypoint", "{0} waypoints", data.waypoints.size(), data.waypoints.size())).append("");
+
return info.append("").toString();
}
Index: io/GpxReader.java
===
--- io/GpxReader.java (revision 2144)
+++ io/GpxReader.java (working copy)
@@ -285,7 +285,8 @@
currentData.tracks.add(currentTrack);
} else if (qName.equals("name") || qName.equals("cmt")
|| qName.equals("desc") || qName.equals("src")
-|| qName.equals("type") || qName.equals("number")) {
+|| qName.equals("type") || qName.equals("number")
+ || qName.equals("url")) {
currentTrack.attr.put(qName, accumulator.toString());
}
break;
Index: data/gpx/GpxTrack.java
===
--- data/gpx/GpxTrack.java (revision 2144)
+++ data/gpx/GpxTrack.java (working copy)
@@ -9,4 +9,25 @@
public class GpxTrack extends WithAttributes {
public Collection> trackSegs
= new LinkedList>();
+
+/**
+ * calculates the length of the track
+ */
+public double length(){
+