Ignore:
Timestamp:
2012-09-05T22:15:03+02:00 (12 years ago)
Author:
bastiK
Message:

add session support for gpx layers (see #4029)

Location:
trunk/src/org/openstreetmap/josm/io
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/GpxImporter.java

    r5494 r5501  
    4040         * The imported GPX layer. May be null if no GPX data.
    4141         */
    42         public GpxLayer gpxLayer;
     42        private GpxLayer gpxLayer;
    4343        /**
    4444         * The imported marker layer. May be null if no marker.
    4545         */
    46         public MarkerLayer markerLayer;
     46        private MarkerLayer markerLayer;
    4747        /**
    4848         * The task to run after GPX and/or marker layer has been added to MapView.
    4949         */
    50         public Runnable postLayerTask;
     50        private Runnable postLayerTask;
     51
     52        public GpxImporterData(GpxLayer gpxLayer, MarkerLayer markerLayer, Runnable postLayerTask) {
     53            this.gpxLayer = gpxLayer;
     54            this.markerLayer = markerLayer;
     55            this.postLayerTask = postLayerTask;
     56        }
     57
     58        public GpxLayer getGpxLayer() {
     59            return gpxLayer;
     60        }
     61
     62        public MarkerLayer getMarkerLayer() {
     63            return markerLayer;
     64        }
     65
     66        public Runnable getPostLayerTask() {
     67            return postLayerTask;
     68        }
    5169    }
    5270
     
    108126     * @see #addLayers
    109127     */
    110     public static GpxImporterData loadLayers(final GpxData data, final boolean parsedProperly, final String gpxLayerName, String markerLayerName) {
    111         final GpxImporterData result = new GpxImporterData();
     128    public static GpxImporterData loadLayers(final GpxData data, final boolean parsedProperly,
     129            final String gpxLayerName, String markerLayerName) {
     130        GpxLayer gpxLayer = null;
     131        MarkerLayer markerLayer = null;
    112132        if (data.hasRoutePoints() || data.hasTrackPoints()) {
    113             result.gpxLayer = new GpxLayer(data, gpxLayerName, data.storageFile != null);
     133            gpxLayer = new GpxLayer(data, gpxLayerName, data.storageFile != null);
    114134        }
    115135        if (Main.pref.getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) {
    116             result.markerLayer = new MarkerLayer(data, markerLayerName, data.storageFile, result.gpxLayer, false);
    117             if (result.markerLayer.data.size() == 0) {
    118                 result.markerLayer = null;
     136            markerLayer = new MarkerLayer(data, markerLayerName, data.storageFile, gpxLayer);
     137            if (markerLayer.data.isEmpty()) {
     138                markerLayer = null;
    119139            }
    120140        }
    121         result.postLayerTask = new Runnable() {
     141        Runnable postLayerTask = new Runnable() {
    122142            @Override
    123143            public void run() {
    124                 if (result.markerLayer != null) {
    125                     result.markerLayer.addMouseHandler();
    126                 }
    127144                if (!parsedProperly) {
    128145                    String msg;
     
    138155            }
    139156        };
    140         return result;
     157        return new GpxImporterData(gpxLayer, markerLayer, postLayerTask);
     158    }
     159
     160    public static GpxImporterData loadLayers(InputStream is, final File associatedFile,
     161            final String gpxLayerName, String markerLayerName, ProgressMonitor progressMonitor) throws IOException {
     162        try {
     163            final GpxReader r = new GpxReader(is);
     164            final boolean parsedProperly = r.parse(true);
     165            r.data.storageFile = associatedFile;
     166            return loadLayers(r.data, parsedProperly, gpxLayerName, markerLayerName);
     167        } catch (SAXException e) {
     168            e.printStackTrace();
     169            throw new IOException(tr("Parsing data for layer ''{0}'' failed", gpxLayerName));
     170        }
    141171    }
    142172}
  • trunk/src/org/openstreetmap/josm/io/session/OsmDataSessionExporter.java

    r5025 r5501  
    4949
    5050    private OsmDataLayer layer;
     51    private JRadioButton link, include;
     52    private JCheckBox export;
    5153
    5254    public OsmDataSessionExporter(OsmDataLayer layer) {
     
    5557
    5658    public OsmDataSessionExporter() {
    57     }
    58 
    59     public OsmDataSessionExporter newInstance(OsmDataLayer layer) {
    60         return new OsmDataSessionExporter(layer);
    6159    }
    6260
     
    6967        public LayerSaveAction() {
    7068            putValue(SMALL_ICON, new ImageProvider("save").setWidth(16).get());
    71             putValue(SHORT_DESCRIPTION, tr("Layer contains unsaved data - save to file."));
     69            putValue(SHORT_DESCRIPTION, layer.requiresSaveToFile() ?
     70                    tr("Layer contains unsaved data - save to file.") :
     71                    tr("Layer does not contain unsaved data."));
    7272            updateEnabledState();
    7373        }
     
    8282        }
    8383    }
    84 
    85     private JRadioButton link, include;
    86     private JCheckBox export;
    8784
    8885    @Override
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r5391 r5501  
    5757        registerSessionLayerImporter("osm-data", OsmDataSessionImporter.class);
    5858        registerSessionLayerImporter("imagery", ImagerySessionImporter.class);
     59        registerSessionLayerImporter("tracks", GpxTracksSessionImporter.class);
    5960    }
    6061
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r5391 r5501  
    2828import javax.xml.transform.stream.StreamResult;
    2929
    30 import org.w3c.dom.Document;
    31 import org.w3c.dom.Element;
    32 import org.w3c.dom.Text;
    33 
     30import org.openstreetmap.josm.gui.layer.GpxLayer;
    3431import org.openstreetmap.josm.gui.layer.Layer;
    3532import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    3835import org.openstreetmap.josm.tools.MultiMap;
    3936import org.openstreetmap.josm.tools.Utils;
     37import org.w3c.dom.Document;
     38import org.w3c.dom.Element;
     39import org.w3c.dom.Text;
    4040
    4141public class SessionWriter {
     
    4747        registerSessionLayerExporter(TMSLayer.class , ImagerySessionExporter.class);
    4848        registerSessionLayerExporter(WMSLayer.class , ImagerySessionExporter.class);
     49        registerSessionLayerExporter(GpxLayer.class , GpxTracksSessionExporter.class);
    4950    }
    5051
     
    8687    }
    8788
     89    /**
     90     * A class that provides some context for the individual {@link SessionLayerExporter}
     91     * when doing the export.
     92     */
    8893    public class ExportSupport {
    8994        private Document doc;
     
    103108        }
    104109
     110        /**
     111         * Get the index of the layer that is currently exported.
     112         * @return the index of the layer that is currently exported
     113         */
    105114        public int getLayerIndex() {
    106115            return layerIndex;
     
    108117
    109118        /**
    110          * Create a file in the zip archive.
     119         * Create a file inside the zip archive.
    111120         *
    112          * @return never close the output stream, but make sure to flush buffers
     121         * @param zipPath the path inside the zip archive, e.g. "layers/03/data.xml"
     122         * @return the OutputStream you can write to. Never close the returned
     123         * output stream, but make sure to flush buffers.
    113124         */
    114125        public OutputStream getOutputStreamZip(String zipPath) throws IOException {
     
    119130        }
    120131
     132        /**
     133         * Check, if the session is exported as a zip archive.
     134         *
     135         * @return true, if the session is exported as a zip archive (.joz file
     136         * extension). It will always return true, if one of the
     137         * {@link SessionLayerExporter} returns true for the
     138         * {@link SessionLayerExporter#requiresZip()} method. Otherwise, the
     139         * user can decide in the file chooser dialog.
     140         */
    121141        public boolean isZip() {
    122142            return zip;
Note: See TracChangeset for help on using the changeset viewer.