Changeset 9746 in josm for trunk/src


Ignore:
Timestamp:
2016-02-06T22:04:49+01:00 (9 years ago)
Author:
Don-vip
Message:

fix #12497 - add support for notes in session files

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

Legend:

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

    r8895 r9746  
    3737        }
    3838        try (InputStream is = Compression.getUncompressedFileInputStream(file)) {
    39             final List<Note> fileNotes = new NoteReader(is).parse();
    40 
    41             List<NoteLayer> noteLayers = null;
    42             if (Main.map != null) {
    43                 noteLayers = Main.map.mapView.getLayersOfType(NoteLayer.class);
    44             }
    45             if (noteLayers != null && !noteLayers.isEmpty()) {
    46                 noteLayers.get(0).getNoteData().addNotes(fileNotes);
    47             } else {
     39            final NoteLayer layer = loadLayer(is, file, file.getName(), progressMonitor);
     40            if (!Main.map.mapView.hasLayer(layer)) {
    4841                GuiHelper.runInEDT(new Runnable() {
    4942                    @Override
    5043                    public void run() {
    51                         Main.main.addLayer(new NoteLayer(fileNotes, file.getName()));
     44                        Main.main.addLayer(layer);
    5245                    }
    5346                });
     
    5952        }
    6053    }
     54
     55    /**
     56     * Load note layer from InputStream.
     57     * @param in input stream
     58     * @param associatedFile filename of data (can be <code>null</code> if the stream does not come from a file)
     59     * @param layerName name of generated layer
     60     * @param progressMonitor handler for progress monitoring and canceling
     61     * @return note layer
     62     * @throws IOException
     63     * @throws SAXException
     64     * @since 9746
     65     */
     66    public NoteLayer loadLayer(InputStream in, final File associatedFile, final String layerName, ProgressMonitor progressMonitor)
     67            throws SAXException, IOException {
     68        final List<Note> fileNotes = new NoteReader(in).parse();
     69        List<NoteLayer> noteLayers = null;
     70        if (Main.map != null) {
     71            noteLayers = Main.map.mapView.getLayersOfType(NoteLayer.class);
     72        }
     73        final NoteLayer layer;
     74        if (noteLayers != null && !noteLayers.isEmpty()) {
     75            layer = noteLayers.get(0);
     76            layer.getNoteData().addNotes(fileNotes);
     77        } else {
     78            layer = new NoteLayer(fileNotes, associatedFile != null ? associatedFile.getName() : tr("Notes"));
     79        }
     80        return layer;
     81    }
    6182}
  • trunk/src/org/openstreetmap/josm/io/session/GenericSessionExporter.java

    r9669 r9746  
    221221    }
    222222
    223     protected abstract void addDataFile(OutputStream out);
     223    protected abstract void addDataFile(OutputStream out) throws IOException;
    224224}
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r9646 r9746  
    7575        registerSessionLayerImporter("geoimage", GeoImageSessionImporter.class);
    7676        registerSessionLayerImporter("markers", MarkerSessionImporter.class);
     77        registerSessionLayerImporter("osm-notes", NoteSessionImporter.class);
    7778    }
    7879
  • trunk/src/org/openstreetmap/josm/io/session/SessionWriter.java

    r9455 r9746  
    3535import org.openstreetmap.josm.gui.layer.GpxLayer;
    3636import org.openstreetmap.josm.gui.layer.Layer;
     37import org.openstreetmap.josm.gui.layer.NoteLayer;
    3738import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    3839import org.openstreetmap.josm.gui.layer.TMSLayer;
     
    7172        registerSessionLayerExporter(GeoImageLayer.class, GeoImageSessionExporter.class);
    7273        registerSessionLayerExporter(MarkerLayer.class, MarkerSessionExporter.class);
     74        registerSessionLayerExporter(NoteLayer.class, NoteSessionExporter.class);
    7375    }
    7476
  • trunk/src/org/openstreetmap/josm/tools/date/DateUtils.java

    r9739 r9746  
    8080     */
    8181    public static synchronized long tsFromString(String str) throws UncheckedParseException {
    82         // "2007-07-25T09:26:24{Z|{+|-}01:00}"
     82        // "2007-07-25T09:26:24{Z|{+|-}01[:00]}"
    8383        if (checkLayout(str, "xxxx-xx-xxTxx:xx:xxZ") ||
    8484                checkLayout(str, "xxxx-xx-xxTxx:xx:xx") ||
    8585                checkLayout(str, "xxxx:xx:xx xx:xx:xx") ||
    8686                checkLayout(str, "xxxx-xx-xx xx:xx:xx UTC") ||
     87                checkLayout(str, "xxxx-xx-xxTxx:xx:xx+xx") ||
     88                checkLayout(str, "xxxx-xx-xxTxx:xx:xx-xx") ||
    8789                checkLayout(str, "xxxx-xx-xxTxx:xx:xx+xx:00") ||
    8890                checkLayout(str, "xxxx-xx-xxTxx:xx:xx-xx:00")) {
     
    9799            c.set(Calendar.MILLISECOND, 0);
    98100
    99             if (str.length() == 25) {
     101            if (str.length() == 22 || str.length() == 25) {
    100102                int plusHr = parsePart2(str, 20);
    101103                int mul = str.charAt(19) == '+' ? -3600000 : 3600000;
Note: See TracChangeset for help on using the changeset viewer.