[6380] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
[626] | 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
[5438] | 4 | import java.util.Collection;
|
---|
[626] | 5 |
|
---|
| 6 | import javax.swing.JFileChooser;
|
---|
[5438] | 7 | import javax.swing.filechooser.FileFilter;
|
---|
[1978] | 8 |
|
---|
[5438] | 9 | import org.openstreetmap.josm.gui.widgets.JFileChooserManager;
|
---|
[1084] | 10 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
[626] | 11 |
|
---|
| 12 | /**
|
---|
[5438] | 13 | * Helper class for all actions that access the disk.
|
---|
| 14 | * @since 78
|
---|
[626] | 15 | */
|
---|
| 16 | abstract public class DiskAccessAction extends JosmAction {
|
---|
| 17 |
|
---|
[5438] | 18 | /**
|
---|
| 19 | * Constructs a new {@code DiskAccessAction}.
|
---|
[6069] | 20 | *
|
---|
[5438] | 21 | * @param name The action's text as displayed on the menu (if it is added to a menu)
|
---|
| 22 | * @param iconName The filename of the icon to use
|
---|
| 23 | * @param tooltip A longer description of the action that will be displayed in the tooltip
|
---|
| 24 | * @param shortcut A ready-created shortcut object or {@code null} if you don't want a shortcut
|
---|
| 25 | * @since 1084
|
---|
| 26 | */
|
---|
[1169] | 27 | public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut) {
|
---|
| 28 | super(name, iconName, tooltip, shortcut, true);
|
---|
| 29 | }
|
---|
[1023] | 30 |
|
---|
[5438] | 31 | /**
|
---|
| 32 | * Constructs a new {@code DiskAccessAction}.
|
---|
| 33 | *
|
---|
| 34 | * @param name The action's text as displayed on the menu (if it is added to a menu)
|
---|
| 35 | * @param iconName The filename of the icon to use
|
---|
| 36 | * @param tooltip A longer description of the action that will be displayed in the tooltip
|
---|
| 37 | * @param shortcut A ready-created shortcut object or null if you don't want a shortcut
|
---|
| 38 | * @param register Register this action for the toolbar preferences?
|
---|
| 39 | * @param toolbarId Identifier for the toolbar preferences. The iconName is used, if this parameter is null
|
---|
| 40 | * @param installAdapters False, if you don't want to install layer changed and selection changed adapters
|
---|
| 41 | * @since 5438
|
---|
| 42 | */
|
---|
| 43 | public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register, String toolbarId, boolean installAdapters) {
|
---|
| 44 | super(name, iconName, tooltip, shortcut, register, toolbarId, installAdapters);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * Creates a new {@link JFileChooser} and makes it visible.
|
---|
[6069] | 49 | * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
|
---|
[5438] | 50 | * @param multiple If true, makes the dialog allow multiple file selections
|
---|
| 51 | * @param title The string that goes in the dialog window's title bar
|
---|
| 52 | * @return The {@code JFileChooser}.
|
---|
| 53 | * @since 1646
|
---|
| 54 | */
|
---|
[1646] | 55 | public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
|
---|
[2020] | 56 | return createAndOpenFileChooser(open, multiple, title, null);
|
---|
| 57 | }
|
---|
| 58 |
|
---|
[5438] | 59 | /**
|
---|
| 60 | * Creates a new {@link JFileChooser} and makes it visible.
|
---|
[6069] | 61 | * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
|
---|
[5438] | 62 | * @param multiple If true, makes the dialog allow multiple file selections
|
---|
| 63 | * @param title The string that goes in the dialog window's title bar
|
---|
| 64 | * @param extension The file extension that will be selected as the default file filter
|
---|
| 65 | * @return The {@code JFileChooser}.
|
---|
| 66 | * @since 2020
|
---|
| 67 | */
|
---|
[2020] | 68 | public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension) {
|
---|
[5438] | 69 | return createAndOpenFileChooser(open, multiple, title, extension, JFileChooser.FILES_ONLY, true, null);
|
---|
| 70 | }
|
---|
[693] | 71 |
|
---|
[5438] | 72 | /**
|
---|
| 73 | * Creates a new {@link JFileChooser} and makes it visible.
|
---|
[6069] | 74 | * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
|
---|
[5438] | 75 | * @param multiple If true, makes the dialog allow multiple file selections
|
---|
| 76 | * @param title The string that goes in the dialog window's title bar
|
---|
| 77 | * @param extension The file extension that will be selected as the default file filter
|
---|
| 78 | * @param selectionMode The selection mode that allows the user to:<br/>
|
---|
[6069] | 79 | * <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
|
---|
| 80 | * <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
|
---|
[5438] | 81 | * <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li>
|
---|
[6069] | 82 | * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox.
|
---|
[5438] | 83 | * If false, only the file filters that include {@code extension} will be proposed
|
---|
[6069] | 84 | * @param lastDirProperty The name of the property used to setup the JFileChooser initial directory.
|
---|
[5438] | 85 | * 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 | * @since 5438
|
---|
| 88 | */
|
---|
| 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();
|
---|
| 91 | }
|
---|
[1637] | 92 |
|
---|
[5438] | 93 | /**
|
---|
| 94 | * Creates a new {@link JFileChooser} for a single {@link FileFilter} and makes it visible.
|
---|
[6069] | 95 | * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
|
---|
[5438] | 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/>
|
---|
[6069] | 100 | * <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
|
---|
| 101 | * <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
|
---|
[5438] | 102 | * <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li>
|
---|
| 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}.
|
---|
| 105 | * @since 5438
|
---|
| 106 | */
|
---|
| 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();
|
---|
| 109 | }
|
---|
[1023] | 110 |
|
---|
[5438] | 111 | /**
|
---|
| 112 | * Creates a new {@link JFileChooser} for several {@link FileFilter}s and makes it visible.
|
---|
[6069] | 113 | * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
|
---|
[5438] | 114 | * @param multiple If true, makes the dialog allow multiple file selections
|
---|
| 115 | * @param title The string that goes in the dialog window's title bar
|
---|
| 116 | * @param filters The file filters that will be proposed by the dialog
|
---|
| 117 | * @param defaultFilter The file filter that will be selected by default
|
---|
| 118 | * @param selectionMode The selection mode that allows the user to:<br/>
|
---|
[6069] | 119 | * <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
|
---|
| 120 | * <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
|
---|
[5438] | 121 | * <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li>
|
---|
| 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}.
|
---|
| 124 | * @since 5438
|
---|
| 125 | */
|
---|
[6069] | 126 | public static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title,
|
---|
[5438] | 127 | Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode, String lastDirProperty) {
|
---|
| 128 | return new JFileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filters, defaultFilter, selectionMode).openFileChooser();
|
---|
[1169] | 129 | }
|
---|
[626] | 130 | }
|
---|