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

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

removed usage of tab stops

  • 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.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 @Deprecated
24 public DiskAccessAction(String name, String iconName, String tooltip, int shortcut, int modifiers) {
25 super(name, iconName, tooltip, shortcut, modifiers, true);
26 }
27
28 protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
29 String curDir = Main.pref.get("lastDirectory");
30 if (curDir.equals(""))
31 curDir = ".";
32 JFileChooser fc = new JFileChooser(new File(curDir));
33 if(title != null)
34 fc.setDialogTitle(title);
35
36 fc.setMultiSelectionEnabled(multiple);
37 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i)
38 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]);
39 fc.setAcceptAllFileFilterUsed(true);
40
41 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
42 if (answer != JFileChooser.APPROVE_OPTION)
43 return null;
44
45 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir))
46 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
47
48 if (!open) {
49 File file = fc.getSelectedFile();
50 if (file == null || (file.exists() && JOptionPane.YES_OPTION !=
51 JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION)))
52 return null;
53 }
54
55 return fc;
56 }
57}
Note: See TracBrowser for help on using the repository browser.