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