Fields Summary |
---|
private static final String | uiClassID |
public static final int | OPEN_DIALOGType value indicating that the JFileChooser supports an
"Open" file operation. |
public static final int | SAVE_DIALOGType value indicating that the JFileChooser supports a
"Save" file operation. |
public static final int | CUSTOM_DIALOGType value indicating that the JFileChooser supports a
developer-specified file operation. |
public static final int | CANCEL_OPTIONReturn value if cancel is chosen. |
public static final int | APPROVE_OPTIONReturn value if approve (yes, ok) is chosen. |
public static final int | ERROR_OPTIONReturn value if an error occured. |
public static final int | FILES_ONLYInstruction to display only files. |
public static final int | DIRECTORIES_ONLYInstruction to display only directories. |
public static final int | FILES_AND_DIRECTORIESInstruction to display both files and directories. |
public static final String | CANCEL_SELECTIONInstruction to cancel the current selection. |
public static final String | APPROVE_SELECTIONInstruction to approve the current selection
(same as pressing yes or ok). |
public static final String | APPROVE_BUTTON_TEXT_CHANGED_PROPERTYIdentifies change in the text on the approve (yes, ok) button. |
public static final String | APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTYIdentifies change in the tooltip text for the approve (yes, ok)
button. |
public static final String | APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTYIdentifies change in the mnemonic for the approve (yes, ok) button. |
public static final String | CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTYInstruction to display the control buttons. |
public static final String | DIRECTORY_CHANGED_PROPERTYIdentifies user's directory change. |
public static final String | SELECTED_FILE_CHANGED_PROPERTYIdentifies change in user's single-file selection. |
public static final String | SELECTED_FILES_CHANGED_PROPERTYIdentifies change in user's multiple-file selection. |
public static final String | MULTI_SELECTION_ENABLED_CHANGED_PROPERTYEnables multiple-file selections. |
public static final String | FILE_SYSTEM_VIEW_CHANGED_PROPERTYSays that a different object is being used to find available drives
on the system. |
public static final String | FILE_VIEW_CHANGED_PROPERTYSays that a different object is being used to retrieve file
information. |
public static final String | FILE_HIDING_CHANGED_PROPERTYIdentifies a change in the display-hidden-files property. |
public static final String | FILE_FILTER_CHANGED_PROPERTYUser changed the kind of files to display. |
public static final String | FILE_SELECTION_MODE_CHANGED_PROPERTYIdentifies a change in the kind of selection (single,
multiple, etc.). |
public static final String | ACCESSORY_CHANGED_PROPERTYSays that a different accessory component is in use
(for example, to preview files). |
public static final String | ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTYIdentifies whether a the AcceptAllFileFilter is used or not. |
public static final String | DIALOG_TITLE_CHANGED_PROPERTYIdentifies a change in the dialog title. |
public static final String | DIALOG_TYPE_CHANGED_PROPERTYIdentifies a change in the type of files displayed (files only,
directories only, or both files and directories). |
public static final String | CHOOSABLE_FILE_FILTER_CHANGED_PROPERTYIdentifies a change in the list of predefined file filters
the user can choose from. |
private String | dialogTitle |
private String | approveButtonText |
private String | approveButtonToolTipText |
private int | approveButtonMnemonic |
private ActionListener | actionListener |
private Vector | filters |
private JDialog | dialog |
private int | dialogType |
private int | returnValue |
private JComponent | accessory |
private FileView | fileView |
private transient FileView | uiFileView |
private boolean | controlsShown |
private boolean | useFileHiding |
private static final String | SHOW_HIDDEN_PROP |
private PropertyChangeListener | showFilesListener |
private int | fileSelectionMode |
private boolean | multiSelectionEnabled |
private boolean | useAcceptAllFileFilter |
private boolean | dragEnabled |
private FileFilter | fileFilter |
private FileSystemView | fileSystemView |
private File | currentDirectory |
private File | selectedFile |
private File[] | selectedFiles |
protected AccessibleContext | accessibleContext |
Methods Summary |
---|
public boolean | accept(java.io.File f)Returns true if the file should be displayed.
boolean shown = true;
if(f != null && fileFilter != null) {
shown = fileFilter.accept(f);
}
return shown;
|
public void | addActionListener(java.awt.event.ActionListener l)Adds an ActionListener to the file chooser.
listenerList.add(ActionListener.class, l);
|
public void | addChoosableFileFilter(javax.swing.filechooser.FileFilter filter)Adds a filter to the list of user choosable file filters.
For information on setting the file selection mode, see
{@link #setFileSelectionMode setFileSelectionMode}.
if(filter != null && !filters.contains(filter)) {
FileFilter[] oldValue = getChoosableFileFilters();
filters.addElement(filter);
firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
}
setFileFilter(filter);
|
public void | approveSelection()Called by the UI when the user hits the Approve button
(labeled "Open" or "Save", by default). This can also be
called by the programmer.
This method causes an action event to fire
with the command string equal to
APPROVE_SELECTION .
returnValue = APPROVE_OPTION;
if(dialog != null) {
dialog.setVisible(false);
}
fireActionPerformed(APPROVE_SELECTION);
|
public void | cancelSelection()Called by the UI when the user chooses the Cancel button.
This can also be called by the programmer.
This method causes an action event to fire
with the command string equal to
CANCEL_SELECTION .
returnValue = CANCEL_OPTION;
if(dialog != null) {
dialog.setVisible(false);
}
fireActionPerformed(CANCEL_SELECTION);
|
public void | changeToParentDirectory()Changes the directory to be set to the parent of the
current directory.
selectedFile = null;
File oldValue = getCurrentDirectory();
setCurrentDirectory(getFileSystemView().getParentDirectory(oldValue));
|
protected javax.swing.JDialog | createDialog(java.awt.Component parent)Creates and returns a new JDialog wrapping
this centered on the parent
in the parent 's frame.
This method can be overriden to further manipulate the dialog,
to disable resizing, set the location, etc. Example:
class MyFileChooser extends JFileChooser {
protected JDialog createDialog(Component parent) throws HeadlessException {
JDialog dialog = super.createDialog(parent);
dialog.setLocation(300, 200);
dialog.setResizable(false);
return dialog;
}
}
String title = getUI().getDialogTitle(this);
getAccessibleContext().setAccessibleDescription(title);
JDialog dialog;
Window window = JOptionPane.getWindowForComponent(parent);
if (window instanceof Frame) {
dialog = new JDialog((Frame)window, title, true);
} else {
dialog = new JDialog((Dialog)window, title, true);
}
dialog.setComponentOrientation(this.getComponentOrientation());
Container contentPane = dialog.getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(this, BorderLayout.CENTER);
if (JDialog.isDefaultLookAndFeelDecorated()) {
boolean supportsWindowDecorations =
UIManager.getLookAndFeel().getSupportsWindowDecorations();
if (supportsWindowDecorations) {
dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
}
}
dialog.pack();
dialog.setLocationRelativeTo(parent);
return dialog;
|
public void | ensureFileIsVisible(java.io.File f)Makes sure that the specified file is viewable, and
not hidden.
getUI().ensureFileIsVisible(this, f);
|
protected void | fireActionPerformed(java.lang.String command)Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the command parameter.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
long mostRecentEventTime = EventQueue.getMostRecentEventTime();
int modifiers = 0;
AWTEvent currentEvent = EventQueue.getCurrentEvent();
if (currentEvent instanceof InputEvent) {
modifiers = ((InputEvent)currentEvent).getModifiers();
} else if (currentEvent instanceof ActionEvent) {
modifiers = ((ActionEvent)currentEvent).getModifiers();
}
ActionEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==ActionListener.class) {
// Lazily create the event:
if (e == null) {
e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
command, mostRecentEventTime,
modifiers);
}
((ActionListener)listeners[i+1]).actionPerformed(e);
}
}
|
public javax.swing.filechooser.FileFilter | getAcceptAllFileFilter()Returns the AcceptAll file filter.
For example, on Microsoft Windows this would be All Files (*.*).
FileFilter filter = null;
if(getUI() != null) {
filter = getUI().getAcceptAllFileFilter(this);
}
return filter;
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this JFileChooser.
For file choosers, the AccessibleContext takes the form of an
AccessibleJFileChooser.
A new AccessibleJFileChooser instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleJFileChooser();
}
return accessibleContext;
|
public javax.swing.JComponent | getAccessory()Returns the accessory component.
return accessory;
|
public java.awt.event.ActionListener[] | getActionListeners()Returns an array of all the action listeners
registered on this file chooser.
return (ActionListener[])listenerList.getListeners(
ActionListener.class);
|
public int | getApproveButtonMnemonic()Returns the approve button's mnemonic.
return approveButtonMnemonic;
|
public java.lang.String | getApproveButtonText()Returns the text used in the ApproveButton in the
FileChooserUI .
If null , the UI object will determine the button's text.
Typically, this would be "Open" or "Save".
return approveButtonText;
|
public java.lang.String | getApproveButtonToolTipText()Returns the tooltip text used in the ApproveButton .
If null , the UI object will determine the button's text.
return approveButtonToolTipText;
|
public javax.swing.filechooser.FileFilter[] | getChoosableFileFilters()Gets the list of user choosable file filters.
FileFilter[] filterArray = new FileFilter[filters.size()];
filters.copyInto(filterArray);
return filterArray;
|
public boolean | getControlButtonsAreShown()Returns the value of the controlButtonsAreShown
property.
return controlsShown;
|
public java.io.File | getCurrentDirectory()Returns the current directory.
return currentDirectory;
|
public java.lang.String | getDescription(java.io.File f)Returns the file description.
String description = null;
if(f != null) {
if(getFileView() != null) {
description = getFileView().getDescription(f);
}
if(description == null && uiFileView != null) {
description = uiFileView.getDescription(f);
}
}
return description;
|
public java.lang.String | getDialogTitle()Gets the string that goes in the JFileChooser 's titlebar.
return dialogTitle;
|
public int | getDialogType()Returns the type of this dialog. The default is
JFileChooser.OPEN_DIALOG .
return dialogType;
|
public boolean | getDragEnabled()Gets the value of the dragEnabled property.
return dragEnabled;
|
public javax.swing.filechooser.FileFilter | getFileFilter()Returns the currently selected file filter.
return fileFilter;
|
public int | getFileSelectionMode()Returns the current file-selection mode. The default is
JFilesChooser.FILES_ONLY .
return fileSelectionMode;
|
public javax.swing.filechooser.FileSystemView | getFileSystemView()Returns the file system view.
return fileSystemView;
|
public javax.swing.filechooser.FileView | getFileView()Returns the current file view.
return fileView;
|
public javax.swing.Icon | getIcon(java.io.File f)Returns the icon for this file or type of file, depending
on the system.
Icon icon = null;
if (f != null) {
if(getFileView() != null) {
icon = getFileView().getIcon(f);
}
if(icon == null && uiFileView != null) {
icon = uiFileView.getIcon(f);
}
}
return icon;
|
public java.lang.String | getName(java.io.File f)Returns the filename.
String filename = null;
if(f != null) {
if(getFileView() != null) {
filename = getFileView().getName(f);
}
if(filename == null && uiFileView != null) {
filename = uiFileView.getName(f);
}
}
return filename;
|
public java.io.File | getSelectedFile()Returns the selected file. This can be set either by the
programmer via setFile or by a user action, such as
either typing the filename into the UI or selecting the
file from a list in the UI.
return selectedFile;
|
public java.io.File[] | getSelectedFiles()Returns a list of selected files if the file chooser is
set to allow multiple selection.
if(selectedFiles == null) {
return new File[0];
} else {
return (File[]) selectedFiles.clone();
}
|
public java.lang.String | getTypeDescription(java.io.File f)Returns the file type.
String typeDescription = null;
if(f != null) {
if(getFileView() != null) {
typeDescription = getFileView().getTypeDescription(f);
}
if(typeDescription == null && uiFileView != null) {
typeDescription = uiFileView.getTypeDescription(f);
}
}
return typeDescription;
|
public javax.swing.plaf.FileChooserUI | getUI()Gets the UI object which implements the L&F for this component.
return (FileChooserUI) ui;
|
public java.lang.String | getUIClassID()Returns a string that specifies the name of the L&F class
that renders this component.
return uiClassID;
|
public boolean | isAcceptAllFileFilterUsed()Returns whether the AcceptAll FileFilter is used.
return useAcceptAllFileFilter;
|
public boolean | isDirectorySelectionEnabled()Convenience call that determines if directories are selectable based
on the current file selection mode.
return ((fileSelectionMode == DIRECTORIES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
|
public boolean | isFileHidingEnabled()Returns true if hidden files are not shown in the file chooser;
otherwise, returns false.
return useFileHiding;
|
public boolean | isFileSelectionEnabled()Convenience call that determines if files are selectable based on the
current file selection mode.
return ((fileSelectionMode == FILES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
|
public boolean | isMultiSelectionEnabled()Returns true if multiple files can be selected.
return multiSelectionEnabled;
|
public boolean | isTraversable(java.io.File f)Returns true if the file (directory) can be visited.
Returns false if the directory cannot be traversed.
Boolean traversable = null;
if (f != null) {
if (getFileView() != null) {
traversable = getFileView().isTraversable(f);
}
if (traversable == null && uiFileView != null) {
traversable = uiFileView.isTraversable(f);
}
if (traversable == null) {
traversable = getFileSystemView().isTraversable(f);
}
}
return (traversable != null && traversable.booleanValue());
|
protected java.lang.String | paramString()Returns a string representation of this JFileChooser .
This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null .
String approveButtonTextString = (approveButtonText != null ?
approveButtonText: "");
String dialogTitleString = (dialogTitle != null ?
dialogTitle: "");
String dialogTypeString;
if (dialogType == OPEN_DIALOG) {
dialogTypeString = "OPEN_DIALOG";
} else if (dialogType == SAVE_DIALOG) {
dialogTypeString = "SAVE_DIALOG";
} else if (dialogType == CUSTOM_DIALOG) {
dialogTypeString = "CUSTOM_DIALOG";
} else dialogTypeString = "";
String returnValueString;
if (returnValue == CANCEL_OPTION) {
returnValueString = "CANCEL_OPTION";
} else if (returnValue == APPROVE_OPTION) {
returnValueString = "APPROVE_OPTION";
} else if (returnValue == ERROR_OPTION) {
returnValueString = "ERROR_OPTION";
} else returnValueString = "";
String useFileHidingString = (useFileHiding ?
"true" : "false");
String fileSelectionModeString;
if (fileSelectionMode == FILES_ONLY) {
fileSelectionModeString = "FILES_ONLY";
} else if (fileSelectionMode == DIRECTORIES_ONLY) {
fileSelectionModeString = "DIRECTORIES_ONLY";
} else if (fileSelectionMode == FILES_AND_DIRECTORIES) {
fileSelectionModeString = "FILES_AND_DIRECTORIES";
} else fileSelectionModeString = "";
String currentDirectoryString = (currentDirectory != null ?
currentDirectory.toString() : "");
String selectedFileString = (selectedFile != null ?
selectedFile.toString() : "");
return super.paramString() +
",approveButtonText=" + approveButtonTextString +
",currentDirectory=" + currentDirectoryString +
",dialogTitle=" + dialogTitleString +
",dialogType=" + dialogTypeString +
",fileSelectionMode=" + fileSelectionModeString +
",returnValue=" + returnValueString +
",selectedFile=" + selectedFileString +
",useFileHiding=" + useFileHidingString;
|
public void | removeActionListener(java.awt.event.ActionListener l)Removes an ActionListener from the file chooser.
listenerList.remove(ActionListener.class, l);
|
public boolean | removeChoosableFileFilter(javax.swing.filechooser.FileFilter f)Removes a filter from the list of user choosable file filters. Returns
true if the file filter was removed.
if(filters.contains(f)) {
if(getFileFilter() == f) {
setFileFilter(null);
}
FileFilter[] oldValue = getChoosableFileFilters();
filters.removeElement(f);
firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
return true;
} else {
return false;
}
|
public void | rescanCurrentDirectory()Tells the UI to rescan its files list from the current directory.
getUI().rescanCurrentDirectory(this);
|
public void | resetChoosableFileFilters()Resets the choosable file filter list to its starting state. Normally,
this removes all added file filters while leaving the
AcceptAll file filter.
FileFilter[] oldValue = getChoosableFileFilters();
setFileFilter(null);
filters.removeAllElements();
if(isAcceptAllFileFilterUsed()) {
addChoosableFileFilter(getAcceptAllFileFilter());
}
firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
|
public void | setAcceptAllFileFilterUsed(boolean b)Determines whether the AcceptAll FileFilter is used
as an available choice in the choosable filter list.
If false, the AcceptAll file filter is removed from
the list of available file filters.
If true, the AcceptAll file filter will become the
the actively used file filter.
boolean oldValue = useAcceptAllFileFilter;
useAcceptAllFileFilter = b;
if(!b) {
removeChoosableFileFilter(getAcceptAllFileFilter());
} else {
removeChoosableFileFilter(getAcceptAllFileFilter());
addChoosableFileFilter(getAcceptAllFileFilter());
}
firePropertyChange(ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY, oldValue, useAcceptAllFileFilter);
|
public void | setAccessory(javax.swing.JComponent newAccessory)Sets the accessory component. An accessory is often used to show a
preview image of the selected file; however, it can be used for anything
that the programmer wishes, such as extra custom file chooser controls.
Note: if there was a previous accessory, you should unregister
any listeners that the accessory might have registered with the
file chooser.
JComponent oldValue = accessory;
accessory = newAccessory;
firePropertyChange(ACCESSORY_CHANGED_PROPERTY, oldValue, accessory);
|
public void | setApproveButtonMnemonic(int mnemonic)Sets the approve button's mnemonic using a numeric keycode.
if(approveButtonMnemonic == mnemonic) {
return;
}
int oldValue = approveButtonMnemonic;
approveButtonMnemonic = mnemonic;
firePropertyChange(APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY, oldValue, approveButtonMnemonic);
|
public void | setApproveButtonMnemonic(char mnemonic)Sets the approve button's mnemonic using a character.
int vk = (int) mnemonic;
if(vk >= 'a" && vk <='z") {
vk -= ('a" - 'A");
}
setApproveButtonMnemonic(vk);
|
public void | setApproveButtonText(java.lang.String approveButtonText)Sets the text used in the ApproveButton in the
FileChooserUI .
if(this.approveButtonText == approveButtonText) {
return;
}
String oldValue = this.approveButtonText;
this.approveButtonText = approveButtonText;
firePropertyChange(APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, oldValue, approveButtonText);
|
public void | setApproveButtonToolTipText(java.lang.String toolTipText)Sets the tooltip text used in the ApproveButton .
If null , the UI object will determine the button's text.
if(approveButtonToolTipText == toolTipText) {
return;
}
String oldValue = approveButtonToolTipText;
approveButtonToolTipText = toolTipText;
firePropertyChange(APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY, oldValue, approveButtonToolTipText);
|
public void | setControlButtonsAreShown(boolean b)Sets the property
that indicates whether the approve and cancel
buttons are shown in the file chooser. This property
is true by default. Look and feels
that always show these buttons will ignore the value
of this property.
This method fires a property-changed event,
using the string value of
CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
as the name of the property.
if(controlsShown == b) {
return;
}
boolean oldValue = controlsShown;
controlsShown = b;
firePropertyChange(CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY, oldValue, controlsShown);
|
public void | setCurrentDirectory(java.io.File dir)Sets the current directory. Passing in null sets the
file chooser to point to the user's default directory.
This default depends on the operating system. It is
typically the "My Documents" folder on Windows, and the user's
home directory on Unix.
If the file passed in as currentDirectory is not a
directory, the parent of the file will be used as the currentDirectory.
If the parent is not traversable, then it will walk up the parent tree
until it finds a traversable directory, or hits the root of the
file system.
File oldValue = currentDirectory;
if (dir != null && !dir.exists()) {
dir = currentDirectory;
}
if (dir == null) {
dir = getFileSystemView().getDefaultDirectory();
}
if (currentDirectory != null) {
/* Verify the toString of object */
if (this.currentDirectory.equals(dir)) {
return;
}
}
File prev = null;
while (!isTraversable(dir) && prev != dir) {
prev = dir;
dir = getFileSystemView().getParentDirectory(dir);
}
currentDirectory = dir;
firePropertyChange(DIRECTORY_CHANGED_PROPERTY, oldValue, currentDirectory);
|
public void | setDialogTitle(java.lang.String dialogTitle)Sets the string that goes in the JFileChooser window's
title bar.
String oldValue = this.dialogTitle;
this.dialogTitle = dialogTitle;
if(dialog != null) {
dialog.setTitle(dialogTitle);
}
firePropertyChange(DIALOG_TITLE_CHANGED_PROPERTY, oldValue, dialogTitle);
|
public void | setDialogType(int dialogType)Sets the type of this dialog. Use OPEN_DIALOG when you
want to bring up a file chooser that the user can use to open a file.
Likewise, use SAVE_DIALOG for letting the user choose
a file for saving.
Use CUSTOM_DIALOG when you want to use the file
chooser in a context other than "Open" or "Save".
For instance, you might want to bring up a file chooser that allows
the user to choose a file to execute. Note that you normally would not
need to set the JFileChooser to use
CUSTOM_DIALOG
since a call to setApproveButtonText does this for you.
The default dialog type is JFileChooser.OPEN_DIALOG .
if(this.dialogType == dialogType) {
return;
}
if(!(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG || dialogType == CUSTOM_DIALOG)) {
throw new IllegalArgumentException("Incorrect Dialog Type: " + dialogType);
}
int oldValue = this.dialogType;
this.dialogType = dialogType;
if(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG) {
setApproveButtonText(null);
}
firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, oldValue, dialogType);
|
public void | setDragEnabled(boolean b)Sets the dragEnabled property,
which must be true to enable
automatic drag handling (the first part of drag and drop)
on this component.
The transferHandler property needs to be set
to a non-null value for the drag to do
anything. The default value of the dragEnabled
property
is false .
When automatic drag handling is enabled,
most look and feels begin a drag-and-drop operation
whenever the user presses the mouse button over a selection
and then moves the mouse a few pixels.
Setting this property to true
can therefore have a subtle effect on
how selections behave.
Some look and feels might not support automatic drag and drop;
they will ignore this property. You can work around such
look and feels by modifying the component
to directly call the exportAsDrag method of a
TransferHandler .
if (b && GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
dragEnabled = b;
|
public void | setFileFilter(javax.swing.filechooser.FileFilter filter)Sets the current file filter. The file filter is used by the
file chooser to filter out files from the user's view.
FileFilter oldValue = fileFilter;
fileFilter = filter;
if (filter != null) {
if (isMultiSelectionEnabled() && selectedFiles != null && selectedFiles.length > 0) {
Vector fList = new Vector();
boolean failed = false;
for (int i = 0; i < selectedFiles.length; i++) {
if (filter.accept(selectedFiles[i])) {
fList.add(selectedFiles[i]);
} else {
failed = true;
}
}
if (failed) {
setSelectedFiles((fList.size() == 0) ? null : (File[])fList.toArray(new File[fList.size()]));
}
} else if (selectedFile != null && !filter.accept(selectedFile)) {
setSelectedFile(null);
}
}
firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, oldValue, fileFilter);
|
public void | setFileHidingEnabled(boolean b)Sets file hiding on or off. If true, hidden files are not shown
in the file chooser. The job of determining which files are
shown is done by the FileView .
// Dump showFilesListener since we'll ignore it from now on
if (showFilesListener != null) {
Toolkit.getDefaultToolkit().removePropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
showFilesListener = null;
}
boolean oldValue = useFileHiding;
useFileHiding = b;
firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, oldValue, useFileHiding);
|
public void | setFileSelectionMode(int mode)Sets the JFileChooser to allow the user to just
select files, just select
directories, or select both files and directories. The default is
JFilesChooser.FILES_ONLY .
if(fileSelectionMode == mode) {
return;
}
if ((mode == FILES_ONLY) || (mode == DIRECTORIES_ONLY) || (mode == FILES_AND_DIRECTORIES)) {
int oldValue = fileSelectionMode;
fileSelectionMode = mode;
firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, oldValue, fileSelectionMode);
} else {
throw new IllegalArgumentException("Incorrect Mode for file selection: " + mode);
}
|
public void | setFileSystemView(javax.swing.filechooser.FileSystemView fsv)Sets the file system view that the JFileChooser uses for
accessing and creating file system resources, such as finding
the floppy drive and getting a list of root drives.
FileSystemView oldValue = fileSystemView;
fileSystemView = fsv;
firePropertyChange(FILE_SYSTEM_VIEW_CHANGED_PROPERTY, oldValue, fileSystemView);
|
public void | setFileView(javax.swing.filechooser.FileView fileView)Sets the file view to used to retrieve UI information, such as
the icon that represents a file or the type description of a file.
FileView oldValue = this.fileView;
this.fileView = fileView;
firePropertyChange(FILE_VIEW_CHANGED_PROPERTY, oldValue, fileView);
|
public void | setMultiSelectionEnabled(boolean b)Sets the file chooser to allow multiple file selections.
if(multiSelectionEnabled == b) {
return;
}
boolean oldValue = multiSelectionEnabled;
multiSelectionEnabled = b;
firePropertyChange(MULTI_SELECTION_ENABLED_CHANGED_PROPERTY, oldValue, multiSelectionEnabled);
|
public void | setSelectedFile(java.io.File file)Sets the selected file. If the file's parent directory is
not the current directory, changes the current directory
to be the file's parent directory.
File oldValue = selectedFile;
selectedFile = file;
if(selectedFile != null) {
if (file.isAbsolute() && !getFileSystemView().isParent(getCurrentDirectory(), selectedFile)) {
setCurrentDirectory(selectedFile.getParentFile());
}
if (!isMultiSelectionEnabled() || selectedFiles == null || selectedFiles.length == 1) {
ensureFileIsVisible(selectedFile);
}
}
firePropertyChange(SELECTED_FILE_CHANGED_PROPERTY, oldValue, selectedFile);
|
public void | setSelectedFiles(java.io.File[] selectedFiles)Sets the list of selected files if the file chooser is
set to allow multiple selection.
File[] oldValue = this.selectedFiles;
if (selectedFiles != null && selectedFiles.length == 0) {
selectedFiles = null;
}
this.selectedFiles = selectedFiles;
setSelectedFile((selectedFiles != null) ? selectedFiles[0] : null);
firePropertyChange(SELECTED_FILES_CHANGED_PROPERTY, oldValue, this.selectedFiles);
|
protected void | setup(javax.swing.filechooser.FileSystemView view)Performs common constructor initialization and setup.
// Track native setting for showing hidden files
Toolkit tk = Toolkit.getDefaultToolkit();
Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
if (showHiddenProperty instanceof Boolean) {
useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
showFilesListener = new WeakPCL(this);
tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
}
if(view == null) {
view = FileSystemView.getFileSystemView();
}
setFileSystemView(view);
updateUI();
if(isAcceptAllFileFilterUsed()) {
setFileFilter(getAcceptAllFileFilter());
}
|
public int | showDialog(java.awt.Component parent, java.lang.String approveButtonText)Pops a custom file chooser dialog with a custom approve button.
For example, the following code
pops up a file chooser with a "Run Application" button
(instead of the normal "Save" or "Open" button):
filechooser.showDialog(parentFrame, "Run Application");
Alternatively, the following code does the same thing:
JFileChooser chooser = new JFileChooser(null);
chooser.setApproveButtonText("Run Application");
chooser.showDialog(parentFrame, null);
The parent argument determines two things:
the frame on which the open dialog depends and
the component whose position the look and feel
should consider when placing the dialog. If the parent
is a Frame object (such as a JFrame )
then the dialog depends on the frame and
the look and feel positions the dialog
relative to the frame (for example, centered over the frame).
If the parent is a component, then the dialog
depends on the frame containing the component,
and is positioned relative to the component
(for example, centered over the component).
If the parent is null , then the dialog depends on
no visible window, and it's placed in a
look-and-feel-dependent position
such as the center of the screen.
if(approveButtonText != null) {
setApproveButtonText(approveButtonText);
setDialogType(CUSTOM_DIALOG);
}
dialog = createDialog(parent);
dialog.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
returnValue = CANCEL_OPTION;
}
});
returnValue = ERROR_OPTION;
rescanCurrentDirectory();
dialog.show();
dialog.dispose();
dialog = null;
return returnValue;
|
public int | showOpenDialog(java.awt.Component parent)Pops up an "Open File" file chooser dialog. Note that the
text that appears in the approve button is determined by
the L&F.
setDialogType(OPEN_DIALOG);
return showDialog(parent, null);
|
public int | showSaveDialog(java.awt.Component parent)Pops up a "Save File" file chooser dialog. Note that the
text that appears in the approve button is determined by
the L&F.
setDialogType(SAVE_DIALOG);
return showDialog(parent, null);
|
public void | updateUI()Resets the UI property to a value from the current look and feel.
if (isAcceptAllFileFilterUsed()) {
removeChoosableFileFilter(getAcceptAllFileFilter());
}
FileChooserUI ui = ((FileChooserUI)UIManager.getUI(this));
if (fileSystemView == null) {
// We were probably deserialized
setFileSystemView(FileSystemView.getFileSystemView());
}
setUI(ui);
uiFileView = getUI().getFileView(this);
if(isAcceptAllFileFilterUsed()) {
addChoosableFileFilter(getAcceptAllFileFilter());
}
|
private void | writeObject(java.io.ObjectOutputStream s)See readObject and writeObject in
JComponent for more
information about serialization in Swing.
FileSystemView fsv = null;
if (isAcceptAllFileFilterUsed()) {
//The AcceptAllFileFilter is UI specific, it will be reset by
//updateUI() after deserialization
removeChoosableFileFilter(getAcceptAllFileFilter());
}
if (fileSystemView.equals(FileSystemView.getFileSystemView())) {
//The default FileSystemView is platform specific, it will be
//reset by updateUI() after deserialization
fsv = fileSystemView;
fileSystemView = null;
}
s.defaultWriteObject();
if (fsv != null) {
fileSystemView = fsv;
}
if (isAcceptAllFileFilterUsed()) {
addChoosableFileFilter(getAcceptAllFileFilter());
}
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
|