source: josm/trunk/src/org/openstreetmap/josm/io/OsmChangeImporter.java@ 5452

Last change on this file since 5452 was 5452, checked in by Don-vip, 12 years ago

Code refactorisation on EDT calls

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
7import java.io.FileInputStream;
8import java.io.FileNotFoundException;
9import java.io.IOException;
10import java.io.InputStream;
11
12import javax.swing.JOptionPane;
13
14import org.openstreetmap.josm.Main;
15import org.openstreetmap.josm.actions.ExtensionFileFilter;
16import org.openstreetmap.josm.data.osm.DataSet;
17import org.openstreetmap.josm.gui.layer.OsmDataLayer;
18import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
19import org.openstreetmap.josm.gui.progress.ProgressMonitor;
20import org.openstreetmap.josm.gui.util.GuiHelper;
21
22public class OsmChangeImporter extends FileImporter {
23
24 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter(
25 "osc,osc.bz2,osc.bz,osc.gz", "osc", tr("OsmChange File") + " (*.osc *.osc.bz2 *.osc.bz *.osc.gz)");
26
27 public OsmChangeImporter() {
28 super(FILE_FILTER);
29 }
30
31 public OsmChangeImporter(ExtensionFileFilter filter) {
32 super(filter);
33 }
34
35 @Override public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException {
36 try {
37 FileInputStream in = new FileInputStream(file);
38
39 if (file.getName().endsWith(".osc")) {
40 importData(in, file);
41 } else if (file.getName().endsWith(".gz")) {
42 importData(getGZipInputStream(in), file);
43 } else {
44 importData(getBZip2InputStream(in), file);
45 }
46
47 } catch (FileNotFoundException e) {
48 e.printStackTrace();
49 throw new IOException(tr("File ''{0}'' does not exist.", file.getName()));
50 }
51 }
52
53 protected void importData(InputStream in, final File associatedFile) throws IllegalDataException {
54 final DataSet dataSet = OsmChangeReader.parseDataSet(in, NullProgressMonitor.INSTANCE);
55 final OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile);
56 addDataLayer(dataSet, layer, associatedFile.getPath());
57 }
58
59 protected void addDataLayer(final DataSet dataSet, final OsmDataLayer layer, final String filePath) {
60 // FIXME: remove UI stuff from IO subsystem
61 //
62 GuiHelper.runInEDT(new Runnable() {
63 @Override
64 public void run() {
65 if (dataSet.allPrimitives().isEmpty()) {
66 JOptionPane.showMessageDialog(
67 Main.parent,
68 tr("No data found in file {0}.", filePath),
69 tr("Open OsmChange file"),
70 JOptionPane.INFORMATION_MESSAGE);
71 }
72 Main.main.addLayer(layer);
73 layer.onPostLoadFromFile();
74 }
75 });
76 }
77}
Note: See TracBrowser for help on using the repository browser.