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

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

Save dialog now distinguish between OSM and GPX. Saving OSM layer as GPX is still possible. Closes #836

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
7
8import javax.swing.JFileChooser;
9import javax.swing.JOptionPane;
10
11import org.openstreetmap.josm.Main;
12
13/**
14 * Helper class for all actions that access the disk
15 */
16abstract public class DiskAccessAction extends JosmAction {
17
18 public DiskAccessAction(String name, String iconName, String tooltip, int shortCut, int modifiers) {
19 super(name, iconName, tooltip, shortCut, modifiers, true);
20 }
21
22 protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
23 String curDir = Main.pref.get("lastDirectory");
24 if (curDir.equals(""))
25 curDir = ".";
26 JFileChooser fc = new JFileChooser(new File(curDir));
27 if(title != null)
28 fc.setDialogTitle(title);
29
30 fc.setMultiSelectionEnabled(multiple);
31 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i)
32 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]);
33 fc.setAcceptAllFileFilterUsed(true);
34
35 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
36 if (answer != JFileChooser.APPROVE_OPTION)
37 return null;
38
39 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
40 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
41
42 if (!open) {
43 File file = fc.getSelectedFile();
44 if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
45 JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION)))
46 return null;
47 }
48
49 return fc;
50 }
51}
Note: See TracBrowser for help on using the repository browser.