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

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

apply patches from xeen for #1977.

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