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

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

applied patch #2185 by bruce89

  • Property svn:eol-style set to native
File size: 2.0 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 org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.gui.ExtendedDialog;
11import org.openstreetmap.josm.tools.Shortcut;
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, Shortcut shortcut) {
19 super(name, iconName, tooltip, shortcut, 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() && 1 !=
45 new ExtendedDialog(Main.parent,
46 tr("Overwrite"),
47 tr("File exists. Overwrite?"),
48 new String[] {tr("Overwrite"), tr("Cancel")},
49 new String[] {"save_as.png", "cancel.png"}).getValue()))
50 return null;
51 }
52
53 return fc;
54 }
55}
Note: See TracBrowser for help on using the repository browser.