Ticket #10024: NativeFileDialog.patch

File NativeFileDialog.patch, 77.6 KB (added by Lesath, 11 years ago)

Patch for native filedialog

  • src/org/openstreetmap/josm/actions/DiskAccessAction.java

     
    33
    44import java.util.Collection;
    55
    6 import javax.swing.JFileChooser;
    76import javax.swing.filechooser.FileFilter;
    87
    9 import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
     8import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
     9import org.openstreetmap.josm.gui.widgets.GenericFileChooserManager;
    1010import org.openstreetmap.josm.tools.Shortcut;
    1111
    1212/**
     
    4545    }
    4646
    4747    /**
    48      * Creates a new {@link JFileChooser} and makes it visible.
     48     * Creates a new {@link GenericFileChooser} and makes it visible.
    4949     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    5050     * @param multiple If true, makes the dialog allow multiple file selections
    5151     * @param title The string that goes in the dialog window's title bar
    52      * @return The {@code JFileChooser}.
     52     * @return The {@code GenericFileChooser}.
    5353     * @since 1646
    5454     */
    55     public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
     55    public static GenericFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
    5656        return createAndOpenFileChooser(open, multiple, title, null);
    5757    }
    5858
    5959    /**
    60      * Creates a new {@link JFileChooser} and makes it visible.
     60     * Creates a new {@link GenericFileChooser} and makes it visible.
    6161     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    6262     * @param multiple If true, makes the dialog allow multiple file selections
    6363     * @param title The string that goes in the dialog window's title bar
    6464     * @param extension The file extension that will be selected as the default file filter
    65      * @return The {@code JFileChooser}.
     65     * @return The {@code GenericFileChooser}.
    6666     * @since 2020
    6767     */
    68     public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension) {
    69         return createAndOpenFileChooser(open, multiple, title, extension, JFileChooser.FILES_ONLY, true, null);
     68    public static GenericFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension) {
     69        return createAndOpenFileChooser(open, multiple, title, extension, GenericFileChooser.FILES_ONLY, true, null);
    7070    }
    7171
    7272    /**
    73      * Creates a new {@link JFileChooser} and makes it visible.
     73     * Creates a new {@link GenericFileChooser} and makes it visible.
    7474     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    7575     * @param multiple If true, makes the dialog allow multiple file selections
    7676     * @param title The string that goes in the dialog window's title bar
    7777     * @param extension The file extension that will be selected as the default file filter
    7878     * @param selectionMode The selection mode that allows the user to:<br><ul>
    79      *                      <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
    80      *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    81      *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
     79     *                      <li>just select files ({@code GenericFileChooser.FILES_ONLY})</li>
     80     *                      <li>just select directories ({@code GenericFileChooser.DIRECTORIES_ONLY})</li>
     81     *                      <li>select both files and directories ({@code GenericFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    8282     * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox.
    8383     *                 If false, only the file filters that include {@code extension} will be proposed
    84      * @param lastDirProperty The name of the property used to setup the JFileChooser initial directory.
     84     * @param lastDirProperty The name of the property used to setup the GenericFileChooser initial directory.
    8585     *        This property will then be updated to the new "last directory" chosen by the user. If null, the default property "lastDirectory" will be used.
    86      * @return The {@code JFileChooser}.
     86     * @return The {@code GenericFileChooser}.
    8787     * @since 5438
    8888     */
    89     public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension, int selectionMode, boolean allTypes, String lastDirProperty) {
    90         return new JFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, extension, allTypes, selectionMode).openFileChooser();
     89    public static GenericFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension, int selectionMode, boolean allTypes, String lastDirProperty) {
     90        return new GenericFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, extension, allTypes, selectionMode).openFileChooser();
    9191    }
    9292
    9393    /**
    94      * Creates a new {@link JFileChooser} for a single {@link FileFilter} and makes it visible.
     94     * Creates a new {@link GenericFileChooser} for a single {@link FileFilter} and makes it visible.
    9595     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    9696     * @param multiple If true, makes the dialog allow multiple file selections
    9797     * @param title The string that goes in the dialog window's title bar
    9898     * @param filter The only file filter that will be proposed by the dialog
    9999     * @param selectionMode The selection mode that allows the user to:<br><ul>
    100      *                      <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
    101      *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    102      *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    103      * @param lastDirProperty The name of the property used to setup the JFileChooser initial directory. This property will then be updated to the new "last directory" chosen by the user
    104      * @return The {@code JFileChooser}.
     100     *                      <li>just select files ({@code GenericFileChooser.FILES_ONLY})</li>
     101     *                      <li>just select directories ({@code GenericFileChooser.DIRECTORIES_ONLY})</li>
     102     *                      <li>select both files and directories ({@code GenericFileChooser.FILES_AND_DIRECTORIES})</li></ul>
     103     * @param lastDirProperty The name of the property used to setup the GenericFileChooser initial directory. This property will then be updated to the new "last directory" chosen by the user
     104     * @return The {@code GenericFileChooser}.
    105105     * @since 5438
    106106     */
    107     public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, FileFilter filter, int selectionMode, String lastDirProperty) {
    108         return new JFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filter, selectionMode).openFileChooser();
     107    public static GenericFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, FileFilter filter, int selectionMode, String lastDirProperty) {
     108        return new GenericFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filter, selectionMode).openFileChooser();
    109109    }
    110110
    111111    /**
    112      * Creates a new {@link JFileChooser} for several {@link FileFilter}s and makes it visible.
     112     * Creates a new {@link GenericFileChooser} for several {@link FileFilter}s and makes it visible.
    113113     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    114114     * @param multiple If true, makes the dialog allow multiple file selections
    115115     * @param title The string that goes in the dialog window's title bar
    116116     * @param filters The file filters that will be proposed by the dialog
    117117     * @param defaultFilter The file filter that will be selected by default
    118118     * @param selectionMode The selection mode that allows the user to:<br><ul>
    119      *                      <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
    120      *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    121      *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    122      * @param lastDirProperty The name of the property used to setup the JFileChooser initial directory. This property will then be updated to the new "last directory" chosen by the user
    123      * @return The {@code JFileChooser}.
     119     *                      <li>just select files ({@code GenericFileChooser.FILES_ONLY})</li>
     120     *                      <li>just select directories ({@code GenericFileChooser.DIRECTORIES_ONLY})</li>
     121     *                      <li>select both files and directories ({@code GenericFileChooser.FILES_AND_DIRECTORIES})</li></ul>
     122     * @param lastDirProperty The name of the property used to setup the GenericFileChooser initial directory. This property will then be updated to the new "last directory" chosen by the user
     123     * @return The {@code GenericFileChooser}.
    124124     * @since 5438
    125125     */
    126     public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title,
     126    public static GenericFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title,
    127127            Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode, String lastDirProperty) {
    128         return new JFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filters, defaultFilter, selectionMode).openFileChooser();
     128        return new GenericFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filters, defaultFilter, selectionMode).openFileChooser();
    129129    }
    130130}
  • src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

     
    88import java.util.LinkedList;
    99import java.util.List;
    1010
    11 import javax.swing.JFileChooser;
    1211import javax.swing.filechooser.FileFilter;
    1312
    1413import org.openstreetmap.josm.Main;
    1514import org.openstreetmap.josm.gui.MapView;
     15import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    1616import org.openstreetmap.josm.io.AllFormatsImporter;
    1717import org.openstreetmap.josm.io.FileExporter;
    1818import org.openstreetmap.josm.io.FileImporter;
     
    198198    }
    199199
    200200    /**
    201      * Applies the choosable {@link FileFilter} to a {@link JFileChooser} before using the
     201     * Applies the choosable {@link FileFilter} to a {@link GenericFileChooser} before using the
    202202     * file chooser for selecting a file for reading.
    203203     *
    204204     * @param fileChooser the file chooser
     
    207207     *                 If false, only the file filters that include {@code extension} will be proposed
    208208     * @since 5438
    209209     */
    210     public static void applyChoosableImportFileFilters(JFileChooser fileChooser, String extension, boolean allTypes) {
     210    public static void applyChoosableImportFileFilters(GenericFileChooser fileChooser, String extension, boolean allTypes) {
    211211        for (ExtensionFileFilter filter: getImportExtensionFileFilters()) {
    212212            if (allTypes || filter.acceptName("file."+extension)) {
    213213                fileChooser.addChoosableFileFilter(filter);
     
    217217    }
    218218
    219219    /**
    220      * Applies the choosable {@link FileFilter} to a {@link JFileChooser} before using the
     220     * Applies the choosable {@link FileFilter} to a {@link GenericFileChooser} before using the
    221221     * file chooser for selecting a file for writing.
    222222     *
    223223     * @param fileChooser the file chooser
     
    226226     *                 If false, only the file filters that include {@code extension} will be proposed
    227227     * @since 5438
    228228     */
    229     public static void applyChoosableExportFileFilters(JFileChooser fileChooser, String extension, boolean allTypes) {
     229    public static void applyChoosableExportFileFilters(GenericFileChooser fileChooser, String extension, boolean allTypes) {
    230230        for (ExtensionFileFilter filter: getExportExtensionFileFilters()) {
    231231            if (allTypes || filter.acceptName("file."+extension)) {
    232232                fileChooser.addChoosableFileFilter(filter);
  • src/org/openstreetmap/josm/actions/OpenFileAction.java

     
    2525import java.util.regex.Matcher;
    2626import java.util.regex.Pattern;
    2727
    28 import javax.swing.JFileChooser;
    2928import javax.swing.JOptionPane;
    3029import javax.swing.SwingUtilities;
    3130import javax.swing.filechooser.FileFilter;
     
    3433import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    3534import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    3635import org.openstreetmap.josm.gui.help.HelpUtil;
     36import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    3737import org.openstreetmap.josm.io.AllFormatsImporter;
    3838import org.openstreetmap.josm.io.FileImporter;
    3939import org.openstreetmap.josm.io.OsmTransferException;
     
    4949 */
    5050public class OpenFileAction extends DiskAccessAction {
    5151
     52    public static final String  USE_NATIVE_FILE_DIALOG = "use.native.file.dialog";
     53    private static final boolean useNativeFileDialog = Main.pref.getBoolean(USE_NATIVE_FILE_DIALOG, false);
     54
    5255    /**
    5356     * The {@link ExtensionFileFilter} matching .url files
    5457     */
     
    6568
    6669    @Override
    6770    public void actionPerformed(ActionEvent e) {
    68         JFileChooser fc = createAndOpenFileChooser(true, true, null);
     71
     72        GenericFileChooser fc = createAndOpenFileChooser(true, true, null);
    6973        if (fc == null)
    7074            return;
    7175        File[] files = fc.getSelectedFiles();
  • src/org/openstreetmap/josm/actions/SaveActionBase.java

     
    1010import java.util.LinkedList;
    1111import java.util.List;
    1212
    13 import javax.swing.JFileChooser;
    1413import javax.swing.JOptionPane;
    1514import javax.swing.filechooser.FileFilter;
    1615
     
    1817import org.openstreetmap.josm.gui.ExtendedDialog;
    1918import org.openstreetmap.josm.gui.layer.Layer;
    2019import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     20import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    2121import org.openstreetmap.josm.io.FileExporter;
    2222import org.openstreetmap.josm.tools.Shortcut;
    2323
     
    125125     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
    126126     */
    127127    public static File createAndOpenSaveFileChooser(String title, ExtensionFileFilter filter) {
    128         JFileChooser fc = createAndOpenFileChooser(false, false, title, filter, JFileChooser.FILES_ONLY, null);
     128        GenericFileChooser fc = createAndOpenFileChooser(false, false, title, filter, GenericFileChooser.FILES_ONLY, null);
    129129        return checkFileAndConfirmOverWrite(fc, filter.getDefaultExtension());
    130130    }
    131131
     
    139139     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, String)
    140140     */
    141141    public static File createAndOpenSaveFileChooser(String title, String extension) {
    142         JFileChooser fc = createAndOpenFileChooser(false, false, title, extension);
     142        GenericFileChooser fc = createAndOpenFileChooser(false, false, title, extension);
    143143        return checkFileAndConfirmOverWrite(fc, extension);
    144144    }
    145145
    146     private static File checkFileAndConfirmOverWrite(JFileChooser fc, String extension) {
     146    private static File checkFileAndConfirmOverWrite(GenericFileChooser fc, String extension) {
    147147        if (fc == null) return null;
    148148        File file = fc.getSelectedFile();
    149149
  • src/org/openstreetmap/josm/actions/SessionLoadAction.java

     
    1313import java.util.Arrays;
    1414import java.util.List;
    1515
    16 import javax.swing.JFileChooser;
    1716import javax.swing.JOptionPane;
    1817import javax.swing.SwingUtilities;
    1918
     
    2423import org.openstreetmap.josm.gui.layer.Layer;
    2524import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2625import org.openstreetmap.josm.gui.util.FileFilterAllFiles;
     26import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    2727import org.openstreetmap.josm.io.IllegalDataException;
    2828import org.openstreetmap.josm.io.session.SessionImporter;
    2929import org.openstreetmap.josm.io.session.SessionReader;
     
    4646
    4747    @Override
    4848    public void actionPerformed(ActionEvent e) {
    49         JFileChooser fc = createAndOpenFileChooser(true, false, tr("Open session"),
     49        GenericFileChooser fc = createAndOpenFileChooser(true, false, tr("Open session"),
    5050                Arrays.asList(SessionImporter.FILE_FILTER, FileFilterAllFiles.getInstance()),
    51                 SessionImporter.FILE_FILTER, JFileChooser.FILES_ONLY, "lastDirectory");
     51                SessionImporter.FILE_FILTER, GenericFileChooser.FILES_ONLY, "lastDirectory");
    5252        if (fc == null) return;
    5353        File file = fc.getSelectedFile();
    5454        boolean zip = file.getName().toLowerCase().endsWith(".joz");
     
    178178                throw e;
    179179            }
    180180        }
    181        
     181
    182182        private void handleException(String dialogTitle, Exception e) {
    183183            Main.error(e);
    184184            HelpAwareOptionPane.showMessageDialogInEDT(
  • src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

     
    2121
    2222import javax.swing.BorderFactory;
    2323import javax.swing.JCheckBox;
    24 import javax.swing.JFileChooser;
    2524import javax.swing.JLabel;
    2625import javax.swing.JOptionPane;
    2726import javax.swing.JPanel;
     
    3534import org.openstreetmap.josm.gui.ExtendedDialog;
    3635import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    3736import org.openstreetmap.josm.gui.layer.Layer;
     37import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    3838import org.openstreetmap.josm.io.session.SessionLayerExporter;
    3939import org.openstreetmap.josm.io.session.SessionWriter;
    4040import org.openstreetmap.josm.tools.GBC;
     
    8181        FileFilter joz = new ExtensionFileFilter("joz", "joz", tr("Session file (archive) (*.joz)"));
    8282        FileFilter jos = new ExtensionFileFilter("jos", "jos", tr("Session file (*.jos)"));
    8383
    84         JFileChooser fc;
     84        GenericFileChooser fc;
    8585
    8686        if (zipRequired) {
    87             fc = createAndOpenFileChooser(false, false, tr("Save session"), joz, JFileChooser.FILES_ONLY, "lastDirectory");
     87            fc = createAndOpenFileChooser(false, false, tr("Save session"), joz, GenericFileChooser.FILES_ONLY, "lastDirectory");
    8888        } else {
    89             fc = createAndOpenFileChooser(false, false, tr("Save session"), Arrays.asList(new FileFilter[]{jos, joz}), jos, JFileChooser.FILES_ONLY, "lastDirectory");
     89            fc = createAndOpenFileChooser(false, false, tr("Save session"), Arrays.asList(new FileFilter[]{jos, joz}), jos, GenericFileChooser.FILES_ONLY, "lastDirectory");
    9090        }
    9191
    9292        if (fc == null)
     
    122122            // TODO: resolve dependencies for layers excluded by the user
    123123            layersOut.add(layer);
    124124        }
    125        
     125
    126126        int active = -1;
    127127        Layer activeLayer = Main.map.mapView.getActiveLayer();
    128128        if (activeLayer != null) {
  • src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

     
    3333import javax.swing.DefaultButtonModel;
    3434import javax.swing.DefaultListSelectionModel;
    3535import javax.swing.JCheckBox;
    36 import javax.swing.JFileChooser;
    3736import javax.swing.JLabel;
    3837import javax.swing.JPanel;
    3938import javax.swing.JPopupMenu;
     
    7271import org.openstreetmap.josm.gui.preferences.SourceEntry;
    7372import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference;
    7473import org.openstreetmap.josm.gui.util.FileFilterAllFiles;
     74import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
     75import org.openstreetmap.josm.gui.widgets.GenericFileChooserManager;
    7576import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    76 import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
    7777import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    7878import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
    7979import org.openstreetmap.josm.tools.GBC;
     
    478478                return;
    479479            final StyleSource s = model.getRow(sel);
    480480
    481             JFileChooserManager fcm = new JFileChooserManager(false, "mappaint.clone-style.lastDirectory", System.getProperty("user.home"));
     481            GenericFileChooserManager fcm = new GenericFileChooserManager(false, "mappaint.clone-style.lastDirectory", System.getProperty("user.home"));
    482482            String suggestion = fcm.getInitialDirectory() + File.separator + s.getFileNamePart();
    483483
    484484            FileFilter ff;
     
    487487            } else {
    488488                ff = new ExtensionFileFilter("xml,zip", "xml", tr("Map paint style file (*.xml, *.zip)"));
    489489            }
    490             fcm.createFileChooser(false, null, Arrays.asList(ff, FileFilterAllFiles.getInstance()), ff, JFileChooser.FILES_ONLY)
     490            fcm.createFileChooser(false, null, Arrays.asList(ff, FileFilterAllFiles.getInstance()), ff, GenericFileChooser.FILES_ONLY)
    491491                    .getFileChooser().setSelectedFile(new File(suggestion));
    492             JFileChooser fc = fcm.openFileChooser();
     492            GenericFileChooser fc = fcm.openFileChooser();
    493493            if (fc == null)
    494494                return;
    495495            Main.worker.submit(new SaveToFileTask(s, fc.getSelectedFile()));
  • src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

     
    4141import javax.swing.BorderFactory;
    4242import javax.swing.JButton;
    4343import javax.swing.JCheckBox;
    44 import javax.swing.JFileChooser;
    4544import javax.swing.JLabel;
    4645import javax.swing.JList;
    4746import javax.swing.JOptionPane;
     
    6968import org.openstreetmap.josm.gui.ExtendedDialog;
    7069import org.openstreetmap.josm.gui.layer.GpxLayer;
    7170import org.openstreetmap.josm.gui.layer.Layer;
     71import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    7272import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    7373import org.openstreetmap.josm.gui.widgets.JosmTextField;
    7474import org.openstreetmap.josm.io.GpxReader;
     
    147147                    return tr("GPX Files (*.gpx *.gpx.gz)");
    148148                }
    149149            };
    150             JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, filter, JFileChooser.FILES_ONLY, null);
     150            GenericFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, filter, GenericFileChooser.FILES_ONLY, null);
    151151            if (fc == null)
    152152                return;
    153153            File sel = fc.getSelectedFile();
     
    379379
    380380                @Override
    381381                public void actionPerformed(ActionEvent ae) {
    382                     JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, JpegFileFilter.getInstance(), JFileChooser.FILES_ONLY, "geoimage.lastdirectory");
     382                    GenericFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, JpegFileFilter.getInstance(), GenericFileChooser.FILES_ONLY, "geoimage.lastdirectory");
    383383                    if (fc == null)
    384384                        return;
    385385                    File sel = fc.getSelectedFile();
  • src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

     
    1414import java.util.Comparator;
    1515
    1616import javax.swing.AbstractAction;
    17 import javax.swing.JFileChooser;
    1817import javax.swing.JOptionPane;
    1918import javax.swing.filechooser.FileFilter;
    2019
     
    2827import org.openstreetmap.josm.gui.layer.GpxLayer;
    2928import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker;
    3029import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
     30import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    3131import org.openstreetmap.josm.tools.AudioUtil;
    3232import org.openstreetmap.josm.tools.ImageProvider;
    3333import org.openstreetmap.josm.tools.Utils;
     
    7676                return tr("Wave Audio files (*.wav)");
    7777            }
    7878        };
    79         JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, true, null, filter, JFileChooser.FILES_ONLY, "markers.lastaudiodirectory");
     79        GenericFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, true, null, filter, GenericFileChooser.FILES_ONLY, "markers.lastaudiodirectory");
    8080        if (fc != null) {
    8181            File[] sel = fc.getSelectedFiles();
    8282            // sort files in increasing order of timestamp (this is the end time, but so
     
    130130        Collection<WayPoint> waypoints = new ArrayList<>();
    131131        boolean timedMarkersOmitted = false;
    132132        boolean untimedMarkersOmitted = false;
    133         double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3); 
     133        double snapDistance = Main.pref.getDouble("marker.audiofromuntimedwaypoints.distance", 1.0e-3);
    134134        // about 25 m
    135135        WayPoint wayPointFromTimeStamp = null;
    136136
  • src/org/openstreetmap/josm/gui/layer/gpx/ImportImagesAction.java

     
    1010import java.util.List;
    1111
    1212import javax.swing.AbstractAction;
    13 import javax.swing.JFileChooser;
    1413import javax.swing.JOptionPane;
    1514
    1615import org.openstreetmap.josm.Main;
    1716import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    1817import org.openstreetmap.josm.gui.layer.GpxLayer;
    1918import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    20 import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
     19import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
     20import org.openstreetmap.josm.gui.widgets.GenericFileChooserManager;
    2121import org.openstreetmap.josm.io.JpgImporter;
    2222import org.openstreetmap.josm.tools.ImageProvider;
    2323
     
    5252            return;
    5353        }
    5454        JpgImporter importer = new JpgImporter(layer);
    55         JFileChooser fc = new JFileChooserManager(true, "geoimage.lastdirectory", Main.pref.get("lastDirectory")).createFileChooser(true, null, importer.filter, JFileChooser.FILES_AND_DIRECTORIES).openFileChooser();
     55        GenericFileChooser fc = new GenericFileChooserManager(true, "geoimage.lastdirectory", Main.pref.get("lastDirectory")).createFileChooser(true, null, importer.filter, GenericFileChooser.FILES_AND_DIRECTORIES).openFileChooser();
    5656        if (fc != null) {
    5757            File[] sel = fc.getSelectedFiles();
    5858            if (sel != null && sel.length > 0) {
  • src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

     
    5252import javax.swing.JButton;
    5353import javax.swing.JCheckBox;
    5454import javax.swing.JComponent;
    55 import javax.swing.JFileChooser;
    5655import javax.swing.JLabel;
    5756import javax.swing.JList;
    5857import javax.swing.JOptionPane;
     
    8685import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    8786import org.openstreetmap.josm.gui.util.FileFilterAllFiles;
    8887import org.openstreetmap.josm.gui.util.TableHelper;
    89 import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
     88import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
     89import org.openstreetmap.josm.gui.widgets.GenericFileChooserManager;
    9090import org.openstreetmap.josm.gui.widgets.JosmTextField;
    9191import org.openstreetmap.josm.io.MirroredInputStream;
    9292import org.openstreetmap.josm.io.OsmTransferException;
     
    697697        }
    698698    }
    699699
    700     private static void prepareFileChooser(String url, JFileChooser fc) {
     700    private static void prepareFileChooser(String url, GenericFileChooser fc) {
    701701        if (url == null || url.trim().length() == 0) return;
    702702        URL sourceUrl = null;
    703703        try {
     
    809809                    Main.error("Unsupported source type: "+sourceType);
    810810                    return;
    811811                }
    812                 JFileChooserManager fcm = new JFileChooserManager(true)
    813                         .createFileChooser(true, null, Arrays.asList(ff, FileFilterAllFiles.getInstance()), ff, JFileChooser.FILES_ONLY);
     812                GenericFileChooserManager fcm = new GenericFileChooserManager(true)
     813                        .createFileChooser(true, null, Arrays.asList(ff, FileFilterAllFiles.getInstance()), ff, GenericFileChooser.FILES_ONLY);
    814814                prepareFileChooser(tfURL.getText(), fcm.getFileChooser());
    815                 JFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this));
     815                GenericFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this));
    816816                if (fc != null) {
    817817                    tfURL.setText(fc.getSelectedFile().toString());
    818818                }
     
    15021502
    15031503            @Override
    15041504            public void actionPerformed(ActionEvent e) {
    1505                 JFileChooserManager fcm = new JFileChooserManager(true).createFileChooser();
     1505                GenericFileChooserManager fcm = new GenericFileChooserManager(true).createFileChooser();
    15061506                if (!isFile) {
    1507                     fcm.getFileChooser().setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     1507                    fcm.getFileChooser().setFileSelectionMode(GenericFileChooser.DIRECTORIES_ONLY);
    15081508                }
    15091509                prepareFileChooser(tfFileName.getText(), fcm.getFileChooser());
    1510                 JFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this));
     1510                GenericFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this));
    15111511                if (fc != null) {
    15121512                    tfFileName.setText(fc.getSelectedFile().toString());
    15131513                }
  • src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java

     
    2020import javax.swing.AbstractAction;
    2121import javax.swing.Box;
    2222import javax.swing.JButton;
    23 import javax.swing.JFileChooser;
    2423import javax.swing.JLabel;
    2524import javax.swing.JMenu;
    2625import javax.swing.JOptionPane;
     
    4443import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory;
    4544import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
    4645import org.openstreetmap.josm.gui.util.GuiHelper;
     46//import javax.swing.JFileChooser;
     47import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    4748import org.openstreetmap.josm.gui.widgets.JosmTextField;
    4849import org.openstreetmap.josm.tools.GBC;
    4950
     
    195196                return tr("JOSM custom settings files (*.xml)");
    196197            }
    197198        };
    198         JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(!saveFileFlag, !saveFileFlag, title, filter, JFileChooser.FILES_ONLY, "customsettings.lastDirectory");
     199        GenericFileChooser fc = DiskAccessAction.createAndOpenFileChooser(!saveFileFlag, !saveFileFlag, title, filter, GenericFileChooser.FILES_ONLY, "customsettings.lastDirectory");
    199200        if (fc != null) {
    200201            File[] sel = fc.isMultiSelectionEnabled() ? fc.getSelectedFiles() : (new File[]{fc.getSelectedFile()});
    201202            if (sel.length==1 && !sel[0].getName().contains(".")) sel[0]=new File(sel[0].getAbsolutePath()+".xml");
  • src/org/openstreetmap/josm/gui/preferences/advanced/ExportProfileAction.java

     
    1010import java.util.Map;
    1111
    1212import javax.swing.AbstractAction;
    13 import javax.swing.JFileChooser;
    1413import javax.swing.JOptionPane;
    1514import javax.swing.filechooser.FileFilter;
    1615
     
    1918import org.openstreetmap.josm.data.CustomConfigurator;
    2019import org.openstreetmap.josm.data.Preferences;
    2120import org.openstreetmap.josm.data.Preferences.Setting;
     21import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    2222
    2323/**
    2424 * Action that exports some fragment of settings to custom configuration file
     
    7070                return tr("JOSM custom settings files (*.xml)");
    7171            }
    7272        };
    73         JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(false, false, title, filter, JFileChooser.FILES_ONLY, "customsettings.lastDirectory");
     73        GenericFileChooser fc = DiskAccessAction.createAndOpenFileChooser(false, false, title, filter, GenericFileChooser.FILES_ONLY, "customsettings.lastDirectory");
    7474        if (fc != null) {
    7575            File sel = fc.getSelectedFile();
    7676            if (!sel.getName().endsWith(".xml")) sel=new File(sel.getAbsolutePath()+".xml");
  • src/org/openstreetmap/josm/gui/widgets/FileDialogManager.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.gui.widgets;
     3
     4import java.awt.Component;
     5import java.awt.FileDialog;
     6import java.awt.Frame;
     7import java.io.File;
     8import java.util.Collection;
     9import java.util.Collections;
     10
     11import javax.swing.filechooser.FileFilter;
     12
     13import org.openstreetmap.josm.Main;
     14import org.openstreetmap.josm.actions.DiskAccessAction;
     15import org.openstreetmap.josm.actions.SaveActionBase;
     16
     17/**
     18 * A chained utility class used to create and open {@link FileDialog} dialogs.<br>
     19 * Use only this class if you need to control specifically your FileDialog dialog.<br>
     20 * <p>
     21 * A simpler usage is to call the {@link DiskAccessAction#createAndOpenFileChooser} methods.
     22 *
     23 * @since 5438
     24 */
     25public class FileDialogManager {
     26    private final boolean open;
     27    private final String lastDirProperty;
     28    private final String curDir;
     29
     30    private FileDialog fc;
     31
     32    /**
     33     * Creates a new {@code FileDialogManager}.
     34     * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
     35     * @see #createFileChooser
     36     */
     37    public FileDialogManager(boolean open) {
     38        this(open, null);
     39    }
     40
     41    /**
     42     * Creates a new {@code FileDialogManager}.
     43     * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
     44     * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the FileDialog.
     45     *                        Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.
     46     * @see #createFileChooser
     47     */
     48    public FileDialogManager(boolean open, String lastDirProperty) {
     49        this(open, lastDirProperty, null);
     50    }
     51
     52    /**
     53     * Creates a new {@code FileDialogManager}.
     54     * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
     55     * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the FileDialog.
     56     *                        Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.
     57     * @param defaultDir The default directory used to initialize the FileDialog if the {@code lastDirProperty} property value is missing.
     58     * @see #createFileChooser
     59     */
     60    public FileDialogManager(boolean open, String lastDirProperty, String defaultDir) {
     61        this.open = open;
     62        this.lastDirProperty = lastDirProperty == null || lastDirProperty.isEmpty() ? "lastDirectory" : lastDirProperty;
     63        this.curDir = Main.pref.get(this.lastDirProperty).isEmpty() ?
     64                (defaultDir == null || defaultDir.isEmpty() ? "." : defaultDir)
     65                : Main.pref.get(this.lastDirProperty);
     66    }
     67
     68    /**
     69     * Replies the {@code FileDialog} that has been previously created.
     70     * @return The {@code FileDialog} that has been previously created, or {@code null} if it has not been created yet.
     71     * @see #createFileChooser
     72     */
     73    public final FileDialog getFileChooser() {
     74        return fc;
     75    }
     76
     77    /**
     78     * Replies the initial directory used to construct the {@code FileDialog}.
     79     * @return The initial directory used to construct the {@code FileDialog}.
     80     */
     81    public final String getInitialDirectory() {
     82        return curDir;
     83    }
     84
     85    /**
     86     * Creates a new {@link FileDialog} with default settings. All files will be accepted.
     87     * @return this
     88     */
     89    public final FileDialogManager createFileChooser() {
     90//        return doCreateFileChooser(false, null, null, null, null, FileDialog.FILES_ONLY, false);
     91        return null;
     92    }
     93
     94    /**
     95     * Creates a new {@link FileDialog} with given settings for a single {@code FileFilter}.
     96     *
     97     * @param multiple If true, makes the dialog allow multiple file selections
     98     * @param title The string that goes in the dialog window's title bar
     99     * @param filter The only file filter that will be proposed by the dialog
     100     * @param selectionMode The selection mode that allows the user to:<br><ul>
     101     *                      <li>just select files ({@code FileDialog.FILES_ONLY})</li>
     102     *                      <li>just select directories ({@code FileDialog.DIRECTORIES_ONLY})</li>
     103     *                      <li>select both files and directories ({@code FileDialog.FILES_AND_DIRECTORIES})</li></ul>
     104     * @return this
     105     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
     106     */
     107    public final FileDialogManager createFileChooser(boolean multiple, String title, FileFilter filter, int selectionMode) {
     108        doCreateFileChooser(multiple, title, Collections.singleton(filter), filter, null, selectionMode, false);
     109//        getFileChooser().setAcceptAllFileFilterUsed(false);
     110        return this;
     111    }
     112
     113    /**
     114     * Creates a new {@link FileDialog} with given settings for a collection of {@code FileFilter}s.
     115     *
     116     * @param multiple If true, makes the dialog allow multiple file selections
     117     * @param title The string that goes in the dialog window's title bar
     118     * @param filters The file filters that will be proposed by the dialog
     119     * @param defaultFilter The file filter that will be selected by default
     120     * @param selectionMode The selection mode that allows the user to:<br><ul>
     121     *                      <li>just select files ({@code FileDialog.FILES_ONLY})</li>
     122     *                      <li>just select directories ({@code FileDialog.DIRECTORIES_ONLY})</li>
     123     *                      <li>select both files and directories ({@code FileDialog.FILES_AND_DIRECTORIES})</li></ul>
     124     * @return this
     125     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, Collection, FileFilter, int, String)
     126     */
     127    public final FileDialogManager createFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode) {
     128        return doCreateFileChooser(multiple, title, filters, defaultFilter, null, selectionMode, false);
     129    }
     130
     131    /**
     132     * Creates a new {@link FileDialog} with given settings for a file extension.
     133     *
     134     * @param multiple If true, makes the dialog allow multiple file selections
     135     * @param title The string that goes in the dialog window's title bar
     136     * @param extension The file extension that will be selected as the default file filter
     137     * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox.
     138     *                 If false, only the file filters that include {@code extension} will be proposed
     139     * @param selectionMode The selection mode that allows the user to:<br><ul>
     140     *                      <li>just select files ({@code FileDialog.FILES_ONLY})</li>
     141     *                      <li>just select directories ({@code FileDialog.DIRECTORIES_ONLY})</li>
     142     *                      <li>select both files and directories ({@code FileDialog.FILES_AND_DIRECTORIES})</li></ul>
     143     * @return this
     144     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
     145     */
     146    public final FileDialogManager createFileChooser(boolean multiple, String title, String extension, boolean allTypes, int selectionMode) {
     147        return doCreateFileChooser(multiple, title, null, null, extension, selectionMode, allTypes);
     148    }
     149
     150    private final FileDialogManager doCreateFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, String extension, int selectionMode, boolean allTypes) {
     151        fc = new FileDialog(((Frame)Main.parent));
     152        fc.setDirectory(curDir);
     153        if (title != null) {
     154            fc.setTitle(title);
     155        }
     156
     157//        fc.setFileSelectionMode(selectionMode);
     158        fc.setMultipleMode(multiple);
     159//        fc.setAcceptAllFileFilterUsed(false);
     160
     161//        if (filters != null) {
     162//            for (FileFilter filter : filters) {
     163//                fc.addChoosableFileFilter(filter);
     164//            }
     165//            if (defaultFilter != null) {
     166//                fc.setFileFilter(defaultFilter);
     167//            }
     168//        } else if (open) {
     169//            ExtensionFileFilter.applyChoosableImportFileFilters(fc, extension, allTypes);
     170//        } else {
     171//            ExtensionFileFilter.applyChoosableExportFileFilters(fc, extension, allTypes);
     172//        }
     173        return this;
     174    }
     175
     176    /**
     177     * Opens the {@code FileDialog} that has been created. Nothing happens if it has not been created yet.
     178     * @return the {@code FileDialog} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
     179     */
     180    public final FileDialog openFileChooser() {
     181        return openFileChooser(null);
     182    }
     183
     184    /**
     185     * Opens the {@code FileDialog} that has been created and waits for the user to choose a file/directory, or cancel the dialog.<br>
     186     * Nothing happens if the dialog has not been created yet.<br>
     187     * When the user choses a file or directory, the {@code lastDirProperty} is updated to the chosen directory path.
     188     *
     189     * @param parent The Component used as the parent of the FileDialog. If null, uses {@code Main.parent}.
     190     * @return the {@code FileDialog} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
     191     */
     192    public FileDialog openFileChooser(Component parent) {
     193        if (fc != null) {
     194            if (parent == null) {
     195                parent = Main.parent;
     196            }
     197
     198//            int answer = open ? fc.showOpenDialog(parent) : fc.showSaveDialog(parent);
     199//            if (answer != FileDialog.APPROVE_OPTION) {
     200//                return null;
     201//            }
     202//
     203//            if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
     204//                Main.pref.put(lastDirProperty, fc.getDirectory().getAbsolutePath());
     205//            }
     206//
     207            if (!open) {
     208                File file = new File(fc.getFile());
     209                if (!SaveActionBase.confirmOverwrite(file)) {
     210                    return null;
     211                }
     212            }
     213        }
     214        return fc;
     215    }
     216}
  • src/org/openstreetmap/josm/gui/widgets/GenericFileChooser.java

     
     1// License: GPL. For details, see LICENSE file.
     2package org.openstreetmap.josm.gui.widgets;
     3
     4import java.awt.Component;
     5import java.awt.FileDialog;
     6import java.awt.Frame;
     7import java.io.File;
     8import java.io.FilenameFilter;
     9import java.util.Locale;
     10
     11import javax.swing.JFileChooser;
     12import javax.swing.filechooser.FileFilter;
     13
     14import org.openstreetmap.josm.Main;
     15
     16/**
     17 * Generic File chooser which chooses based on "use.native.file.dialog" the native dialog via FileDialog,
     18 * or the more generic JFileChooser. This class should behave like a normal JFileChooser. If something is
     19 * missing form JFileChooser please implement here with both dialogs handled (if possible).
     20 *
     21 * Generally speaking this directs the input to the right instance of JFileChooser or FileDialog or implements
     22 * the missing features. It should act like a JFileChooser as a facade and implement for a FileDialog the missing
     23 * (so possible) features.
     24 *
     25 * Basically this is only a facade for different Open/Save Dialogs.
     26 *
     27 * This implements only the currently in JOSM needed methods - no more no less.
     28 *
     29 * It will construct/update both instances to avoid keeping out of sync dialogs.
     30 *
     31 * @author lesath
     32 *
     33 */
     34public class GenericFileChooser {
     35
     36    public static final int FILES_ONLY = JFileChooser.FILES_ONLY;
     37    public static final int APPROVE_OPTION = JFileChooser.APPROVE_OPTION;
     38    public static final int FILES_AND_DIRECTORIES = JFileChooser.FILES_AND_DIRECTORIES;
     39    public static final int DIRECTORIES_ONLY = JFileChooser.DIRECTORIES_ONLY;
     40
     41    /** The JFileChooser which we use for this. */
     42    private JFileChooser jFileChooser;
     43
     44    /** The instance of the fileDialog */
     45    private FileDialog fileDialog;
     46
     47    /** The locale for both Dialogs */
     48    private static Locale locale;
     49
     50    /** Based on this every method decides what to do with the different dialogs. */
     51    private boolean usesNativeFileDialog;
     52
     53    public GenericFileChooser(File file) {
     54
     55        // Try to fetch value from start-properties
     56        usesNativeFileDialog = Main.pref.getBoolean("use.native.file.dialog");
     57
     58        jFileChooser = new JFileChooser(file);
     59
     60        fileDialog = new FileDialog((Frame) Main.parent);
     61        if(file != null) {
     62            fileDialog.setDirectory(file.getAbsolutePath());
     63            fileDialog.setFile(file.toString());
     64        }
     65    }
     66
     67    public void setDialogTitle(String title) {
     68        fileDialog.setTitle(title);
     69        jFileChooser.setDialogTitle(title);
     70    }
     71
     72    /**
     73     * <code>java.awt.FileDialog</code> does not support a selection mode for different types
     74     * of files, so this is not used when using FileDialog.
     75     */
     76    public void setFileSelectionMode(int selectionMode) {
     77        jFileChooser.setFileSelectionMode(selectionMode);
     78    }
     79
     80    public void setMultiSelectionEnabled(boolean multiple) {
     81        jFileChooser.setMultiSelectionEnabled(multiple);
     82        fileDialog.setMultipleMode(multiple);
     83    }
     84
     85    public File getSelectedFile() {
     86        if(usesNativeFileDialog) {
     87            return new File(fileDialog.getDirectory()+fileDialog.getFile());
     88        }
     89        else {
     90            return jFileChooser.getSelectedFile();
     91        }
     92    }
     93    public File[] getSelectedFiles() {
     94        if(usesNativeFileDialog) {
     95            return fileDialog.getFiles();
     96        }
     97        return jFileChooser.getSelectedFiles();
     98    }
     99    public void setSelectedFile(File file) {
     100        fileDialog.setDirectory(file.getAbsolutePath());
     101        fileDialog.setFile(file.getName());
     102        jFileChooser.setSelectedFile(file);
     103    }
     104
     105    /**
     106     * <code>java.awt.FileDialog</code> does not support a selection mode for different types
     107     * of files, so this is not used when using FileDialog.
     108     */
     109    public void setAcceptAllFileFilterUsed(boolean b) {
     110        jFileChooser.setAcceptAllFileFilterUsed(b);
     111    }
     112
     113    /**
     114     * <code>java.awt.FileDialog</code> uses "somewhat" of a filefilter - named <code>FilenameFilter</code>.
     115     * This is not supported by some platforms (namely Windows), so this is only implemented for for
     116     * jFileChooser yet.
     117     *
     118     * @return The currently used FileFilter.
     119     */
     120    public FileFilter getFileFilter() {
     121        return jFileChooser.getFileFilter();
     122    }
     123    /**
     124     * <code>java.awt.FileDialog</code> uses "somewhat" of a filefilter - named <code>FilenameFilter</code>.
     125     */
     126    public FileFilter[] getChoosableFileFilters() {
     127        return jFileChooser.getChoosableFileFilters();
     128    }
     129    public void addChoosableFileFilter(FileFilter filter) {
     130        jFileChooser.addChoosableFileFilter(filter);
     131    }
     132    public void setFileFilter(final FileFilter cff) {
     133        FilenameFilter filter = new FilenameFilter() {
     134            public boolean accept(File Directory, String fileName) {
     135                return cff.accept(new File(Directory.getAbsolutePath()+fileName));
     136            }
     137        };
     138        fileDialog.setFilenameFilter(filter);
     139        jFileChooser.setFileFilter(cff);
     140    }
     141
     142    public boolean isMultiSelectionEnabled() {
     143        if(usesNativeFileDialog) {
     144            return fileDialog.isMultipleMode();
     145        }
     146        return jFileChooser.isMultiSelectionEnabled();
     147    }
     148    public int showOpenDialog(Component parent) {
     149        if(usesNativeFileDialog) {
     150            fileDialog.setLocale(locale);
     151            fileDialog.setMode(FileDialog.LOAD);
     152            fileDialog.setVisible(true);
     153            return fileDialog.getFile() == null ? JFileChooser.CANCEL_OPTION : JFileChooser.APPROVE_OPTION;
     154        }
     155        jFileChooser.setLocale(locale);
     156        return jFileChooser.showOpenDialog(parent);
     157    }
     158    public int showSaveDialog(Component parent) {
     159        if(usesNativeFileDialog) {
     160            fileDialog.setLocale(locale);
     161            fileDialog.setMode(FileDialog.SAVE);
     162            fileDialog.setVisible(true);
     163            return fileDialog.getFile() == null ? JFileChooser.CANCEL_OPTION : JFileChooser.APPROVE_OPTION;
     164        }
     165        return jFileChooser.showSaveDialog(parent);
     166    }
     167    public File getCurrentDirectory() {
     168        if(usesNativeFileDialog) {
     169            return new File(fileDialog.getDirectory());
     170        }
     171        return jFileChooser.getCurrentDirectory();
     172    }
     173    public void setCurrentDirectory(File f) {
     174        jFileChooser.setCurrentDirectory(f);
     175        fileDialog.setDirectory(f.toString());
     176    }
     177    public static void setDefaultLocale(Locale l) {
     178        GenericFileChooser.locale = l;
     179    }
     180}
  • src/org/openstreetmap/josm/gui/widgets/GenericFileChooserManager.java

     
    66import java.util.Collection;
    77import java.util.Collections;
    88
    9 import javax.swing.JFileChooser;
    109import javax.swing.filechooser.FileFilter;
    1110
    1211import org.openstreetmap.josm.Main;
     
    1514import org.openstreetmap.josm.actions.SaveActionBase;
    1615
    1716/**
    18  * A chained utility class used to create and open {@link JFileChooser} dialogs.<br>
    19  * Use only this class if you need to control specifically your JFileChooser dialog.<br>
     17 * A chained utility class used to create and open {@link GenericFileChooser} dialogs.<br>
     18 * Use only this class if you need to control specifically your GenericFileChooser dialog.<br>
    2019 * <p>
    2120 * A simpler usage is to call the {@link DiskAccessAction#createAndOpenFileChooser} methods.
    2221 *
    2322 * @since 5438
    2423 */
    25 public class JFileChooserManager {
     24public class GenericFileChooserManager {
    2625    private final boolean open;
    2726    private final String lastDirProperty;
    2827    private final String curDir;
    2928
    30     private JFileChooser fc;
     29    private GenericFileChooser fc;
    3130
    3231    /**
    33      * Creates a new {@code JFileChooserManager}.
     32     * Creates a new {@code GenericFileChooserManager}.
    3433     * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
    3534     * @see #createFileChooser
    3635     */
    37     public JFileChooserManager(boolean open) {
     36    public GenericFileChooserManager(boolean open) {
    3837        this(open, null);
    3938    }
    4039
    4140    /**
    42      * Creates a new {@code JFileChooserManager}.
     41     * Creates a new {@code GenericFileChooserManager}.
    4342     * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
    44      * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the JFileChooser.
     43     * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the GenericFileChooser.
    4544     *                        Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.
    4645     * @see #createFileChooser
    4746     */
    48     public JFileChooserManager(boolean open, String lastDirProperty) {
     47    public GenericFileChooserManager(boolean open, String lastDirProperty) {
    4948        this(open, lastDirProperty, null);
    5049    }
    5150
    5251    /**
    53      * Creates a new {@code JFileChooserManager}.
     52     * Creates a new {@code GenericFileChooserManager}.
    5453     * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
    55      * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the JFileChooser.
     54     * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the GenericFileChooser.
    5655     *                        Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.
    57      * @param defaultDir The default directory used to initialize the JFileChooser if the {@code lastDirProperty} property value is missing.
     56     * @param defaultDir The default directory used to initialize the GenericFileChooser if the {@code lastDirProperty} property value is missing.
    5857     * @see #createFileChooser
    5958     */
    60     public JFileChooserManager(boolean open, String lastDirProperty, String defaultDir) {
     59    public GenericFileChooserManager(boolean open, String lastDirProperty, String defaultDir) {
    6160        this.open = open;
    6261        this.lastDirProperty = lastDirProperty == null || lastDirProperty.isEmpty() ? "lastDirectory" : lastDirProperty;
    6362        this.curDir = Main.pref.get(this.lastDirProperty).isEmpty() ?
     
    6665    }
    6766
    6867    /**
    69      * Replies the {@code JFileChooser} that has been previously created.
    70      * @return The {@code JFileChooser} that has been previously created, or {@code null} if it has not been created yet.
     68     * Replies the {@code GenericFileChooser} that has been previously created.
     69     * @return The {@code GenericFileChooser} that has been previously created, or {@code null} if it has not been created yet.
    7170     * @see #createFileChooser
    7271     */
    73     public final JFileChooser getFileChooser() {
     72    public final GenericFileChooser getFileChooser() {
    7473        return fc;
    7574    }
    7675
    7776    /**
    78      * Replies the initial directory used to construct the {@code JFileChooser}.
    79      * @return The initial directory used to construct the {@code JFileChooser}.
     77     * Replies the initial directory used to construct the {@code GenericFileChooser}.
     78     * @return The initial directory used to construct the {@code GenericFileChooser}.
    8079     */
    8180    public final String getInitialDirectory() {
    8281        return curDir;
    8382    }
    8483
    8584    /**
    86      * Creates a new {@link JFileChooser} with default settings. All files will be accepted.
     85     * Creates a new {@link GenericFileChooser} with default settings. All files will be accepted.
    8786     * @return this
    8887     */
    89     public final JFileChooserManager createFileChooser() {
    90         return doCreateFileChooser(false, null, null, null, null, JFileChooser.FILES_ONLY, false);
     88    public final GenericFileChooserManager createFileChooser() {
     89        return doCreateFileChooser(false, null, null, null, null, GenericFileChooser.FILES_ONLY, false);
    9190    }
    9291
    9392    /**
    94      * Creates a new {@link JFileChooser} with given settings for a single {@code FileFilter}.
     93     * Creates a new {@link GenericFileChooser} with given settings for a single {@code FileFilter}.
    9594     *
    9695     * @param multiple If true, makes the dialog allow multiple file selections
    9796     * @param title The string that goes in the dialog window's title bar
    9897     * @param filter The only file filter that will be proposed by the dialog
    9998     * @param selectionMode The selection mode that allows the user to:<br><ul>
    100      *                      <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
    101      *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    102      *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
     99     *                      <li>just select files ({@code GenericFileChooser.FILES_ONLY})</li>
     100     *                      <li>just select directories ({@code GenericFileChooser.DIRECTORIES_ONLY})</li>
     101     *                      <li>select both files and directories ({@code GenericFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    103102     * @return this
    104103     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
    105104     */
    106     public final JFileChooserManager createFileChooser(boolean multiple, String title, FileFilter filter, int selectionMode) {
     105    public final GenericFileChooserManager createFileChooser(boolean multiple, String title, FileFilter filter, int selectionMode) {
    107106        doCreateFileChooser(multiple, title, Collections.singleton(filter), filter, null, selectionMode, false);
    108107        getFileChooser().setAcceptAllFileFilterUsed(false);
    109108        return this;
    110109    }
    111110
    112111    /**
    113      * Creates a new {@link JFileChooser} with given settings for a collection of {@code FileFilter}s.
     112     * Creates a new {@link GenericFileChooser} with given settings for a collection of {@code FileFilter}s.
    114113     *
    115114     * @param multiple If true, makes the dialog allow multiple file selections
    116115     * @param title The string that goes in the dialog window's title bar
    117116     * @param filters The file filters that will be proposed by the dialog
    118117     * @param defaultFilter The file filter that will be selected by default
    119118     * @param selectionMode The selection mode that allows the user to:<br><ul>
    120      *                      <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
    121      *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    122      *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
     119     *                      <li>just select files ({@code GenericFileChooser.FILES_ONLY})</li>
     120     *                      <li>just select directories ({@code GenericFileChooser.DIRECTORIES_ONLY})</li>
     121     *                      <li>select both files and directories ({@code GenericFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    123122     * @return this
    124123     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, Collection, FileFilter, int, String)
    125124     */
    126     public final JFileChooserManager createFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode) {
     125    public final GenericFileChooserManager createFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode) {
    127126        return doCreateFileChooser(multiple, title, filters, defaultFilter, null, selectionMode, false);
    128127    }
    129128
    130129    /**
    131      * Creates a new {@link JFileChooser} with given settings for a file extension.
     130     * Creates a new {@link GenericFileChooser} with given settings for a file extension.
    132131     *
    133132     * @param multiple If true, makes the dialog allow multiple file selections
    134133     * @param title The string that goes in the dialog window's title bar
     
    136135     * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox.
    137136     *                 If false, only the file filters that include {@code extension} will be proposed
    138137     * @param selectionMode The selection mode that allows the user to:<br><ul>
    139      *                      <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
    140      *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    141      *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
     138     *                      <li>just select files ({@code GenericFileChooser.FILES_ONLY})</li>
     139     *                      <li>just select directories ({@code GenericFileChooser.DIRECTORIES_ONLY})</li>
     140     *                      <li>select both files and directories ({@code GenericFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    142141     * @return this
    143142     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
    144143     */
    145     public final JFileChooserManager createFileChooser(boolean multiple, String title, String extension, boolean allTypes, int selectionMode) {
     144    public final GenericFileChooserManager createFileChooser(boolean multiple, String title, String extension, boolean allTypes, int selectionMode) {
    146145        return doCreateFileChooser(multiple, title, null, null, extension, selectionMode, allTypes);
    147146    }
    148147
    149     private final JFileChooserManager doCreateFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, String extension, int selectionMode, boolean allTypes) {
    150         fc = new JFileChooser(new File(curDir));
     148    private final GenericFileChooserManager doCreateFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, String extension, int selectionMode, boolean allTypes) {
     149        fc = new GenericFileChooser(new File(curDir));
    151150        if (title != null) {
    152151            fc.setDialogTitle(title);
    153152        }
     
    172171    }
    173172
    174173    /**
    175      * Opens the {@code JFileChooser} that has been created. Nothing happens if it has not been created yet.
    176      * @return the {@code JFileChooser} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
     174     * Opens the {@code GenericFileChooser} that has been created. Nothing happens if it has not been created yet.
     175     * @return the {@code GenericFileChooser} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
    177176     */
    178     public final JFileChooser openFileChooser() {
     177    public final GenericFileChooser openFileChooser() {
    179178        return openFileChooser(null);
    180179    }
    181180
    182181    /**
    183      * Opens the {@code JFileChooser} that has been created and waits for the user to choose a file/directory, or cancel the dialog.<br>
     182     * Opens the {@code GenericFileChooser} that has been created and waits for the user to choose a file/directory, or cancel the dialog.<br>
    184183     * Nothing happens if the dialog has not been created yet.<br>
    185184     * When the user choses a file or directory, the {@code lastDirProperty} is updated to the chosen directory path.
    186185     *
    187      * @param parent The Component used as the parent of the JFileChooser. If null, uses {@code Main.parent}.
    188      * @return the {@code JFileChooser} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
     186     * @param parent The Component used as the parent of the GenericFileChooser. If null, uses {@code Main.parent}.
     187     * @return the {@code GenericFileChooser} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
    189188     */
    190     public JFileChooser openFileChooser(Component parent) {
     189    public GenericFileChooser openFileChooser(Component parent) {
    191190        if (fc != null) {
    192191            if (parent == null) {
    193192                parent = Main.parent;
    194193            }
    195194
    196195            int answer = open ? fc.showOpenDialog(parent) : fc.showSaveDialog(parent);
    197             if (answer != JFileChooser.APPROVE_OPTION) {
     196            if (answer != GenericFileChooser.APPROVE_OPTION) {
    198197                return null;
    199198            }
    200199
  • src/org/openstreetmap/josm/gui/widgets/JFileChooserManager.java

     
    1 // License: GPL. For details, see LICENSE file.
    2 package org.openstreetmap.josm.gui.widgets;
    3 
    4 import java.awt.Component;
    5 import java.io.File;
    6 import java.util.Collection;
    7 import java.util.Collections;
    8 
    9 import javax.swing.JFileChooser;
    10 import javax.swing.filechooser.FileFilter;
    11 
    12 import org.openstreetmap.josm.Main;
    13 import org.openstreetmap.josm.actions.DiskAccessAction;
    14 import org.openstreetmap.josm.actions.ExtensionFileFilter;
    15 import org.openstreetmap.josm.actions.SaveActionBase;
    16 
    17 /**
    18  * A chained utility class used to create and open {@link JFileChooser} dialogs.<br>
    19  * Use only this class if you need to control specifically your JFileChooser dialog.<br>
    20  * <p>
    21  * A simpler usage is to call the {@link DiskAccessAction#createAndOpenFileChooser} methods.
    22  *
    23  * @since 5438
    24  */
    25 public class JFileChooserManager {
    26     private final boolean open;
    27     private final String lastDirProperty;
    28     private final String curDir;
    29 
    30     private JFileChooser fc;
    31 
    32     /**
    33      * Creates a new {@code JFileChooserManager}.
    34      * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
    35      * @see #createFileChooser
    36      */
    37     public JFileChooserManager(boolean open) {
    38         this(open, null);
    39     }
    40 
    41     /**
    42      * Creates a new {@code JFileChooserManager}.
    43      * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
    44      * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the JFileChooser.
    45      *                        Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.
    46      * @see #createFileChooser
    47      */
    48     public JFileChooserManager(boolean open, String lastDirProperty) {
    49         this(open, lastDirProperty, null);
    50     }
    51 
    52     /**
    53      * Creates a new {@code JFileChooserManager}.
    54      * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
    55      * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the JFileChooser.
    56      *                        Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.
    57      * @param defaultDir The default directory used to initialize the JFileChooser if the {@code lastDirProperty} property value is missing.
    58      * @see #createFileChooser
    59      */
    60     public JFileChooserManager(boolean open, String lastDirProperty, String defaultDir) {
    61         this.open = open;
    62         this.lastDirProperty = lastDirProperty == null || lastDirProperty.isEmpty() ? "lastDirectory" : lastDirProperty;
    63         this.curDir = Main.pref.get(this.lastDirProperty).isEmpty() ?
    64                 (defaultDir == null || defaultDir.isEmpty() ? "." : defaultDir)
    65                 : Main.pref.get(this.lastDirProperty);
    66     }
    67 
    68     /**
    69      * Replies the {@code JFileChooser} that has been previously created.
    70      * @return The {@code JFileChooser} that has been previously created, or {@code null} if it has not been created yet.
    71      * @see #createFileChooser
    72      */
    73     public final JFileChooser getFileChooser() {
    74         return fc;
    75     }
    76 
    77     /**
    78      * Replies the initial directory used to construct the {@code JFileChooser}.
    79      * @return The initial directory used to construct the {@code JFileChooser}.
    80      */
    81     public final String getInitialDirectory() {
    82         return curDir;
    83     }
    84 
    85     /**
    86      * Creates a new {@link JFileChooser} with default settings. All files will be accepted.
    87      * @return this
    88      */
    89     public final JFileChooserManager createFileChooser() {
    90         return doCreateFileChooser(false, null, null, null, null, JFileChooser.FILES_ONLY, false);
    91     }
    92 
    93     /**
    94      * Creates a new {@link JFileChooser} with given settings for a single {@code FileFilter}.
    95      *
    96      * @param multiple If true, makes the dialog allow multiple file selections
    97      * @param title The string that goes in the dialog window's title bar
    98      * @param filter The only file filter that will be proposed by the dialog
    99      * @param selectionMode The selection mode that allows the user to:<br><ul>
    100      *                      <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
    101      *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    102      *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    103      * @return this
    104      * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
    105      */
    106     public final JFileChooserManager createFileChooser(boolean multiple, String title, FileFilter filter, int selectionMode) {
    107         doCreateFileChooser(multiple, title, Collections.singleton(filter), filter, null, selectionMode, false);
    108         getFileChooser().setAcceptAllFileFilterUsed(false);
    109         return this;
    110     }
    111 
    112     /**
    113      * Creates a new {@link JFileChooser} with given settings for a collection of {@code FileFilter}s.
    114      *
    115      * @param multiple If true, makes the dialog allow multiple file selections
    116      * @param title The string that goes in the dialog window's title bar
    117      * @param filters The file filters that will be proposed by the dialog
    118      * @param defaultFilter The file filter that will be selected by default
    119      * @param selectionMode The selection mode that allows the user to:<br><ul>
    120      *                      <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
    121      *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    122      *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    123      * @return this
    124      * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, Collection, FileFilter, int, String)
    125      */
    126     public final JFileChooserManager createFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode) {
    127         return doCreateFileChooser(multiple, title, filters, defaultFilter, null, selectionMode, false);
    128     }
    129 
    130     /**
    131      * Creates a new {@link JFileChooser} with given settings for a file extension.
    132      *
    133      * @param multiple If true, makes the dialog allow multiple file selections
    134      * @param title The string that goes in the dialog window's title bar
    135      * @param extension The file extension that will be selected as the default file filter
    136      * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox.
    137      *                 If false, only the file filters that include {@code extension} will be proposed
    138      * @param selectionMode The selection mode that allows the user to:<br><ul>
    139      *                      <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
    140      *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    141      *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    142      * @return this
    143      * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
    144      */
    145     public final JFileChooserManager createFileChooser(boolean multiple, String title, String extension, boolean allTypes, int selectionMode) {
    146         return doCreateFileChooser(multiple, title, null, null, extension, selectionMode, allTypes);
    147     }
    148 
    149     private final JFileChooserManager doCreateFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, String extension, int selectionMode, boolean allTypes) {
    150         fc = new JFileChooser(new File(curDir));
    151         if (title != null) {
    152             fc.setDialogTitle(title);
    153         }
    154 
    155         fc.setFileSelectionMode(selectionMode);
    156         fc.setMultiSelectionEnabled(multiple);
    157         fc.setAcceptAllFileFilterUsed(false);
    158 
    159         if (filters != null) {
    160             for (FileFilter filter : filters) {
    161                 fc.addChoosableFileFilter(filter);
    162             }
    163             if (defaultFilter != null) {
    164                 fc.setFileFilter(defaultFilter);
    165             }
    166         } else if (open) {
    167             ExtensionFileFilter.applyChoosableImportFileFilters(fc, extension, allTypes);
    168         } else {
    169             ExtensionFileFilter.applyChoosableExportFileFilters(fc, extension, allTypes);
    170         }
    171         return this;
    172     }
    173 
    174     /**
    175      * Opens the {@code JFileChooser} that has been created. Nothing happens if it has not been created yet.
    176      * @return the {@code JFileChooser} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
    177      */
    178     public final JFileChooser openFileChooser() {
    179         return openFileChooser(null);
    180     }
    181 
    182     /**
    183      * Opens the {@code JFileChooser} that has been created and waits for the user to choose a file/directory, or cancel the dialog.<br>
    184      * Nothing happens if the dialog has not been created yet.<br>
    185      * When the user choses a file or directory, the {@code lastDirProperty} is updated to the chosen directory path.
    186      *
    187      * @param parent The Component used as the parent of the JFileChooser. If null, uses {@code Main.parent}.
    188      * @return the {@code JFileChooser} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
    189      */
    190     public JFileChooser openFileChooser(Component parent) {
    191         if (fc != null) {
    192             if (parent == null) {
    193                 parent = Main.parent;
    194             }
    195 
    196             int answer = open ? fc.showOpenDialog(parent) : fc.showSaveDialog(parent);
    197             if (answer != JFileChooser.APPROVE_OPTION) {
    198                 return null;
    199             }
    200 
    201             if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
    202                 Main.pref.put(lastDirProperty, fc.getCurrentDirectory().getAbsolutePath());
    203             }
    204 
    205             if (!open) {
    206                 File file = fc.getSelectedFile();
    207                 if (!SaveActionBase.confirmOverwrite(file)) {
    208                     return null;
    209                 }
    210             }
    211         }
    212         return fc;
    213     }
    214 }
  • src/org/openstreetmap/josm/tools/I18n.java

     
    2020import java.util.zip.ZipEntry;
    2121
    2222import javax.swing.JColorChooser;
    23 import javax.swing.JFileChooser;
    2423import javax.swing.UIManager;
    2524
    2625import org.openstreetmap.gui.jmapviewer.FeatureAdapter.TranslationAdapter;
    2726import org.openstreetmap.josm.Main;
     27import org.openstreetmap.josm.gui.widgets.GenericFileChooser;
    2828
    2929/**
    3030 * Internationalisation support.
     
    640640    public static void translateJavaInternalMessages() {
    641641        Locale l = Locale.getDefault();
    642642
    643         JFileChooser.setDefaultLocale(l);
     643        GenericFileChooser.setDefaultLocale(l);
    644644        JColorChooser.setDefaultLocale(l);
    645645        for (String key : javaInternalMessageKeys) {
    646646            String us = UIManager.getString(key, Locale.US);