Changeset 5684 in josm for trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
- Timestamp:
- 2013-01-28T14:06:52+01:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java
r5681 r5684 8 8 import java.net.MalformedURLException; 9 9 import java.net.URL; 10 import java.text.DateFormat; 11 import java.text.SimpleDateFormat; 10 12 import java.util.ArrayList; 11 13 import java.util.Collection; 14 import java.util.Date; 12 15 import java.util.HashMap; 13 16 import java.util.LinkedList; 14 17 import java.util.List; 15 18 import java.util.Map; 19 import java.util.TimeZone; 16 20 17 21 import javax.swing.Icon; … … 23 27 import org.openstreetmap.josm.data.coor.EastNorth; 24 28 import org.openstreetmap.josm.data.coor.LatLon; 29 import org.openstreetmap.josm.data.gpx.Extensions; 25 30 import org.openstreetmap.josm.data.gpx.GpxConstants; 26 31 import org.openstreetmap.josm.data.gpx.GpxLink; … … 181 186 Marker.markerProducers.add(new MarkerProducers() { 182 187 @SuppressWarnings("unchecked") 188 @Override 183 189 public Marker createMarker(WayPoint wpt, File relativePath, MarkerLayer parentLayer, double time, double offset) { 184 190 String uri = null; … … 217 223 } 218 224 else if (url.toString().endsWith(".wav")) { 219 return new AudioMarker(wpt.getCoor(), wpt, url, parentLayer, time, offset); 225 AudioMarker audioMarker = new AudioMarker(wpt.getCoor(), wpt, url, parentLayer, time, offset); 226 Extensions exts = (Extensions) wpt.get(GpxConstants.META_EXTENSIONS); 227 if (exts != null && exts.containsKey("offset")) { 228 try { 229 double syncOffset = Double.parseDouble(exts.get("sync-offset")); 230 audioMarker.syncOffset = syncOffset; 231 } catch (NumberFormatException nfe) {} 232 } 233 return audioMarker; 220 234 } else if (url.toString().endsWith(".png") || url.toString().endsWith(".jpg") || url.toString().endsWith(".jpeg") || url.toString().endsWith(".gif")) { 221 235 return new ImageMarker(wpt.getCoor(), url, parentLayer, time, offset); … … 234 248 * @param relativePath An path to use for constructing relative URLs or 235 249 * <code>null</code> for no relative URLs 250 * @param parentLayer the <code>MarkerLayer</code> that will contain the created <code>Marker</code> 251 * @param time time of the marker in seconds since epoch 236 252 * @param offset double in seconds as the time offset of this marker from 237 253 * the GPX file from which it was derived (if any). … … 247 263 } 248 264 265 private static final DateFormat timeFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); 266 static { 267 TimeZone tz = TimeZone.getTimeZone("UTC"); 268 timeFormatter.setTimeZone(tz); 269 } 270 249 271 public static final String MARKER_OFFSET = "waypointOffset"; 250 272 public static final String MARKER_FORMATTED_OFFSET = "formattedWaypointOffset"; … … 254 276 public static final String LABEL_PATTERN_DESC = "{desc}"; 255 277 256 257 278 private final TemplateEngineDataProvider dataProvider; 258 279 private final String text; … … 260 281 public final Icon symbol; 261 282 public final MarkerLayer parentLayer; 262 public double time; /* absolute time of marker since epoch */283 public double time; /* absolute time of marker in seconds since epoch */ 263 284 public double offset; /* time offset in seconds from the gpx point from which it was derived, 264 285 may be adjusted later to sync with other data, so not final */ … … 296 317 } 297 318 319 /** 320 * Convert Marker to WayPoint so it can be exported to a GPX file. 321 * 322 * Override in subclasses to add all necessary attributes. 323 * 324 * @return the corresponding WayPoint with all relevant attributes 325 */ 326 public WayPoint convertToWayPoint() { 327 WayPoint wpt = new WayPoint(getCoor()); 328 wpt.put("time", timeFormatter.format(new Date(Math.round(time * 1000)))); 329 if (text != null) { 330 wpt.addExtension("text", text); 331 } else if (dataProvider != null) { 332 for (String key : dataProvider.getTemplateKeys()) { 333 Object value = dataProvider.getTemplateValue(key, false); 334 if (value != null && GpxConstants.WPT_KEYS.contains(key)) { 335 wpt.put(key, value); 336 } 337 } 338 } 339 return wpt; 340 } 341 298 342 public final void setCoor(LatLon coor) { 299 343 if(this.coor == null) { … … 343 387 * @param mv map view 344 388 * @param mousePressed true if the left mouse button is pressed 389 * @param showTextOrIcon true if text and icon shall be drawn 345 390 */ 346 391 public void paint(Graphics g, MapView mv, boolean mousePressed, boolean showTextOrIcon) { … … 398 443 } 399 444 400 private String formatOffset 445 private String formatOffset() { 401 446 int wholeSeconds = (int)(offset + 0.5); 402 447 if (wholeSeconds < 60)
Note:
See TracChangeset
for help on using the changeset viewer.