Changeset 5501 in josm for trunk/src/org/openstreetmap/josm


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
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    r5438 r5501  
    5151    private boolean zipRequired;
    5252
    53     /**
    54      * Construct the action with "Save" as label.
    55      */
    5653    public SessionSaveAsAction() {
    5754        super(tr("Save Session As..."), "save_as", tr("Save the current session to a new file."), null, true, "save_as-session", true);
     
    7269        for (Layer l : layers) {
    7370            SessionLayerExporter ex = exporters.get(l);
    74             if (ex.requiresZip()) {
     71            if (ex != null && ex.requiresZip()) {
    7572                zipRequired = true;
    7673                break;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r5494 r5501  
    124124            GpxImporterData layers = GpxImporter.loadLayers(rawData, reader.isGpxParsedProperly(), name, tr("Markers from {0}", name));
    125125           
    126             GpxLayer gpxLayer = addOrMergeLayer(layers.gpxLayer, findGpxMergeLayer());
    127             addOrMergeLayer(layers.markerLayer, findMarkerMergeLayer(gpxLayer));
     126            GpxLayer gpxLayer = addOrMergeLayer(layers.getGpxLayer(), findGpxMergeLayer());
     127            addOrMergeLayer(layers.getMarkerLayer(), findMarkerMergeLayer(gpxLayer));
    128128           
    129             layers.postLayerTask.run();
     129            layers.getPostLayerTask().run();
    130130        }
    131131       
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/Marker.java

    r5481 r5501  
    170170    }
    171171
    172 
    173172    /**
    174173     * Plugins can add their Marker creation stuff at the bottom or top of this list
     
    210209                }
    211210
    212 
    213211                if (url == null) {
    214212                    String symbolName = wpt.getString("symbol");
  • trunk/src/org/openstreetmap/josm/gui/layer/markerlayer/MarkerLayer.java

    r5481 r5501  
    6868    private Marker currentMarker;
    6969
     70    @Deprecated
     71    public MarkerLayer(GpxData indata, String name, File associatedFile, GpxLayer fromLayer, boolean addMouseHandlerInConstructor) {
     72        this(indata, name, associatedFile, fromLayer);
     73    }
     74
    7075    public MarkerLayer(GpxData indata, String name, File associatedFile, GpxLayer fromLayer) {
    71         this(indata, name, associatedFile, fromLayer, true);
    72     }
    73 
    74     public MarkerLayer(GpxData indata, String name, File associatedFile, GpxLayer fromLayer, boolean addMouseHandlerInConstructor) {
    7576        super(name);
    7677        this.setAssociatedFile(associatedFile);
     
    105106            }
    106107        }
    107 
    108         if (addMouseHandlerInConstructor) {
    109             SwingUtilities.invokeLater(new Runnable(){
    110                 public void run() {
    111                     addMouseHandler();
    112                 }
    113             });
    114         }
    115     }
    116 
    117     public void addMouseHandler() {
     108    }
     109
     110    @Override
     111    public void hookUpMapView() {
    118112        Main.map.mapView.addMouseListener(new MouseAdapter() {
    119113            @Override public void mousePressed(MouseEvent e) {
  • 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.