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

Last change on this file since 22 was 22, checked in by imi, 19 years ago

starting restructure of dataset. Checkpoint is broken!

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.JFileChooser;
11import javax.swing.JOptionPane;
12
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.gui.ImageProvider;
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", ImageProvider.get("savegpx"));
31 putValue(MNEMONIC_KEY, KeyEvent.VK_S);
32 putValue(SHORT_DESCRIPTION, "Save the current active layer as GPX file.");
33 }
34
35 @SuppressWarnings("unchecked")
36 public void actionPerformed(ActionEvent event) {
37 if (Main.main.getMapFrame() == null) {
38 JOptionPane.showMessageDialog(Main.main, "No document open so nothing to save.");
39 return;
40 }
41 JFileChooser fc = new JFileChooser("data");
42 fc.showSaveDialog(Main.main);
43 File gpxFile = fc.getSelectedFile();
44 if (gpxFile == null)
45 return;
46
47 try {
48 FileWriter fileWriter = new FileWriter(gpxFile);
49 GpxWriter out = new GpxWriter(fileWriter);
50 out.output();
51 fileWriter.close();
52 } catch (IOException e) {
53 e.printStackTrace();
54 JOptionPane.showMessageDialog(Main.main, "An error occoured while saving.\n"+e.getMessage());
55 }
56 }
57
58}
Note: See TracBrowser for help on using the repository browser.