Changeset 7578 in josm for trunk


Ignore:
Timestamp:
2014-09-22T22:00:21+02:00 (10 years ago)
Author:
Don-vip
Message:

fix #10024 - Add an option in Preferences/Look-and-Feel to use native file-choosing dialogs.
They look nicer but they do not support file filters, so we cannot use them (yet) as default.
Based on patch by Lesath and code review by simon04.
The native dialogs are not used if selection mode is not supported ("files and directories" on all platforms, "directories" on systems other than OS X)

Location:
trunk/src/org/openstreetmap/josm
Files:
3 added
15 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java

    r6889 r7578  
    77import javax.swing.filechooser.FileFilter;
    88
    9 import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
     9import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
     10import org.openstreetmap.josm.gui.widgets.FileChooserManager;
    1011import org.openstreetmap.josm.tools.Shortcut;
    1112
     
    4647
    4748    /**
    48      * Creates a new {@link JFileChooser} and makes it visible.
     49     * Creates a new {@link AbstractFileChooser} and makes it visible.
    4950     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    5051     * @param multiple If true, makes the dialog allow multiple file selections
    5152     * @param title The string that goes in the dialog window's title bar
    52      * @return The {@code JFileChooser}.
     53     * @return The {@code AbstractFileChooser}.
    5354     * @since 1646
    5455     */
    55     public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
     56    public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
    5657        return createAndOpenFileChooser(open, multiple, title, null);
    5758    }
    5859
    5960    /**
    60      * Creates a new {@link JFileChooser} and makes it visible.
     61     * Creates a new {@link AbstractFileChooser} and makes it visible.
    6162     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    6263     * @param multiple If true, makes the dialog allow multiple file selections
    6364     * @param title The string that goes in the dialog window's title bar
    6465     * @param extension The file extension that will be selected as the default file filter
    65      * @return The {@code JFileChooser}.
     66     * @return The {@code AbstractFileChooser}.
    6667     * @since 2020
    6768     */
    68     public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension) {
     69    public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension) {
    6970        return createAndOpenFileChooser(open, multiple, title, extension, JFileChooser.FILES_ONLY, true, null);
    7071    }
    7172
    7273    /**
    73      * Creates a new {@link JFileChooser} and makes it visible.
     74     * Creates a new {@link AbstractFileChooser} and makes it visible.
    7475     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    7576     * @param multiple If true, makes the dialog allow multiple file selections
     
    8283     * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox.
    8384     *                 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.
     85     * @param lastDirProperty The name of the property used to setup the AbstractFileChooser initial directory.
    8586     *        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}.
     87     * @return The {@code AbstractFileChooser}.
    8788     * @since 5438
    8889     */
    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();
     90    public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension, int selectionMode, boolean allTypes, String lastDirProperty) {
     91        return new FileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, extension, allTypes, selectionMode).openFileChooser();
    9192    }
    9293
    9394    /**
    94      * Creates a new {@link JFileChooser} for a single {@link FileFilter} and makes it visible.
     95     * Creates a new {@link AbstractFileChooser} for a single {@link FileFilter} and makes it visible.
    9596     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    9697     * @param multiple If true, makes the dialog allow multiple file selections
     
    101102     *                      <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
    102103     *                      <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}.
     104     * @param lastDirProperty The name of the property used to setup the AbstractFileChooser initial directory. This property will then be updated to the new "last directory" chosen by the user
     105     * @return The {@code AbstractFileChooser}.
    105106     * @since 5438
    106107     */
    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();
     108    public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, FileFilter filter, int selectionMode, String lastDirProperty) {
     109        return new FileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filter, selectionMode).openFileChooser();
    109110    }
    110111
    111112    /**
    112      * Creates a new {@link JFileChooser} for several {@link FileFilter}s and makes it visible.
     113     * Creates a new {@link AbstractFileChooser} for several {@link FileFilter}s and makes it visible.
    113114     * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
    114115     * @param multiple If true, makes the dialog allow multiple file selections
     
    121122     *                      <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
    122123     * @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}.
     124     * @return The {@code AbstractFileChooser}.
    124125     * @since 5438
    125126     */
    126     public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title,
     127    public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title,
    127128            Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode, String lastDirProperty) {
    128         return new JFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filters, defaultFilter, selectionMode).openFileChooser();
     129        return new FileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filters, defaultFilter, selectionMode).openFileChooser();
    129130    }
    130131}
  • trunk/src/org/openstreetmap/josm/actions/ExtensionFileFilter.java

    r7538 r7578  
    1010import java.util.ServiceConfigurationError;
    1111
    12 import javax.swing.JFileChooser;
    1312import javax.swing.filechooser.FileFilter;
    1413
    1514import org.openstreetmap.josm.Main;
    1615import org.openstreetmap.josm.gui.MapView;
     16import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    1717import org.openstreetmap.josm.io.AllFormatsImporter;
    1818import org.openstreetmap.josm.io.FileExporter;
     
    224224
    225225    /**
    226      * Applies the choosable {@link FileFilter} to a {@link JFileChooser} before using the
     226     * Applies the choosable {@link FileFilter} to a {@link AbstractFileChooser} before using the
    227227     * file chooser for selecting a file for reading.
    228228     *
     
    233233     * @since 5438
    234234     */
    235     public static void applyChoosableImportFileFilters(JFileChooser fileChooser, String extension, boolean allTypes) {
     235    public static void applyChoosableImportFileFilters(AbstractFileChooser fileChooser, String extension, boolean allTypes) {
    236236        for (ExtensionFileFilter filter: getImportExtensionFileFilters()) {
    237237            if (allTypes || filter.acceptName("file."+extension)) {
     
    243243
    244244    /**
    245      * Applies the choosable {@link FileFilter} to a {@link JFileChooser} before using the
     245     * Applies the choosable {@link FileFilter} to a {@link AbstractFileChooser} before using the
    246246     * file chooser for selecting a file for writing.
    247247     *
     
    252252     * @since 5438
    253253     */
    254     public static void applyChoosableExportFileFilters(JFileChooser fileChooser, String extension, boolean allTypes) {
     254    public static void applyChoosableExportFileFilters(AbstractFileChooser fileChooser, String extension, boolean allTypes) {
    255255        for (ExtensionFileFilter filter: getExportExtensionFileFilters()) {
    256256            if (allTypes || filter.acceptName("file."+extension)) {
  • trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java

    r7453 r7578  
    2525import java.util.regex.Pattern;
    2626
    27 import javax.swing.JFileChooser;
    2827import javax.swing.JOptionPane;
    2928import javax.swing.SwingUtilities;
     
    3433import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    3534import org.openstreetmap.josm.gui.help.HelpUtil;
     35import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    3636import org.openstreetmap.josm.io.AllFormatsImporter;
    3737import org.openstreetmap.josm.io.FileImporter;
     
    6565    @Override
    6666    public void actionPerformed(ActionEvent e) {
    67         JFileChooser fc = createAndOpenFileChooser(true, true, null);
     67        AbstractFileChooser fc = createAndOpenFileChooser(true, true, null);
    6868        if (fc == null)
    6969            return;
  • trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java

    r7204 r7578  
    1919import org.openstreetmap.josm.gui.layer.Layer;
    2020import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     21import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    2122import org.openstreetmap.josm.io.FileExporter;
    2223import org.openstreetmap.josm.tools.Shortcut;
     
    136137     */
    137138    public static File createAndOpenSaveFileChooser(String title, ExtensionFileFilter filter) {
    138         JFileChooser fc = createAndOpenFileChooser(false, false, title, filter, JFileChooser.FILES_ONLY, null);
     139        AbstractFileChooser fc = createAndOpenFileChooser(false, false, title, filter, JFileChooser.FILES_ONLY, null);
    139140        return checkFileAndConfirmOverWrite(fc, filter.getDefaultExtension());
    140141    }
     
    150151     */
    151152    public static File createAndOpenSaveFileChooser(String title, String extension) {
    152         JFileChooser fc = createAndOpenFileChooser(false, false, title, extension);
     153        AbstractFileChooser fc = createAndOpenFileChooser(false, false, title, extension);
    153154        return checkFileAndConfirmOverWrite(fc, extension);
    154155    }
    155156
    156     private static File checkFileAndConfirmOverWrite(JFileChooser fc, String extension) {
     157    private static File checkFileAndConfirmOverWrite(AbstractFileChooser fc, String extension) {
    157158        if (fc == null) return null;
    158159        File file = fc.getSelectedFile();
  • trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java

    r7326 r7578  
    2525import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2626import org.openstreetmap.josm.gui.util.FileFilterAllFiles;
     27import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    2728import org.openstreetmap.josm.io.IllegalDataException;
    2829import org.openstreetmap.josm.io.session.SessionImporter;
     
    4748    @Override
    4849    public void actionPerformed(ActionEvent e) {
    49         JFileChooser fc = createAndOpenFileChooser(true, false, tr("Open session"),
     50        AbstractFileChooser fc = createAndOpenFileChooser(true, false, tr("Open session"),
    5051                Arrays.asList(SessionImporter.FILE_FILTER, FileFilterAllFiles.getInstance()),
    5152                SessionImporter.FILE_FILTER, JFileChooser.FILES_ONLY, "lastDirectory");
  • trunk/src/org/openstreetmap/josm/actions/SessionSaveAsAction.java

    r7509 r7578  
    3636import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    3737import org.openstreetmap.josm.gui.layer.Layer;
     38import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    3839import org.openstreetmap.josm.io.session.SessionLayerExporter;
    3940import org.openstreetmap.josm.io.session.SessionWriter;
     
    8283        FileFilter jos = new ExtensionFileFilter("jos", "jos", tr("Session file (*.jos)"));
    8384
    84         JFileChooser fc;
     85        AbstractFileChooser fc;
    8586
    8687        if (zipRequired) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r7553 r7578  
    7373import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference;
    7474import org.openstreetmap.josm.gui.util.FileFilterAllFiles;
     75import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
     76import org.openstreetmap.josm.gui.widgets.FileChooserManager;
    7577import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    76 import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
    7778import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    7879import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     
    443444            final StyleSource s = model.getRow(sel);
    444445
    445             JFileChooserManager fcm = new JFileChooserManager(false, "mappaint.clone-style.lastDirectory", System.getProperty("user.home"));
     446            FileChooserManager fcm = new FileChooserManager(false, "mappaint.clone-style.lastDirectory", System.getProperty("user.home"));
    446447            String suggestion = fcm.getInitialDirectory() + File.separator + s.getFileNamePart();
    447448
     
    454455            fcm.createFileChooser(false, null, Arrays.asList(ff, FileFilterAllFiles.getInstance()), ff, JFileChooser.FILES_ONLY)
    455456                    .getFileChooser().setSelectedFile(new File(suggestion));
    456             JFileChooser fc = fcm.openFileChooser();
     457            AbstractFileChooser fc = fcm.openFileChooser();
    457458            if (fc == null)
    458459                return;
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/CorrelateGpxWithImages.java

    r7518 r7578  
    7272import org.openstreetmap.josm.gui.layer.GpxLayer;
    7373import org.openstreetmap.josm.gui.layer.Layer;
     74import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    7475import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    7576import org.openstreetmap.josm.gui.widgets.JosmTextField;
     
    151152                }
    152153            };
    153             JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, filter, JFileChooser.FILES_ONLY, null);
     154            AbstractFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, filter, JFileChooser.FILES_ONLY, null);
    154155            if (fc == null)
    155156                return;
     
    383384                @Override
    384385                public void actionPerformed(ActionEvent ae) {
    385                     JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, JpegFileFilter.getInstance(),
     386                    AbstractFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, false, null, JpegFileFilter.getInstance(),
    386387                            JFileChooser.FILES_ONLY, "geoimage.lastdirectory");
    387388                    if (fc == null)
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

    r7518 r7578  
    3030import org.openstreetmap.josm.gui.layer.markerlayer.AudioMarker;
    3131import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;
     32import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    3233import org.openstreetmap.josm.tools.AudioUtil;
    3334import org.openstreetmap.josm.tools.ImageProvider;
     
    7879            }
    7980        };
    80         JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, true, null, filter, JFileChooser.FILES_ONLY, "markers.lastaudiodirectory");
     81        AbstractFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, true, null, filter, JFileChooser.FILES_ONLY, "markers.lastaudiodirectory");
    8182        if (fc != null) {
    8283            File[] sel = fc.getSelectedFiles();
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportImagesAction.java

    r7005 r7578  
    1818import org.openstreetmap.josm.gui.layer.GpxLayer;
    1919import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    20 import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
     20import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
     21import org.openstreetmap.josm.gui.widgets.FileChooserManager;
    2122import org.openstreetmap.josm.io.JpgImporter;
    2223import org.openstreetmap.josm.tools.ImageProvider;
     
    5354        }
    5455        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();
     56        AbstractFileChooser fc = new FileChooserManager(true, "geoimage.lastdirectory", Main.pref.get("lastDirectory")).
     57                createFileChooser(true, null, importer.filter, JFileChooser.FILES_AND_DIRECTORIES).openFileChooser();
    5658        if (fc != null) {
    5759            File[] sel = fc.getSelectedFiles();
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r7434 r7578  
    8989import org.openstreetmap.josm.gui.util.GuiHelper;
    9090import org.openstreetmap.josm.gui.util.TableHelper;
    91 import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
     91import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
     92import org.openstreetmap.josm.gui.widgets.FileChooserManager;
    9293import org.openstreetmap.josm.gui.widgets.JosmTextField;
    9394import org.openstreetmap.josm.io.CachedFile;
     
    701702    }
    702703
    703     private static void prepareFileChooser(String url, JFileChooser fc) {
     704    private static void prepareFileChooser(String url, AbstractFileChooser fc) {
    704705        if (url == null || url.trim().length() == 0) return;
    705706        URL sourceUrl = null;
     
    813814                    return;
    814815                }
    815                 JFileChooserManager fcm = new JFileChooserManager(true)
     816                FileChooserManager fcm = new FileChooserManager(true)
    816817                        .createFileChooser(true, null, Arrays.asList(ff, FileFilterAllFiles.getInstance()), ff, JFileChooser.FILES_ONLY);
    817818                prepareFileChooser(tfURL.getText(), fcm.getFileChooser());
    818                 JFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this));
     819                AbstractFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this));
    819820                if (fc != null) {
    820821                    tfURL.setText(fc.getSelectedFile().toString());
     
    15121513            @Override
    15131514            public void actionPerformed(ActionEvent e) {
    1514                 JFileChooserManager fcm = new JFileChooserManager(true).createFileChooser();
     1515                FileChooserManager fcm = new FileChooserManager(true).createFileChooser();
    15151516                if (!isFile) {
    15161517                    fcm.getFileChooser().setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    15171518                }
    15181519                prepareFileChooser(tfFileName.getText(), fcm.getFileChooser());
    1519                 JFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this));
     1520                AbstractFileChooser fc = fcm.openFileChooser(JOptionPane.getFrameForComponent(SourceEditor.this));
    15201521                if (fc != null) {
    15211522                    tfFileName.setText(fc.getSelectedFile().toString());
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java

    r7536 r7578  
    4646import org.openstreetmap.josm.gui.preferences.PreferenceTabbedPane;
    4747import org.openstreetmap.josm.gui.util.GuiHelper;
     48import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    4849import org.openstreetmap.josm.gui.widgets.JosmTextField;
    4950import org.openstreetmap.josm.tools.GBC;
     
    197198            }
    198199        };
    199         JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(!saveFileFlag, !saveFileFlag, title, filter, JFileChooser.FILES_ONLY, "customsettings.lastDirectory");
     200        AbstractFileChooser fc = DiskAccessAction.createAndOpenFileChooser(!saveFileFlag, !saveFileFlag, title, filter,
     201                JFileChooser.FILES_ONLY, "customsettings.lastDirectory");
    200202        if (fc != null) {
    201203            File[] sel = fc.isMultiSelectionEnabled() ? fc.getSelectedFiles() : (new File[]{fc.getSelectedFile()});
  • trunk/src/org/openstreetmap/josm/gui/preferences/advanced/ExportProfileAction.java

    r7027 r7578  
    2020import org.openstreetmap.josm.data.Preferences;
    2121import org.openstreetmap.josm.data.Preferences.Setting;
     22import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    2223
    2324/**
     
    7172            }
    7273        };
    73         JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(false, false, title, filter, JFileChooser.FILES_ONLY, "customsettings.lastDirectory");
     74        AbstractFileChooser fc = DiskAccessAction.createAndOpenFileChooser(false, false, title, filter, JFileChooser.FILES_ONLY, "customsettings.lastDirectory");
    7475        if (fc != null) {
    7576            File sel = fc.getSelectedFile();
  • trunk/src/org/openstreetmap/josm/gui/preferences/display/LafPreference.java

    r7299 r7578  
    3030import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting;
    3131import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting;
     32import org.openstreetmap.josm.gui.widgets.FileChooserManager;
    3233import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    3334import org.openstreetmap.josm.tools.GBC;
     
    6061    private JCheckBox dynamicButtons = new JCheckBox(tr("Dynamic buttons in side menus"));
    6162    private JCheckBox isoDates = new JCheckBox(tr("Display ISO dates"));
     63    private JCheckBox nativeFileChoosers = new JCheckBox(tr("Use native file choosers (nicer, but do not support file filters)"));
    6264
    6365    @Override
     
    134136        panel.add(isoDates, GBC.eop().insets(20, 0, 0, 0));
    135137
     138        nativeFileChoosers.setToolTipText(
     139                tr("Use file choosers that behave more like native ones. They look nicer but do not support some features like file filters"));
     140        nativeFileChoosers.setSelected(FileChooserManager.PROP_USE_NATIVE_FILE_DIALOG.get());
     141        panel.add(nativeFileChoosers, GBC.eop().insets(20, 0, 0, 0));
     142
    136143        panel.add(Box.createVerticalGlue(), GBC.eol().insets(0, 20, 0, 0));
    137144
     
    154161        Main.pref.put(ToggleDialog.PROP_DYNAMIC_BUTTONS.getKey(), dynamicButtons.isSelected());
    155162        Main.pref.put(DateUtils.PROP_ISO_DATES.getKey(), isoDates.isSelected());
     163        Main.pref.put(FileChooserManager.PROP_USE_NATIVE_FILE_DIALOG.getKey(), nativeFileChoosers.isSelected());
    156164        mod |= Main.pref.put("laf", ((LookAndFeelInfo)lafCombo.getSelectedItem()).getClassName());
    157165        return mod;
  • trunk/src/org/openstreetmap/josm/gui/widgets/FileChooserManager.java

    r7577 r7578  
    1414import org.openstreetmap.josm.actions.ExtensionFileFilter;
    1515import org.openstreetmap.josm.actions.SaveActionBase;
     16import org.openstreetmap.josm.data.preferences.BooleanProperty;
    1617
    1718/**
    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>
     19 * A chained utility class used to create and open {@link AbstractFileChooser} dialogs.<br>
     20 * Use only this class if you need to control specifically your AbstractFileChooser dialog.<br>
    2021 * <p>
    2122 * A simpler usage is to call the {@link DiskAccessAction#createAndOpenFileChooser} methods.
    2223 *
    23  * @since 5438
     24 * @since 5438 (creation)
     25 * @since 7578 (rename)
    2426 */
    25 public class JFileChooserManager {
     27public class FileChooserManager {
     28
     29    /**
     30     * Property to enable use of native file dialogs.
     31     */
     32    public static final BooleanProperty PROP_USE_NATIVE_FILE_DIALOG = new BooleanProperty("use.native.file.dialog", false);
     33
    2634    private final boolean open;
    2735    private final String lastDirProperty;
    2836    private final String curDir;
    2937
    30     private JFileChooser fc;
    31 
    32     /**
    33      * Creates a new {@code JFileChooserManager}.
     38    private AbstractFileChooser fc;
     39
     40    /**
     41     * Creates a new {@code FileChooserManager}.
    3442     * @param open If true, "Open File" dialogs will be created. If false, "Save File" dialogs will be created.
    3543     * @see #createFileChooser
    3644     */
    37     public JFileChooserManager(boolean open) {
     45    public FileChooserManager(boolean open) {
    3846        this(open, null);
    3947    }
    4048
    4149    /**
    42      * Creates a new {@code JFileChooserManager}.
     50     * Creates a new {@code FileChooserManager}.
    4351     * @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.
     52     * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the AbstractFileChooser.
    4553     *                        Then, if the user effectively chooses a file or a directory, this property will be updated to the directory path.
    4654     * @see #createFileChooser
    4755     */
    48     public JFileChooserManager(boolean open, String lastDirProperty) {
     56    public FileChooserManager(boolean open, String lastDirProperty) {
    4957        this(open, lastDirProperty, null);
    5058    }
    5159
    5260    /**
    53      * Creates a new {@code JFileChooserManager}.
     61     * Creates a new {@code FileChooserManager}.
    5462     * @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.
     63     * @param lastDirProperty The name of the property used to get the last directory. This directory is used to initialize the AbstractFileChooser.
    5664     *                        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) {
     65     * @param defaultDir The default directory used to initialize the AbstractFileChooser if the {@code lastDirProperty} property value is missing.
     66     * @see #createFileChooser
     67     */
     68    public FileChooserManager(boolean open, String lastDirProperty, String defaultDir) {
    6169        this.open = open;
    6270        this.lastDirProperty = lastDirProperty == null || lastDirProperty.isEmpty() ? "lastDirectory" : lastDirProperty;
     
    6775
    6876    /**
    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() {
     77     * Replies the {@code AbstractFileChooser} that has been previously created.
     78     * @return The {@code AbstractFileChooser} that has been previously created, or {@code null} if it has not been created yet.
     79     * @see #createFileChooser
     80     */
     81    public final AbstractFileChooser getFileChooser() {
    7482        return fc;
    7583    }
    7684
    7785    /**
    78      * Replies the initial directory used to construct the {@code JFileChooser}.
    79      * @return The initial directory used to construct the {@code JFileChooser}.
     86     * Replies the initial directory used to construct the {@code AbstractFileChooser}.
     87     * @return The initial directory used to construct the {@code AbstractFileChooser}.
    8088     */
    8189    public final String getInitialDirectory() {
     
    8492
    8593    /**
    86      * Creates a new {@link JFileChooser} with default settings. All files will be accepted.
    87      * @return this
    88      */
    89     public final JFileChooserManager createFileChooser() {
     94     * Creates a new {@link AbstractFileChooser} with default settings. All files will be accepted.
     95     * @return this
     96     */
     97    public final FileChooserManager createFileChooser() {
    9098        return doCreateFileChooser(false, null, null, null, null, JFileChooser.FILES_ONLY, false);
    9199    }
    92100
    93101    /**
    94      * Creates a new {@link JFileChooser} with given settings for a single {@code FileFilter}.
     102     * Creates a new {@link AbstractFileChooser} with given settings for a single {@code FileFilter}.
    95103     *
    96104     * @param multiple If true, makes the dialog allow multiple file selections
     
    104112     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
    105113     */
    106     public final JFileChooserManager createFileChooser(boolean multiple, String title, FileFilter filter, int selectionMode) {
     114    public final FileChooserManager createFileChooser(boolean multiple, String title, FileFilter filter, int selectionMode) {
    107115        doCreateFileChooser(multiple, title, Collections.singleton(filter), filter, null, selectionMode, false);
    108116        getFileChooser().setAcceptAllFileFilterUsed(false);
     
    111119
    112120    /**
    113      * Creates a new {@link JFileChooser} with given settings for a collection of {@code FileFilter}s.
     121     * Creates a new {@link AbstractFileChooser} with given settings for a collection of {@code FileFilter}s.
    114122     *
    115123     * @param multiple If true, makes the dialog allow multiple file selections
     
    124132     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, Collection, FileFilter, int, String)
    125133     */
    126     public final JFileChooserManager createFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode) {
     134    public final FileChooserManager createFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters,
     135            FileFilter defaultFilter, int selectionMode) {
    127136        return doCreateFileChooser(multiple, title, filters, defaultFilter, null, selectionMode, false);
    128137    }
    129138
    130139    /**
    131      * Creates a new {@link JFileChooser} with given settings for a file extension.
     140     * Creates a new {@link AbstractFileChooser} with given settings for a file extension.
    132141     *
    133142     * @param multiple If true, makes the dialog allow multiple file selections
     
    143152     * @see DiskAccessAction#createAndOpenFileChooser(boolean, boolean, String, FileFilter, int, String)
    144153     */
    145     public final JFileChooserManager createFileChooser(boolean multiple, String title, String extension, boolean allTypes, int selectionMode) {
     154    public final FileChooserManager createFileChooser(boolean multiple, String title, String extension, boolean allTypes, int selectionMode) {
    146155        return doCreateFileChooser(multiple, title, null, null, extension, selectionMode, allTypes);
    147156    }
    148157
    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));
     158    private final FileChooserManager doCreateFileChooser(boolean multiple, String title, Collection<? extends FileFilter> filters,
     159            FileFilter defaultFilter, String extension, int selectionMode, boolean allTypes) {
     160        File file = new File(curDir);
     161        // Use native dialog is preference is set, unless an unsupported selection mode is specifically wanted
     162        if (PROP_USE_NATIVE_FILE_DIALOG.get() && NativeFileChooser.supportsSelectionMode(selectionMode)) {
     163            fc = new NativeFileChooser(file);
     164        } else {
     165            fc = new SwingFileChooser(file);
     166        }
     167
    151168        if (title != null) {
    152169            fc.setDialogTitle(title);
     
    173190
    174191    /**
    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() {
     192     * Opens the {@code AbstractFileChooser} that has been created. Nothing happens if it has not been created yet.
     193     * @return the {@code AbstractFileChooser} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
     194     */
     195    public final AbstractFileChooser openFileChooser() {
    179196        return openFileChooser(null);
    180197    }
    181198
    182199    /**
    183      * Opens the {@code JFileChooser} that has been created and waits for the user to choose a file/directory, or cancel the dialog.<br>
     200     * Opens the {@code AbstractFileChooser} that has been created and waits for the user to choose a file/directory, or cancel the dialog.<br>
    184201     * Nothing happens if the dialog has not been created yet.<br>
    185202     * When the user choses a file or directory, the {@code lastDirProperty} is updated to the chosen directory path.
    186203     *
    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) {
     204     * @param parent The Component used as the parent of the AbstractFileChooser. If null, uses {@code Main.parent}.
     205     * @return the {@code AbstractFileChooser} if the user effectively choses a file or directory. {@code null} if the user cancelled the dialog.
     206     */
     207    public AbstractFileChooser openFileChooser(Component parent) {
    191208        if (fc != null) {
    192209            if (parent == null) {
  • trunk/src/org/openstreetmap/josm/tools/I18n.java

    r7082 r7578  
    2626import org.openstreetmap.gui.jmapviewer.FeatureAdapter.TranslationAdapter;
    2727import org.openstreetmap.josm.Main;
     28import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
    2829
    2930/**
     
    641642        Locale l = Locale.getDefault();
    642643
     644        AbstractFileChooser.setDefaultLocale(l);
    643645        JFileChooser.setDefaultLocale(l);
    644646        JColorChooser.setDefaultLocale(l);
Note: See TracChangeset for help on using the changeset viewer.