Changeset 552 in josm for trunk/src/org
- Timestamp:
- 2008-02-20T18:53:10+01:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r444 r552 3 3 4 4 package org.openstreetmap.josm.data.gpx; 5 6 import java.text.ParsePosition; 7 import java.text.SimpleDateFormat; 8 import java.util.Date; 5 9 6 10 import org.openstreetmap.josm.Main; … … 22 26 return "WayPoint (" + (attr.containsKey("name") ? attr.get("name") + ", " :"") + latlon.toString() + ", " + attr + ")"; 23 27 } 28 29 /** 30 * convert the time stamp of ther waypoint into seconds from the epoch 31 * @return seconds 32 */ 33 public double time () { 34 if (! attr.containsKey("time")) 35 return 0.0; 36 SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ignore timezone 37 Date d = f.parse(attr.get("time").toString(), new ParsePosition(0)); 38 if (d == null /* failed to parse */) 39 return 0.0; 40 return d.getTime() / 1000.0; /* ms => seconds */ 41 } 42 24 43 } -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r547 r552 11 11 import java.awt.GridBagLayout; 12 12 import java.awt.Point; 13 import java.util.ArrayList; 13 14 import java.util.Collection; 14 15 import java.util.LinkedList; … … 57 58 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 58 59 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 60 import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker; 59 61 import org.openstreetmap.josm.gui.layer.markerlayer.Marker; 60 62 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; … … 140 142 markersFromNamedTrackpoints.addActionListener(new ActionListener() { 141 143 public void actionPerformed(ActionEvent e) { 142 /*143 public Collection<GpxTrack> tracks = new LinkedList<GpxTrack>();144 public Collection<Collection<WayPoint>> trackSegs145 = new LinkedList<Collection<WayPoint>>();146 */147 144 GpxData namedTrackPoints = new GpxData(); 148 145 for (GpxTrack track : data.tracks) … … 156 153 Main.main.addLayer(ml); 157 154 } 155 } 156 }); 157 158 JMenuItem applyAudio = new JMenuItem(tr("Make Sampled Audio Layer"), ImageProvider.get("applyaudio")); 159 applyAudio.addActionListener(new ActionListener() { 160 public void actionPerformed(ActionEvent e) { 161 JFileChooser fc = new JFileChooser(Main.pref.get("tagimages.lastdirectory")); 162 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 163 fc.setAcceptAllFileFilterUsed(false); 164 fc.setFileFilter(new FileFilter(){ 165 @Override public boolean accept(File f) { 166 return f.isDirectory() || f.getName().toLowerCase().endsWith(".wav"); 167 } 168 @Override public String getDescription() { 169 return tr("Wave Audio files (*.wav)"); 170 } 171 }); 172 fc.showOpenDialog(Main.parent); 173 File sel = fc.getSelectedFile(); 174 if (sel == null) 175 return; 176 applyAudio(sel); 177 Main.map.repaint(); 158 178 } 159 179 }); … … 216 236 line, 217 237 tagimage, 238 applyAudio, 218 239 markersFromNamedTrackpoints, 219 240 new JMenuItem(new ConvertToDataLayerAction()), … … 456 477 } 457 478 479 /** 480 * 481 * 482 */ 483 private void applyAudio(File wavFile) { 484 String uri = "file:".concat(wavFile.getAbsolutePath()); 485 double audioGapSecs = 15.0; 486 try { 487 audioGapSecs = Double.parseDouble(Main.pref.get("marker.audiosampleminsecs", Double.toString(audioGapSecs))); 488 } catch (NumberFormatException e) { 489 } 490 double audioGapMetres = 75.0; 491 try { 492 audioGapMetres = Double.parseDouble(Main.pref.get("marker.audiosampleminmetres", Double.toString(audioGapMetres))); 493 } catch (NumberFormatException e) { 494 } 495 double audioGapRadians = (audioGapMetres / 40041455.0 /* circumference of Earth in metres */) * 2.0 * Math.PI; 496 double audioGapRadiansSquared = audioGapRadians * audioGapRadians; 497 double firstTime = -1.0; 498 double prevOffset = - (audioGapSecs + 1.0); // first point always exceeds time difference 499 WayPoint prevPoint = null; 500 501 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Sampled audio markers from {0}", name), associatedFile); 502 503 for (GpxTrack track : data.tracks) { 504 for (Collection<WayPoint> seg : track.trackSegs) { 505 for (WayPoint point : seg) { 506 double time = point.time(); 507 if (firstTime < 0.0) 508 firstTime = time; 509 double offset = time - firstTime; 510 if (prevPoint == null || 511 (offset - prevOffset > audioGapSecs && 512 /* note: distance is misleading: it actually gives distance _squared_ */ 513 point.eastNorth.distance(prevPoint.eastNorth) > audioGapRadiansSquared)) 514 { 515 String markerName; 516 int wholeSeconds = (int)(offset + 0.5); 517 if (wholeSeconds < 60) 518 markerName = Integer.toString(wholeSeconds); 519 else if (wholeSeconds < 3600) 520 markerName = String.format("%d:%02d", wholeSeconds / 60, wholeSeconds % 60); 521 else 522 markerName = String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60); 523 AudioMarker am = AudioMarker.create(point.latlon, markerName, uri, offset); 524 ml.data.add(am); 525 prevPoint = point; 526 prevOffset = offset; 527 } 528 } 529 } 530 } 531 532 if (ml.data.size() > 0) { 533 Main.main.addLayer(ml); 534 } 535 } 458 536 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/ButtonMarker.java
r547 r552 61 61 b.paintBorder(mv, g, r.x, r.y, r.width, r.height); 62 62 } 63 if ((text != null) && (show.equalsIgnoreCase("show")) && Main.pref.getBoolean("marker.buttonlabels" ))63 if ((text != null) && (show.equalsIgnoreCase("show")) && Main.pref.getBoolean("marker.buttonlabels", true)) 64 64 g.drawString(text, screen.x+4, screen.y+2); 65 65 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r551 r552 17 17 import java.util.Collection; 18 18 import java.util.Iterator; 19 import java.util.Date;20 import java.text.SimpleDateFormat;21 import java.text.ParsePosition;22 import java.text.ParseException;23 19 import java.net.URL; 24 20 … … 70 66 this.associatedFile = associatedFile; 71 67 this.data = new ArrayList<Marker>(); 72 double offset = 0.0; 73 Date firstDate = null; 68 double firstTime = -1.0; 74 69 75 70 for (WayPoint wpt : indata.waypoints) { 76 71 /* calculate time differences in waypoints */ 77 if (wpt.attr.containsKey("time")) { 78 SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ignore timezone, as it is all relative 79 Date d = f.parse(wpt.attr.get("time").toString(), new ParsePosition(0)); 80 if (d == null /* failed to parse */) { 81 offset = 0.0; 82 } else if (firstDate == null) { 83 firstDate = d; 84 offset = 0.0; 85 } else { 86 offset = (d.getTime() - firstDate.getTime()) / 1000.0; /* ms => seconds */ 87 } 88 } 89 90 Marker m = Marker.createMarker(wpt, indata.storageFile, offset); 72 double time = wpt.time(); 73 if (firstTime < 0) 74 firstTime = time; 75 Marker m = Marker.createMarker(wpt, indata.storageFile, time - firstTime); 91 76 if (m != null) 92 77 data.add(m);
Note:
See TracChangeset
for help on using the changeset viewer.