Changeset 15646 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2020-01-06T20:05:34+01:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r14761 r15646 16 16 import org.openstreetmap.josm.data.Bounds.ParseMethod; 17 17 import org.openstreetmap.josm.data.ProjectionBounds; 18 import org.openstreetmap.josm.data.gpx.GpxConstants; 18 19 import org.openstreetmap.josm.data.gpx.GpxData; 19 20 import org.openstreetmap.josm.gui.MainApplication; … … 34 35 import org.openstreetmap.josm.spi.preferences.Config; 35 36 import org.openstreetmap.josm.tools.CheckParameterUtil; 37 import org.openstreetmap.josm.tools.Utils; 36 38 import org.xml.sax.SAXException; 37 39 … … 44 46 private GpxLayer gpxLayer; 45 47 46 protected String newLayerName;48 protected String url; 47 49 48 50 @Override … … 68 70 public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 69 71 CheckParameterUtil.ensureParameterNotNull(url, "url"); 72 this.url = url; 70 73 final Optional<String> mappedUrl = Stream.of(GpxUrlPattern.USER_TRACE_ID, GpxUrlPattern.EDIT_TRACE_ID) 71 74 .map(p -> Pattern.compile(p.pattern()).matcher(url)) … … 81 84 downloadTask = new DownloadTask(settings, 82 85 new OsmServerLocationReader(url), progressMonitor); 83 // Extract .gpx filename from URL to set the new layer name84 Matcher matcher = Pattern.compile(GpxUrlPattern.EXTERNAL_GPX_FILE.pattern()).matcher(url);85 newLayerName = matcher.matches() ? matcher.group(1) : null;86 86 // We need submit instead of execute so we can wait for it to finish and get the error 87 87 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. … … 139 139 if (rawData == null) 140 140 return; 141 String name = newLayerName!= null ? newLayerName : tr("Downloaded GPX Data");141 String name = getLayerName(); 142 142 143 143 GpxImporterData layers = GpxImporter.loadLayers(rawData, reader.isGpxParsedProperly(), name, … … 149 149 150 150 layers.getPostLayerTask().run(); 151 } 152 153 private String getLayerName() { 154 // Extract .gpx filename from URL to set the new layer name 155 final Matcher matcher = Pattern.compile(GpxUrlPattern.EXTERNAL_GPX_FILE.pattern()).matcher(url); 156 final String newLayerName = matcher.matches() ? matcher.group(1) : null; 157 final String metadataName = rawData != null ? rawData.getString(GpxConstants.META_NAME) : null; 158 final String defaultName = tr("Downloaded GPX Data"); 159 160 if (Config.getPref().getBoolean("gpx.prefermetadataname", false)) { 161 return Utils.firstNotEmptyString(defaultName, metadataName, newLayerName); 162 } else { 163 return Utils.firstNotEmptyString(defaultName, newLayerName, metadataName); 164 } 151 165 } 152 166 -
trunk/src/org/openstreetmap/josm/gui/layer/GpxLayer.java
r15502 r15646 107 107 */ 108 108 public GpxLayer(GpxData d, String name, boolean isLocal) { 109 super( d.getString(GpxConstants.META_NAME));109 super(name); 110 110 data = d; 111 111 data.addWeakChangeListener(dataChangeListener); 112 112 trackVisibility = new boolean[data.getTracks().size()]; 113 113 Arrays.fill(trackVisibility, true); 114 setName(name);115 114 isLocalFile = isLocal; 116 115 ExpertToggleAction.addExpertModeChangeListener(this, true); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r15590 r15646 747 747 748 748 /** 749 * Returns the first not empty string in the given candidates, otherwise the default string. 750 * @param defaultString default string returned if all candidates would be empty if stripped 751 * @param candidates string candidates to consider 752 * @return the first not empty string in the given candidates, otherwise the default string 753 * @since 15646 754 */ 755 public static String firstNotEmptyString(String defaultString, String... candidates) { 756 for (String candidate : candidates) { 757 if (!Utils.isStripEmpty(candidate)) { 758 return candidate; 759 } 760 } 761 return defaultString; 762 } 763 764 /** 749 765 * Determines if the given String would be empty if stripped. 750 766 * This is an efficient alternative to {@code strip(s).isEmpty()} that avoids to create useless String object.
Note:
See TracChangeset
for help on using the changeset viewer.