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

Last change on this file since 3769 was 1495, checked in by nick, 18 years ago

New waypoint import plugin for JOSM

File size: 1.9 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 org.openstreetmap.josm.Main;
18import org.openstreetmap.josm.data.osm.DataSet;
19import org.openstreetmap.josm.gui.layer.OsmDataLayer;
20import org.openstreetmap.josm.actions.DiskAccessAction;
21import org.xml.sax.SAXException;
22
23/**
24 * Based on standard JOSM OpenAction
25 * For opening a waypoint file to convert to nodes.
26 */
27public class WaypointOpenAction extends DiskAccessAction {
28
29 /**
30 * Create an open action. The name is "Open a file".
31 */
32 public WaypointOpenAction() {
33 super(tr("Open waypoints file"), "open", tr("Open a waypoints file."),
34 KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK);
35 }
36
37 public void actionPerformed(ActionEvent e) {
38 JFileChooser fc = createAndOpenFileChooser(true, true);
39 if (fc == null)
40 return;
41 File[] files = fc.getSelectedFiles();
42 for (int i = files.length; i > 0; --i)
43 openFile(files[i-1]);
44 }
45
46 /**
47 * Open the given file.
48 */
49 public void openFile(File file) {
50 String fn = file.getName();
51 try {
52 DataSet dataSet =
53 WaypointReader.parse(new FileInputStream(file));
54 Main.main.addLayer(new OsmDataLayer(dataSet, file.getName(),
55 file));
56 } catch (SAXException x) {
57 x.printStackTrace();
58 JOptionPane.showMessageDialog(Main.parent,
59 tr("Error while parsing {0}",fn)+": "+x.getMessage());
60 } catch (IOException x) {
61 x.printStackTrace();
62 JOptionPane.showMessageDialog(Main.parent,
63 tr("Could not read \"{0}\"",fn)+"\n"+x.getMessage());
64 }
65 }
66}
Note: See TracBrowser for help on using the repository browser.