source: josm/src/org/openstreetmap/josm/actions/DiskAccessAction.java@ 78

Last change on this file since 78 was 78, checked in by imi, 18 years ago
  • added more context menu items to layer list
  • added GPX export (raw gps and osm)
File size: 2.0 KB
Line 
1package org.openstreetmap.josm.actions;
2
3import java.io.File;
4
5import javax.swing.JFileChooser;
6import javax.swing.JOptionPane;
7import javax.swing.KeyStroke;
8
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.data.osm.OsmPrimitive;
11
12/**
13 * Helper class for all actions, that access the disk
14 */
15abstract public class DiskAccessAction extends JosmAction {
16
17 public DiskAccessAction(String name, String iconName, String tooltip, String shortCutName, KeyStroke shortCut) {
18 super(name, iconName, tooltip, shortCutName, shortCut);
19 }
20
21
22 /**
23 * Check the data set if it would be empty on save. It is empty, if it contains
24 * no objects (after all objects that are created and deleted without beeing
25 * transfered to the server have been removed).
26 *
27 * @return <code>true</code>, if a save result in an empty data set.
28 */
29 protected boolean isDataSetEmpty() {
30 for (OsmPrimitive osm : Main.main.ds.allNonDeletedPrimitives())
31 if (osm.id > 0)
32 return false;
33 return true;
34 }
35
36 protected JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) {
37 String curDir = Main.pref.get("lastDirectory");
38 if (curDir.equals(""))
39 curDir = ".";
40 JFileChooser fc = new JFileChooser(new File(curDir));
41 fc.setMultiSelectionEnabled(multiple);
42 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i)
43 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]);
44 fc.setAcceptAllFileFilterUsed(true);
45
46 int answer = open ? fc.showOpenDialog(Main.main) : fc.showSaveDialog(Main.main);
47 if (answer != JFileChooser.APPROVE_OPTION)
48 return null;
49
50 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
51 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
52
53 if (!open) {
54 File file = fc.getSelectedFile();
55 if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
56 JOptionPane.showConfirmDialog(Main.main, "File exists. Overwrite?", "Overwrite", JOptionPane.YES_NO_OPTION)))
57 return null;
58 }
59
60 return fc;
61 }}
Note: See TracBrowser for help on using the repository browser.