Changeset 553 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2008-02-21T19:53:16+01:00 (17 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenAction.java
r529 r553 89 89 } 90 90 r.data.storageFile = file; 91 Main.main.addLayer(new GpxLayer(r.data, fn)); 92 MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), file); 91 GpxLayer gpxLayer = new GpxLayer(r.data, fn); 92 Main.main.addLayer(gpxLayer); 93 MarkerLayer ml = new MarkerLayer(r.data, tr("Markers from {0}", fn), file, gpxLayer); 93 94 if (ml.data.size() > 0) { 94 95 Main.main.addLayer(ml); -
trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java
r477 r553 27 27 } 28 28 29 public EastNorth interpolate(EastNorth en2, double proportion) { 30 return new EastNorth(this.x + proportion * (en2.x - this.x),this.y + proportion * (en2.y - this.y)); 31 } 32 29 33 @Override public String toString() { 30 34 return "EastNorth[e="+x+", n="+y+"]"; -
trunk/src/org/openstreetmap/josm/data/gpx/WayPoint.java
r552 r553 16 16 public final LatLon latlon; 17 17 public final EastNorth eastNorth; 18 public double time; 18 19 19 20 public WayPoint(LatLon ll) { 20 21 latlon = ll; 21 eastNorth = Main.proj.latlon2eastNorth(ll); 22 eastNorth = Main.proj.latlon2eastNorth(ll); 22 23 } 23 24 … … 31 32 * @return seconds 32 33 */ 33 public double time () {34 public void setTime () { 34 35 if (! attr.containsKey("time")) 35 return0.0;36 time = 0.0; 36 37 SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); // ignore timezone 37 38 Date d = f.parse(attr.get("time").toString(), new ParsePosition(0)); 38 39 if (d == null /* failed to parse */) 39 return0.0;40 returnd.getTime() / 1000.0; /* ms => seconds */40 time = 0.0; 41 time = d.getTime() / 1000.0; /* ms => seconds */ 41 42 } 42 43 -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r527 r553 10 10 import java.awt.event.ComponentEvent; 11 11 import java.awt.event.KeyEvent; 12 import java.awt.event.ActionListener; 13 import java.awt.event.ActionEvent; 12 14 import java.util.ArrayList; 13 15 import java.util.Collection; … … 72 74 */ 73 75 private Layer activeLayer; 76 74 77 /** 75 78 * The listener of the active layer changes. -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r552 r553 69 69 public class GpxLayer extends Layer { 70 70 public GpxData data; 71 71 private final GpxLayer me; 72 72 73 public GpxLayer(GpxData d) { 73 74 super((String) d.attr.get("name")); 74 data = d; 75 data = d; 76 me = this; 75 77 } 76 78 … … 149 151 namedTrackPoints.waypoints.add(point); 150 152 151 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), associatedFile );153 MarkerLayer ml = new MarkerLayer(namedTrackPoints, tr("Named Trackpoints from {0}", name), associatedFile, me); 152 154 if (ml.data.size() > 0) { 153 155 Main.main.addLayer(ml); … … 499 501 WayPoint prevPoint = null; 500 502 501 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Sampled audio markers from {0}", name), associatedFile );503 MarkerLayer ml = new MarkerLayer(new GpxData(), tr("Sampled audio markers from {0}", name), associatedFile, me); 502 504 503 505 for (GpxTrack track : data.tracks) { 504 506 for (Collection<WayPoint> seg : track.trackSegs) { 505 507 for (WayPoint point : seg) { 506 double time = point.time ();508 double time = point.time; 507 509 if (firstTime < 0.0) 508 510 firstTime = time; … … 521 523 else 522 524 markerName = String.format("%d:%02d:%02d", wholeSeconds / 3600, (wholeSeconds % 3600)/60, wholeSeconds % 60); 523 AudioMarker am = AudioMarker.create(point.latlon, markerName, uri, offset);525 AudioMarker am = AudioMarker.create(point.latlon, markerName, uri, ml, time, offset); 524 526 ml.data.add(am); 525 527 prevPoint = point; -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/AudioMarker.java
r547 r553 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.Graphics; 7 import java.awt.Point; 8 import java.awt.Rectangle; 6 9 import java.awt.event.ActionEvent; 10 import java.awt.event.ActionListener; 7 11 import java.io.IOException; 8 12 import java.net.URL; 9 13 10 import javax.sound.sampled.AudioFormat; 11 import javax.sound.sampled.AudioInputStream; 12 import javax.sound.sampled.AudioSystem; 13 import javax.sound.sampled.DataLine; 14 import javax.sound.sampled.SourceDataLine; 14 import javax.swing.Icon; 15 15 import javax.swing.JOptionPane; 16 import javax.swing.Timer; 16 17 17 18 import org.openstreetmap.josm.Main; 18 19 import org.openstreetmap.josm.data.coor.LatLon; 19 20 import org.openstreetmap.josm.tools.AudioPlayer; 21 import org.openstreetmap.josm.data.gpx.WayPoint; 22 import org.openstreetmap.josm.data.coor.EastNorth; 23 import org.openstreetmap.josm.gui.MapView; 24 25 import org.openstreetmap.josm.tools.ImageProvider; 20 26 21 27 /** … … 27 33 public class AudioMarker extends ButtonMarker { 28 34 29 private URL audioUrl; 30 private double syncOffset; 35 private URL audioUrl; 31 36 private static AudioMarker recentlyPlayedMarker = null; 32 37 public double syncOffset; 38 33 39 /** 34 40 * Verifies the parameter whether a new AudioMarker can be created and return 35 41 * one or return <code>null</code>. 36 42 */ 37 public static AudioMarker create(LatLon ll, String text, String url, double offset) {43 public static AudioMarker create(LatLon ll, String text, String url, MarkerLayer parentLayer, double time, double offset) { 38 44 try { 39 return new AudioMarker(ll, text, new URL(url), offset);45 return new AudioMarker(ll, text, new URL(url), parentLayer, time, offset); 40 46 } catch (Exception ex) { 41 47 return null; … … 43 49 } 44 50 45 private AudioMarker(LatLon ll, String text, URL audioUrl, double offset) {46 super(ll, text, "speech.png", offset);51 private AudioMarker(LatLon ll, String text, URL audioUrl, MarkerLayer parentLayer, double time, double offset) { 52 super(ll, text, "speech.png", parentLayer, time, offset); 47 53 this.audioUrl = audioUrl; 48 54 this.syncOffset = 0.0; … … 60 66 return audioUrl; 61 67 } 62 68 63 69 /** 64 70 * Starts playing the audio associated with the marker: used in response to pressing … … 68 74 public void play() { 69 75 try { 76 // first enable tracing the audio along the track 77 if (Main.pref.getBoolean("marker.traceaudio") && parentLayer != null) { 78 parentLayer.traceAudio(); 79 } 80 70 81 AudioPlayer.play(audioUrl, offset + syncOffset); 71 82 recentlyPlayedMarker = this; … … 74 85 } 75 86 } 76 87 77 88 public void adjustOffset(double adjustment) { 78 89 syncOffset = adjustment; // added to offset may turn out negative, but that's ok -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/ButtonMarker.java
r552 r553 25 25 26 26 private Rectangle buttonRectangle; 27 protected Graphics graphicsContext = null; 27 28 28 public ButtonMarker(LatLon ll, String buttonImage, double offset) {29 super(ll, null, buttonImage, offset);29 public ButtonMarker(LatLon ll, String buttonImage, MarkerLayer parentLayer, double time, double offset) { 30 super(ll, null, buttonImage, parentLayer, time, offset); 30 31 buttonRectangle = new Rectangle(0, 0, symbol.getIconWidth(), symbol.getIconHeight()); 31 32 } 32 33 33 public ButtonMarker(LatLon ll, String text, String buttonImage, double offset) {34 super(ll, text, buttonImage, offset);34 public ButtonMarker(LatLon ll, String text, String buttonImage, MarkerLayer parentLayer, double time, double offset) { 35 super(ll, text, buttonImage, parentLayer, time, offset); 35 36 buttonRectangle = new Rectangle(0, 0, symbol.getIconWidth(), symbol.getIconHeight()); 36 37 } … … 43 44 44 45 @Override public void paint(Graphics g, MapView mv, boolean mousePressed, String show) { 46 graphicsContext = g; 45 47 Point screen = mv.getPoint(eastNorth); 46 48 buttonRectangle.setLocation(screen.x+4, screen.y+2); -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/ImageMarker.java
r547 r553 22 22 import org.openstreetmap.josm.data.coor.LatLon; 23 23 import org.openstreetmap.josm.tools.ImageProvider; 24 import org.openstreetmap.josm.gui.layer.Layer; 24 25 25 26 /** … … 34 35 public URL imageUrl; 35 36 36 public static ImageMarker create(LatLon ll, String url, double offset) {37 public static ImageMarker create(LatLon ll, String url, MarkerLayer parentLayer, double time, double offset) { 37 38 try { 38 return new ImageMarker(ll, new URL(url), offset);39 return new ImageMarker(ll, new URL(url), parentLayer, time, offset); 39 40 } catch (Exception ex) { 40 41 return null; … … 42 43 } 43 44 44 private ImageMarker(LatLon ll, URL imageUrl, double offset) {45 super(ll, "photo.png", offset);45 private ImageMarker(LatLon ll, URL imageUrl, MarkerLayer parentLayer, double time, double offset) { 46 super(ll, "photo.png", parentLayer, time, offset); 46 47 this.imageUrl = imageUrl; 47 48 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r547 r553 22 22 import org.openstreetmap.josm.data.gpx.WayPoint; 23 23 import org.openstreetmap.josm.gui.MapView; 24 import org.openstreetmap.josm.gui.layer.Layer; 24 25 import org.openstreetmap.josm.tools.ImageProvider; 25 26 … … 64 65 public final String text; 65 66 public final Icon symbol; 67 public final MarkerLayer parentLayer; 68 public double time; /* avbsolute time of marker since epocj */ 66 69 public double offset; /* time offset in seconds from the gpx point from which it was derived, 67 70 may be adjusted later to sync with other data, so not final */ … … 78 81 Marker.markerProducers.add(new MarkerProducers() { 79 82 public Marker createMarker(WayPoint wpt, File relativePath) { 80 return createMarker(wpt, relativePath, 0.0);83 return createMarker(wpt, relativePath, null, 0.0, 0.0); 81 84 } 82 85 83 public Marker createMarker(WayPoint wpt, File relativePath, double offset) {86 public Marker createMarker(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time, double offset) { 84 87 String uri = null; 85 88 // cheapest way to check whether "link" object exists and is a non-empty … … 104 107 105 108 if (uri == null) 106 return new Marker(wpt.latlon, name_desc, wpt.getString("symbol"), offset);109 return new Marker(wpt.latlon, name_desc, wpt.getString("symbol"), parentLayer, time, offset); 107 110 else if (uri.endsWith(".wav")) 108 return AudioMarker.create(wpt.latlon, name_desc, uri, offset);111 return AudioMarker.create(wpt.latlon, name_desc, uri, parentLayer, time, offset); 109 112 else if (uri.endsWith(".png") || uri.endsWith(".jpg") || uri.endsWith(".jpeg") || uri.endsWith(".gif")) 110 return ImageMarker.create(wpt.latlon, uri, offset);113 return ImageMarker.create(wpt.latlon, uri, parentLayer, time, offset); 111 114 else 112 return WebMarker.create(wpt.latlon, uri, offset);115 return WebMarker.create(wpt.latlon, uri, parentLayer, time, offset); 113 116 } 114 117 … … 124 127 } 125 128 126 public Marker(LatLon ll, String text, String iconName, double offset) {129 public Marker(LatLon ll, String text, String iconName, MarkerLayer parentLayer, double time, double offset) { 127 130 eastNorth = Main.proj.latlon2eastNorth(ll); 128 131 this.text = text; 129 132 this.offset = offset; 133 this.time = time; 130 134 Icon symbol = ImageProvider.getIfAvailable("markers",iconName); 131 135 if (symbol == null) … … 134 138 symbol = ImageProvider.getIfAvailable("nodes",iconName); 135 139 this.symbol = symbol; 140 this.parentLayer = parentLayer; 136 141 } 137 142 … … 187 192 * @return a new Marker object 188 193 */ 189 public static Marker createMarker(WayPoint wpt, File relativePath, double offset) {194 public static Marker createMarker(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time, double offset) { 190 195 for (MarkerProducers maker : Marker.markerProducers) { 191 Marker marker = maker.createMarker(wpt, relativePath, offset);196 Marker marker = maker.createMarker(wpt, relativePath, parentLayer, time, offset); 192 197 if (marker != null) 193 198 return marker; … … 207 212 208 213 public AudioMarker audioMarkerFromMarker(String uri) { 209 AudioMarker audioMarker = AudioMarker.create(Main.proj.eastNorth2latlon(this.eastNorth), this.text, uri, this. offset);214 AudioMarker audioMarker = AudioMarker.create(Main.proj.eastNorth2latlon(this.eastNorth), this.text, uri, this.parentLayer, this.time, this.offset); 210 215 return audioMarker; 211 216 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java
r552 r553 9 9 import java.awt.Graphics; 10 10 import java.awt.Point; 11 import java.awt.Rectangle; 11 12 import java.awt.event.ActionEvent; 12 13 import java.awt.event.ActionListener; … … 26 27 import javax.swing.JSeparator; 27 28 import javax.swing.SwingUtilities; 29 import javax.swing.Timer; 28 30 import javax.swing.filechooser.FileFilter; 29 31 30 32 import org.openstreetmap.josm.Main; 31 33 import org.openstreetmap.josm.actions.RenameLayerAction; 34 import org.openstreetmap.josm.command.Command; 35 import org.openstreetmap.josm.data.coor.EastNorth; 32 36 import org.openstreetmap.josm.data.gpx.GpxData; 37 import org.openstreetmap.josm.data.gpx.GpxTrack; 33 38 import org.openstreetmap.josm.data.gpx.WayPoint; 34 39 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; … … 37 42 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 38 43 import org.openstreetmap.josm.gui.layer.Layer; 44 import org.openstreetmap.josm.gui.layer.GpxLayer; 39 45 import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker; 40 46 import org.openstreetmap.josm.tools.ColorHelper; … … 60 66 public final Collection<Marker> data; 61 67 private boolean mousePressed = false; 62 63 public MarkerLayer(GpxData indata, String name, File associatedFile) { 68 public GpxLayer fromLayer = null; 69 private Rectangle audioTracer = null; 70 private Icon audioTracerIcon = null; 71 private EastNorth audioTracerPosition = null; 72 private static Timer timer = null; 73 private static double audioAnimationInterval = 0.0; // seconds 74 private static double previousTime = -1.0; 75 76 public MarkerLayer(GpxData indata, String name, File associatedFile, GpxLayer fromLayer) { 64 77 65 78 super(name); 66 79 this.associatedFile = associatedFile; 67 80 this.data = new ArrayList<Marker>(); 81 this.fromLayer = fromLayer; 68 82 double firstTime = -1.0; 69 83 70 84 for (WayPoint wpt : indata.waypoints) { 71 85 /* calculate time differences in waypoints */ 72 double time = wpt.time ();86 double time = wpt.time; 73 87 if (firstTime < 0) 74 88 firstTime = time; 75 Marker m = Marker.createMarker(wpt, indata.storageFile, t ime - firstTime);89 Marker m = Marker.createMarker(wpt, indata.storageFile, this, time, time - firstTime); 76 90 if (m != null) 77 91 data.add(m); … … 147 161 } 148 162 } 163 164 if (audioTracer != null) { 165 Point screen = Main.map.mapView.getPoint(audioTracerPosition); 166 audioTracer.setLocation(screen.x, screen.y); 167 audioTracerIcon.paintIcon(Main.map.mapView, g, screen.x, screen.y); 168 } 169 } 170 171 protected void traceAudio() { 172 if (timer == null) { 173 audioAnimationInterval = Double.parseDouble(Main.pref.get("marker.audioanimationinterval", "1")); //milliseconds 174 timer = new Timer((int)(audioAnimationInterval * 1000.0), new ActionListener() { 175 public void actionPerformed(ActionEvent e) { 176 timerAction(); 177 } 178 }); 179 timer.start(); 180 } 181 } 182 183 /** 184 * callback for AudioPlayer when position changes 185 * @param position seconds into the audio stream 186 */ 187 public void timerAction() { 188 AudioMarker recentlyPlayedMarker = AudioMarker.recentlyPlayedMarker(); 189 if (recentlyPlayedMarker == null) 190 return; 191 double audioTime = recentlyPlayedMarker.time + 192 AudioPlayer.position() - 193 recentlyPlayedMarker.offset - 194 recentlyPlayedMarker.syncOffset; 195 if (Math.abs(audioTime- previousTime) < audioAnimationInterval) 196 return; 197 if (fromLayer == null) 198 return; 199 /* find the pair of track points for this position (adjusted by the syncOffset) 200 * and interpolate between them 201 */ 202 WayPoint w1 = null; 203 WayPoint w2 = null; 204 205 for (GpxTrack track : fromLayer.data.tracks) { 206 for (Collection<WayPoint> trackseg : track.trackSegs) { 207 for (Iterator<WayPoint> it = trackseg.iterator(); it.hasNext();) { 208 WayPoint w = it.next(); 209 if (audioTime < w.time) { 210 w2 = w; 211 break; 212 } 213 w1 = w; 214 } 215 if (w2 != null) break; 216 } 217 if (w2 != null) break; 218 } 219 220 if (w1 == null) 221 return; 222 audioTracerPosition = w2 == null ? 223 w1.eastNorth : 224 w1.eastNorth.interpolate(w2.eastNorth, 225 (audioTime - w1.time)/(w2.time - w1.time)); 226 227 if (audioTracer == null) { 228 audioTracerIcon = ImageProvider.getIfAvailable("markers",Main.pref.get("marker.audiotracericon", "audio-tracer")); 229 audioTracer = new Rectangle(0, 0, audioTracerIcon.getIconWidth(), audioTracerIcon.getIconHeight()); 230 } 231 previousTime = audioTime; 232 Main.map.mapView.repaint(); 149 233 } 150 234 -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerProducers.java
r547 r553 7 7 import org.openstreetmap.josm.data.coor.LatLon; 8 8 import org.openstreetmap.josm.data.gpx.WayPoint; 9 import org.openstreetmap.josm.gui.layer.Layer; 9 10 10 11 /** … … 27 28 * @return A Marker object, or <code>null</code>. 28 29 */ 29 public Marker createMarker(WayPoint wp, File relativePath, double offset);30 public Marker createMarker(WayPoint wp, File relativePath, MarkerLayer parentLayer, double time, double offset); 30 31 } -
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/WebMarker.java
r547 r553 12 12 import org.openstreetmap.josm.data.coor.LatLon; 13 13 import org.openstreetmap.josm.tools.OpenBrowser; 14 import org.openstreetmap.josm.gui.layer.Layer; 14 15 15 16 /** … … 23 24 public URL webUrl; 24 25 25 public static WebMarker create (LatLon ll, String url, double offset) {26 public static WebMarker create (LatLon ll, String url, MarkerLayer parentLayer, double time, double offset) { 26 27 try { 27 return new WebMarker(ll, new URL(url), offset);28 return new WebMarker(ll, new URL(url), parentLayer, time, offset); 28 29 } catch (Exception ex) { 29 30 return null; … … 31 32 } 32 33 33 private WebMarker(LatLon ll, URL webUrl, double offset) {34 super(ll, "web.png", offset);34 private WebMarker(LatLon ll, URL webUrl, MarkerLayer parentLayer, double time, double offset) { 35 super(ll, "web.png", parentLayer, time, offset); 35 36 this.webUrl = webUrl; 36 37 } -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java
r486 r553 40 40 public final JPanel connection = createPreferenceTab("connection", I18n.tr("Connection Settings"), I18n.tr("Connection Settings for the OSM server.")); 41 41 public final JPanel map = createPreferenceTab("map", I18n.tr("Map Settings"), I18n.tr("Settings for the map projection and data interpretation.")); 42 42 public final JPanel audio = createPreferenceTab("audio", I18n.tr("Audio Settings"), I18n.tr("Settings for the audio player and audio markers.")); 43 43 44 /** 44 45 * Construct a JPanel for the preference settings. Layout is GridBagLayout … … 109 110 settings.add(new PluginPreference()); 110 111 settings.add(Main.toolbar); 111 112 settings.add(new AudioPreference()); 113 112 114 for (PluginProxy plugin : Main.plugins) { 113 115 PreferenceSetting p = plugin.getPreferenceSetting(); -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r547 r553 234 234 } else if (qName.equals("rtept")) { 235 235 currentState = states.pop(); 236 currentWayPoint.setTime(); 236 237 currentRoute.routePoints.add(currentWayPoint); 237 238 } else if (qName.equals("trkpt")) { 238 239 currentState = states.pop(); 240 currentWayPoint.setTime(); 239 241 currentTrackSeg.add(currentWayPoint); 240 242 if (Main.pref.getBoolean("marker.namedtrackpoints") && … … 246 248 } else if (qName.equals("wpt")) { 247 249 currentState = states.pop(); 250 currentWayPoint.setTime(); 248 251 currentData.waypoints.add(currentWayPoint); 249 252 } -
trunk/src/org/openstreetmap/josm/tools/AudioPlayer.java
r549 r553 35 35 private double position; // seconds 36 36 private double bytesPerSecond; 37 37 38 38 /** 39 39 * Passes information from the control thread to the playing thread
Note:
See TracChangeset
for help on using the changeset viewer.