1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.File;
|
---|
7 | import java.io.FileNotFoundException;
|
---|
8 | import java.io.IOException;
|
---|
9 | import java.io.InputStream;
|
---|
10 |
|
---|
11 | import javax.swing.JOptionPane;
|
---|
12 |
|
---|
13 | import org.openstreetmap.josm.Main;
|
---|
14 | import org.openstreetmap.josm.actions.ExtensionFileFilter;
|
---|
15 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
16 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
17 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
18 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
19 |
|
---|
20 | public class OsmChangeImporter extends FileImporter {
|
---|
21 |
|
---|
22 | public static final ExtensionFileFilter FILE_FILTER = ExtensionFileFilter.newFilterWithArchiveExtensions(
|
---|
23 | "osc", "osc", tr("OsmChange File"), true);
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Constructs a new {@code OsmChangeImporter}.
|
---|
27 | */
|
---|
28 | public OsmChangeImporter() {
|
---|
29 | super(FILE_FILTER);
|
---|
30 | }
|
---|
31 |
|
---|
32 | public OsmChangeImporter(ExtensionFileFilter filter) {
|
---|
33 | super(filter);
|
---|
34 | }
|
---|
35 |
|
---|
36 | @Override
|
---|
37 | public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
|
---|
38 | try {
|
---|
39 | importData(Compression.getUncompressedFileInputStream(file), file, progressMonitor);
|
---|
40 | } catch (FileNotFoundException e) {
|
---|
41 | Main.error(e);
|
---|
42 | throw new IOException(tr("File ''{0}'' does not exist.", file.getName()), e);
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | protected void importData(InputStream in, final File associatedFile, ProgressMonitor progressMonitor) throws IllegalDataException {
|
---|
47 | final DataSet dataSet = OsmChangeReader.parseDataSet(in, progressMonitor);
|
---|
48 | final OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile);
|
---|
49 | addDataLayer(dataSet, layer, associatedFile.getPath());
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected void addDataLayer(final DataSet dataSet, final OsmDataLayer layer, final String filePath) {
|
---|
53 | // FIXME: remove UI stuff from IO subsystem
|
---|
54 | //
|
---|
55 | GuiHelper.runInEDT(new Runnable() {
|
---|
56 | @Override
|
---|
57 | public void run() {
|
---|
58 | if (dataSet.allPrimitives().isEmpty()) {
|
---|
59 | JOptionPane.showMessageDialog(
|
---|
60 | Main.parent,
|
---|
61 | tr("No data found in file {0}.", filePath),
|
---|
62 | tr("Open OsmChange file"),
|
---|
63 | JOptionPane.INFORMATION_MESSAGE);
|
---|
64 | }
|
---|
65 | Main.main.addLayer(layer);
|
---|
66 | layer.onPostLoadFromFile();
|
---|
67 | }
|
---|
68 | });
|
---|
69 | }
|
---|
70 | }
|
---|