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

Last change on this file since 5419 was 4608, checked in by bastiK, 12 years ago

add missing showDialog() (in currently unused code)

  • Property svn:eol-style set to native
File size: 2.4 KB
RevLine 
[298]1// License: GPL. Copyright 2007 by Immanuel Scholz and others
[626]2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
[1978]7
[626]8import javax.swing.JFileChooser;
[1978]9
[626]10import org.openstreetmap.josm.Main;
[1397]11import org.openstreetmap.josm.gui.ExtendedDialog;
[1084]12import org.openstreetmap.josm.tools.Shortcut;
[626]13
14/**
[655]15 * Helper class for all actions that access the disk
[626]16 */
17abstract public class DiskAccessAction extends JosmAction {
18
[1169]19 public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut) {
20 super(name, iconName, tooltip, shortcut, true);
21 }
[1023]22
[1646]23 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
[2020]24 return createAndOpenFileChooser(open, multiple, title, null);
25 }
26
27 public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension) {
[1169]28 String curDir = Main.pref.get("lastDirectory");
[1808]29 if (curDir.equals("")) {
[1169]30 curDir = ".";
[1808]31 }
[1169]32 JFileChooser fc = new JFileChooser(new File(curDir));
[1808]33 if (title != null) {
[1169]34 fc.setDialogTitle(title);
[1808]35 }
[693]36
[2702]37 fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
[1169]38 fc.setMultiSelectionEnabled(multiple);
[1978]39 fc.setAcceptAllFileFilterUsed(false);
[2029]40 ExtensionFileFilter.applyChoosableImportFileFilters(fc, extension);
[1637]41
[1169]42 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent);
43 if (answer != JFileChooser.APPROVE_OPTION)
44 return null;
[1023]45
[1808]46 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
[1169]47 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
[1808]48 }
[626]49
[1169]50 if (!open) {
51 File file = fc.getSelectedFile();
[2070]52 if (file != null && file.exists()) {
53 ExtendedDialog dialog = new ExtendedDialog(
54 Main.parent,
[1648]55 tr("Overwrite"),
[2070]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"});
[4608]60 dialog.showDialog();
[2070]61 if (dialog.getValue() != 1)
62 return null;
63 }
[1169]64 }
[1023]65
[1169]66 return fc;
67 }
[626]68}
Note: See TracBrowser for help on using the repository browser.