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/actions
Files:
6 edited

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) {
Note: See TracChangeset for help on using the changeset viewer.