Changeset 7414 in josm for trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
- Timestamp:
- 2014-08-16T04:29:00+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r7402 r7414 23 23 import java.util.Arrays; 24 24 import java.util.Collection; 25 import java.util.Collections; 25 26 import java.util.HashMap; 26 27 import java.util.HashSet; … … 95 96 * 96 97 * @author imi 98 * @since 17 97 99 */ 98 100 public class OsmDataLayer extends AbstractModifiableLayer implements Listener, SelectionChangedListener { 101 /** Property used to know if this layer has to be saved on disk */ 99 102 public static final String REQUIRES_SAVE_TO_DISK_PROP = OsmDataLayer.class.getName() + ".requiresSaveToDisk"; 103 /** Property used to know if this layer has to be uploaded */ 100 104 public static final String REQUIRES_UPLOAD_TO_SERVER_PROP = OsmDataLayer.class.getName() + ".requiresUploadToServer"; 101 105 … … 232 236 } 233 237 238 /** 239 * Replies background color for downloaded areas. 240 * @return background color for downloaded areas. Black by default 241 */ 234 242 public static Color getBackgroundColor() { 235 243 return Main.pref.getColor(marktr("background"), Color.BLACK); 236 244 } 237 245 246 /** 247 * Replies background color for non-downloaded areas. 248 * @return background color for non-downloaded areas. Yellow by default 249 */ 238 250 public static Color getOutsideColor() { 239 251 return Main.pref.getColor(marktr("outside downloaded area"), Color.YELLOW); … … 257 269 258 270 /** 259 * Construct a OsmDataLayer. 271 * Construct a new {@code OsmDataLayer}. 272 * @param data OSM data 273 * @param name Layer name 274 * @param associatedFile Associated .osm file (can be null) 260 275 */ 261 276 public OsmDataLayer(final DataSet data, final String name, final File associatedFile) { … … 524 539 } 525 540 541 /** 542 * Converts given OSM dataset to GPX data. 543 * @param data OSM dataset 544 * @param file output .gpx file 545 * @return GPX data 546 */ 526 547 public static GpxData toGpxData(DataSet data, File file) { 527 548 GpxData gpxData = new GpxData(); 528 549 gpxData.storageFile = file; 529 550 HashSet<Node> doneNodes = new HashSet<>(); 530 for (Way w : data.getWays()) { 551 waysToGpxData(data.getWays(), gpxData, doneNodes); 552 nodesToGpxData(data.getNodes(), gpxData, doneNodes); 553 return gpxData; 554 } 555 556 private static void waysToGpxData(Collection<Way> ways, GpxData gpxData, HashSet<Node> doneNodes) { 557 for (Way w : ways) { 531 558 if (!w.isUsable()) { 532 559 continue; … … 562 589 gpxData.tracks.add(new ImmutableGpxTrack(trk, trkAttr)); 563 590 } 564 565 for (Node n : data.getNodes()) { 566 if (n.isIncomplete() || n.isDeleted() || doneNodes.contains(n)) { 591 } 592 593 private static void nodesToGpxData(Collection<Node> nodes, GpxData gpxData, HashSet<Node> doneNodes) { 594 List<Node> sortedNodes = new ArrayList<>(nodes); 595 sortedNodes.removeAll(doneNodes); 596 Collections.sort(sortedNodes); 597 for (Node n : sortedNodes) { 598 if (n.isIncomplete() || n.isDeleted()) { 567 599 continue; 568 600 } … … 583 615 gpxData.waypoints.add(wpt); 584 616 } 585 return gpxData; 586 } 587 617 } 618 619 /** 620 * Converts OSM data behind this layer to GPX data. 621 * @return GPX data 622 */ 588 623 public GpxData toGpxData() { 589 624 return toGpxData(data, getAssociatedFile()); 590 625 } 591 626 627 /** 628 * Action that converts this OSM layer to a GPX layer. 629 */ 592 630 public class ConvertToGpxLayerAction extends AbstractAction { 631 /** 632 * Constructs a new {@code ConvertToGpxLayerAction}. 633 */ 593 634 public ConvertToGpxLayerAction() { 594 635 super(tr("Convert to GPX layer"), ImageProvider.get("converttogpx")); … … 602 643 } 603 644 645 /** 646 * Determines if this layer contains data at the given coordinate. 647 * @param coor the coordinate 648 * @return {@code true} if data sources bounding boxes contain {@code coor} 649 */ 604 650 public boolean containsPoint(LatLon coor) { 605 651 // we'll assume that if this has no data sources … … 619 665 620 666 /** 621 * replies the set of conflicts currently managed in this layer667 * Replies the set of conflicts currently managed in this layer. 622 668 * 623 669 * @return the set of conflicts currently managed in this layer … … 643 689 } 644 690 691 /** 692 * Actions run after data has been downloaded to this layer. 693 */ 645 694 public void onPostDownloadFromServer() { 646 695 setRequiresSaveToFile(true); … … 708 757 @Override 709 758 public void projectionChanged(Projection oldValue, Projection newValue) { 710 /* 711 * No reprojection required. The dataset itself is registered as projection 712 * change listener and already got notified. 713 */ 759 // No reprojection required. The dataset itself is registered as projection 760 // change listener and already got notified. 714 761 } 715 762 … … 719 766 } 720 767 768 /** 769 * Sets the "discouraged upload" flag. 770 * @param uploadDiscouraged {@code true} if upload of data managed by this layer is discouraged. This feature allows to use "private" data layers. 771 */ 721 772 public final void setUploadDiscouraged(boolean uploadDiscouraged) { 722 773 if (uploadDiscouraged ^ isUploadDiscouraged()) {
Note:
See TracChangeset
for help on using the changeset viewer.