author | psadhukhan |
Mon, 16 Nov 2015 10:56:21 +0300 | |
changeset 34397 | 86a74cb6c903 |
parent 33253 | 78e735319356 |
child 37551 | 9473ac197eb9 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
2 |
* Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.swing; |
|
26 |
||
27 |
import javax.swing.event.*; |
|
28 |
import javax.swing.filechooser.*; |
|
29 |
import javax.swing.plaf.FileChooserUI; |
|
30 |
||
31 |
import javax.accessibility.*; |
|
32 |
||
33 |
import java.io.File; |
|
34 |
import java.io.ObjectOutputStream; |
|
35 |
import java.io.IOException; |
|
36 |
||
37 |
import java.util.Vector; |
|
38 |
import java.awt.AWTEvent; |
|
39 |
import java.awt.Component; |
|
40 |
import java.awt.Container; |
|
41 |
import java.awt.BorderLayout; |
|
42 |
import java.awt.Window; |
|
43 |
import java.awt.Dialog; |
|
44 |
import java.awt.Frame; |
|
45 |
import java.awt.GraphicsEnvironment; |
|
46 |
import java.awt.HeadlessException; |
|
47 |
import java.awt.EventQueue; |
|
48 |
import java.awt.Toolkit; |
|
49 |
import java.awt.event.*; |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
50 |
import java.beans.JavaBean; |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
51 |
import java.beans.BeanProperty; |
2 | 52 |
import java.beans.PropertyChangeListener; |
53 |
import java.beans.PropertyChangeEvent; |
|
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
54 |
import java.io.InvalidObjectException; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
55 |
import java.io.ObjectInputStream; |
2 | 56 |
import java.lang.ref.WeakReference; |
57 |
||
58 |
/** |
|
59 |
* <code>JFileChooser</code> provides a simple mechanism for the user to |
|
60 |
* choose a file. |
|
61 |
* For information about using <code>JFileChooser</code>, see |
|
62 |
* <a |
|
20455
f6f9a0c2796b
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents:
20119
diff
changeset
|
63 |
href="http://docs.oracle.com/javase/tutorial/uiswing/components/filechooser.html">How to Use File Choosers</a>, |
2 | 64 |
* a section in <em>The Java Tutorial</em>. |
65 |
* |
|
66 |
* <p> |
|
67 |
* |
|
68 |
* The following code pops up a file chooser for the user's home directory that |
|
69 |
* sees only .jpg and .gif images: |
|
70 |
* <pre> |
|
71 |
* JFileChooser chooser = new JFileChooser(); |
|
72 |
* FileNameExtensionFilter filter = new FileNameExtensionFilter( |
|
21592 | 73 |
* "JPG & GIF Images", "jpg", "gif"); |
2 | 74 |
* chooser.setFileFilter(filter); |
75 |
* int returnVal = chooser.showOpenDialog(parent); |
|
76 |
* if(returnVal == JFileChooser.APPROVE_OPTION) { |
|
77 |
* System.out.println("You chose to open this file: " + |
|
78 |
* chooser.getSelectedFile().getName()); |
|
79 |
* } |
|
80 |
* </pre> |
|
81 |
* <p> |
|
82 |
* <strong>Warning:</strong> Swing is not thread safe. For more |
|
83 |
* information see <a |
|
84 |
* href="package-summary.html#threading">Swing's Threading |
|
85 |
* Policy</a>. |
|
86 |
* |
|
87 |
* @author Jeff Dinkins |
|
25201
4adc75e0c4e5
8046485: Add missing @since tag under javax.swing.*
henryjen
parents:
23697
diff
changeset
|
88 |
* @since 1.2 |
2 | 89 |
*/ |
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
90 |
@JavaBean(defaultProperty = "UI", description = "A component which allows for the interactive selection of a file.") |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
91 |
@SwingContainer(false) |
23697 | 92 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 93 |
public class JFileChooser extends JComponent implements Accessible { |
94 |
||
95 |
/** |
|
96 |
* @see #getUIClassID |
|
97 |
* @see #readObject |
|
98 |
*/ |
|
99 |
private static final String uiClassID = "FileChooserUI"; |
|
100 |
||
101 |
// ************************ |
|
102 |
// ***** Dialog Types ***** |
|
103 |
// ************************ |
|
104 |
||
105 |
/** |
|
106 |
* Type value indicating that the <code>JFileChooser</code> supports an |
|
107 |
* "Open" file operation. |
|
108 |
*/ |
|
109 |
public static final int OPEN_DIALOG = 0; |
|
110 |
||
111 |
/** |
|
112 |
* Type value indicating that the <code>JFileChooser</code> supports a |
|
113 |
* "Save" file operation. |
|
114 |
*/ |
|
115 |
public static final int SAVE_DIALOG = 1; |
|
116 |
||
117 |
/** |
|
118 |
* Type value indicating that the <code>JFileChooser</code> supports a |
|
119 |
* developer-specified file operation. |
|
120 |
*/ |
|
121 |
public static final int CUSTOM_DIALOG = 2; |
|
122 |
||
123 |
||
124 |
// ******************************** |
|
125 |
// ***** Dialog Return Values ***** |
|
126 |
// ******************************** |
|
127 |
||
128 |
/** |
|
129 |
* Return value if cancel is chosen. |
|
130 |
*/ |
|
131 |
public static final int CANCEL_OPTION = 1; |
|
132 |
||
133 |
/** |
|
134 |
* Return value if approve (yes, ok) is chosen. |
|
135 |
*/ |
|
136 |
public static final int APPROVE_OPTION = 0; |
|
137 |
||
138 |
/** |
|
21278 | 139 |
* Return value if an error occurred. |
2 | 140 |
*/ |
141 |
public static final int ERROR_OPTION = -1; |
|
142 |
||
143 |
||
144 |
// ********************************** |
|
145 |
// ***** JFileChooser properties ***** |
|
146 |
// ********************************** |
|
147 |
||
148 |
||
149 |
/** Instruction to display only files. */ |
|
150 |
public static final int FILES_ONLY = 0; |
|
151 |
||
152 |
/** Instruction to display only directories. */ |
|
153 |
public static final int DIRECTORIES_ONLY = 1; |
|
154 |
||
155 |
/** Instruction to display both files and directories. */ |
|
156 |
public static final int FILES_AND_DIRECTORIES = 2; |
|
157 |
||
158 |
/** Instruction to cancel the current selection. */ |
|
159 |
public static final String CANCEL_SELECTION = "CancelSelection"; |
|
160 |
||
161 |
/** |
|
162 |
* Instruction to approve the current selection |
|
163 |
* (same as pressing yes or ok). |
|
164 |
*/ |
|
165 |
public static final String APPROVE_SELECTION = "ApproveSelection"; |
|
166 |
||
167 |
/** Identifies change in the text on the approve (yes, ok) button. */ |
|
168 |
public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY = "ApproveButtonTextChangedProperty"; |
|
169 |
||
170 |
/** |
|
171 |
* Identifies change in the tooltip text for the approve (yes, ok) |
|
172 |
* button. |
|
173 |
*/ |
|
174 |
public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY = "ApproveButtonToolTipTextChangedProperty"; |
|
175 |
||
176 |
/** Identifies change in the mnemonic for the approve (yes, ok) button. */ |
|
177 |
public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY = "ApproveButtonMnemonicChangedProperty"; |
|
178 |
||
179 |
/** Instruction to display the control buttons. */ |
|
180 |
public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY = "ControlButtonsAreShownChangedProperty"; |
|
181 |
||
182 |
/** Identifies user's directory change. */ |
|
183 |
public static final String DIRECTORY_CHANGED_PROPERTY = "directoryChanged"; |
|
184 |
||
185 |
/** Identifies change in user's single-file selection. */ |
|
186 |
public static final String SELECTED_FILE_CHANGED_PROPERTY = "SelectedFileChangedProperty"; |
|
187 |
||
188 |
/** Identifies change in user's multiple-file selection. */ |
|
189 |
public static final String SELECTED_FILES_CHANGED_PROPERTY = "SelectedFilesChangedProperty"; |
|
190 |
||
191 |
/** Enables multiple-file selections. */ |
|
192 |
public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY = "MultiSelectionEnabledChangedProperty"; |
|
193 |
||
194 |
/** |
|
195 |
* Says that a different object is being used to find available drives |
|
196 |
* on the system. |
|
197 |
*/ |
|
198 |
public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY = "FileSystemViewChanged"; |
|
199 |
||
200 |
/** |
|
201 |
* Says that a different object is being used to retrieve file |
|
202 |
* information. |
|
203 |
*/ |
|
204 |
public static final String FILE_VIEW_CHANGED_PROPERTY = "fileViewChanged"; |
|
205 |
||
206 |
/** Identifies a change in the display-hidden-files property. */ |
|
207 |
public static final String FILE_HIDING_CHANGED_PROPERTY = "FileHidingChanged"; |
|
208 |
||
209 |
/** User changed the kind of files to display. */ |
|
210 |
public static final String FILE_FILTER_CHANGED_PROPERTY = "fileFilterChanged"; |
|
211 |
||
212 |
/** |
|
213 |
* Identifies a change in the kind of selection (single, |
|
214 |
* multiple, etc.). |
|
215 |
*/ |
|
216 |
public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY = "fileSelectionChanged"; |
|
217 |
||
218 |
/** |
|
219 |
* Says that a different accessory component is in use |
|
220 |
* (for example, to preview files). |
|
221 |
*/ |
|
222 |
public static final String ACCESSORY_CHANGED_PROPERTY = "AccessoryChangedProperty"; |
|
223 |
||
224 |
/** |
|
225 |
* Identifies whether a the AcceptAllFileFilter is used or not. |
|
226 |
*/ |
|
227 |
public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY = "acceptAllFileFilterUsedChanged"; |
|
228 |
||
229 |
/** Identifies a change in the dialog title. */ |
|
230 |
public static final String DIALOG_TITLE_CHANGED_PROPERTY = "DialogTitleChangedProperty"; |
|
231 |
||
232 |
/** |
|
233 |
* Identifies a change in the type of files displayed (files only, |
|
234 |
* directories only, or both files and directories). |
|
235 |
*/ |
|
236 |
public static final String DIALOG_TYPE_CHANGED_PROPERTY = "DialogTypeChangedProperty"; |
|
237 |
||
238 |
/** |
|
239 |
* Identifies a change in the list of predefined file filters |
|
240 |
* the user can choose from. |
|
241 |
*/ |
|
242 |
public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY = "ChoosableFileFilterChangedProperty"; |
|
243 |
||
244 |
// ****************************** |
|
245 |
// ***** instance variables ***** |
|
246 |
// ****************************** |
|
247 |
||
248 |
private String dialogTitle = null; |
|
249 |
private String approveButtonText = null; |
|
250 |
private String approveButtonToolTipText = null; |
|
251 |
private int approveButtonMnemonic = 0; |
|
252 |
||
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
253 |
private Vector<FileFilter> filters = new Vector<FileFilter>(5); |
2 | 254 |
private JDialog dialog = null; |
255 |
private int dialogType = OPEN_DIALOG; |
|
256 |
private int returnValue = ERROR_OPTION; |
|
257 |
private JComponent accessory = null; |
|
258 |
||
259 |
private FileView fileView = null; |
|
260 |
||
261 |
private boolean controlsShown = true; |
|
262 |
||
263 |
private boolean useFileHiding = true; |
|
264 |
private static final String SHOW_HIDDEN_PROP = "awt.file.showHiddenFiles"; |
|
265 |
||
266 |
// Listens to changes in the native setting for showing hidden files. |
|
267 |
// The Listener is removed and the native setting is ignored if |
|
268 |
// setFileHidingEnabled() is ever called. |
|
269 |
private transient PropertyChangeListener showFilesListener = null; |
|
270 |
||
271 |
private int fileSelectionMode = FILES_ONLY; |
|
272 |
||
273 |
private boolean multiSelectionEnabled = false; |
|
274 |
||
275 |
private boolean useAcceptAllFileFilter = true; |
|
276 |
||
277 |
private boolean dragEnabled = false; |
|
278 |
||
279 |
private FileFilter fileFilter = null; |
|
280 |
||
281 |
private FileSystemView fileSystemView = null; |
|
282 |
||
283 |
private File currentDirectory = null; |
|
284 |
private File selectedFile = null; |
|
285 |
private File[] selectedFiles; |
|
286 |
||
287 |
// ************************************* |
|
288 |
// ***** JFileChooser Constructors ***** |
|
289 |
// ************************************* |
|
290 |
||
291 |
/** |
|
292 |
* Constructs a <code>JFileChooser</code> pointing to the user's |
|
293 |
* default directory. This default depends on the operating system. |
|
294 |
* It is typically the "My Documents" folder on Windows, and the |
|
295 |
* user's home directory on Unix. |
|
296 |
*/ |
|
297 |
public JFileChooser() { |
|
298 |
this((File) null, (FileSystemView) null); |
|
299 |
} |
|
300 |
||
301 |
/** |
|
302 |
* Constructs a <code>JFileChooser</code> using the given path. |
|
303 |
* Passing in a <code>null</code> |
|
304 |
* string causes the file chooser to point to the user's default directory. |
|
305 |
* This default depends on the operating system. It is |
|
306 |
* typically the "My Documents" folder on Windows, and the user's |
|
307 |
* home directory on Unix. |
|
308 |
* |
|
309 |
* @param currentDirectoryPath a <code>String</code> giving the path |
|
310 |
* to a file or directory |
|
311 |
*/ |
|
312 |
public JFileChooser(String currentDirectoryPath) { |
|
313 |
this(currentDirectoryPath, (FileSystemView) null); |
|
314 |
} |
|
315 |
||
316 |
/** |
|
317 |
* Constructs a <code>JFileChooser</code> using the given <code>File</code> |
|
318 |
* as the path. Passing in a <code>null</code> file |
|
319 |
* causes the file chooser to point to the user's default directory. |
|
320 |
* This default depends on the operating system. It is |
|
321 |
* typically the "My Documents" folder on Windows, and the user's |
|
322 |
* home directory on Unix. |
|
323 |
* |
|
324 |
* @param currentDirectory a <code>File</code> object specifying |
|
325 |
* the path to a file or directory |
|
326 |
*/ |
|
327 |
public JFileChooser(File currentDirectory) { |
|
328 |
this(currentDirectory, (FileSystemView) null); |
|
329 |
} |
|
330 |
||
331 |
/** |
|
332 |
* Constructs a <code>JFileChooser</code> using the given |
|
333 |
* <code>FileSystemView</code>. |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
334 |
* |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
335 |
* @param fsv a {@code FileSystemView} |
2 | 336 |
*/ |
337 |
public JFileChooser(FileSystemView fsv) { |
|
338 |
this((File) null, fsv); |
|
339 |
} |
|
340 |
||
341 |
||
342 |
/** |
|
343 |
* Constructs a <code>JFileChooser</code> using the given current directory |
|
344 |
* and <code>FileSystemView</code>. |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
345 |
* |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
346 |
* @param currentDirectory a {@code File} object specifying the path to a |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
347 |
* file or directory |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
348 |
* @param fsv a {@code FileSystemView} |
2 | 349 |
*/ |
350 |
public JFileChooser(File currentDirectory, FileSystemView fsv) { |
|
351 |
setup(fsv); |
|
352 |
setCurrentDirectory(currentDirectory); |
|
353 |
} |
|
354 |
||
355 |
/** |
|
356 |
* Constructs a <code>JFileChooser</code> using the given current directory |
|
357 |
* path and <code>FileSystemView</code>. |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
358 |
* |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
359 |
* @param currentDirectoryPath a {@code String} specifying the path to a file |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
360 |
* or directory |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
361 |
* @param fsv a {@code FileSystemView} |
2 | 362 |
*/ |
363 |
public JFileChooser(String currentDirectoryPath, FileSystemView fsv) { |
|
364 |
setup(fsv); |
|
365 |
if(currentDirectoryPath == null) { |
|
366 |
setCurrentDirectory(null); |
|
367 |
} else { |
|
368 |
setCurrentDirectory(fileSystemView.createFileObject(currentDirectoryPath)); |
|
369 |
} |
|
370 |
} |
|
371 |
||
372 |
/** |
|
373 |
* Performs common constructor initialization and setup. |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
374 |
* |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
375 |
* @param view the {@code FileSystemView} used for setup |
2 | 376 |
*/ |
377 |
protected void setup(FileSystemView view) { |
|
378 |
installShowFilesListener(); |
|
20119
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
379 |
installHierarchyListener(); |
2 | 380 |
|
381 |
if(view == null) { |
|
382 |
view = FileSystemView.getFileSystemView(); |
|
383 |
} |
|
384 |
setFileSystemView(view); |
|
385 |
updateUI(); |
|
386 |
if(isAcceptAllFileFilterUsed()) { |
|
387 |
setFileFilter(getAcceptAllFileFilter()); |
|
388 |
} |
|
389 |
enableEvents(AWTEvent.MOUSE_EVENT_MASK); |
|
390 |
} |
|
391 |
||
20119
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
392 |
private void installHierarchyListener() { |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
393 |
addHierarchyListener(new HierarchyListener() { |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
394 |
@Override |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
395 |
public void hierarchyChanged(HierarchyEvent e) { |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
396 |
if ((e.getChangeFlags() & HierarchyEvent.PARENT_CHANGED) |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
397 |
== HierarchyEvent.PARENT_CHANGED) { |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
398 |
JFileChooser fc = JFileChooser.this; |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
399 |
JRootPane rootPane = SwingUtilities.getRootPane(fc); |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
400 |
if (rootPane != null) { |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
401 |
rootPane.setDefaultButton(fc.getUI().getDefaultButton(fc)); |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
402 |
} |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
403 |
} |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
404 |
} |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
405 |
}); |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
406 |
} |
e209efee23ed
8021253: JFileChooser does not react on pressing enter since java 7
alexsch
parents:
19018
diff
changeset
|
407 |
|
2 | 408 |
private void installShowFilesListener() { |
409 |
// Track native setting for showing hidden files |
|
410 |
Toolkit tk = Toolkit.getDefaultToolkit(); |
|
411 |
Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP); |
|
412 |
if (showHiddenProperty instanceof Boolean) { |
|
413 |
useFileHiding = !((Boolean)showHiddenProperty).booleanValue(); |
|
414 |
showFilesListener = new WeakPCL(this); |
|
415 |
tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener); |
|
416 |
} |
|
417 |
} |
|
418 |
||
419 |
/** |
|
420 |
* Sets the <code>dragEnabled</code> property, |
|
421 |
* which must be <code>true</code> to enable |
|
422 |
* automatic drag handling (the first part of drag and drop) |
|
423 |
* on this component. |
|
424 |
* The <code>transferHandler</code> property needs to be set |
|
425 |
* to a non-<code>null</code> value for the drag to do |
|
426 |
* anything. The default value of the <code>dragEnabled</code> |
|
427 |
* property |
|
428 |
* is <code>false</code>. |
|
429 |
* |
|
430 |
* <p> |
|
431 |
* |
|
432 |
* When automatic drag handling is enabled, |
|
433 |
* most look and feels begin a drag-and-drop operation |
|
434 |
* whenever the user presses the mouse button over an item |
|
435 |
* and then moves the mouse a few pixels. |
|
436 |
* Setting this property to <code>true</code> |
|
437 |
* can therefore have a subtle effect on |
|
438 |
* how selections behave. |
|
439 |
* |
|
440 |
* <p> |
|
441 |
* |
|
442 |
* Some look and feels might not support automatic drag and drop; |
|
443 |
* they will ignore this property. You can work around such |
|
444 |
* look and feels by modifying the component |
|
445 |
* to directly call the <code>exportAsDrag</code> method of a |
|
446 |
* <code>TransferHandler</code>. |
|
447 |
* |
|
448 |
* @param b the value to set the <code>dragEnabled</code> property to |
|
449 |
* @exception HeadlessException if |
|
450 |
* <code>b</code> is <code>true</code> and |
|
451 |
* <code>GraphicsEnvironment.isHeadless()</code> |
|
452 |
* returns <code>true</code> |
|
453 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
454 |
* @see #getDragEnabled |
|
455 |
* @see #setTransferHandler |
|
456 |
* @see TransferHandler |
|
457 |
* @since 1.4 |
|
458 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
459 |
@BeanProperty(bound = false, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
460 |
= "determines whether automatic drag handling is enabled") |
2 | 461 |
public void setDragEnabled(boolean b) { |
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
462 |
checkDragEnabled(b); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
463 |
dragEnabled = b; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
464 |
} |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
465 |
|
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
466 |
private static void checkDragEnabled(boolean b) { |
2 | 467 |
if (b && GraphicsEnvironment.isHeadless()) { |
468 |
throw new HeadlessException(); |
|
469 |
} |
|
470 |
} |
|
471 |
||
472 |
/** |
|
473 |
* Gets the value of the <code>dragEnabled</code> property. |
|
474 |
* |
|
475 |
* @return the value of the <code>dragEnabled</code> property |
|
476 |
* @see #setDragEnabled |
|
477 |
* @since 1.4 |
|
478 |
*/ |
|
479 |
public boolean getDragEnabled() { |
|
480 |
return dragEnabled; |
|
481 |
} |
|
482 |
||
483 |
// ***************************** |
|
484 |
// ****** File Operations ****** |
|
485 |
// ***************************** |
|
486 |
||
487 |
/** |
|
488 |
* Returns the selected file. This can be set either by the |
|
489 |
* programmer via <code>setSelectedFile</code> or by a user action, such as |
|
490 |
* either typing the filename into the UI or selecting the |
|
491 |
* file from a list in the UI. |
|
492 |
* |
|
493 |
* @see #setSelectedFile |
|
494 |
* @return the selected file |
|
495 |
*/ |
|
496 |
public File getSelectedFile() { |
|
497 |
return selectedFile; |
|
498 |
} |
|
499 |
||
500 |
/** |
|
501 |
* Sets the selected file. If the file's parent directory is |
|
502 |
* not the current directory, changes the current directory |
|
503 |
* to be the file's parent directory. |
|
504 |
* |
|
505 |
* @see #getSelectedFile |
|
506 |
* |
|
507 |
* @param file the selected file |
|
508 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
509 |
@BeanProperty(preferred = true) |
2 | 510 |
public void setSelectedFile(File file) { |
511 |
File oldValue = selectedFile; |
|
512 |
selectedFile = file; |
|
513 |
if(selectedFile != null) { |
|
514 |
if (file.isAbsolute() && !getFileSystemView().isParent(getCurrentDirectory(), selectedFile)) { |
|
515 |
setCurrentDirectory(selectedFile.getParentFile()); |
|
516 |
} |
|
517 |
if (!isMultiSelectionEnabled() || selectedFiles == null || selectedFiles.length == 1) { |
|
518 |
ensureFileIsVisible(selectedFile); |
|
519 |
} |
|
520 |
} |
|
521 |
firePropertyChange(SELECTED_FILE_CHANGED_PROPERTY, oldValue, selectedFile); |
|
522 |
} |
|
523 |
||
524 |
/** |
|
525 |
* Returns a list of selected files if the file chooser is |
|
526 |
* set to allow multiple selection. |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
527 |
* |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
528 |
* @return an array of selected {@code File}s |
2 | 529 |
*/ |
530 |
public File[] getSelectedFiles() { |
|
531 |
if(selectedFiles == null) { |
|
532 |
return new File[0]; |
|
533 |
} else { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
534 |
return selectedFiles.clone(); |
2 | 535 |
} |
536 |
} |
|
537 |
||
538 |
/** |
|
539 |
* Sets the list of selected files if the file chooser is |
|
540 |
* set to allow multiple selection. |
|
541 |
* |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
542 |
* @param selectedFiles an array {@code File}s to be selected |
2 | 543 |
*/ |
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
544 |
@BeanProperty(description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
545 |
= "The list of selected files if the chooser is in multiple selection mode.") |
2 | 546 |
public void setSelectedFiles(File[] selectedFiles) { |
547 |
File[] oldValue = this.selectedFiles; |
|
548 |
if (selectedFiles == null || selectedFiles.length == 0) { |
|
549 |
selectedFiles = null; |
|
550 |
this.selectedFiles = null; |
|
551 |
setSelectedFile(null); |
|
552 |
} else { |
|
553 |
this.selectedFiles = selectedFiles.clone(); |
|
554 |
setSelectedFile(this.selectedFiles[0]); |
|
555 |
} |
|
556 |
firePropertyChange(SELECTED_FILES_CHANGED_PROPERTY, oldValue, selectedFiles); |
|
557 |
} |
|
558 |
||
559 |
/** |
|
560 |
* Returns the current directory. |
|
561 |
* |
|
562 |
* @return the current directory |
|
563 |
* @see #setCurrentDirectory |
|
564 |
*/ |
|
565 |
public File getCurrentDirectory() { |
|
566 |
return currentDirectory; |
|
567 |
} |
|
568 |
||
569 |
/** |
|
570 |
* Sets the current directory. Passing in <code>null</code> sets the |
|
571 |
* file chooser to point to the user's default directory. |
|
572 |
* This default depends on the operating system. It is |
|
573 |
* typically the "My Documents" folder on Windows, and the user's |
|
574 |
* home directory on Unix. |
|
575 |
* |
|
576 |
* If the file passed in as <code>currentDirectory</code> is not a |
|
577 |
* directory, the parent of the file will be used as the currentDirectory. |
|
578 |
* If the parent is not traversable, then it will walk up the parent tree |
|
579 |
* until it finds a traversable directory, or hits the root of the |
|
580 |
* file system. |
|
581 |
* |
|
582 |
* @param dir the current directory to point to |
|
583 |
* @see #getCurrentDirectory |
|
584 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
585 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
586 |
= "The directory that the JFileChooser is showing files of.") |
2 | 587 |
public void setCurrentDirectory(File dir) { |
588 |
File oldValue = currentDirectory; |
|
589 |
||
590 |
if (dir != null && !dir.exists()) { |
|
591 |
dir = currentDirectory; |
|
592 |
} |
|
593 |
if (dir == null) { |
|
594 |
dir = getFileSystemView().getDefaultDirectory(); |
|
595 |
} |
|
596 |
if (currentDirectory != null) { |
|
597 |
/* Verify the toString of object */ |
|
598 |
if (this.currentDirectory.equals(dir)) { |
|
599 |
return; |
|
600 |
} |
|
601 |
} |
|
602 |
||
603 |
File prev = null; |
|
604 |
while (!isTraversable(dir) && prev != dir) { |
|
605 |
prev = dir; |
|
606 |
dir = getFileSystemView().getParentDirectory(dir); |
|
607 |
} |
|
608 |
currentDirectory = dir; |
|
609 |
||
610 |
firePropertyChange(DIRECTORY_CHANGED_PROPERTY, oldValue, currentDirectory); |
|
611 |
} |
|
612 |
||
613 |
/** |
|
614 |
* Changes the directory to be set to the parent of the |
|
615 |
* current directory. |
|
616 |
* |
|
617 |
* @see #getCurrentDirectory |
|
618 |
*/ |
|
619 |
public void changeToParentDirectory() { |
|
620 |
selectedFile = null; |
|
621 |
File oldValue = getCurrentDirectory(); |
|
622 |
setCurrentDirectory(getFileSystemView().getParentDirectory(oldValue)); |
|
623 |
} |
|
624 |
||
625 |
/** |
|
626 |
* Tells the UI to rescan its files list from the current directory. |
|
627 |
*/ |
|
628 |
public void rescanCurrentDirectory() { |
|
629 |
getUI().rescanCurrentDirectory(this); |
|
630 |
} |
|
631 |
||
632 |
/** |
|
633 |
* Makes sure that the specified file is viewable, and |
|
634 |
* not hidden. |
|
635 |
* |
|
636 |
* @param f a File object |
|
637 |
*/ |
|
638 |
public void ensureFileIsVisible(File f) { |
|
639 |
getUI().ensureFileIsVisible(this, f); |
|
640 |
} |
|
641 |
||
642 |
// ************************************** |
|
643 |
// ***** JFileChooser Dialog methods ***** |
|
644 |
// ************************************** |
|
645 |
||
646 |
/** |
|
647 |
* Pops up an "Open File" file chooser dialog. Note that the |
|
648 |
* text that appears in the approve button is determined by |
|
21592 | 649 |
* the L&F. |
2 | 650 |
* |
651 |
* @param parent the parent component of the dialog, |
|
652 |
* can be <code>null</code>; |
|
653 |
* see <code>showDialog</code> for details |
|
654 |
* @return the return state of the file chooser on popdown: |
|
655 |
* <ul> |
|
656 |
* <li>JFileChooser.CANCEL_OPTION |
|
657 |
* <li>JFileChooser.APPROVE_OPTION |
|
658 |
* <li>JFileChooser.ERROR_OPTION if an error occurs or the |
|
659 |
* dialog is dismissed |
|
660 |
* </ul> |
|
661 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless() |
|
662 |
* returns true. |
|
663 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
664 |
* @see #showDialog |
|
665 |
*/ |
|
666 |
public int showOpenDialog(Component parent) throws HeadlessException { |
|
667 |
setDialogType(OPEN_DIALOG); |
|
668 |
return showDialog(parent, null); |
|
669 |
} |
|
670 |
||
671 |
/** |
|
672 |
* Pops up a "Save File" file chooser dialog. Note that the |
|
673 |
* text that appears in the approve button is determined by |
|
21592 | 674 |
* the L&F. |
2 | 675 |
* |
676 |
* @param parent the parent component of the dialog, |
|
677 |
* can be <code>null</code>; |
|
678 |
* see <code>showDialog</code> for details |
|
679 |
* @return the return state of the file chooser on popdown: |
|
680 |
* <ul> |
|
681 |
* <li>JFileChooser.CANCEL_OPTION |
|
682 |
* <li>JFileChooser.APPROVE_OPTION |
|
683 |
* <li>JFileChooser.ERROR_OPTION if an error occurs or the |
|
684 |
* dialog is dismissed |
|
685 |
* </ul> |
|
686 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless() |
|
687 |
* returns true. |
|
688 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
689 |
* @see #showDialog |
|
690 |
*/ |
|
691 |
public int showSaveDialog(Component parent) throws HeadlessException { |
|
692 |
setDialogType(SAVE_DIALOG); |
|
693 |
return showDialog(parent, null); |
|
694 |
} |
|
695 |
||
696 |
/** |
|
697 |
* Pops a custom file chooser dialog with a custom approve button. |
|
698 |
* For example, the following code |
|
699 |
* pops up a file chooser with a "Run Application" button |
|
700 |
* (instead of the normal "Save" or "Open" button): |
|
701 |
* <pre> |
|
702 |
* filechooser.showDialog(parentFrame, "Run Application"); |
|
703 |
* </pre> |
|
704 |
* |
|
705 |
* Alternatively, the following code does the same thing: |
|
706 |
* <pre> |
|
707 |
* JFileChooser chooser = new JFileChooser(null); |
|
708 |
* chooser.setApproveButtonText("Run Application"); |
|
709 |
* chooser.showDialog(parentFrame, null); |
|
710 |
* </pre> |
|
711 |
* |
|
712 |
* <!--PENDING(jeff) - the following method should be added to the api: |
|
713 |
* showDialog(Component parent);--> |
|
714 |
* <!--PENDING(kwalrath) - should specify modality and what |
|
715 |
* "depends" means.--> |
|
716 |
* |
|
717 |
* <p> |
|
718 |
* |
|
719 |
* The <code>parent</code> argument determines two things: |
|
720 |
* the frame on which the open dialog depends and |
|
721 |
* the component whose position the look and feel |
|
722 |
* should consider when placing the dialog. If the parent |
|
723 |
* is a <code>Frame</code> object (such as a <code>JFrame</code>) |
|
724 |
* then the dialog depends on the frame and |
|
725 |
* the look and feel positions the dialog |
|
726 |
* relative to the frame (for example, centered over the frame). |
|
727 |
* If the parent is a component, then the dialog |
|
728 |
* depends on the frame containing the component, |
|
729 |
* and is positioned relative to the component |
|
730 |
* (for example, centered over the component). |
|
731 |
* If the parent is <code>null</code>, then the dialog depends on |
|
732 |
* no visible window, and it's placed in a |
|
733 |
* look-and-feel-dependent position |
|
734 |
* such as the center of the screen. |
|
735 |
* |
|
736 |
* @param parent the parent component of the dialog; |
|
737 |
* can be <code>null</code> |
|
738 |
* @param approveButtonText the text of the <code>ApproveButton</code> |
|
739 |
* @return the return state of the file chooser on popdown: |
|
740 |
* <ul> |
|
741 |
* <li>JFileChooser.CANCEL_OPTION |
|
742 |
* <li>JFileChooser.APPROVE_OPTION |
|
3982
b8872825ad04
6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents:
3346
diff
changeset
|
743 |
* <li>JFileChooser.ERROR_OPTION if an error occurs or the |
2 | 744 |
* dialog is dismissed |
745 |
* </ul> |
|
746 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless() |
|
747 |
* returns true. |
|
748 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
749 |
*/ |
|
28231
b608ffcaed74
8066621: Suppress deprecation warnings in java.desktop module
darcy
parents:
26037
diff
changeset
|
750 |
@SuppressWarnings("deprecation") |
2 | 751 |
public int showDialog(Component parent, String approveButtonText) |
752 |
throws HeadlessException { |
|
3982
b8872825ad04
6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents:
3346
diff
changeset
|
753 |
if (dialog != null) { |
b8872825ad04
6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents:
3346
diff
changeset
|
754 |
// Prevent to show second instance of dialog if the previous one still exists |
b8872825ad04
6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents:
3346
diff
changeset
|
755 |
return JFileChooser.ERROR_OPTION; |
b8872825ad04
6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents:
3346
diff
changeset
|
756 |
} |
b8872825ad04
6489130: FileChooserDemo hung by keeping pressing Enter key
rupashka
parents:
3346
diff
changeset
|
757 |
|
2 | 758 |
if(approveButtonText != null) { |
759 |
setApproveButtonText(approveButtonText); |
|
760 |
setDialogType(CUSTOM_DIALOG); |
|
761 |
} |
|
762 |
dialog = createDialog(parent); |
|
763 |
dialog.addWindowListener(new WindowAdapter() { |
|
764 |
public void windowClosing(WindowEvent e) { |
|
765 |
returnValue = CANCEL_OPTION; |
|
766 |
} |
|
767 |
}); |
|
768 |
returnValue = ERROR_OPTION; |
|
769 |
rescanCurrentDirectory(); |
|
770 |
||
771 |
dialog.show(); |
|
772 |
firePropertyChange("JFileChooserDialogIsClosingProperty", dialog, null); |
|
3346
1c65be97eaa2
6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents:
1301
diff
changeset
|
773 |
|
1c65be97eaa2
6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents:
1301
diff
changeset
|
774 |
// Remove all components from dialog. The MetalFileChooserUI.installUI() method (and other LAFs) |
1c65be97eaa2
6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents:
1301
diff
changeset
|
775 |
// registers AWT listener for dialogs and produces memory leaks. It happens when |
1c65be97eaa2
6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents:
1301
diff
changeset
|
776 |
// installUI invoked after the showDialog method. |
1c65be97eaa2
6460525: javax/swing/JFileChooser/6396844/TwentyThousandTest.java times out
rupashka
parents:
1301
diff
changeset
|
777 |
dialog.getContentPane().removeAll(); |
2 | 778 |
dialog.dispose(); |
779 |
dialog = null; |
|
780 |
return returnValue; |
|
781 |
} |
|
782 |
||
783 |
/** |
|
784 |
* Creates and returns a new <code>JDialog</code> wrapping |
|
785 |
* <code>this</code> centered on the <code>parent</code> |
|
786 |
* in the <code>parent</code>'s frame. |
|
787 |
* This method can be overriden to further manipulate the dialog, |
|
788 |
* to disable resizing, set the location, etc. Example: |
|
789 |
* <pre> |
|
790 |
* class MyFileChooser extends JFileChooser { |
|
791 |
* protected JDialog createDialog(Component parent) throws HeadlessException { |
|
792 |
* JDialog dialog = super.createDialog(parent); |
|
793 |
* dialog.setLocation(300, 200); |
|
794 |
* dialog.setResizable(false); |
|
795 |
* return dialog; |
|
796 |
* } |
|
797 |
* } |
|
798 |
* </pre> |
|
799 |
* |
|
800 |
* @param parent the parent component of the dialog; |
|
801 |
* can be <code>null</code> |
|
802 |
* @return a new <code>JDialog</code> containing this instance |
|
803 |
* @exception HeadlessException if GraphicsEnvironment.isHeadless() |
|
804 |
* returns true. |
|
805 |
* @see java.awt.GraphicsEnvironment#isHeadless |
|
806 |
* @since 1.4 |
|
807 |
*/ |
|
808 |
protected JDialog createDialog(Component parent) throws HeadlessException { |
|
680
eaff686e34f7
5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF
rupashka
parents:
2
diff
changeset
|
809 |
FileChooserUI ui = getUI(); |
eaff686e34f7
5035693: "Open" button should be a default one in JFileChooser under Windows XP LAF
rupashka
parents:
2
diff
changeset
|
810 |
String title = ui.getDialogTitle(this); |
2 | 811 |
putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY, |
812 |
title); |
|
813 |
||
814 |
JDialog dialog; |
|
815 |
Window window = JOptionPane.getWindowForComponent(parent); |
|
816 |
if (window instanceof Frame) { |
|
817 |
dialog = new JDialog((Frame)window, title, true); |
|
818 |
} else { |
|
819 |
dialog = new JDialog((Dialog)window, title, true); |
|
820 |
} |
|
821 |
dialog.setComponentOrientation(this.getComponentOrientation()); |
|
822 |
||
823 |
Container contentPane = dialog.getContentPane(); |
|
824 |
contentPane.setLayout(new BorderLayout()); |
|
825 |
contentPane.add(this, BorderLayout.CENTER); |
|
826 |
||
827 |
if (JDialog.isDefaultLookAndFeelDecorated()) { |
|
828 |
boolean supportsWindowDecorations = |
|
829 |
UIManager.getLookAndFeel().getSupportsWindowDecorations(); |
|
830 |
if (supportsWindowDecorations) { |
|
831 |
dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG); |
|
832 |
} |
|
833 |
} |
|
834 |
dialog.pack(); |
|
835 |
dialog.setLocationRelativeTo(parent); |
|
836 |
||
837 |
return dialog; |
|
838 |
} |
|
839 |
||
840 |
// ************************** |
|
841 |
// ***** Dialog Options ***** |
|
842 |
// ************************** |
|
843 |
||
844 |
/** |
|
845 |
* Returns the value of the <code>controlButtonsAreShown</code> |
|
846 |
* property. |
|
847 |
* |
|
848 |
* @return the value of the <code>controlButtonsAreShown</code> |
|
849 |
* property |
|
850 |
* |
|
851 |
* @see #setControlButtonsAreShown |
|
852 |
* @since 1.3 |
|
853 |
*/ |
|
854 |
public boolean getControlButtonsAreShown() { |
|
855 |
return controlsShown; |
|
856 |
} |
|
857 |
||
858 |
||
859 |
/** |
|
860 |
* Sets the property |
|
861 |
* that indicates whether the <i>approve</i> and <i>cancel</i> |
|
862 |
* buttons are shown in the file chooser. This property |
|
863 |
* is <code>true</code> by default. Look and feels |
|
864 |
* that always show these buttons will ignore the value |
|
865 |
* of this property. |
|
866 |
* This method fires a property-changed event, |
|
867 |
* using the string value of |
|
868 |
* <code>CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY</code> |
|
869 |
* as the name of the property. |
|
870 |
* |
|
871 |
* @param b <code>false</code> if control buttons should not be |
|
872 |
* shown; otherwise, <code>true</code> |
|
873 |
* |
|
874 |
* @see #getControlButtonsAreShown |
|
875 |
* @see #CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY |
|
876 |
* @since 1.3 |
|
877 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
878 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
879 |
= "Sets whether the approve & cancel buttons are shown.") |
2 | 880 |
public void setControlButtonsAreShown(boolean b) { |
881 |
if(controlsShown == b) { |
|
882 |
return; |
|
883 |
} |
|
884 |
boolean oldValue = controlsShown; |
|
885 |
controlsShown = b; |
|
886 |
firePropertyChange(CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY, oldValue, controlsShown); |
|
887 |
} |
|
888 |
||
889 |
/** |
|
890 |
* Returns the type of this dialog. The default is |
|
891 |
* <code>JFileChooser.OPEN_DIALOG</code>. |
|
892 |
* |
|
893 |
* @return the type of dialog to be displayed: |
|
894 |
* <ul> |
|
895 |
* <li>JFileChooser.OPEN_DIALOG |
|
896 |
* <li>JFileChooser.SAVE_DIALOG |
|
897 |
* <li>JFileChooser.CUSTOM_DIALOG |
|
898 |
* </ul> |
|
899 |
* |
|
900 |
* @see #setDialogType |
|
901 |
*/ |
|
902 |
public int getDialogType() { |
|
903 |
return dialogType; |
|
904 |
} |
|
905 |
||
906 |
/** |
|
907 |
* Sets the type of this dialog. Use <code>OPEN_DIALOG</code> when you |
|
908 |
* want to bring up a file chooser that the user can use to open a file. |
|
909 |
* Likewise, use <code>SAVE_DIALOG</code> for letting the user choose |
|
910 |
* a file for saving. |
|
911 |
* Use <code>CUSTOM_DIALOG</code> when you want to use the file |
|
912 |
* chooser in a context other than "Open" or "Save". |
|
913 |
* For instance, you might want to bring up a file chooser that allows |
|
914 |
* the user to choose a file to execute. Note that you normally would not |
|
915 |
* need to set the <code>JFileChooser</code> to use |
|
916 |
* <code>CUSTOM_DIALOG</code> |
|
917 |
* since a call to <code>setApproveButtonText</code> does this for you. |
|
918 |
* The default dialog type is <code>JFileChooser.OPEN_DIALOG</code>. |
|
919 |
* |
|
920 |
* @param dialogType the type of dialog to be displayed: |
|
921 |
* <ul> |
|
922 |
* <li>JFileChooser.OPEN_DIALOG |
|
923 |
* <li>JFileChooser.SAVE_DIALOG |
|
924 |
* <li>JFileChooser.CUSTOM_DIALOG |
|
925 |
* </ul> |
|
926 |
* |
|
927 |
* @exception IllegalArgumentException if <code>dialogType</code> is |
|
928 |
* not legal |
|
929 |
* |
|
930 |
* @see #getDialogType |
|
931 |
* @see #setApproveButtonText |
|
932 |
*/ |
|
933 |
// PENDING(jeff) - fire button text change property |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
934 |
@BeanProperty(preferred = true, enumerationValues = { |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
935 |
"JFileChooser.OPEN_DIALOG", |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
936 |
"JFileChooser.SAVE_DIALOG", |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
937 |
"JFileChooser.CUSTOM_DIALOG"}, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
938 |
= "The type (open, save, custom) of the JFileChooser.") |
2 | 939 |
public void setDialogType(int dialogType) { |
940 |
if(this.dialogType == dialogType) { |
|
941 |
return; |
|
942 |
} |
|
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
943 |
checkDialogType(dialogType); |
2 | 944 |
int oldValue = this.dialogType; |
945 |
this.dialogType = dialogType; |
|
946 |
if(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG) { |
|
947 |
setApproveButtonText(null); |
|
948 |
} |
|
949 |
firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, oldValue, dialogType); |
|
950 |
} |
|
951 |
||
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
952 |
private static void checkDialogType(int dialogType) { |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
953 |
if (!(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
954 |
|| dialogType == CUSTOM_DIALOG)) { |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
955 |
throw new IllegalArgumentException( |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
956 |
"Incorrect Dialog Type: " + dialogType); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
957 |
} |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
958 |
} |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
959 |
|
2 | 960 |
/** |
961 |
* Sets the string that goes in the <code>JFileChooser</code> window's |
|
962 |
* title bar. |
|
963 |
* |
|
964 |
* @param dialogTitle the new <code>String</code> for the title bar |
|
965 |
* |
|
966 |
* @see #getDialogTitle |
|
967 |
* |
|
968 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
969 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
970 |
= "The title of the JFileChooser dialog window.") |
2 | 971 |
public void setDialogTitle(String dialogTitle) { |
972 |
String oldValue = this.dialogTitle; |
|
973 |
this.dialogTitle = dialogTitle; |
|
974 |
if(dialog != null) { |
|
975 |
dialog.setTitle(dialogTitle); |
|
976 |
} |
|
977 |
firePropertyChange(DIALOG_TITLE_CHANGED_PROPERTY, oldValue, dialogTitle); |
|
978 |
} |
|
979 |
||
980 |
/** |
|
981 |
* Gets the string that goes in the <code>JFileChooser</code>'s titlebar. |
|
982 |
* |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
983 |
* @return the string from the {@code JFileChooser} window's title bar |
2 | 984 |
* @see #setDialogTitle |
985 |
*/ |
|
986 |
public String getDialogTitle() { |
|
987 |
return dialogTitle; |
|
988 |
} |
|
989 |
||
990 |
// ************************************ |
|
991 |
// ***** JFileChooser View Options ***** |
|
992 |
// ************************************ |
|
993 |
||
994 |
||
995 |
||
996 |
/** |
|
997 |
* Sets the tooltip text used in the <code>ApproveButton</code>. |
|
998 |
* If <code>null</code>, the UI object will determine the button's text. |
|
999 |
* |
|
1000 |
* @param toolTipText the tooltip text for the approve button |
|
1001 |
* @see #setApproveButtonText |
|
1002 |
* @see #setDialogType |
|
1003 |
* @see #showDialog |
|
1004 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1005 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1006 |
= "The tooltip text for the ApproveButton.") |
2 | 1007 |
public void setApproveButtonToolTipText(String toolTipText) { |
1008 |
if(approveButtonToolTipText == toolTipText) { |
|
1009 |
return; |
|
1010 |
} |
|
1011 |
String oldValue = approveButtonToolTipText; |
|
1012 |
approveButtonToolTipText = toolTipText; |
|
1013 |
firePropertyChange(APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY, oldValue, approveButtonToolTipText); |
|
1014 |
} |
|
1015 |
||
1016 |
||
1017 |
/** |
|
1018 |
* Returns the tooltip text used in the <code>ApproveButton</code>. |
|
1019 |
* If <code>null</code>, the UI object will determine the button's text. |
|
1020 |
* |
|
1021 |
* @return the tooltip text used for the approve button |
|
1022 |
* |
|
1023 |
* @see #setApproveButtonText |
|
1024 |
* @see #setDialogType |
|
1025 |
* @see #showDialog |
|
1026 |
*/ |
|
1027 |
public String getApproveButtonToolTipText() { |
|
1028 |
return approveButtonToolTipText; |
|
1029 |
} |
|
1030 |
||
1031 |
/** |
|
1032 |
* Returns the approve button's mnemonic. |
|
1033 |
* @return an integer value for the mnemonic key |
|
1034 |
* |
|
1035 |
* @see #setApproveButtonMnemonic |
|
1036 |
*/ |
|
1037 |
public int getApproveButtonMnemonic() { |
|
1038 |
return approveButtonMnemonic; |
|
1039 |
} |
|
1040 |
||
1041 |
/** |
|
1042 |
* Sets the approve button's mnemonic using a numeric keycode. |
|
1043 |
* |
|
1044 |
* @param mnemonic an integer value for the mnemonic key |
|
1045 |
* |
|
1046 |
* @see #getApproveButtonMnemonic |
|
1047 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1048 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1049 |
= "The mnemonic key accelerator for the ApproveButton.") |
2 | 1050 |
public void setApproveButtonMnemonic(int mnemonic) { |
1051 |
if(approveButtonMnemonic == mnemonic) { |
|
1052 |
return; |
|
1053 |
} |
|
1054 |
int oldValue = approveButtonMnemonic; |
|
1055 |
approveButtonMnemonic = mnemonic; |
|
1056 |
firePropertyChange(APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY, oldValue, approveButtonMnemonic); |
|
1057 |
} |
|
1058 |
||
1059 |
/** |
|
1060 |
* Sets the approve button's mnemonic using a character. |
|
1061 |
* @param mnemonic a character value for the mnemonic key |
|
1062 |
* |
|
1063 |
* @see #getApproveButtonMnemonic |
|
1064 |
*/ |
|
1065 |
public void setApproveButtonMnemonic(char mnemonic) { |
|
1066 |
int vk = (int) mnemonic; |
|
1067 |
if(vk >= 'a' && vk <='z') { |
|
1068 |
vk -= ('a' - 'A'); |
|
1069 |
} |
|
1070 |
setApproveButtonMnemonic(vk); |
|
1071 |
} |
|
1072 |
||
1073 |
||
1074 |
/** |
|
1075 |
* Sets the text used in the <code>ApproveButton</code> in the |
|
1076 |
* <code>FileChooserUI</code>. |
|
1077 |
* |
|
1078 |
* @param approveButtonText the text used in the <code>ApproveButton</code> |
|
1079 |
* |
|
1080 |
* @see #getApproveButtonText |
|
1081 |
* @see #setDialogType |
|
1082 |
* @see #showDialog |
|
1083 |
*/ |
|
1084 |
// PENDING(jeff) - have ui set this on dialog type change |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1085 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1086 |
= "The text that goes in the ApproveButton.") |
2 | 1087 |
public void setApproveButtonText(String approveButtonText) { |
1088 |
if(this.approveButtonText == approveButtonText) { |
|
1089 |
return; |
|
1090 |
} |
|
1091 |
String oldValue = this.approveButtonText; |
|
1092 |
this.approveButtonText = approveButtonText; |
|
1093 |
firePropertyChange(APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, oldValue, approveButtonText); |
|
1094 |
} |
|
1095 |
||
1096 |
/** |
|
1097 |
* Returns the text used in the <code>ApproveButton</code> in the |
|
1098 |
* <code>FileChooserUI</code>. |
|
1099 |
* If <code>null</code>, the UI object will determine the button's text. |
|
1100 |
* |
|
1101 |
* Typically, this would be "Open" or "Save". |
|
1102 |
* |
|
1103 |
* @return the text used in the <code>ApproveButton</code> |
|
1104 |
* |
|
1105 |
* @see #setApproveButtonText |
|
1106 |
* @see #setDialogType |
|
1107 |
* @see #showDialog |
|
1108 |
*/ |
|
1109 |
public String getApproveButtonText() { |
|
1110 |
return approveButtonText; |
|
1111 |
} |
|
1112 |
||
1113 |
/** |
|
1114 |
* Gets the list of user choosable file filters. |
|
1115 |
* |
|
1116 |
* @return a <code>FileFilter</code> array containing all the choosable |
|
1117 |
* file filters |
|
1118 |
* |
|
1119 |
* @see #addChoosableFileFilter |
|
1120 |
* @see #removeChoosableFileFilter |
|
1121 |
* @see #resetChoosableFileFilters |
|
1122 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1123 |
@BeanProperty(bound = false) |
2 | 1124 |
public FileFilter[] getChoosableFileFilters() { |
1125 |
FileFilter[] filterArray = new FileFilter[filters.size()]; |
|
1126 |
filters.copyInto(filterArray); |
|
1127 |
return filterArray; |
|
1128 |
} |
|
1129 |
||
1130 |
/** |
|
1131 |
* Adds a filter to the list of user choosable file filters. |
|
1132 |
* For information on setting the file selection mode, see |
|
1133 |
* {@link #setFileSelectionMode setFileSelectionMode}. |
|
1134 |
* |
|
1135 |
* @param filter the <code>FileFilter</code> to add to the choosable file |
|
1136 |
* filter list |
|
1137 |
* |
|
1138 |
* @see #getChoosableFileFilters |
|
1139 |
* @see #removeChoosableFileFilter |
|
1140 |
* @see #resetChoosableFileFilters |
|
1141 |
* @see #setFileSelectionMode |
|
1142 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1143 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1144 |
= "Adds a filter to the list of user choosable file filters.") |
2 | 1145 |
public void addChoosableFileFilter(FileFilter filter) { |
1146 |
if(filter != null && !filters.contains(filter)) { |
|
1147 |
FileFilter[] oldValue = getChoosableFileFilters(); |
|
1148 |
filters.addElement(filter); |
|
1149 |
firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters()); |
|
1150 |
if (fileFilter == null && filters.size() == 1) { |
|
1151 |
setFileFilter(filter); |
|
1152 |
} |
|
1153 |
} |
|
1154 |
} |
|
1155 |
||
1156 |
/** |
|
1157 |
* Removes a filter from the list of user choosable file filters. Returns |
|
1158 |
* true if the file filter was removed. |
|
1159 |
* |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1160 |
* @param f the file filter to be removed |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1161 |
* @return true if the file filter was removed, false otherwise |
2 | 1162 |
* @see #addChoosableFileFilter |
1163 |
* @see #getChoosableFileFilters |
|
1164 |
* @see #resetChoosableFileFilters |
|
1165 |
*/ |
|
1166 |
public boolean removeChoosableFileFilter(FileFilter f) { |
|
18134
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1167 |
int index = filters.indexOf(f); |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1168 |
if (index >= 0) { |
2 | 1169 |
if(getFileFilter() == f) { |
19018
14d6859b9dcc
8019975: closed/javax/swing/JFileChooser/4966171/bug4966171.java throws java.io.NotSerializableException: javax.swing.plaf.basic.BasicFileChooserUI$AcceptAllFileFilter
malenkov
parents:
18134
diff
changeset
|
1170 |
FileFilter aaff = getAcceptAllFileFilter(); |
14d6859b9dcc
8019975: closed/javax/swing/JFileChooser/4966171/bug4966171.java throws java.io.NotSerializableException: javax.swing.plaf.basic.BasicFileChooserUI$AcceptAllFileFilter
malenkov
parents:
18134
diff
changeset
|
1171 |
if (isAcceptAllFileFilterUsed() && (aaff != f)) { |
18134
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1172 |
// choose default filter if it is used |
19018
14d6859b9dcc
8019975: closed/javax/swing/JFileChooser/4966171/bug4966171.java throws java.io.NotSerializableException: javax.swing.plaf.basic.BasicFileChooserUI$AcceptAllFileFilter
malenkov
parents:
18134
diff
changeset
|
1173 |
setFileFilter(aaff); |
18134
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1174 |
} |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1175 |
else if (index > 0) { |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1176 |
// choose the first filter, because it is not removed |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1177 |
setFileFilter(filters.get(0)); |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1178 |
} |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1179 |
else if (filters.size() > 1) { |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1180 |
// choose the second filter, because the first one is removed |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1181 |
setFileFilter(filters.get(1)); |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1182 |
} |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1183 |
else { |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1184 |
// no more filters |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1185 |
setFileFilter(null); |
af8df2260431
8013442: No file filter selected in file type combo box when using JFileChooser
malenkov
parents:
9035
diff
changeset
|
1186 |
} |
2 | 1187 |
} |
1188 |
FileFilter[] oldValue = getChoosableFileFilters(); |
|
1189 |
filters.removeElement(f); |
|
1190 |
firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters()); |
|
1191 |
return true; |
|
1192 |
} else { |
|
1193 |
return false; |
|
1194 |
} |
|
1195 |
} |
|
1196 |
||
1197 |
/** |
|
1198 |
* Resets the choosable file filter list to its starting state. Normally, |
|
1199 |
* this removes all added file filters while leaving the |
|
1200 |
* <code>AcceptAll</code> file filter. |
|
1201 |
* |
|
1202 |
* @see #addChoosableFileFilter |
|
1203 |
* @see #getChoosableFileFilters |
|
1204 |
* @see #removeChoosableFileFilter |
|
1205 |
*/ |
|
1206 |
public void resetChoosableFileFilters() { |
|
1207 |
FileFilter[] oldValue = getChoosableFileFilters(); |
|
1208 |
setFileFilter(null); |
|
1209 |
filters.removeAllElements(); |
|
1210 |
if(isAcceptAllFileFilterUsed()) { |
|
1211 |
addChoosableFileFilter(getAcceptAllFileFilter()); |
|
1212 |
} |
|
1213 |
firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters()); |
|
1214 |
} |
|
1215 |
||
1216 |
/** |
|
1217 |
* Returns the <code>AcceptAll</code> file filter. |
|
1218 |
* For example, on Microsoft Windows this would be All Files (*.*). |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1219 |
* |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1220 |
* @return the {@code AcceptAll} file filter |
2 | 1221 |
*/ |
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1222 |
@BeanProperty(bound = false) |
2 | 1223 |
public FileFilter getAcceptAllFileFilter() { |
1224 |
FileFilter filter = null; |
|
1225 |
if(getUI() != null) { |
|
1226 |
filter = getUI().getAcceptAllFileFilter(this); |
|
1227 |
} |
|
1228 |
return filter; |
|
1229 |
} |
|
1230 |
||
1231 |
/** |
|
1232 |
* Returns whether the <code>AcceptAll FileFilter</code> is used. |
|
1233 |
* @return true if the <code>AcceptAll FileFilter</code> is used |
|
1234 |
* @see #setAcceptAllFileFilterUsed |
|
1235 |
* @since 1.3 |
|
1236 |
*/ |
|
1237 |
public boolean isAcceptAllFileFilterUsed() { |
|
1238 |
return useAcceptAllFileFilter; |
|
1239 |
} |
|
1240 |
||
1241 |
/** |
|
1242 |
* Determines whether the <code>AcceptAll FileFilter</code> is used |
|
1243 |
* as an available choice in the choosable filter list. |
|
1244 |
* If false, the <code>AcceptAll</code> file filter is removed from |
|
1245 |
* the list of available file filters. |
|
1246 |
* If true, the <code>AcceptAll</code> file filter will become the |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1247 |
* actively used file filter. |
2 | 1248 |
* |
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1249 |
* @param b a {@code boolean} which determines whether the {@code AcceptAll} |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1250 |
* file filter is an available choice in the choosable filter list |
2 | 1251 |
* |
1252 |
* @see #isAcceptAllFileFilterUsed |
|
1253 |
* @see #getAcceptAllFileFilter |
|
1254 |
* @see #setFileFilter |
|
1255 |
* @since 1.3 |
|
1256 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1257 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1258 |
= "Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.") |
2 | 1259 |
public void setAcceptAllFileFilterUsed(boolean b) { |
1260 |
boolean oldValue = useAcceptAllFileFilter; |
|
1261 |
useAcceptAllFileFilter = b; |
|
1262 |
if(!b) { |
|
1263 |
removeChoosableFileFilter(getAcceptAllFileFilter()); |
|
1264 |
} else { |
|
1265 |
removeChoosableFileFilter(getAcceptAllFileFilter()); |
|
1266 |
addChoosableFileFilter(getAcceptAllFileFilter()); |
|
1267 |
} |
|
1268 |
firePropertyChange(ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY, oldValue, useAcceptAllFileFilter); |
|
1269 |
} |
|
1270 |
||
1271 |
/** |
|
1272 |
* Returns the accessory component. |
|
1273 |
* |
|
1274 |
* @return this JFileChooser's accessory component, or null |
|
1275 |
* @see #setAccessory |
|
1276 |
*/ |
|
1277 |
public JComponent getAccessory() { |
|
1278 |
return accessory; |
|
1279 |
} |
|
1280 |
||
1281 |
/** |
|
1282 |
* Sets the accessory component. An accessory is often used to show a |
|
1283 |
* preview image of the selected file; however, it can be used for anything |
|
1284 |
* that the programmer wishes, such as extra custom file chooser controls. |
|
1285 |
* |
|
1286 |
* <p> |
|
1287 |
* Note: if there was a previous accessory, you should unregister |
|
1288 |
* any listeners that the accessory might have registered with the |
|
1289 |
* file chooser. |
|
1290 |
* |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1291 |
* @param newAccessory the accessory component to be set |
2 | 1292 |
*/ |
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1293 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1294 |
= "Sets the accessory component on the JFileChooser.") |
2 | 1295 |
public void setAccessory(JComponent newAccessory) { |
1296 |
JComponent oldValue = accessory; |
|
1297 |
accessory = newAccessory; |
|
1298 |
firePropertyChange(ACCESSORY_CHANGED_PROPERTY, oldValue, accessory); |
|
1299 |
} |
|
1300 |
||
1301 |
/** |
|
1302 |
* Sets the <code>JFileChooser</code> to allow the user to just |
|
1303 |
* select files, just select |
|
1304 |
* directories, or select both files and directories. The default is |
|
1305 |
* <code>JFilesChooser.FILES_ONLY</code>. |
|
1306 |
* |
|
1307 |
* @param mode the type of files to be displayed: |
|
1308 |
* <ul> |
|
1309 |
* <li>JFileChooser.FILES_ONLY |
|
1310 |
* <li>JFileChooser.DIRECTORIES_ONLY |
|
1311 |
* <li>JFileChooser.FILES_AND_DIRECTORIES |
|
1312 |
* </ul> |
|
1313 |
* |
|
1314 |
* @exception IllegalArgumentException if <code>mode</code> is an |
|
1315 |
* illegal file selection mode |
|
1316 |
* |
|
1317 |
* @see #getFileSelectionMode |
|
1318 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1319 |
@BeanProperty(preferred = true, enumerationValues = { |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1320 |
"JFileChooser.FILES_ONLY", |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1321 |
"JFileChooser.DIRECTORIES_ONLY", |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1322 |
"JFileChooser.FILES_AND_DIRECTORIES"}, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1323 |
= "Sets the types of files that the JFileChooser can choose.") |
2 | 1324 |
public void setFileSelectionMode(int mode) { |
1325 |
if(fileSelectionMode == mode) { |
|
1326 |
return; |
|
1327 |
} |
|
1328 |
||
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1329 |
checkFileSelectionMode(mode); |
2 | 1330 |
int oldValue = fileSelectionMode; |
1331 |
fileSelectionMode = mode; |
|
1332 |
firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, oldValue, fileSelectionMode); |
|
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1333 |
} |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1334 |
|
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1335 |
private static void checkFileSelectionMode(int mode) { |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1336 |
if ((mode != FILES_ONLY) && (mode != DIRECTORIES_ONLY) |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1337 |
&& (mode != FILES_AND_DIRECTORIES)) { |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1338 |
throw new IllegalArgumentException( |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1339 |
"Incorrect Mode for file selection: " + mode); |
2 | 1340 |
} |
1341 |
} |
|
1342 |
||
1343 |
/** |
|
1344 |
* Returns the current file-selection mode. The default is |
|
1345 |
* <code>JFilesChooser.FILES_ONLY</code>. |
|
1346 |
* |
|
1347 |
* @return the type of files to be displayed, one of the following: |
|
1348 |
* <ul> |
|
1349 |
* <li>JFileChooser.FILES_ONLY |
|
1350 |
* <li>JFileChooser.DIRECTORIES_ONLY |
|
1351 |
* <li>JFileChooser.FILES_AND_DIRECTORIES |
|
1352 |
* </ul> |
|
1353 |
* @see #setFileSelectionMode |
|
1354 |
*/ |
|
1355 |
public int getFileSelectionMode() { |
|
1356 |
return fileSelectionMode; |
|
1357 |
} |
|
1358 |
||
1359 |
/** |
|
1360 |
* Convenience call that determines if files are selectable based on the |
|
1361 |
* current file selection mode. |
|
1362 |
* |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1363 |
* @return true if files are selectable, false otherwise |
2 | 1364 |
* @see #setFileSelectionMode |
1365 |
* @see #getFileSelectionMode |
|
1366 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1367 |
@BeanProperty(bound = false) |
2 | 1368 |
public boolean isFileSelectionEnabled() { |
1369 |
return ((fileSelectionMode == FILES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES)); |
|
1370 |
} |
|
1371 |
||
1372 |
/** |
|
1373 |
* Convenience call that determines if directories are selectable based |
|
1374 |
* on the current file selection mode. |
|
1375 |
* |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1376 |
* @return true if directories are selectable, false otherwise |
2 | 1377 |
* @see #setFileSelectionMode |
1378 |
* @see #getFileSelectionMode |
|
1379 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1380 |
@BeanProperty(bound = false) |
2 | 1381 |
public boolean isDirectorySelectionEnabled() { |
1382 |
return ((fileSelectionMode == DIRECTORIES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES)); |
|
1383 |
} |
|
1384 |
||
1385 |
/** |
|
1386 |
* Sets the file chooser to allow multiple file selections. |
|
1387 |
* |
|
1388 |
* @param b true if multiple files may be selected |
|
1389 |
* |
|
1390 |
* @see #isMultiSelectionEnabled |
|
1391 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1392 |
@BeanProperty(description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1393 |
= "Sets multiple file selection mode.") |
2 | 1394 |
public void setMultiSelectionEnabled(boolean b) { |
1395 |
if(multiSelectionEnabled == b) { |
|
1396 |
return; |
|
1397 |
} |
|
1398 |
boolean oldValue = multiSelectionEnabled; |
|
1399 |
multiSelectionEnabled = b; |
|
1400 |
firePropertyChange(MULTI_SELECTION_ENABLED_CHANGED_PROPERTY, oldValue, multiSelectionEnabled); |
|
1401 |
} |
|
1402 |
||
1403 |
/** |
|
1404 |
* Returns true if multiple files can be selected. |
|
1405 |
* @return true if multiple files can be selected |
|
1406 |
* @see #setMultiSelectionEnabled |
|
1407 |
*/ |
|
1408 |
public boolean isMultiSelectionEnabled() { |
|
1409 |
return multiSelectionEnabled; |
|
1410 |
} |
|
1411 |
||
1412 |
||
1413 |
/** |
|
1414 |
* Returns true if hidden files are not shown in the file chooser; |
|
1415 |
* otherwise, returns false. |
|
1416 |
* |
|
1417 |
* @return the status of the file hiding property |
|
1418 |
* @see #setFileHidingEnabled |
|
1419 |
*/ |
|
1420 |
public boolean isFileHidingEnabled() { |
|
1421 |
return useFileHiding; |
|
1422 |
} |
|
1423 |
||
1424 |
/** |
|
1425 |
* Sets file hiding on or off. If true, hidden files are not shown |
|
1426 |
* in the file chooser. The job of determining which files are |
|
1427 |
* shown is done by the <code>FileView</code>. |
|
1428 |
* |
|
1429 |
* @param b the boolean value that determines whether file hiding is |
|
1430 |
* turned on |
|
1431 |
* @see #isFileHidingEnabled |
|
1432 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1433 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1434 |
= "Sets file hiding on or off.") |
2 | 1435 |
public void setFileHidingEnabled(boolean b) { |
1436 |
// Dump showFilesListener since we'll ignore it from now on |
|
1437 |
if (showFilesListener != null) { |
|
1438 |
Toolkit.getDefaultToolkit().removePropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener); |
|
1439 |
showFilesListener = null; |
|
1440 |
} |
|
1441 |
boolean oldValue = useFileHiding; |
|
1442 |
useFileHiding = b; |
|
1443 |
firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, oldValue, useFileHiding); |
|
1444 |
} |
|
1445 |
||
1446 |
/** |
|
1447 |
* Sets the current file filter. The file filter is used by the |
|
1448 |
* file chooser to filter out files from the user's view. |
|
1449 |
* |
|
1450 |
* @param filter the new current file filter to use |
|
1451 |
* @see #getFileFilter |
|
1452 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1453 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1454 |
= "Sets the File Filter used to filter out files of type.") |
2 | 1455 |
public void setFileFilter(FileFilter filter) { |
1456 |
FileFilter oldValue = fileFilter; |
|
1457 |
fileFilter = filter; |
|
1458 |
if (filter != null) { |
|
1459 |
if (isMultiSelectionEnabled() && selectedFiles != null && selectedFiles.length > 0) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
1460 |
Vector<File> fList = new Vector<File>(); |
2 | 1461 |
boolean failed = false; |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
1462 |
for (File file : selectedFiles) { |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
1463 |
if (filter.accept(file)) { |
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
1464 |
fList.add(file); |
2 | 1465 |
} else { |
1466 |
failed = true; |
|
1467 |
} |
|
1468 |
} |
|
1469 |
if (failed) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
1470 |
setSelectedFiles((fList.size() == 0) ? null : fList.toArray(new File[fList.size()])); |
2 | 1471 |
} |
1472 |
} else if (selectedFile != null && !filter.accept(selectedFile)) { |
|
1473 |
setSelectedFile(null); |
|
1474 |
} |
|
1475 |
} |
|
1476 |
firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, oldValue, fileFilter); |
|
1477 |
} |
|
1478 |
||
1479 |
||
1480 |
/** |
|
1481 |
* Returns the currently selected file filter. |
|
1482 |
* |
|
1483 |
* @return the current file filter |
|
1484 |
* @see #setFileFilter |
|
1485 |
* @see #addChoosableFileFilter |
|
1486 |
*/ |
|
1487 |
public FileFilter getFileFilter() { |
|
1488 |
return fileFilter; |
|
1489 |
} |
|
1490 |
||
1491 |
/** |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1492 |
* Sets the file view to be used to retrieve UI information, such as |
2 | 1493 |
* the icon that represents a file or the type description of a file. |
1494 |
* |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1495 |
* @param fileView a {@code FileView} to be used to retrieve UI information |
2 | 1496 |
* |
1497 |
* @see #getFileView |
|
1498 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1499 |
@BeanProperty(preferred = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1500 |
= "Sets the File View used to get file type information.") |
2 | 1501 |
public void setFileView(FileView fileView) { |
1502 |
FileView oldValue = this.fileView; |
|
1503 |
this.fileView = fileView; |
|
1504 |
firePropertyChange(FILE_VIEW_CHANGED_PROPERTY, oldValue, fileView); |
|
1505 |
} |
|
1506 |
||
1507 |
/** |
|
1508 |
* Returns the current file view. |
|
1509 |
* |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1510 |
* @return the current file view |
2 | 1511 |
* @see #setFileView |
1512 |
*/ |
|
1513 |
public FileView getFileView() { |
|
1514 |
return fileView; |
|
1515 |
} |
|
1516 |
||
1517 |
// ****************************** |
|
1518 |
// *****FileView delegation ***** |
|
1519 |
// ****************************** |
|
1520 |
||
1521 |
// NOTE: all of the following methods attempt to delegate |
|
1522 |
// first to the client set fileView, and if <code>null</code> is returned |
|
1523 |
// (or there is now client defined fileView) then calls the |
|
1524 |
// UI's default fileView. |
|
1525 |
||
1526 |
/** |
|
1527 |
* Returns the filename. |
|
1528 |
* @param f the <code>File</code> |
|
1529 |
* @return the <code>String</code> containing the filename for |
|
1530 |
* <code>f</code> |
|
1531 |
* @see FileView#getName |
|
1532 |
*/ |
|
1533 |
public String getName(File f) { |
|
1534 |
String filename = null; |
|
1535 |
if(f != null) { |
|
1536 |
if(getFileView() != null) { |
|
1537 |
filename = getFileView().getName(f); |
|
1538 |
} |
|
7961
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1539 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1540 |
FileView uiFileView = getUI().getFileView(this); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1541 |
|
2 | 1542 |
if(filename == null && uiFileView != null) { |
1543 |
filename = uiFileView.getName(f); |
|
1544 |
} |
|
1545 |
} |
|
1546 |
return filename; |
|
1547 |
} |
|
1548 |
||
1549 |
/** |
|
1550 |
* Returns the file description. |
|
1551 |
* @param f the <code>File</code> |
|
1552 |
* @return the <code>String</code> containing the file description for |
|
1553 |
* <code>f</code> |
|
1554 |
* @see FileView#getDescription |
|
1555 |
*/ |
|
1556 |
public String getDescription(File f) { |
|
1557 |
String description = null; |
|
1558 |
if(f != null) { |
|
1559 |
if(getFileView() != null) { |
|
1560 |
description = getFileView().getDescription(f); |
|
1561 |
} |
|
7961
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1562 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1563 |
FileView uiFileView = getUI().getFileView(this); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1564 |
|
2 | 1565 |
if(description == null && uiFileView != null) { |
1566 |
description = uiFileView.getDescription(f); |
|
1567 |
} |
|
1568 |
} |
|
1569 |
return description; |
|
1570 |
} |
|
1571 |
||
1572 |
/** |
|
1573 |
* Returns the file type. |
|
1574 |
* @param f the <code>File</code> |
|
1575 |
* @return the <code>String</code> containing the file type description for |
|
1576 |
* <code>f</code> |
|
1577 |
* @see FileView#getTypeDescription |
|
1578 |
*/ |
|
1579 |
public String getTypeDescription(File f) { |
|
1580 |
String typeDescription = null; |
|
1581 |
if(f != null) { |
|
1582 |
if(getFileView() != null) { |
|
1583 |
typeDescription = getFileView().getTypeDescription(f); |
|
1584 |
} |
|
7961
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1585 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1586 |
FileView uiFileView = getUI().getFileView(this); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1587 |
|
2 | 1588 |
if(typeDescription == null && uiFileView != null) { |
1589 |
typeDescription = uiFileView.getTypeDescription(f); |
|
1590 |
} |
|
1591 |
} |
|
1592 |
return typeDescription; |
|
1593 |
} |
|
1594 |
||
1595 |
/** |
|
1596 |
* Returns the icon for this file or type of file, depending |
|
1597 |
* on the system. |
|
1598 |
* @param f the <code>File</code> |
|
1599 |
* @return the <code>Icon</code> for this file, or type of file |
|
1600 |
* @see FileView#getIcon |
|
1601 |
*/ |
|
1602 |
public Icon getIcon(File f) { |
|
1603 |
Icon icon = null; |
|
1604 |
if (f != null) { |
|
1605 |
if(getFileView() != null) { |
|
1606 |
icon = getFileView().getIcon(f); |
|
1607 |
} |
|
7961
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1608 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1609 |
FileView uiFileView = getUI().getFileView(this); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1610 |
|
2 | 1611 |
if(icon == null && uiFileView != null) { |
1612 |
icon = uiFileView.getIcon(f); |
|
1613 |
} |
|
1614 |
} |
|
1615 |
return icon; |
|
1616 |
} |
|
1617 |
||
1618 |
/** |
|
1619 |
* Returns true if the file (directory) can be visited. |
|
1620 |
* Returns false if the directory cannot be traversed. |
|
1621 |
* @param f the <code>File</code> |
|
1622 |
* @return true if the file/directory can be traversed, otherwise false |
|
1623 |
* @see FileView#isTraversable |
|
1624 |
*/ |
|
1625 |
public boolean isTraversable(File f) { |
|
1626 |
Boolean traversable = null; |
|
1627 |
if (f != null) { |
|
1628 |
if (getFileView() != null) { |
|
1629 |
traversable = getFileView().isTraversable(f); |
|
1630 |
} |
|
7961
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1631 |
|
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1632 |
FileView uiFileView = getUI().getFileView(this); |
252a7e8c37c1
6342301: Bad interaction between setting the ui and file filters in JFileChooser
rupashka
parents:
5506
diff
changeset
|
1633 |
|
2 | 1634 |
if (traversable == null && uiFileView != null) { |
1635 |
traversable = uiFileView.isTraversable(f); |
|
1636 |
} |
|
1637 |
if (traversable == null) { |
|
1638 |
traversable = getFileSystemView().isTraversable(f); |
|
1639 |
} |
|
1640 |
} |
|
1641 |
return (traversable != null && traversable.booleanValue()); |
|
1642 |
} |
|
1643 |
||
1644 |
/** |
|
1645 |
* Returns true if the file should be displayed. |
|
1646 |
* @param f the <code>File</code> |
|
1647 |
* @return true if the file should be displayed, otherwise false |
|
1648 |
* @see FileFilter#accept |
|
1649 |
*/ |
|
1650 |
public boolean accept(File f) { |
|
1651 |
boolean shown = true; |
|
1652 |
if(f != null && fileFilter != null) { |
|
1653 |
shown = fileFilter.accept(f); |
|
1654 |
} |
|
1655 |
return shown; |
|
1656 |
} |
|
1657 |
||
1658 |
/** |
|
1659 |
* Sets the file system view that the <code>JFileChooser</code> uses for |
|
1660 |
* accessing and creating file system resources, such as finding |
|
1661 |
* the floppy drive and getting a list of root drives. |
|
1662 |
* @param fsv the new <code>FileSystemView</code> |
|
1663 |
* |
|
1664 |
* @see FileSystemView |
|
1665 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1666 |
@BeanProperty(expert = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1667 |
= "Sets the FileSytemView used to get filesystem information.") |
2 | 1668 |
public void setFileSystemView(FileSystemView fsv) { |
1669 |
FileSystemView oldValue = fileSystemView; |
|
1670 |
fileSystemView = fsv; |
|
1671 |
firePropertyChange(FILE_SYSTEM_VIEW_CHANGED_PROPERTY, oldValue, fileSystemView); |
|
1672 |
} |
|
1673 |
||
1674 |
/** |
|
1675 |
* Returns the file system view. |
|
1676 |
* @return the <code>FileSystemView</code> object |
|
1677 |
* @see #setFileSystemView |
|
1678 |
*/ |
|
1679 |
public FileSystemView getFileSystemView() { |
|
1680 |
return fileSystemView; |
|
1681 |
} |
|
1682 |
||
1683 |
// ************************** |
|
1684 |
// ***** Event Handling ***** |
|
1685 |
// ************************** |
|
1686 |
||
1687 |
/** |
|
1688 |
* Called by the UI when the user hits the Approve button |
|
1689 |
* (labeled "Open" or "Save", by default). This can also be |
|
1690 |
* called by the programmer. |
|
1691 |
* This method causes an action event to fire |
|
1692 |
* with the command string equal to |
|
1693 |
* <code>APPROVE_SELECTION</code>. |
|
1694 |
* |
|
1695 |
* @see #APPROVE_SELECTION |
|
1696 |
*/ |
|
1697 |
public void approveSelection() { |
|
1698 |
returnValue = APPROVE_OPTION; |
|
1699 |
if(dialog != null) { |
|
1700 |
dialog.setVisible(false); |
|
1701 |
} |
|
1702 |
fireActionPerformed(APPROVE_SELECTION); |
|
1703 |
} |
|
1704 |
||
1705 |
/** |
|
1706 |
* Called by the UI when the user chooses the Cancel button. |
|
1707 |
* This can also be called by the programmer. |
|
1708 |
* This method causes an action event to fire |
|
1709 |
* with the command string equal to |
|
1710 |
* <code>CANCEL_SELECTION</code>. |
|
1711 |
* |
|
1712 |
* @see #CANCEL_SELECTION |
|
1713 |
*/ |
|
1714 |
public void cancelSelection() { |
|
1715 |
returnValue = CANCEL_OPTION; |
|
1716 |
if(dialog != null) { |
|
1717 |
dialog.setVisible(false); |
|
1718 |
} |
|
1719 |
fireActionPerformed(CANCEL_SELECTION); |
|
1720 |
} |
|
1721 |
||
1722 |
/** |
|
1723 |
* Adds an <code>ActionListener</code> to the file chooser. |
|
1724 |
* |
|
1725 |
* @param l the listener to be added |
|
1726 |
* |
|
1727 |
* @see #approveSelection |
|
1728 |
* @see #cancelSelection |
|
1729 |
*/ |
|
1730 |
public void addActionListener(ActionListener l) { |
|
1731 |
listenerList.add(ActionListener.class, l); |
|
1732 |
} |
|
1733 |
||
1734 |
/** |
|
1735 |
* Removes an <code>ActionListener</code> from the file chooser. |
|
1736 |
* |
|
1737 |
* @param l the listener to be removed |
|
1738 |
* |
|
1739 |
* @see #addActionListener |
|
1740 |
*/ |
|
1741 |
public void removeActionListener(ActionListener l) { |
|
1742 |
listenerList.remove(ActionListener.class, l); |
|
1743 |
} |
|
1744 |
||
1745 |
/** |
|
1746 |
* Returns an array of all the action listeners |
|
1747 |
* registered on this file chooser. |
|
1748 |
* |
|
1749 |
* @return all of this file chooser's <code>ActionListener</code>s |
|
1750 |
* or an empty |
|
1751 |
* array if no action listeners are currently registered |
|
1752 |
* |
|
1753 |
* @see #addActionListener |
|
1754 |
* @see #removeActionListener |
|
1755 |
* |
|
1756 |
* @since 1.4 |
|
1757 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1758 |
@BeanProperty(bound = false) |
2 | 1759 |
public ActionListener[] getActionListeners() { |
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
1760 |
return listenerList.getListeners(ActionListener.class); |
2 | 1761 |
} |
1762 |
||
1763 |
/** |
|
1764 |
* Notifies all listeners that have registered interest for |
|
1765 |
* notification on this event type. The event instance |
|
1766 |
* is lazily created using the <code>command</code> parameter. |
|
1767 |
* |
|
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1768 |
* @param command a string that may specify a command associated with |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
1769 |
* the event |
2 | 1770 |
* @see EventListenerList |
1771 |
*/ |
|
1772 |
protected void fireActionPerformed(String command) { |
|
1773 |
// Guaranteed to return a non-null array |
|
1774 |
Object[] listeners = listenerList.getListenerList(); |
|
1775 |
long mostRecentEventTime = EventQueue.getMostRecentEventTime(); |
|
1776 |
int modifiers = 0; |
|
1777 |
AWTEvent currentEvent = EventQueue.getCurrentEvent(); |
|
1778 |
if (currentEvent instanceof InputEvent) { |
|
1779 |
modifiers = ((InputEvent)currentEvent).getModifiers(); |
|
1780 |
} else if (currentEvent instanceof ActionEvent) { |
|
1781 |
modifiers = ((ActionEvent)currentEvent).getModifiers(); |
|
1782 |
} |
|
1783 |
ActionEvent e = null; |
|
1784 |
// Process the listeners last to first, notifying |
|
1785 |
// those that are interested in this event |
|
1786 |
for (int i = listeners.length-2; i>=0; i-=2) { |
|
1787 |
if (listeners[i]==ActionListener.class) { |
|
1788 |
// Lazily create the event: |
|
1789 |
if (e == null) { |
|
1790 |
e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, |
|
1791 |
command, mostRecentEventTime, |
|
1792 |
modifiers); |
|
1793 |
} |
|
1794 |
((ActionListener)listeners[i+1]).actionPerformed(e); |
|
1795 |
} |
|
1796 |
} |
|
1797 |
} |
|
1798 |
||
1799 |
private static class WeakPCL implements PropertyChangeListener { |
|
1800 |
WeakReference<JFileChooser> jfcRef; |
|
1801 |
||
1802 |
public WeakPCL(JFileChooser jfc) { |
|
1301
15e81207e1f2
6727662: Code improvement and warnings removing from swing packages
rupashka
parents:
715
diff
changeset
|
1803 |
jfcRef = new WeakReference<JFileChooser>(jfc); |
2 | 1804 |
} |
1805 |
public void propertyChange(PropertyChangeEvent ev) { |
|
1806 |
assert ev.getPropertyName().equals(SHOW_HIDDEN_PROP); |
|
1807 |
JFileChooser jfc = jfcRef.get(); |
|
1808 |
if (jfc == null) { |
|
1809 |
// Our JFileChooser is no longer around, so we no longer need to |
|
1810 |
// listen for PropertyChangeEvents. |
|
1811 |
Toolkit.getDefaultToolkit().removePropertyChangeListener(SHOW_HIDDEN_PROP, this); |
|
1812 |
} |
|
1813 |
else { |
|
1814 |
boolean oldValue = jfc.useFileHiding; |
|
1815 |
jfc.useFileHiding = !((Boolean)ev.getNewValue()).booleanValue(); |
|
1816 |
jfc.firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, oldValue, jfc.useFileHiding); |
|
1817 |
} |
|
1818 |
} |
|
1819 |
} |
|
1820 |
||
1821 |
// ********************************* |
|
1822 |
// ***** Pluggable L&F methods ***** |
|
1823 |
// ********************************* |
|
1824 |
||
1825 |
/** |
|
1826 |
* Resets the UI property to a value from the current look and feel. |
|
1827 |
* |
|
1828 |
* @see JComponent#updateUI |
|
1829 |
*/ |
|
1830 |
public void updateUI() { |
|
1831 |
if (isAcceptAllFileFilterUsed()) { |
|
1832 |
removeChoosableFileFilter(getAcceptAllFileFilter()); |
|
1833 |
} |
|
1834 |
FileChooserUI ui = ((FileChooserUI)UIManager.getUI(this)); |
|
1835 |
if (fileSystemView == null) { |
|
1836 |
// We were probably deserialized |
|
1837 |
setFileSystemView(FileSystemView.getFileSystemView()); |
|
1838 |
} |
|
1839 |
setUI(ui); |
|
1840 |
||
1841 |
if(isAcceptAllFileFilterUsed()) { |
|
1842 |
addChoosableFileFilter(getAcceptAllFileFilter()); |
|
1843 |
} |
|
1844 |
} |
|
1845 |
||
1846 |
/** |
|
21592 | 1847 |
* Returns a string that specifies the name of the L&F class |
2 | 1848 |
* that renders this component. |
1849 |
* |
|
1850 |
* @return the string "FileChooserUI" |
|
1851 |
* @see JComponent#getUIClassID |
|
1852 |
* @see UIDefaults#getUI |
|
1853 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1854 |
@BeanProperty(bound = false, expert = true, description |
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1855 |
= "A string that specifies the name of the L&F class.") |
2 | 1856 |
public String getUIClassID() { |
1857 |
return uiClassID; |
|
1858 |
} |
|
1859 |
||
1860 |
/** |
|
21592 | 1861 |
* Gets the UI object which implements the L&F for this component. |
2 | 1862 |
* |
21592 | 1863 |
* @return the FileChooserUI object that implements the FileChooserUI L&F |
2 | 1864 |
*/ |
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
1865 |
@BeanProperty(bound = false) |
2 | 1866 |
public FileChooserUI getUI() { |
1867 |
return (FileChooserUI) ui; |
|
1868 |
} |
|
1869 |
||
1870 |
/** |
|
1871 |
* See <code>readObject</code> and <code>writeObject</code> in |
|
1872 |
* <code>JComponent</code> for more |
|
1873 |
* information about serialization in Swing. |
|
1874 |
*/ |
|
1875 |
private void readObject(java.io.ObjectInputStream in) |
|
1876 |
throws IOException, ClassNotFoundException { |
|
26001
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1877 |
ObjectInputStream.GetField f = in.readFields(); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1878 |
|
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1879 |
dialogTitle = (String) f.get("dialogTitle", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1880 |
approveButtonText = (String) f.get("approveButtonText", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1881 |
approveButtonToolTipText = |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1882 |
(String) f.get("approveButtonToolTipText", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1883 |
approveButtonMnemonic = f.get("approveButtonMnemonic", 0); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1884 |
@SuppressWarnings("unchecked") |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1885 |
Vector<FileFilter> newFilters = (Vector<FileFilter>) f.get("filters", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1886 |
if (newFilters == null) { |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1887 |
throw new InvalidObjectException("Null filters"); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1888 |
} |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1889 |
filters = newFilters; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1890 |
dialog = (JDialog) f.get("dialog", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1891 |
int newDialogType = f.get("dialogType", OPEN_DIALOG); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1892 |
checkDialogType(newDialogType); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1893 |
dialogType = newDialogType; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1894 |
returnValue = f.get("returnValue", 0); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1895 |
accessory = (JComponent) f.get("accessory", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1896 |
fileView = (FileView) f.get("fileView", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1897 |
controlsShown = f.get("controlsShown", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1898 |
useFileHiding = f.get("useFileHiding", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1899 |
int newFileSelectionMode = f.get("fileSelectionMode", FILES_ONLY); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1900 |
checkFileSelectionMode(newFileSelectionMode); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1901 |
fileSelectionMode = newFileSelectionMode; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1902 |
multiSelectionEnabled = f.get("multiSelectionEnabled", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1903 |
useAcceptAllFileFilter = f.get("useAcceptAllFileFilter", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1904 |
boolean newDragEnabled = f.get("dragEnabled", false); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1905 |
checkDragEnabled(newDragEnabled); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1906 |
dragEnabled = newDragEnabled; |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1907 |
fileFilter = (FileFilter) f.get("fileFilter", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1908 |
fileSystemView = (FileSystemView) f.get("fileSystemView", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1909 |
currentDirectory = (File) f.get("currentDirectory", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1910 |
selectedFile = (File) f.get("selectedFile", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1911 |
selectedFiles = (File[]) f.get("selectedFiles", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1912 |
accessibleContext = (AccessibleContext) f.get("accessibleContext", null); |
991e1be0b235
8038937: Validate fields on Swing classes deserialization
alexsch
parents:
25386
diff
changeset
|
1913 |
|
2 | 1914 |
installShowFilesListener(); |
1915 |
} |
|
1916 |
||
1917 |
/** |
|
1918 |
* See <code>readObject</code> and <code>writeObject</code> in |
|
1919 |
* <code>JComponent</code> for more |
|
1920 |
* information about serialization in Swing. |
|
1921 |
*/ |
|
1922 |
private void writeObject(ObjectOutputStream s) throws IOException { |
|
1923 |
FileSystemView fsv = null; |
|
1924 |
||
1925 |
if (isAcceptAllFileFilterUsed()) { |
|
1926 |
//The AcceptAllFileFilter is UI specific, it will be reset by |
|
1927 |
//updateUI() after deserialization |
|
1928 |
removeChoosableFileFilter(getAcceptAllFileFilter()); |
|
1929 |
} |
|
1930 |
if (fileSystemView.equals(FileSystemView.getFileSystemView())) { |
|
1931 |
//The default FileSystemView is platform specific, it will be |
|
1932 |
//reset by updateUI() after deserialization |
|
1933 |
fsv = fileSystemView; |
|
1934 |
fileSystemView = null; |
|
1935 |
} |
|
1936 |
s.defaultWriteObject(); |
|
1937 |
if (fsv != null) { |
|
1938 |
fileSystemView = fsv; |
|
1939 |
} |
|
1940 |
if (isAcceptAllFileFilterUsed()) { |
|
1941 |
addChoosableFileFilter(getAcceptAllFileFilter()); |
|
1942 |
} |
|
1943 |
if (getUIClassID().equals(uiClassID)) { |
|
1944 |
byte count = JComponent.getWriteObjCounter(this); |
|
1945 |
JComponent.setWriteObjCounter(this, --count); |
|
1946 |
if (count == 0 && ui != null) { |
|
1947 |
ui.installUI(this); |
|
1948 |
} |
|
1949 |
} |
|
1950 |
} |
|
1951 |
||
1952 |
||
1953 |
/** |
|
1954 |
* Returns a string representation of this <code>JFileChooser</code>. |
|
1955 |
* This method |
|
1956 |
* is intended to be used only for debugging purposes, and the |
|
1957 |
* content and format of the returned string may vary between |
|
1958 |
* implementations. The returned string may be empty but may not |
|
1959 |
* be <code>null</code>. |
|
1960 |
* |
|
1961 |
* @return a string representation of this <code>JFileChooser</code> |
|
1962 |
*/ |
|
1963 |
protected String paramString() { |
|
1964 |
String approveButtonTextString = (approveButtonText != null ? |
|
1965 |
approveButtonText: ""); |
|
1966 |
String dialogTitleString = (dialogTitle != null ? |
|
1967 |
dialogTitle: ""); |
|
1968 |
String dialogTypeString; |
|
1969 |
if (dialogType == OPEN_DIALOG) { |
|
1970 |
dialogTypeString = "OPEN_DIALOG"; |
|
1971 |
} else if (dialogType == SAVE_DIALOG) { |
|
1972 |
dialogTypeString = "SAVE_DIALOG"; |
|
1973 |
} else if (dialogType == CUSTOM_DIALOG) { |
|
1974 |
dialogTypeString = "CUSTOM_DIALOG"; |
|
1975 |
} else dialogTypeString = ""; |
|
1976 |
String returnValueString; |
|
1977 |
if (returnValue == CANCEL_OPTION) { |
|
1978 |
returnValueString = "CANCEL_OPTION"; |
|
1979 |
} else if (returnValue == APPROVE_OPTION) { |
|
1980 |
returnValueString = "APPROVE_OPTION"; |
|
1981 |
} else if (returnValue == ERROR_OPTION) { |
|
1982 |
returnValueString = "ERROR_OPTION"; |
|
1983 |
} else returnValueString = ""; |
|
1984 |
String useFileHidingString = (useFileHiding ? |
|
1985 |
"true" : "false"); |
|
1986 |
String fileSelectionModeString; |
|
1987 |
if (fileSelectionMode == FILES_ONLY) { |
|
1988 |
fileSelectionModeString = "FILES_ONLY"; |
|
1989 |
} else if (fileSelectionMode == DIRECTORIES_ONLY) { |
|
1990 |
fileSelectionModeString = "DIRECTORIES_ONLY"; |
|
1991 |
} else if (fileSelectionMode == FILES_AND_DIRECTORIES) { |
|
1992 |
fileSelectionModeString = "FILES_AND_DIRECTORIES"; |
|
1993 |
} else fileSelectionModeString = ""; |
|
1994 |
String currentDirectoryString = (currentDirectory != null ? |
|
1995 |
currentDirectory.toString() : ""); |
|
1996 |
String selectedFileString = (selectedFile != null ? |
|
1997 |
selectedFile.toString() : ""); |
|
1998 |
||
1999 |
return super.paramString() + |
|
2000 |
",approveButtonText=" + approveButtonTextString + |
|
2001 |
",currentDirectory=" + currentDirectoryString + |
|
2002 |
",dialogTitle=" + dialogTitleString + |
|
2003 |
",dialogType=" + dialogTypeString + |
|
2004 |
",fileSelectionMode=" + fileSelectionModeString + |
|
2005 |
",returnValue=" + returnValueString + |
|
2006 |
",selectedFile=" + selectedFileString + |
|
2007 |
",useFileHiding=" + useFileHidingString; |
|
2008 |
} |
|
2009 |
||
2010 |
///////////////// |
|
2011 |
// Accessibility support |
|
2012 |
//////////////// |
|
2013 |
||
25386
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
2014 |
/** |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
2015 |
* {@code AccessibleContext} associated with this {@code JFileChooser} |
9ef80c24fd74
8046590: fix doclint issues in swing classes, part 1 of 4
yan
parents:
25201
diff
changeset
|
2016 |
*/ |
2 | 2017 |
protected AccessibleContext accessibleContext = null; |
2018 |
||
2019 |
/** |
|
2020 |
* Gets the AccessibleContext associated with this JFileChooser. |
|
2021 |
* For file choosers, the AccessibleContext takes the form of an |
|
2022 |
* AccessibleJFileChooser. |
|
2023 |
* A new AccessibleJFileChooser instance is created if necessary. |
|
2024 |
* |
|
2025 |
* @return an AccessibleJFileChooser that serves as the |
|
2026 |
* AccessibleContext of this JFileChooser |
|
2027 |
*/ |
|
33253
78e735319356
4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents:
28231
diff
changeset
|
2028 |
@BeanProperty(bound = false) |
2 | 2029 |
public AccessibleContext getAccessibleContext() { |
2030 |
if (accessibleContext == null) { |
|
2031 |
accessibleContext = new AccessibleJFileChooser(); |
|
2032 |
} |
|
2033 |
return accessibleContext; |
|
2034 |
} |
|
2035 |
||
2036 |
/** |
|
2037 |
* This class implements accessibility support for the |
|
2038 |
* <code>JFileChooser</code> class. It provides an implementation of the |
|
2039 |
* Java Accessibility API appropriate to file chooser user-interface |
|
2040 |
* elements. |
|
2041 |
*/ |
|
23697 | 2042 |
@SuppressWarnings("serial") // Superclass is not serializable across versions |
2 | 2043 |
protected class AccessibleJFileChooser extends AccessibleJComponent { |
2044 |
||
2045 |
/** |
|
2046 |
* Gets the role of this object. |
|
2047 |
* |
|
2048 |
* @return an instance of AccessibleRole describing the role of the |
|
2049 |
* object |
|
2050 |
* @see AccessibleRole |
|
2051 |
*/ |
|
2052 |
public AccessibleRole getAccessibleRole() { |
|
2053 |
return AccessibleRole.FILE_CHOOSER; |
|
2054 |
} |
|
2055 |
||
2056 |
} // inner class AccessibleJFileChooser |
|
2057 |
||
2058 |
} |