Changeset 12157 in josm for trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
- Timestamp:
- 2017-05-15T14:41:08+02:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r12156 r12157 10 10 import java.text.DateFormat; 11 11 import java.util.Arrays; 12 import java.util.Collection;13 12 import java.util.Date; 14 import java.util.LinkedList;15 import java.util.List;16 13 17 14 import javax.swing.Action; … … 20 17 import javax.swing.SwingUtilities; 21 18 22 import org.openstreetmap.josm.Main;23 19 import org.openstreetmap.josm.actions.RenameLayerAction; 24 20 import org.openstreetmap.josm.actions.SaveActionBase; … … 28 24 import org.openstreetmap.josm.data.gpx.GpxData; 29 25 import org.openstreetmap.josm.data.gpx.GpxTrack; 30 import org.openstreetmap.josm.data.gpx.WayPoint;31 26 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 32 27 import org.openstreetmap.josm.data.preferences.ColorProperty; … … 66 61 public boolean[] trackVisibility = new boolean[0]; 67 62 68 private final GpxDrawHelper drawHelper;69 70 63 /** 71 64 * Constructs a new {@code GpxLayer} without name. … … 95 88 data = d; 96 89 data.addWeakChangeListener(e -> this.invalidate()); 97 drawHelper = new GpxDrawHelper(data); 98 SystemOfMeasurement.addSoMChangeListener(drawHelper); 99 ensureTrackVisibilityLength(); 90 trackVisibility = new boolean[data.getTracks().size()]; 91 Arrays.fill(trackVisibility, true); 100 92 setName(name); 101 93 isLocalFile = isLocal; … … 280 272 throw new IllegalArgumentException("not a GpxLayer: " + from); 281 273 data.mergeFrom(((GpxLayer) from).data); 282 drawHelper.dataChanged(); 283 } 284 285 @Override 286 public void paint(Graphics2D g, MapView mv, Bounds box) { 287 List<WayPoint> visibleSegments = listVisibleSegments(box); 288 if (!visibleSegments.isEmpty()) { 289 drawHelper.readPreferences(getName()); 290 drawHelper.drawAll(g, mv, visibleSegments); 291 if (Main.getLayerManager().getActiveLayer() == this) { 292 drawHelper.drawColorBar(g, mv); 293 } 294 } 295 } 296 297 private List<WayPoint> listVisibleSegments(Bounds box) { 298 WayPoint last = null; 299 LinkedList<WayPoint> visibleSegments = new LinkedList<>(); 300 301 ensureTrackVisibilityLength(); 302 for (Collection<WayPoint> segment : data.getLinesIterable(trackVisibility)) { 303 304 for (WayPoint pt : segment) { 305 Bounds b = new Bounds(pt.getCoor()); 306 if (pt.drawLine && last != null) { 307 b.extend(last.getCoor()); 308 } 309 if (b.intersects(box)) { 310 if (last != null && (visibleSegments.isEmpty() 311 || visibleSegments.getLast() != last)) { 312 if (last.drawLine) { 313 WayPoint l = new WayPoint(last); 314 l.drawLine = false; 315 visibleSegments.add(l); 316 } else { 317 visibleSegments.add(last); 318 } 319 } 320 visibleSegments.add(pt); 321 } 322 last = pt; 323 } 324 } 325 return visibleSegments; 274 invalidate(); 326 275 } 327 276 … … 339 288 public void setAssociatedFile(File file) { 340 289 data.storageFile = file; 341 }342 343 /** ensures the trackVisibility array has the correct length without losing data.344 * additional entries are initialized to true;345 */346 private void ensureTrackVisibilityLength() {347 final int l = data.getTracks().size();348 if (l == trackVisibility.length)349 return;350 final int m = Math.min(l, trackVisibility.length);351 trackVisibility = Arrays.copyOf(trackVisibility, l);352 for (int i = m; i < l; i++) {353 trackVisibility[i] = true;354 }355 invalidate();356 290 } 357 291 … … 383 317 384 318 @Override 385 public synchronized void destroy() { 386 super.destroy(); 387 SystemOfMeasurement.removeSoMChangeListener(drawHelper); 319 public void paint(Graphics2D g, MapView mv, Bounds bbox) { 320 // unused - we use a painter so this is not called. 321 } 322 323 @Override 324 protected LayerPainter createMapViewPainter(MapViewEvent event) { 325 return new GpxDrawHelper(this); 388 326 } 389 327 }
Note:
See TracChangeset
for help on using the changeset viewer.