source: josm/trunk/src/org/openstreetmap/josm/actions/DiskAccessAction.java@ 9276

Last change on this file since 9276 was 8509, checked in by Don-vip, 9 years ago

fix many checkstyle violations

  • Property svn:eol-style set to native
File size: 8.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import java.util.Collection;
5
6import javax.swing.JFileChooser;
7import javax.swing.filechooser.FileFilter;
8
9import org.openstreetmap.josm.gui.widgets.AbstractFileChooser;
10import org.openstreetmap.josm.gui.widgets.FileChooserManager;
11import org.openstreetmap.josm.tools.Shortcut;
12
13/**
14 * Helper class for all actions that access the disk.
15 * @since 78
16 */
17public abstract class DiskAccessAction extends JosmAction {
18
19 /**
20 * Constructs a new {@code DiskAccessAction}.
21 *
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 */
28 public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut) {
29 super(name, iconName, tooltip, shortcut, true);
30 }
31
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 */
44 public DiskAccessAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register,
45 String toolbarId, boolean installAdapters) {
46 super(name, iconName, tooltip, shortcut, register, toolbarId, installAdapters);
47 }
48
49 /**
50 * Creates a new {@link AbstractFileChooser} and makes it visible.
51 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
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
54 * @return The {@code AbstractFileChooser}.
55 * @since 1646
56 */
57 public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title) {
58 return createAndOpenFileChooser(open, multiple, title, null);
59 }
60
61 /**
62 * Creates a new {@link AbstractFileChooser} and makes it visible.
63 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
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
67 * @return The {@code AbstractFileChooser}.
68 * @since 2020
69 */
70 public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, String extension) {
71 return createAndOpenFileChooser(open, multiple, title, extension, JFileChooser.FILES_ONLY, true, null);
72 }
73
74 /**
75 * Creates a new {@link AbstractFileChooser} and makes it visible.
76 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
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
80 * @param selectionMode The selection mode that allows the user to:<br><ul>
81 * <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
82 * <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
83 * <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
84 * @param allTypes If true, all the files types known by JOSM will be proposed in the "file type" combobox.
85 * If false, only the file filters that include {@code extension} will be proposed
86 * @param lastDirProperty The name of the property used to setup the AbstractFileChooser initial directory.
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.
89 * @return The {@code AbstractFileChooser}.
90 * @since 5438
91 */
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();
96 }
97
98 /**
99 * Creates a new {@link AbstractFileChooser} for a single {@link FileFilter} and makes it visible.
100 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
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
104 * @param selectionMode The selection mode that allows the user to:<br><ul>
105 * <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
106 * <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
107 * <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
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
110 * @return The {@code AbstractFileChooser}.
111 * @since 5438
112 */
113 public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title, FileFilter filter,
114 int selectionMode, String lastDirProperty) {
115 return new FileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filter, selectionMode).openFileChooser();
116 }
117
118 /**
119 * Creates a new {@link AbstractFileChooser} for several {@link FileFilter}s and makes it visible.
120 * @param open If true, pops up an "Open File" dialog. If false, pops up a "Save File" dialog
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
125 * @param selectionMode The selection mode that allows the user to:<br><ul>
126 * <li>just select files ({@code JFileChooser.FILES_ONLY})</li>
127 * <li>just select directories ({@code JFileChooser.DIRECTORIES_ONLY})</li>
128 * <li>select both files and directories ({@code JFileChooser.FILES_AND_DIRECTORIES})</li></ul>
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
131 * @return The {@code AbstractFileChooser}.
132 * @since 5438
133 */
134 public static AbstractFileChooser createAndOpenFileChooser(boolean open, boolean multiple, String title,
135 Collection<? extends FileFilter> filters, FileFilter defaultFilter, int selectionMode, String lastDirProperty) {
136 return new FileChooserManager(open, lastDirProperty).createFileChooser(multiple, title, filters, defaultFilter, selectionMode)
137 .openFileChooser();
138 }
139}
Note: See TracBrowser for help on using the repository browser.