Changeset 7414 in josm
- Timestamp:
- 2014-08-16T04:29:00+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java
r6643 r7414 25 25 /** 26 26 * Exports data to gpx. 27 * @since 78 27 28 */ 28 29 public class GpxExportAction extends DiskAccessAction { 29 30 31 /** 32 * Constructs a new {@code GpxExportAction}. 33 */ 30 34 public GpxExportAction() { 31 35 super(tr("Export to GPX..."), "exportgpx", tr("Export the data to GPX file."), … … 95 99 /** 96 100 * Refreshes the enabled state 97 *98 101 */ 99 102 @Override -
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()) { -
trunk/src/org/openstreetmap/josm/io/GpxExporter.java
r7037 r7414 37 37 import org.openstreetmap.josm.tools.GBC; 38 38 39 /** 40 * Exports data to a .gpx file. Data may be native GPX or OSM data which will be converted. 41 * @since 1949 42 */ 39 43 public class GpxExporter extends FileExporter implements GpxConstants { 40 private static final String warningGpl = "<html><font color='red' size='-2'>" 44 45 private static final String GPL_WARNING = "<html><font color='red' size='-2'>" 41 46 + tr("Note: GPL is not compatible with the OSM license. Do not upload GPL licensed tracks.") + "</html>"; 42 47 … … 74 79 GpxData gpxData; 75 80 // At this moment, we only need to know the attributes of the GpxData, 76 // conversion of OsmDataLayer (if needed) will be done after the dialog 77 // is closed. 81 // conversion of OsmDataLayer (if needed) will be done after the dialog is closed. 78 82 if (layer instanceof GpxLayer) { 79 83 gpxData = ((GpxLayer) layer).data; … … 175 179 } 176 180 177 178 181 try (OutputStream fo = Compression.getCompressedFileOutputStream(file)) { 179 182 new GpxWriter(fo).write(gpxData); … … 194 197 copyrightLabel.setEnabled(enable); 195 198 copyrightYearLabel.setEnabled(enable); 196 warning.setText(enable ? warningGpl: "<html><font size='-2'> </html");199 warning.setText(enable ? GPL_WARNING : "<html><font size='-2'> </html"); 197 200 198 201 if (enable) { … … 220 223 /** 221 224 * Add all those listeners to handle the enable state of the fields. 222 * @param copyrightYearLabel223 * @param copyrightLabel224 * @param emailLabel225 * @param nameLabel226 * @param warning227 225 */ 228 226 private static void addDependencies( … … 299 297 return; 300 298 final String[] urls = { 301 "https://creativecommons.org/licenses/by-sa/ 2.5",299 "https://creativecommons.org/licenses/by-sa/3.0", 302 300 "http://opendatacommons.org/licenses/odbl/1.0", 303 301 "public domain", … … 329 327 return Main.main.getCurrentDataSet(); 330 328 } 331 332 329 }
Note:
See TracChangeset
for help on using the changeset viewer.