source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/AbstractFileChooser.java@ 8440

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

fix javadoc warnings

  • Property svn:eol-style set to native
File size: 7.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import java.awt.Component;
5import java.awt.HeadlessException;
6import java.io.File;
7import java.util.Locale;
8
9import javax.swing.filechooser.FileFilter;
10
11/**
12 * Abstract class to allow different file chooser implementations.
13 * @since 7578
14 */
15public 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 * @see #isMultiSelectionEnabled
165 */
166 public abstract void setMultiSelectionEnabled(boolean multiple);
167
168 /**
169 * Sets the selected file. If the file's parent directory is
170 * not the current directory, changes the current directory
171 * to be the file's parent directory.
172 *
173 * @param file the selected file
174 * @see #getSelectedFile
175 */
176 public abstract void setSelectedFile(File file);
177
178 /**
179 * Pops up an "Open File" file chooser dialog. Note that the
180 * text that appears in the approve button is determined by
181 * the L&F.
182 *
183 * @param parent the parent component of the dialog,
184 * can be <code>null</code>;
185 * see <code>showDialog</code> for details
186 * @return the return state of the file chooser on popdown:
187 * <ul>
188 * <li>JFileChooser.CANCEL_OPTION
189 * <li>JFileChooser.APPROVE_OPTION
190 * <li>JFileChooser.ERROR_OPTION if an error occurs or the
191 * dialog is dismissed
192 * </ul>
193 * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
194 * @see java.awt.GraphicsEnvironment#isHeadless
195 */
196 public abstract int showOpenDialog(Component parent);
197
198 /**
199 * Pops up a "Save File" file chooser dialog. Note that the
200 * text that appears in the approve button is determined by
201 * the L&F.
202 *
203 * @param parent the parent component of the dialog,
204 * can be <code>null</code>;
205 * see <code>showDialog</code> for details
206 * @return the return state of the file chooser on popdown:
207 * <ul>
208 * <li>JFileChooser.CANCEL_OPTION
209 * <li>JFileChooser.APPROVE_OPTION
210 * <li>JFileChooser.ERROR_OPTION if an error occurs or the
211 * dialog is dismissed
212 * </ul>
213 * @throws HeadlessException if GraphicsEnvironment.isHeadless() returns true.
214 * @see java.awt.GraphicsEnvironment#isHeadless
215 */
216 public abstract int showSaveDialog(Component parent);
217}
Note: See TracBrowser for help on using the repository browser.