Changeset 18068 in josm
- Timestamp:
- 2021-07-18T19:53:41+02:00 (3 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java
r17188 r18068 17 17 import org.openstreetmap.josm.gui.MainApplication; 18 18 import org.openstreetmap.josm.gui.io.importexport.FileExporter; 19 import org.openstreetmap.josm.gui.io.importexport.GpxExporter; 19 20 import org.openstreetmap.josm.gui.io.importexport.GpxImporter; 20 import org.openstreetmap.josm.gui.layer.GpxLayer;21 21 import org.openstreetmap.josm.gui.layer.Layer; 22 import org.openstreetmap.josm.gui.layer.OsmDataLayer;23 22 import org.openstreetmap.josm.tools.CheckParameterUtil; 24 23 import org.openstreetmap.josm.tools.Shortcut; … … 59 58 /** 60 59 * Get the layer to export. 61 * @return The layer to export, either a {@link GpxLayer} or {@link OsmDataLayer}.60 * @return The layer to export, if supported, otherwise {@code null}. 62 61 */ 63 62 protected Layer getLayer() { 64 63 Layer layer = getLayerManager().getActiveLayer(); 65 return (layer instanceof GpxLayer || layer instanceof OsmDataLayer) ? layer : null;64 return GpxExporter.isSupportedLayer(layer) ? layer : null; 66 65 } 67 66 … … 86 85 * Exports a layer to a file. Launches a file chooser to request the user to enter a file name. 87 86 * 88 * <code>layer</code> must not be null. <code>layer</code> must be an instance of 89 * {@link OsmDataLayer} or {@link GpxLayer}. 87 * <code>layer</code> must not be null. <code>layer</code> must be of a supported type. 90 88 * 91 89 * @param layer the layer 92 90 * @throws IllegalArgumentException if layer is null 93 * @throws IllegalArgumentException if layer is n either an instance of {@link OsmDataLayer}94 * nor of {@link GpxLayer}91 * @throws IllegalArgumentException if layer is not of a supported type. 92 * @see GpxExporter#isSupportedLayer 95 93 */ 96 94 public void export(Layer layer) { 97 95 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 98 if (! (layer instanceof OsmDataLayer) && !(layer instanceof GpxLayer))99 throw new IllegalArgumentException(MessageFormat.format("Expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.",100 layer.getClass().getName()));96 if (!GpxExporter.isSupportedLayer(layer)) 97 throw new IllegalArgumentException(MessageFormat.format("Expected instance of {0}. Got ''{1}''.", 98 GpxExporter.getSupportedLayers(), layer.getClass().getName())); 101 99 102 100 File file = createAndOpenSaveFileChooser(tr("Export GPX file"), GpxImporter.getFileFilter()); -
trunk/src/org/openstreetmap/josm/gui/io/importexport/GpxExporter.java
r16629 r18068 14 14 import java.time.Year; 15 15 import java.time.ZoneId; 16 import java.util.Arrays; 17 import java.util.List; 16 18 import java.util.Optional; 17 19 … … 33 35 import org.openstreetmap.josm.gui.layer.Layer; 34 36 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 37 import org.openstreetmap.josm.gui.layer.geoimage.GeoImageLayer; 35 38 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 36 39 import org.openstreetmap.josm.gui.widgets.JosmTextField; … … 47 50 public class GpxExporter extends FileExporter implements GpxConstants { 48 51 52 private static final List<Class<? extends Layer>> SUPPORTED_LAYERS = Arrays.asList( 53 GpxLayer.class, OsmDataLayer.class, GeoImageLayer.class); 54 49 55 private static final String GPL_WARNING = "<html><font color='red' size='-2'>" 50 56 + tr("Note: GPL is not compatible with the OSM license. Do not upload GPL licensed tracks.") + "</html>"; … … 73 79 @Override 74 80 public boolean acceptFile(File pathname, Layer layer) { 75 if (!(layer instanceof OsmDataLayer) && !(layer instanceof GpxLayer)) 76 return false; 77 return super.acceptFile(pathname, layer); 81 return isSupportedLayer(layer) ? super.acceptFile(pathname, layer) : false; 78 82 } 79 83 … … 90 94 private void exportData(File file, Layer layer, boolean quiet) throws IOException { 91 95 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 92 if (! (layer instanceof OsmDataLayer) && !(layer instanceof GpxLayer))96 if (!isSupportedLayer(layer)) 93 97 throw new IllegalArgumentException(MessageFormat.format("Expected instance of OsmDataLayer or GpxLayer. Got ''{0}''.", layer 94 98 .getClass().getName())); … … 120 124 if (layer instanceof GpxLayer) { 121 125 gpxData = ((GpxLayer) layer).data; 126 } else if (layer instanceof GeoImageLayer) { 127 gpxData = ((GeoImageLayer) layer).getFauxGpxData(); 122 128 } else { 123 129 gpxData = new GpxData(); … … 270 276 } 271 277 278 /** 279 * Returns the list of supported layers. 280 * @return the list of supported layers 281 * @since 18068 282 */ 283 public static List<Class<? extends Layer>> getSupportedLayers() { 284 return SUPPORTED_LAYERS; 285 } 286 287 /** 288 * Determines if the given layer is supported by this action. 289 * @param layer layer to test 290 * @return {@code true} if the given layer is supported by this action 291 * @since 18068 292 */ 293 public static boolean isSupportedLayer(Layer layer) { 294 return SUPPORTED_LAYERS.stream().anyMatch(c -> c.isInstance(layer)); 295 } 296 272 297 private static GpxData getGpxData(Layer layer, File file) { 273 298 if (layer instanceof OsmDataLayer) { … … 275 300 } else if (layer instanceof GpxLayer) { 276 301 return ((GpxLayer) layer).data; 302 } else if (layer instanceof GeoImageLayer) { 303 return ((GeoImageLayer) layer).getFauxGpxData(); 277 304 } 278 305 return OsmDataLayer.toGpxData(MainApplication.getLayerManager().getEditDataSet(), file); -
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java
r18065 r18068 257 257 if (ExpertToggleAction.isExpert()) { 258 258 entries.add(new EditImagesSequenceAction(this)); 259 entries.add(new LayerGpxExportAction(this)); 259 260 } 260 261 entries.add(new ShowThumbnailAction(this));
Note:
See TracChangeset
for help on using the changeset viewer.