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

Last change on this file since 655 was 655, checked in by ramack, 16 years ago

patch by bruce89, closes #812; thanks bruce

  • 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) {
23 String curDir = Main.pref.get("lastDirectory");
24 if (curDir.equals(""))
25 curDir = ".";
26 JFileChooser fc = new JFileChooser(new File(curDir));
27 fc.setMultiSelectionEnabled(multiple);
28 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i)
29 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]);
30 fc.setAcceptAllFileFilterUsed(true);
31
32 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
33 if (answer != JFileChooser.APPROVE_OPTION)
34 return null;
35
36 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
37 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
38
39 if (!open) {
40 File file = fc.getSelectedFile();
41 if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
42 JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION)))
43 return null;
44 }
45
46 return fc;
47 }
48}
Note: See TracBrowser for help on using the repository browser.