1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.widgets;
|
---|
3 |
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.awt.HeadlessException;
|
---|
6 | import java.io.File;
|
---|
7 | import java.util.Locale;
|
---|
8 |
|
---|
9 | import javax.swing.filechooser.FileFilter;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Abstract class to allow different file chooser implementations.
|
---|
13 | * @since 7578
|
---|
14 | */
|
---|
15 | public abstract class AbstractFileChooser {
|
---|
16 |
|
---|
17 | /** The locale for both implementations */
|
---|
18 | protected static volatile Locale locale;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Sets the default locale for all implementations.
|
---|
22 | * @param l locale
|
---|
23 | */
|
---|
24 | public static void setDefaultLocale(Locale l) {
|
---|
25 | locale = l;
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Adds a filter to the list of user choosable file filters.
|
---|
30 | * For information on setting the file selection mode, see
|
---|
31 | * {@link #setFileSelectionMode setFileSelectionMode}.
|
---|
32 | *
|
---|
33 | * @param filter the <code>FileFilter</code> to add to the choosable file
|
---|
34 | * filter list
|
---|
35 | *
|
---|
36 | * @see #getChoosableFileFilters
|
---|
37 | * @see #setFileSelectionMode
|
---|
38 | */
|
---|
39 | public abstract void addChoosableFileFilter(FileFilter filter);
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Gets the list of user choosable file filters.
|
---|
43 | *
|
---|
44 | * @return a <code>FileFilter</code> array containing all the choosable
|
---|
45 | * file filters
|
---|
46 | *
|
---|
47 | * @see #addChoosableFileFilter
|
---|
48 | */
|
---|
49 | public abstract FileFilter[] getChoosableFileFilters();
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * Returns the current directory.
|
---|
53 | *
|
---|
54 | * @return the current directory
|
---|
55 | * @see #setCurrentDirectory
|
---|
56 | */
|
---|
57 | public abstract File getCurrentDirectory();
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Returns the currently selected file filter.
|
---|
61 | *
|
---|
62 | * @return the current file filter
|
---|
63 | * @see #setFileFilter
|
---|
64 | * @see #addChoosableFileFilter
|
---|
65 | */
|
---|
66 | public abstract FileFilter getFileFilter();
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Returns the selected file. This can be set either by the
|
---|
70 | * programmer via <code>setSelectedFile</code> or by a user action, such as
|
---|
71 | * either typing the filename into the UI or selecting the
|
---|
72 | * file from a list in the UI.
|
---|
73 | *
|
---|
74 | * @return the selected file
|
---|
75 | * @see #setSelectedFile
|
---|
76 | */
|
---|
77 | public abstract File getSelectedFile();
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * Returns a list of selected files if the file chooser is
|
---|
81 | * set to allow multiple selection.
|
---|
82 | * @return a list of selected files if the file chooser is
|
---|
83 | * set to allow multiple selection, or an empty array otherwise.
|
---|
84 | */
|
---|
85 | public abstract File[] getSelectedFiles();
|
---|
86 |
|
---|
87 | /**
|
---|
88 | * Returns true if multiple files can be selected.
|
---|
89 | * @return true if multiple files can be selected
|
---|
90 | * @see #setMultiSelectionEnabled
|
---|
91 | */
|
---|
92 | public abstract boolean isMultiSelectionEnabled();
|
---|
93 |
|
---|
94 | /**
|
---|
95 | * Determines whether the <code>AcceptAll FileFilter</code> is used
|
---|
96 | * as an available choice in the choosable filter list.
|
---|
97 | * If false, the <code>AcceptAll</code> file filter is removed from
|
---|
98 | * the list of available file filters.
|
---|
99 | * If true, the <code>AcceptAll</code> file filter will become the
|
---|
100 | * the actively used file filter.
|
---|
101 | * @param b whether the <code>AcceptAll FileFilter</code> is used
|
---|
102 | * as an available choice in the choosable filter list
|
---|
103 | *
|
---|
104 | * @see #setFileFilter
|
---|
105 | */
|
---|
106 | public abstract void setAcceptAllFileFilterUsed(boolean b);
|
---|
107 |
|
---|
108 | /**
|
---|
109 | * Sets the current directory. Passing in <code>null</code> sets the
|
---|
110 | * file chooser to point to the user's default directory.
|
---|
111 | * This default depends on the operating system. It is
|
---|
112 | * typically the "My Documents" folder on Windows, and the user's
|
---|
113 | * home directory on Unix.
|
---|
114 | *
|
---|
115 | * If the file passed in as <code>currentDirectory</code> is not a
|
---|
116 | * directory, the parent of the file will be used as the currentDirectory.
|
---|
117 | * If the parent is not traversable, then it will walk up the parent tree
|
---|
118 | * until it finds a traversable directory, or hits the root of the
|
---|
119 | * file system.
|
---|
120 | *
|
---|
121 | * @param dir the current directory to point to
|
---|
122 | * @see #getCurrentDirectory
|
---|
123 | */
|
---|
124 | public abstract void setCurrentDirectory(File dir);
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * Sets the string that goes in the <code>JFileChooser</code> window's
|
---|
128 | * title bar.
|
---|
129 | *
|
---|
130 | * @param title the new <code>String</code> for the title bar
|
---|
131 | */
|
---|
132 | public abstract void setDialogTitle(String title);
|
---|
133 |
|
---|
134 | /**
|
---|
135 | * Sets the current file filter. The file filter is used by the
|
---|
136 | * file chooser to filter out files from the user's view.
|
---|
137 | *
|
---|
138 | * @param filter the new current file filter to use
|
---|
139 | * @see #getFileFilter
|
---|
140 | */
|
---|
141 | public abstract void setFileFilter(final FileFilter filter);
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Sets the <code>JFileChooser</code> to allow the user to just
|
---|
145 | * select files, just select
|
---|
146 | * directories, or select both files and directories. The default is
|
---|
147 | * <code>JFilesChooser.FILES_ONLY</code>.
|
---|
148 | *
|
---|
149 | * @param selectionMode the type of files to be displayed:
|
---|
150 | * <ul>
|
---|
151 | * <li>JFileChooser.FILES_ONLY
|
---|
152 | * <li>JFileChooser.DIRECTORIES_ONLY
|
---|
153 | * <li>JFileChooser.FILES_AND_DIRECTORIES
|
---|
154 | * </ul>
|
---|
155 | *
|
---|
156 | * @throws IllegalArgumentException if <code>mode</code> is an illegal file selection mode
|
---|
157 | */
|
---|
158 | public abstract void setFileSelectionMode(int selectionMode);
|
---|
159 |
|
---|
160 | /**
|
---|
161 | * Sets the file chooser to allow multiple file selections.
|
---|
162 | *
|
---|
163 | * @param multiple true if multiple files may be selected
|
---|
164 | * @beaninfo
|
---|
165 | * bound: true
|
---|
166 | * description: Sets multiple file selection mode.
|
---|
167 | *
|
---|
168 | * @see #isMultiSelectionEnabled
|
---|
169 | */
|
---|
170 | public abstract void setMultiSelectionEnabled(boolean multiple);
|
---|
171 |
|
---|
172 | /**
|
---|
173 | * Sets the selected file. If the file's parent directory is
|
---|
174 | * not the current directory, changes the current directory
|
---|
175 | * to be the file's parent directory.
|
---|
176 | *
|
---|
177 | * @param file the selected file
|
---|
178 | * @see #getSelectedFile
|
---|
179 | */
|
---|
180 | public abstract void setSelectedFile(File file);
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Pops up an "Open File" file chooser dialog. Note that the
|
---|
184 | * text that appears in the approve button is determined by
|
---|
185 | * the L&F.
|
---|
186 | *
|
---|
187 | * @param parent the parent component of the dialog,
|
---|
188 | * can be <code>null</code>;
|
---|
189 | * see <code>showDialog</code> for details
|
---|
190 | * @return the return state of the file chooser on popdown:
|
---|
191 | * <ul>
|
---|
192 | * <li>JFileChooser.CANCEL_OPTION
|
---|
193 | * <li>JFileChooser.APPROVE_OPTION
|
---|
194 | * <li>JFileChooser.ERROR_OPTION if an error occurs or the
|
---|
195 | * dialog is dismissed
|
---|
196 | * </ul>
|
---|
197 | * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
|
---|
198 | * @see java.awt.GraphicsEnvironment#isHeadless
|
---|
199 | */
|
---|
200 | public abstract int showOpenDialog(Component parent);
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * Pops up a "Save File" file chooser dialog. Note that the
|
---|
204 | * text that appears in the approve button is determined by
|
---|
205 | * the L&F.
|
---|
206 | *
|
---|
207 | * @param parent the parent component of the dialog,
|
---|
208 | * can be <code>null</code>;
|
---|
209 | * see <code>showDialog</code> for details
|
---|
210 | * @return the return state of the file chooser on popdown:
|
---|
211 | * <ul>
|
---|
212 | * <li>JFileChooser.CANCEL_OPTION
|
---|
213 | * <li>JFileChooser.APPROVE_OPTION
|
---|
214 | * <li>JFileChooser.ERROR_OPTION if an error occurs or the
|
---|
215 | * dialog is dismissed
|
---|
216 | * </ul>
|
---|
217 | * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
|
---|
218 | * @see java.awt.GraphicsEnvironment#isHeadless
|
---|
219 | */
|
---|
220 | public abstract int showSaveDialog(Component parent);
|
---|
221 | }
|
---|