Changeset 5859 in josm for trunk/src


Ignore:
Timestamp:
2013-04-14T19:10:11+02:00 (12 years ago)
Author:
akks
Message:

see #8274, #8601 : cancel now works while parsing OSM

Location:
trunk/src/org/openstreetmap/josm
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryLoadTask.java

    r5856 r5859  
    161161    protected void cancel() {
    162162        System.out.println("Cancel!");
    163         //OsmApi.getOsmApi().cancel();
    164         // fix #8601 : could not cancel when server is extremely slow
    165163        if (reader!=null) reader.cancel();
    166164        canceled = true;
  • trunk/src/org/openstreetmap/josm/io/OsmBzip2Importer.java

    r5361 r5859  
    2222    @Override
    2323    public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
    24         importData(getBZip2InputStream(new FileInputStream(file)), file);
     24        importData(getBZip2InputStream(new FileInputStream(file)), file, progressMonitor);
    2525    }
    2626}
  • trunk/src/org/openstreetmap/josm/io/OsmChangeImporter.java

    r5452 r5859  
    3838           
    3939            if (file.getName().endsWith(".osc")) {
    40                 importData(in, file);
     40                importData(in, file, progressMonitor);
    4141            } else if (file.getName().endsWith(".gz")) {
    42                 importData(getGZipInputStream(in), file);
     42                importData(getGZipInputStream(in), file, progressMonitor);
    4343            } else {
    44                 importData(getBZip2InputStream(in), file);
     44                importData(getBZip2InputStream(in), file, progressMonitor);
    4545            }
    4646           
     
    5252
    5353    protected void importData(InputStream in, final File associatedFile) throws IllegalDataException {
    54         final DataSet dataSet = OsmChangeReader.parseDataSet(in, NullProgressMonitor.INSTANCE);
     54        importData(in, associatedFile, NullProgressMonitor.INSTANCE);
     55    }
     56   
     57    protected void importData(InputStream in, final File associatedFile, ProgressMonitor  progressMonitor) throws IllegalDataException {
     58        final DataSet dataSet = OsmChangeReader.parseDataSet(in, progressMonitor);
    5559        final OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile);
    5660        addDataLayer(dataSet, layer, associatedFile.getPath());
  • trunk/src/org/openstreetmap/josm/io/OsmGzipImporter.java

    r5361 r5859  
    2222    @Override
    2323    public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
    24         importData(getGZipInputStream(new FileInputStream(file)), file);
     24        importData(getGZipInputStream(new FileInputStream(file)), file, progressMonitor);
    2525    }
    2626}
  • trunk/src/org/openstreetmap/josm/io/OsmImporter.java

    r5361 r5859  
    5252    }
    5353
     54    /**
     55     * Imports OSM data from file @param file
     56     * This method supports progress monitoring and canceling by using @param progressMonitor
     57     */
    5458    @Override
    5559    public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
     
    5761        try {
    5862            in = new FileInputStream(file);
    59             importData(in, file);
     63            importData(in, file, progressMonitor);
    6064        } catch (FileNotFoundException e) {
    6165            e.printStackTrace();
     
    6872    }
    6973
     74    /**
     75     * Imports OSM data from stream @param in , sitle will be generated from name of file @param associatedFile
     76     */
    7077    protected void importData(InputStream in, final File associatedFile) throws IllegalDataException {
     78        importData(in, associatedFile, NullProgressMonitor.INSTANCE);
     79    }
     80   
     81    /**
     82     * Imports OSM data from stream @param in , layer name will be generated from name of file @param associatedFile
     83     * This method supports progress monitoring and canceling by using @param progressMonitor
     84     */
     85    protected void importData(InputStream in, final File associatedFile, ProgressMonitor pm) throws IllegalDataException {
    7186        final OsmImporterData data = loadLayer(in, associatedFile,
    72                 associatedFile == null ? OsmDataLayer.createNewName() : associatedFile.getName(), NullProgressMonitor.INSTANCE);
     87                associatedFile == null ? OsmDataLayer.createNewName() : associatedFile.getName(), pm);
    7388
    7489        // FIXME: remove UI stuff from IO subsystem
  • trunk/src/org/openstreetmap/josm/io/OsmReader.java

    r5326 r5859  
    5050    protected XMLStreamReader parser;
    5151
     52    protected boolean cancel;
     53
    5254    /** Used by plugins to register themselves as data postprocessors. */
    5355    public static ArrayList<OsmServerReadPostprocessor> postprocessors;
     
    128130        while (true) {
    129131            int event = parser.next();
     132           
     133            if (cancel) {
     134                cancel = false;
     135                throwException(tr("Reading was canceled"));
     136            }
     137           
    130138            if (event == XMLStreamConstants.START_ELEMENT) {
    131139                if (parser.getLocalName().equals("bounds")) {
     
    561569            progressMonitor = NullProgressMonitor.INSTANCE;
    562570        }
     571        ProgressMonitor.CancelListener cancelListener = new ProgressMonitor.CancelListener() {
     572            @Override public void operationCanceled() {
     573                cancel = true;
     574            }
     575        };
     576        progressMonitor.addCancelListener(cancelListener);
    563577        CheckParameterUtil.ensureParameterNotNull(source, "source");
    564578        try {
     
    603617        } finally {
    604618            progressMonitor.finishTask();
     619            progressMonitor.removeCancelListener(cancelListener);
    605620        }
    606621    }
Note: See TracChangeset for help on using the changeset viewer.