[1637] | 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.FileInputStream;
|
---|
| 8 | import java.io.FileNotFoundException;
|
---|
| 9 | import java.io.IOException;
|
---|
[1653] | 10 | import java.io.InputStream;
|
---|
[1637] | 11 |
|
---|
[2050] | 12 | import javax.swing.SwingUtilities;
|
---|
| 13 |
|
---|
[1637] | 14 | import org.openstreetmap.josm.Main;
|
---|
| 15 | import org.openstreetmap.josm.actions.ExtensionFileFilter;
|
---|
| 16 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
| 17 | import org.openstreetmap.josm.gui.layer.OsmDataLayer;
|
---|
[1811] | 18 | import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
|
---|
[2851] | 19 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
[1637] | 20 |
|
---|
| 21 | public class OsmImporter extends FileImporter {
|
---|
| 22 |
|
---|
| 23 | public OsmImporter() {
|
---|
| 24 | super(new ExtensionFileFilter("osm,xml", "osm", tr("OSM Server Files") + " (*.osm *.xml)"));
|
---|
| 25 | }
|
---|
| 26 |
|
---|
[1653] | 27 | public OsmImporter(ExtensionFileFilter filter) {
|
---|
| 28 | super(filter);
|
---|
| 29 | }
|
---|
| 30 |
|
---|
[2851] | 31 | @Override public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
|
---|
[1637] | 32 | try {
|
---|
[1653] | 33 | FileInputStream in = new FileInputStream(file);
|
---|
| 34 | importData(in, file);
|
---|
[1637] | 35 | } catch (FileNotFoundException e) {
|
---|
| 36 | e.printStackTrace();
|
---|
[2181] | 37 | throw new IOException(tr("File ''{0}'' does not exist.", file.getName()));
|
---|
[1637] | 38 | }
|
---|
| 39 | }
|
---|
[1653] | 40 |
|
---|
[2070] | 41 | protected void importData(InputStream in, File associatedFile) throws IllegalDataException {
|
---|
| 42 | DataSet dataSet = OsmReader.parseDataSet(in, NullProgressMonitor.INSTANCE);
|
---|
[2050] | 43 | final OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile);
|
---|
| 44 | // FIXME: remove UI stuff from IO subsystem
|
---|
| 45 | //
|
---|
| 46 | Runnable uiStuff = new Runnable() {
|
---|
| 47 | public void run() {
|
---|
| 48 | Main.main.addLayer(layer);
|
---|
| 49 | layer.onPostLoadFromFile();
|
---|
| 50 | }
|
---|
| 51 | };
|
---|
| 52 | if (SwingUtilities.isEventDispatchThread()) {
|
---|
| 53 | uiStuff.run();
|
---|
| 54 | } else {
|
---|
| 55 | SwingUtilities.invokeLater(uiStuff);
|
---|
| 56 | }
|
---|
[1653] | 57 | }
|
---|
[1637] | 58 | }
|
---|