source: josm/src/org/openstreetmap/josm/actions/SaveGpxAction.java@ 16

Last change on this file since 16 was 16, checked in by imi, 19 years ago
  • reverted to 14, but kept the global Projection.
  • improved the preference settings for projections.
File size: 1.6 KB
Line 
1package org.openstreetmap.josm.actions;
2
3import java.awt.event.ActionEvent;
4import java.awt.event.KeyEvent;
5import java.io.File;
6import java.io.FileWriter;
7import java.io.IOException;
8
9import javax.swing.AbstractAction;
10import javax.swing.ImageIcon;
11import javax.swing.JFileChooser;
12import javax.swing.JOptionPane;
13
14import org.openstreetmap.josm.gui.Main;
15import org.openstreetmap.josm.io.GpxWriter;
16
17/**
18 * Export the current selected window's DataSet as gpx values. Remember, that some
19 * information could be lost. If so, an information message will ask the user to proceed.
20 * (Means, if all information can be saved, no warning message appears).
21 *
22 * @author imi
23 */
24public class SaveGpxAction extends AbstractAction {
25
26 /**
27 * Construct the action with "Save GPX" as label.
28 */
29 public SaveGpxAction() {
30 super("Save GPX", new ImageIcon(Main.class.getResource("/images/savegpx.png")));
31 putValue(MNEMONIC_KEY, KeyEvent.VK_S);
32 }
33
34 @SuppressWarnings("unchecked")
35 public void actionPerformed(ActionEvent event) {
36 if (Main.main.getMapFrame() == null) {
37 JOptionPane.showMessageDialog(Main.main, "No document open so nothing to save.");
38 return;
39 }
40 JFileChooser fc = new JFileChooser("data");
41 fc.showSaveDialog(Main.main);
42 File gpxFile = fc.getSelectedFile();
43 if (gpxFile == null)
44 return;
45
46 try {
47 FileWriter fileWriter = new FileWriter(gpxFile);
48 GpxWriter out = new GpxWriter(fileWriter, Main.main.getMapFrame().mapView.dataSet);
49 out.output();
50 fileWriter.close();
51 } catch (IOException e) {
52 e.printStackTrace();
53 JOptionPane.showMessageDialog(Main.main, "An error occoured while saving.\n"+e.getMessage());
54 }
55 }
56
57}
Note: See TracBrowser for help on using the repository browser.