source: osm/applications/editors/josm/plugins/waypoints/src/WaypointOpenAction.java@ 9949

Last change on this file since 9949 was 9949, checked in by stoecker, 16 years ago

fixed build of two more modules

File size: 2.1 KB
Line 
1package waypoints;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.awt.event.ActionEvent;
6import java.awt.event.InputEvent;
7import java.awt.event.KeyEvent;
8import java.io.File;
9import java.io.FileInputStream;
10import java.io.IOException;
11import java.util.Collection;
12import java.util.LinkedList;
13
14import javax.swing.JFileChooser;
15import javax.swing.JOptionPane;
16
17import javax.xml.parsers.ParserConfigurationException;
18
19import org.openstreetmap.josm.Main;
20import org.openstreetmap.josm.data.osm.DataSet;
21import org.openstreetmap.josm.gui.layer.OsmDataLayer;
22import org.openstreetmap.josm.actions.DiskAccessAction;
23import org.xml.sax.SAXException;
24
25/**
26 * Based on standard JOSM OpenAction
27 * For opening a waypoint file to convert to nodes.
28 */
29public class WaypointOpenAction extends DiskAccessAction {
30
31 /**
32 * Create an open action. The name is "Open a file".
33 */
34 public WaypointOpenAction() {
35 super(tr("Open waypoints file"), "open", tr("Open a waypoints file."),
36 KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK);
37 }
38
39 public void actionPerformed(ActionEvent e) {
40 JFileChooser fc = createAndOpenFileChooser(true, true, null);
41 if (fc == null)
42 return;
43 File[] files = fc.getSelectedFiles();
44 for (int i = files.length; i > 0; --i)
45 openFile(files[i-1]);
46 }
47
48 /**
49 * Open the given file.
50 */
51 public void openFile(File file) {
52 String fn = file.getName();
53 try {
54 DataSet dataSet =
55 WaypointReader.parse(new FileInputStream(file));
56 Main.main.addLayer(new OsmDataLayer(dataSet, file.getName(),
57 file));
58 } catch (SAXException x) {
59 x.printStackTrace();
60 JOptionPane.showMessageDialog(Main.parent,
61 tr("Error while parsing {0}",fn)+": "+x.getMessage());
62 } catch (ParserConfigurationException x) {
63 x.printStackTrace(); // broken SAXException chaining
64 JOptionPane.showMessageDialog(Main.parent,
65 tr("Error while parsing {0}",fn)+": "+x.getMessage());
66 } catch (IOException x) {
67 x.printStackTrace();
68 JOptionPane.showMessageDialog(Main.parent,
69 tr("Could not read \"{0}\"",fn)+"\n"+x.getMessage());
70 }
71 }
72}
Note: See TracBrowser for help on using the repository browser.