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

Last change on this file since 290 was 290, checked in by imi, 17 years ago
  • added support for multiple data layers
File size: 1.5 KB
Line 
1package org.openstreetmap.josm.actions;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.io.File;
6
7import javax.swing.JFileChooser;
8import javax.swing.JOptionPane;
9
10import org.openstreetmap.josm.Main;
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, int shortCut, int modifiers) {
18 super(name, iconName, tooltip, shortCut, modifiers, true);
19 }
20
21 protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) {
22 String curDir = Main.pref.get("lastDirectory");
23 if (curDir.equals(""))
24 curDir = ".";
25 JFileChooser fc = new JFileChooser(new File(curDir));
26 fc.setMultiSelectionEnabled(multiple);
27 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i)
28 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]);
29 fc.setAcceptAllFileFilterUsed(true);
30
31 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
32 if (answer != JFileChooser.APPROVE_OPTION)
33 return null;
34
35 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
36 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
37
38 if (!open) {
39 File file = fc.getSelectedFile();
40 if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
41 JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION)))
42 return null;
43 }
44
45 return fc;
46 }
47}
Note: See TracBrowser for help on using the repository browser.