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

Last change on this file since 2684 was 2070, checked in by Gubaer, 15 years ago

new: rewrite of CombineWay action
new: conflict resolution dialog for CombineWay, including conflicts for different relation memberships
cleanup: cleanup in OsmReader, reduces memory footprint and reduces parsing time
cleanup: made most of the public fields in OsmPrimitive @deprecated, added accessors and changed the code
cleanup: replaced usages of @deprecated constructors for ExtendedDialog
fixed #3208: Combine ways brokes relation order

WARNING: this changeset touches a lot of code all over the code base. "latest" might become slightly unstable in the next days. Also experience incompatibility issues with plugins in the next few days.

  • Property svn:eol-style set to native
File size: 2.3 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;
9
10import org.openstreetmap.josm.Main;
11import org.openstreetmap.josm.gui.ExtendedDialog;
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 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
24 return createAndOpenFileChooser(open, multiple, title, null);
25 }
26
27 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension) {
28 String curDir = Main.pref.get("lastDirectory");
29 if (curDir.equals("")) {
30 curDir = ".";
31 }
32 JFileChooser fc = new JFileChooser(new File(curDir));
33 if (title != null) {
34 fc.setDialogTitle(title);
35 }
36
37 fc.setMultiSelectionEnabled(multiple);
38 fc.setAcceptAllFileFilterUsed(false);
39 System.out.println("opening fc for extension " + extension);
40 ExtensionFileFilter.applyChoosableImportFileFilters(fc, extension);
41
42 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
43 if (answer != JFileChooser.APPROVE_OPTION)
44 return null;
45
46 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
47 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
48 }
49
50 if (!open) {
51 File file = fc.getSelectedFile();
52 if (file != null && file.exists()) {
53 ExtendedDialog dialog = new ExtendedDialog(
54 Main.parent,
55 tr("Overwrite"),
56 new String[] {tr("Overwrite"), tr("Cancel")}
57 );
58 dialog.setContent(tr("File exists. Overwrite?"));
59 dialog.setButtonIcons(new String[] {"save_as.png", "cancel.png"});
60 if (dialog.getValue() != 1)
61 return null;
62 }
63 }
64
65 return fc;
66 }
67}
Note: See TracBrowser for help on using the repository browser.