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

Last change on this file since 1180 was 1180, checked in by stoecker, 15 years ago

fixed bug #1871, removed all deprecations

  • Property svn:eol-style set to native
File size: 1.8 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;
12import org.openstreetmap.josm.tools.Shortcut;
13
14/**
15 * Helper class for all actions that access the disk
16 */
17abstract public class DiskAccessAction extends JosmAction {
18
19 public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut) {
20 super(name, iconName, tooltip, shortcut, true);
21 }
22
23 protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
24 String curDir = Main.pref.get("lastDirectory");
25 if (curDir.equals(""))
26 curDir = ".";
27 JFileChooser fc = new JFileChooser(new File(curDir));
28 if(title != null)
29 fc.setDialogTitle(title);
30
31 fc.setMultiSelectionEnabled(multiple);
32 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i)
33 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]);
34 fc.setAcceptAllFileFilterUsed(true);
35
36 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
37 if (answer != JFileChooser.APPROVE_OPTION)
38 return null;
39
40 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
41 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
42
43 if (!open) {
44 File file = fc.getSelectedFile();
45 if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
46 JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION)))
47 return null;
48 }
49
50 return fc;
51 }
52}
Note: See TracBrowser for help on using the repository browser.