0N/A/*
3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.swing;
0N/A
0N/Aimport javax.swing.event.*;
0N/Aimport javax.swing.filechooser.*;
0N/Aimport javax.swing.plaf.FileChooserUI;
0N/A
0N/Aimport javax.accessibility.*;
0N/A
0N/Aimport java.io.File;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.IOException;
0N/A
0N/Aimport java.util.Vector;
0N/Aimport java.awt.AWTEvent;
0N/Aimport java.awt.Component;
0N/Aimport java.awt.Container;
0N/Aimport java.awt.BorderLayout;
0N/Aimport java.awt.Window;
0N/Aimport java.awt.Dialog;
0N/Aimport java.awt.Frame;
0N/Aimport java.awt.GraphicsEnvironment;
0N/Aimport java.awt.HeadlessException;
0N/Aimport java.awt.EventQueue;
0N/Aimport java.awt.Toolkit;
0N/Aimport java.awt.event.*;
0N/Aimport java.beans.PropertyChangeListener;
0N/Aimport java.beans.PropertyChangeEvent;
0N/Aimport java.lang.ref.WeakReference;
0N/A
0N/A/**
0N/A * <code>JFileChooser</code> provides a simple mechanism for the user to
0N/A * choose a file.
0N/A * For information about using <code>JFileChooser</code>, see
0N/A * <a
0N/A href="http://java.sun.com/docs/books/tutorial/uiswing/components/filechooser.html">How to Use File Choosers</a>,
0N/A * a section in <em>The Java Tutorial</em>.
0N/A *
0N/A * <p>
0N/A *
0N/A * The following code pops up a file chooser for the user's home directory that
0N/A * sees only .jpg and .gif images:
0N/A * <pre>
0N/A * JFileChooser chooser = new JFileChooser();
0N/A * FileNameExtensionFilter filter = new FileNameExtensionFilter(
0N/A * "JPG & GIF Images", "jpg", "gif");
0N/A * chooser.setFileFilter(filter);
0N/A * int returnVal = chooser.showOpenDialog(parent);
0N/A * if(returnVal == JFileChooser.APPROVE_OPTION) {
0N/A * System.out.println("You chose to open this file: " +
0N/A * chooser.getSelectedFile().getName());
0N/A * }
0N/A * </pre>
0N/A * <p>
0N/A * <strong>Warning:</strong> Swing is not thread safe. For more
0N/A * information see <a
0N/A * href="package-summary.html#threading">Swing's Threading
0N/A * Policy</a>.
0N/A *
0N/A * @beaninfo
0N/A * attribute: isContainer false
0N/A * description: A component which allows for the interactive selection of a file.
0N/A *
0N/A * @author Jeff Dinkins
0N/A *
0N/A */
0N/Apublic class JFileChooser extends JComponent implements Accessible {
0N/A
0N/A /**
0N/A * @see #getUIClassID
0N/A * @see #readObject
0N/A */
0N/A private static final String uiClassID = "FileChooserUI";
0N/A
0N/A // ************************
0N/A // ***** Dialog Types *****
0N/A // ************************
0N/A
0N/A /**
0N/A * Type value indicating that the <code>JFileChooser</code> supports an
0N/A * "Open" file operation.
0N/A */
0N/A public static final int OPEN_DIALOG = 0;
0N/A
0N/A /**
0N/A * Type value indicating that the <code>JFileChooser</code> supports a
0N/A * "Save" file operation.
0N/A */
0N/A public static final int SAVE_DIALOG = 1;
0N/A
0N/A /**
0N/A * Type value indicating that the <code>JFileChooser</code> supports a
0N/A * developer-specified file operation.
0N/A */
0N/A public static final int CUSTOM_DIALOG = 2;
0N/A
0N/A
0N/A // ********************************
0N/A // ***** Dialog Return Values *****
0N/A // ********************************
0N/A
0N/A /**
0N/A * Return value if cancel is chosen.
0N/A */
0N/A public static final int CANCEL_OPTION = 1;
0N/A
0N/A /**
0N/A * Return value if approve (yes, ok) is chosen.
0N/A */
0N/A public static final int APPROVE_OPTION = 0;
0N/A
0N/A /**
0N/A * Return value if an error occured.
0N/A */
0N/A public static final int ERROR_OPTION = -1;
0N/A
0N/A
0N/A // **********************************
0N/A // ***** JFileChooser properties *****
0N/A // **********************************
0N/A
0N/A
0N/A /** Instruction to display only files. */
0N/A public static final int FILES_ONLY = 0;
0N/A
0N/A /** Instruction to display only directories. */
0N/A public static final int DIRECTORIES_ONLY = 1;
0N/A
0N/A /** Instruction to display both files and directories. */
0N/A public static final int FILES_AND_DIRECTORIES = 2;
0N/A
0N/A /** Instruction to cancel the current selection. */
0N/A public static final String CANCEL_SELECTION = "CancelSelection";
0N/A
0N/A /**
0N/A * Instruction to approve the current selection
0N/A * (same as pressing yes or ok).
0N/A */
0N/A public static final String APPROVE_SELECTION = "ApproveSelection";
0N/A
0N/A /** Identifies change in the text on the approve (yes, ok) button. */
0N/A public static final String APPROVE_BUTTON_TEXT_CHANGED_PROPERTY = "ApproveButtonTextChangedProperty";
0N/A
0N/A /**
0N/A * Identifies change in the tooltip text for the approve (yes, ok)
0N/A * button.
0N/A */
0N/A public static final String APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY = "ApproveButtonToolTipTextChangedProperty";
0N/A
0N/A /** Identifies change in the mnemonic for the approve (yes, ok) button. */
0N/A public static final String APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY = "ApproveButtonMnemonicChangedProperty";
0N/A
0N/A /** Instruction to display the control buttons. */
0N/A public static final String CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY = "ControlButtonsAreShownChangedProperty";
0N/A
0N/A /** Identifies user's directory change. */
0N/A public static final String DIRECTORY_CHANGED_PROPERTY = "directoryChanged";
0N/A
0N/A /** Identifies change in user's single-file selection. */
0N/A public static final String SELECTED_FILE_CHANGED_PROPERTY = "SelectedFileChangedProperty";
0N/A
0N/A /** Identifies change in user's multiple-file selection. */
0N/A public static final String SELECTED_FILES_CHANGED_PROPERTY = "SelectedFilesChangedProperty";
0N/A
0N/A /** Enables multiple-file selections. */
0N/A public static final String MULTI_SELECTION_ENABLED_CHANGED_PROPERTY = "MultiSelectionEnabledChangedProperty";
0N/A
0N/A /**
0N/A * Says that a different object is being used to find available drives
0N/A * on the system.
0N/A */
0N/A public static final String FILE_SYSTEM_VIEW_CHANGED_PROPERTY = "FileSystemViewChanged";
0N/A
0N/A /**
0N/A * Says that a different object is being used to retrieve file
0N/A * information.
0N/A */
0N/A public static final String FILE_VIEW_CHANGED_PROPERTY = "fileViewChanged";
0N/A
0N/A /** Identifies a change in the display-hidden-files property. */
0N/A public static final String FILE_HIDING_CHANGED_PROPERTY = "FileHidingChanged";
0N/A
0N/A /** User changed the kind of files to display. */
0N/A public static final String FILE_FILTER_CHANGED_PROPERTY = "fileFilterChanged";
0N/A
0N/A /**
0N/A * Identifies a change in the kind of selection (single,
0N/A * multiple, etc.).
0N/A */
0N/A public static final String FILE_SELECTION_MODE_CHANGED_PROPERTY = "fileSelectionChanged";
0N/A
0N/A /**
0N/A * Says that a different accessory component is in use
0N/A * (for example, to preview files).
0N/A */
0N/A public static final String ACCESSORY_CHANGED_PROPERTY = "AccessoryChangedProperty";
0N/A
0N/A /**
0N/A * Identifies whether a the AcceptAllFileFilter is used or not.
0N/A */
0N/A public static final String ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY = "acceptAllFileFilterUsedChanged";
0N/A
0N/A /** Identifies a change in the dialog title. */
0N/A public static final String DIALOG_TITLE_CHANGED_PROPERTY = "DialogTitleChangedProperty";
0N/A
0N/A /**
0N/A * Identifies a change in the type of files displayed (files only,
0N/A * directories only, or both files and directories).
0N/A */
0N/A public static final String DIALOG_TYPE_CHANGED_PROPERTY = "DialogTypeChangedProperty";
0N/A
0N/A /**
0N/A * Identifies a change in the list of predefined file filters
0N/A * the user can choose from.
0N/A */
0N/A public static final String CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY = "ChoosableFileFilterChangedProperty";
0N/A
0N/A // ******************************
0N/A // ***** instance variables *****
0N/A // ******************************
0N/A
0N/A private String dialogTitle = null;
0N/A private String approveButtonText = null;
0N/A private String approveButtonToolTipText = null;
0N/A private int approveButtonMnemonic = 0;
0N/A
625N/A private Vector<FileFilter> filters = new Vector<FileFilter>(5);
0N/A private JDialog dialog = null;
0N/A private int dialogType = OPEN_DIALOG;
0N/A private int returnValue = ERROR_OPTION;
0N/A private JComponent accessory = null;
0N/A
0N/A private FileView fileView = null;
0N/A
0N/A private boolean controlsShown = true;
0N/A
0N/A private boolean useFileHiding = true;
0N/A private static final String SHOW_HIDDEN_PROP = "awt.file.showHiddenFiles";
0N/A
0N/A // Listens to changes in the native setting for showing hidden files.
0N/A // The Listener is removed and the native setting is ignored if
0N/A // setFileHidingEnabled() is ever called.
0N/A private transient PropertyChangeListener showFilesListener = null;
0N/A
0N/A private int fileSelectionMode = FILES_ONLY;
0N/A
0N/A private boolean multiSelectionEnabled = false;
0N/A
0N/A private boolean useAcceptAllFileFilter = true;
0N/A
0N/A private boolean dragEnabled = false;
0N/A
0N/A private FileFilter fileFilter = null;
0N/A
0N/A private FileSystemView fileSystemView = null;
0N/A
0N/A private File currentDirectory = null;
0N/A private File selectedFile = null;
0N/A private File[] selectedFiles;
0N/A
0N/A // *************************************
0N/A // ***** JFileChooser Constructors *****
0N/A // *************************************
0N/A
0N/A /**
0N/A * Constructs a <code>JFileChooser</code> pointing to the user's
0N/A * default directory. This default depends on the operating system.
0N/A * It is typically the "My Documents" folder on Windows, and the
0N/A * user's home directory on Unix.
0N/A */
0N/A public JFileChooser() {
0N/A this((File) null, (FileSystemView) null);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>JFileChooser</code> using the given path.
0N/A * Passing in a <code>null</code>
0N/A * string causes the file chooser to point to the user's default directory.
0N/A * This default depends on the operating system. It is
0N/A * typically the "My Documents" folder on Windows, and the user's
0N/A * home directory on Unix.
0N/A *
0N/A * @param currentDirectoryPath a <code>String</code> giving the path
0N/A * to a file or directory
0N/A */
0N/A public JFileChooser(String currentDirectoryPath) {
0N/A this(currentDirectoryPath, (FileSystemView) null);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>JFileChooser</code> using the given <code>File</code>
0N/A * as the path. Passing in a <code>null</code> file
0N/A * causes the file chooser to point to the user's default directory.
0N/A * This default depends on the operating system. It is
0N/A * typically the "My Documents" folder on Windows, and the user's
0N/A * home directory on Unix.
0N/A *
0N/A * @param currentDirectory a <code>File</code> object specifying
0N/A * the path to a file or directory
0N/A */
0N/A public JFileChooser(File currentDirectory) {
0N/A this(currentDirectory, (FileSystemView) null);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>JFileChooser</code> using the given
0N/A * <code>FileSystemView</code>.
0N/A */
0N/A public JFileChooser(FileSystemView fsv) {
0N/A this((File) null, fsv);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Constructs a <code>JFileChooser</code> using the given current directory
0N/A * and <code>FileSystemView</code>.
0N/A */
0N/A public JFileChooser(File currentDirectory, FileSystemView fsv) {
0N/A setup(fsv);
0N/A setCurrentDirectory(currentDirectory);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>JFileChooser</code> using the given current directory
0N/A * path and <code>FileSystemView</code>.
0N/A */
0N/A public JFileChooser(String currentDirectoryPath, FileSystemView fsv) {
0N/A setup(fsv);
0N/A if(currentDirectoryPath == null) {
0N/A setCurrentDirectory(null);
0N/A } else {
0N/A setCurrentDirectory(fileSystemView.createFileObject(currentDirectoryPath));
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Performs common constructor initialization and setup.
0N/A */
0N/A protected void setup(FileSystemView view) {
0N/A installShowFilesListener();
0N/A
0N/A if(view == null) {
0N/A view = FileSystemView.getFileSystemView();
0N/A }
0N/A setFileSystemView(view);
0N/A updateUI();
0N/A if(isAcceptAllFileFilterUsed()) {
0N/A setFileFilter(getAcceptAllFileFilter());
0N/A }
0N/A enableEvents(AWTEvent.MOUSE_EVENT_MASK);
0N/A }
0N/A
0N/A private void installShowFilesListener() {
0N/A // Track native setting for showing hidden files
0N/A Toolkit tk = Toolkit.getDefaultToolkit();
0N/A Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
0N/A if (showHiddenProperty instanceof Boolean) {
0N/A useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
0N/A showFilesListener = new WeakPCL(this);
0N/A tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>dragEnabled</code> property,
0N/A * which must be <code>true</code> to enable
0N/A * automatic drag handling (the first part of drag and drop)
0N/A * on this component.
0N/A * The <code>transferHandler</code> property needs to be set
0N/A * to a non-<code>null</code> value for the drag to do
0N/A * anything. The default value of the <code>dragEnabled</code>
0N/A * property
0N/A * is <code>false</code>.
0N/A *
0N/A * <p>
0N/A *
0N/A * When automatic drag handling is enabled,
0N/A * most look and feels begin a drag-and-drop operation
0N/A * whenever the user presses the mouse button over an item
0N/A * and then moves the mouse a few pixels.
0N/A * Setting this property to <code>true</code>
0N/A * can therefore have a subtle effect on
0N/A * how selections behave.
0N/A *
0N/A * <p>
0N/A *
0N/A * Some look and feels might not support automatic drag and drop;
0N/A * they will ignore this property. You can work around such
0N/A * look and feels by modifying the component
0N/A * to directly call the <code>exportAsDrag</code> method of a
0N/A * <code>TransferHandler</code>.
0N/A *
0N/A * @param b the value to set the <code>dragEnabled</code> property to
0N/A * @exception HeadlessException if
0N/A * <code>b</code> is <code>true</code> and
0N/A * <code>GraphicsEnvironment.isHeadless()</code>
0N/A * returns <code>true</code>
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see #getDragEnabled
0N/A * @see #setTransferHandler
0N/A * @see TransferHandler
0N/A * @since 1.4
0N/A *
0N/A * @beaninfo
0N/A * description: determines whether automatic drag handling is enabled
0N/A * bound: false
0N/A */
0N/A public void setDragEnabled(boolean b) {
0N/A if (b && GraphicsEnvironment.isHeadless()) {
0N/A throw new HeadlessException();
0N/A }
0N/A dragEnabled = b;
0N/A }
0N/A
0N/A /**
0N/A * Gets the value of the <code>dragEnabled</code> property.
0N/A *
0N/A * @return the value of the <code>dragEnabled</code> property
0N/A * @see #setDragEnabled
0N/A * @since 1.4
0N/A */
0N/A public boolean getDragEnabled() {
0N/A return dragEnabled;
0N/A }
0N/A
0N/A // *****************************
0N/A // ****** File Operations ******
0N/A // *****************************
0N/A
0N/A /**
0N/A * Returns the selected file. This can be set either by the
0N/A * programmer via <code>setSelectedFile</code> or by a user action, such as
0N/A * either typing the filename into the UI or selecting the
0N/A * file from a list in the UI.
0N/A *
0N/A * @see #setSelectedFile
0N/A * @return the selected file
0N/A */
0N/A public File getSelectedFile() {
0N/A return selectedFile;
0N/A }
0N/A
0N/A /**
0N/A * Sets the selected file. If the file's parent directory is
0N/A * not the current directory, changes the current directory
0N/A * to be the file's parent directory.
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A *
0N/A * @see #getSelectedFile
0N/A *
0N/A * @param file the selected file
0N/A */
0N/A public void setSelectedFile(File file) {
0N/A File oldValue = selectedFile;
0N/A selectedFile = file;
0N/A if(selectedFile != null) {
0N/A if (file.isAbsolute() && !getFileSystemView().isParent(getCurrentDirectory(), selectedFile)) {
0N/A setCurrentDirectory(selectedFile.getParentFile());
0N/A }
0N/A if (!isMultiSelectionEnabled() || selectedFiles == null || selectedFiles.length == 1) {
0N/A ensureFileIsVisible(selectedFile);
0N/A }
0N/A }
0N/A firePropertyChange(SELECTED_FILE_CHANGED_PROPERTY, oldValue, selectedFile);
0N/A }
0N/A
0N/A /**
0N/A * Returns a list of selected files if the file chooser is
0N/A * set to allow multiple selection.
0N/A */
0N/A public File[] getSelectedFiles() {
0N/A if(selectedFiles == null) {
0N/A return new File[0];
0N/A } else {
625N/A return selectedFiles.clone();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets the list of selected files if the file chooser is
0N/A * set to allow multiple selection.
0N/A *
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: The list of selected files if the chooser is in multiple selection mode.
0N/A */
0N/A public void setSelectedFiles(File[] selectedFiles) {
0N/A File[] oldValue = this.selectedFiles;
0N/A if (selectedFiles == null || selectedFiles.length == 0) {
0N/A selectedFiles = null;
0N/A this.selectedFiles = null;
0N/A setSelectedFile(null);
0N/A } else {
0N/A this.selectedFiles = selectedFiles.clone();
0N/A setSelectedFile(this.selectedFiles[0]);
0N/A }
0N/A firePropertyChange(SELECTED_FILES_CHANGED_PROPERTY, oldValue, selectedFiles);
0N/A }
0N/A
0N/A /**
0N/A * Returns the current directory.
0N/A *
0N/A * @return the current directory
0N/A * @see #setCurrentDirectory
0N/A */
0N/A public File getCurrentDirectory() {
0N/A return currentDirectory;
0N/A }
0N/A
0N/A /**
0N/A * Sets the current directory. Passing in <code>null</code> sets the
0N/A * file chooser to point to the user's default directory.
0N/A * This default depends on the operating system. It is
0N/A * typically the "My Documents" folder on Windows, and the user's
0N/A * home directory on Unix.
0N/A *
0N/A * If the file passed in as <code>currentDirectory</code> is not a
0N/A * directory, the parent of the file will be used as the currentDirectory.
0N/A * If the parent is not traversable, then it will walk up the parent tree
0N/A * until it finds a traversable directory, or hits the root of the
0N/A * file system.
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The directory that the JFileChooser is showing files of.
0N/A *
0N/A * @param dir the current directory to point to
0N/A * @see #getCurrentDirectory
0N/A */
0N/A public void setCurrentDirectory(File dir) {
0N/A File oldValue = currentDirectory;
0N/A
0N/A if (dir != null && !dir.exists()) {
0N/A dir = currentDirectory;
0N/A }
0N/A if (dir == null) {
0N/A dir = getFileSystemView().getDefaultDirectory();
0N/A }
0N/A if (currentDirectory != null) {
0N/A /* Verify the toString of object */
0N/A if (this.currentDirectory.equals(dir)) {
0N/A return;
0N/A }
0N/A }
0N/A
0N/A File prev = null;
0N/A while (!isTraversable(dir) && prev != dir) {
0N/A prev = dir;
0N/A dir = getFileSystemView().getParentDirectory(dir);
0N/A }
0N/A currentDirectory = dir;
0N/A
0N/A firePropertyChange(DIRECTORY_CHANGED_PROPERTY, oldValue, currentDirectory);
0N/A }
0N/A
0N/A /**
0N/A * Changes the directory to be set to the parent of the
0N/A * current directory.
0N/A *
0N/A * @see #getCurrentDirectory
0N/A */
0N/A public void changeToParentDirectory() {
0N/A selectedFile = null;
0N/A File oldValue = getCurrentDirectory();
0N/A setCurrentDirectory(getFileSystemView().getParentDirectory(oldValue));
0N/A }
0N/A
0N/A /**
0N/A * Tells the UI to rescan its files list from the current directory.
0N/A */
0N/A public void rescanCurrentDirectory() {
0N/A getUI().rescanCurrentDirectory(this);
0N/A }
0N/A
0N/A /**
0N/A * Makes sure that the specified file is viewable, and
0N/A * not hidden.
0N/A *
0N/A * @param f a File object
0N/A */
0N/A public void ensureFileIsVisible(File f) {
0N/A getUI().ensureFileIsVisible(this, f);
0N/A }
0N/A
0N/A // **************************************
0N/A // ***** JFileChooser Dialog methods *****
0N/A // **************************************
0N/A
0N/A /**
0N/A * Pops up an "Open File" file chooser dialog. Note that the
0N/A * text that appears in the approve button is determined by
0N/A * the L&F.
0N/A *
0N/A * @param parent the parent component of the dialog,
0N/A * can be <code>null</code>;
0N/A * see <code>showDialog</code> for details
0N/A * @return the return state of the file chooser on popdown:
0N/A * <ul>
0N/A * <li>JFileChooser.CANCEL_OPTION
0N/A * <li>JFileChooser.APPROVE_OPTION
0N/A * <li>JFileChooser.ERROR_OPTION if an error occurs or the
0N/A * dialog is dismissed
0N/A * </ul>
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true.
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see #showDialog
0N/A */
0N/A public int showOpenDialog(Component parent) throws HeadlessException {
0N/A setDialogType(OPEN_DIALOG);
0N/A return showDialog(parent, null);
0N/A }
0N/A
0N/A /**
0N/A * Pops up a "Save File" file chooser dialog. Note that the
0N/A * text that appears in the approve button is determined by
0N/A * the L&F.
0N/A *
0N/A * @param parent the parent component of the dialog,
0N/A * can be <code>null</code>;
0N/A * see <code>showDialog</code> for details
0N/A * @return the return state of the file chooser on popdown:
0N/A * <ul>
0N/A * <li>JFileChooser.CANCEL_OPTION
0N/A * <li>JFileChooser.APPROVE_OPTION
0N/A * <li>JFileChooser.ERROR_OPTION if an error occurs or the
0N/A * dialog is dismissed
0N/A * </ul>
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true.
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @see #showDialog
0N/A */
0N/A public int showSaveDialog(Component parent) throws HeadlessException {
0N/A setDialogType(SAVE_DIALOG);
0N/A return showDialog(parent, null);
0N/A }
0N/A
0N/A /**
0N/A * Pops a custom file chooser dialog with a custom approve button.
0N/A * For example, the following code
0N/A * pops up a file chooser with a "Run Application" button
0N/A * (instead of the normal "Save" or "Open" button):
0N/A * <pre>
0N/A * filechooser.showDialog(parentFrame, "Run Application");
0N/A * </pre>
0N/A *
0N/A * Alternatively, the following code does the same thing:
0N/A * <pre>
0N/A * JFileChooser chooser = new JFileChooser(null);
0N/A * chooser.setApproveButtonText("Run Application");
0N/A * chooser.showDialog(parentFrame, null);
0N/A * </pre>
0N/A *
0N/A * <!--PENDING(jeff) - the following method should be added to the api:
0N/A * showDialog(Component parent);-->
0N/A * <!--PENDING(kwalrath) - should specify modality and what
0N/A * "depends" means.-->
0N/A *
0N/A * <p>
0N/A *
0N/A * The <code>parent</code> argument determines two things:
0N/A * the frame on which the open dialog depends and
0N/A * the component whose position the look and feel
0N/A * should consider when placing the dialog. If the parent
0N/A * is a <code>Frame</code> object (such as a <code>JFrame</code>)
0N/A * then the dialog depends on the frame and
0N/A * the look and feel positions the dialog
0N/A * relative to the frame (for example, centered over the frame).
0N/A * If the parent is a component, then the dialog
0N/A * depends on the frame containing the component,
0N/A * and is positioned relative to the component
0N/A * (for example, centered over the component).
0N/A * If the parent is <code>null</code>, then the dialog depends on
0N/A * no visible window, and it's placed in a
0N/A * look-and-feel-dependent position
0N/A * such as the center of the screen.
0N/A *
0N/A * @param parent the parent component of the dialog;
0N/A * can be <code>null</code>
0N/A * @param approveButtonText the text of the <code>ApproveButton</code>
0N/A * @return the return state of the file chooser on popdown:
0N/A * <ul>
0N/A * <li>JFileChooser.CANCEL_OPTION
0N/A * <li>JFileChooser.APPROVE_OPTION
1740N/A * <li>JFileChooser.ERROR_OPTION if an error occurs or the
0N/A * dialog is dismissed
0N/A * </ul>
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true.
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A */
0N/A public int showDialog(Component parent, String approveButtonText)
0N/A throws HeadlessException {
1740N/A if (dialog != null) {
1740N/A // Prevent to show second instance of dialog if the previous one still exists
1740N/A return JFileChooser.ERROR_OPTION;
1740N/A }
1740N/A
0N/A if(approveButtonText != null) {
0N/A setApproveButtonText(approveButtonText);
0N/A setDialogType(CUSTOM_DIALOG);
0N/A }
0N/A dialog = createDialog(parent);
0N/A dialog.addWindowListener(new WindowAdapter() {
0N/A public void windowClosing(WindowEvent e) {
0N/A returnValue = CANCEL_OPTION;
0N/A }
0N/A });
0N/A returnValue = ERROR_OPTION;
0N/A rescanCurrentDirectory();
0N/A
0N/A dialog.show();
0N/A firePropertyChange("JFileChooserDialogIsClosingProperty", dialog, null);
1453N/A
1453N/A // Remove all components from dialog. The MetalFileChooserUI.installUI() method (and other LAFs)
1453N/A // registers AWT listener for dialogs and produces memory leaks. It happens when
1453N/A // installUI invoked after the showDialog method.
1453N/A dialog.getContentPane().removeAll();
0N/A dialog.dispose();
0N/A dialog = null;
0N/A return returnValue;
0N/A }
0N/A
0N/A /**
0N/A * Creates and returns a new <code>JDialog</code> wrapping
0N/A * <code>this</code> centered on the <code>parent</code>
0N/A * in the <code>parent</code>'s frame.
0N/A * This method can be overriden to further manipulate the dialog,
0N/A * to disable resizing, set the location, etc. Example:
0N/A * <pre>
0N/A * class MyFileChooser extends JFileChooser {
0N/A * protected JDialog createDialog(Component parent) throws HeadlessException {
0N/A * JDialog dialog = super.createDialog(parent);
0N/A * dialog.setLocation(300, 200);
0N/A * dialog.setResizable(false);
0N/A * return dialog;
0N/A * }
0N/A * }
0N/A * </pre>
0N/A *
0N/A * @param parent the parent component of the dialog;
0N/A * can be <code>null</code>
0N/A * @return a new <code>JDialog</code> containing this instance
0N/A * @exception HeadlessException if GraphicsEnvironment.isHeadless()
0N/A * returns true.
0N/A * @see java.awt.GraphicsEnvironment#isHeadless
0N/A * @since 1.4
0N/A */
0N/A protected JDialog createDialog(Component parent) throws HeadlessException {
346N/A FileChooserUI ui = getUI();
346N/A String title = ui.getDialogTitle(this);
0N/A putClientProperty(AccessibleContext.ACCESSIBLE_DESCRIPTION_PROPERTY,
0N/A title);
0N/A
0N/A JDialog dialog;
0N/A Window window = JOptionPane.getWindowForComponent(parent);
0N/A if (window instanceof Frame) {
0N/A dialog = new JDialog((Frame)window, title, true);
0N/A } else {
0N/A dialog = new JDialog((Dialog)window, title, true);
0N/A }
0N/A dialog.setComponentOrientation(this.getComponentOrientation());
0N/A
0N/A Container contentPane = dialog.getContentPane();
0N/A contentPane.setLayout(new BorderLayout());
0N/A contentPane.add(this, BorderLayout.CENTER);
0N/A
0N/A if (JDialog.isDefaultLookAndFeelDecorated()) {
0N/A boolean supportsWindowDecorations =
0N/A UIManager.getLookAndFeel().getSupportsWindowDecorations();
0N/A if (supportsWindowDecorations) {
0N/A dialog.getRootPane().setWindowDecorationStyle(JRootPane.FILE_CHOOSER_DIALOG);
0N/A }
0N/A }
346N/A dialog.getRootPane().setDefaultButton(ui.getDefaultButton(this));
0N/A dialog.pack();
0N/A dialog.setLocationRelativeTo(parent);
0N/A
0N/A return dialog;
0N/A }
0N/A
0N/A // **************************
0N/A // ***** Dialog Options *****
0N/A // **************************
0N/A
0N/A /**
0N/A * Returns the value of the <code>controlButtonsAreShown</code>
0N/A * property.
0N/A *
0N/A * @return the value of the <code>controlButtonsAreShown</code>
0N/A * property
0N/A *
0N/A * @see #setControlButtonsAreShown
0N/A * @since 1.3
0N/A */
0N/A public boolean getControlButtonsAreShown() {
0N/A return controlsShown;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the property
0N/A * that indicates whether the <i>approve</i> and <i>cancel</i>
0N/A * buttons are shown in the file chooser. This property
0N/A * is <code>true</code> by default. Look and feels
0N/A * that always show these buttons will ignore the value
0N/A * of this property.
0N/A * This method fires a property-changed event,
0N/A * using the string value of
0N/A * <code>CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY</code>
0N/A * as the name of the property.
0N/A *
0N/A * @param b <code>false</code> if control buttons should not be
0N/A * shown; otherwise, <code>true</code>
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Sets whether the approve & cancel buttons are shown.
0N/A *
0N/A * @see #getControlButtonsAreShown
0N/A * @see #CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
0N/A * @since 1.3
0N/A */
0N/A public void setControlButtonsAreShown(boolean b) {
0N/A if(controlsShown == b) {
0N/A return;
0N/A }
0N/A boolean oldValue = controlsShown;
0N/A controlsShown = b;
0N/A firePropertyChange(CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY, oldValue, controlsShown);
0N/A }
0N/A
0N/A /**
0N/A * Returns the type of this dialog. The default is
0N/A * <code>JFileChooser.OPEN_DIALOG</code>.
0N/A *
0N/A * @return the type of dialog to be displayed:
0N/A * <ul>
0N/A * <li>JFileChooser.OPEN_DIALOG
0N/A * <li>JFileChooser.SAVE_DIALOG
0N/A * <li>JFileChooser.CUSTOM_DIALOG
0N/A * </ul>
0N/A *
0N/A * @see #setDialogType
0N/A */
0N/A public int getDialogType() {
0N/A return dialogType;
0N/A }
0N/A
0N/A /**
0N/A * Sets the type of this dialog. Use <code>OPEN_DIALOG</code> when you
0N/A * want to bring up a file chooser that the user can use to open a file.
0N/A * Likewise, use <code>SAVE_DIALOG</code> for letting the user choose
0N/A * a file for saving.
0N/A * Use <code>CUSTOM_DIALOG</code> when you want to use the file
0N/A * chooser in a context other than "Open" or "Save".
0N/A * For instance, you might want to bring up a file chooser that allows
0N/A * the user to choose a file to execute. Note that you normally would not
0N/A * need to set the <code>JFileChooser</code> to use
0N/A * <code>CUSTOM_DIALOG</code>
0N/A * since a call to <code>setApproveButtonText</code> does this for you.
0N/A * The default dialog type is <code>JFileChooser.OPEN_DIALOG</code>.
0N/A *
0N/A * @param dialogType the type of dialog to be displayed:
0N/A * <ul>
0N/A * <li>JFileChooser.OPEN_DIALOG
0N/A * <li>JFileChooser.SAVE_DIALOG
0N/A * <li>JFileChooser.CUSTOM_DIALOG
0N/A * </ul>
0N/A *
0N/A * @exception IllegalArgumentException if <code>dialogType</code> is
0N/A * not legal
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The type (open, save, custom) of the JFileChooser.
0N/A * enum:
0N/A * OPEN_DIALOG JFileChooser.OPEN_DIALOG
0N/A * SAVE_DIALOG JFileChooser.SAVE_DIALOG
0N/A * CUSTOM_DIALOG JFileChooser.CUSTOM_DIALOG
0N/A *
0N/A * @see #getDialogType
0N/A * @see #setApproveButtonText
0N/A */
0N/A // PENDING(jeff) - fire button text change property
0N/A public void setDialogType(int dialogType) {
0N/A if(this.dialogType == dialogType) {
0N/A return;
0N/A }
0N/A if(!(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG || dialogType == CUSTOM_DIALOG)) {
0N/A throw new IllegalArgumentException("Incorrect Dialog Type: " + dialogType);
0N/A }
0N/A int oldValue = this.dialogType;
0N/A this.dialogType = dialogType;
0N/A if(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG) {
0N/A setApproveButtonText(null);
0N/A }
0N/A firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, oldValue, dialogType);
0N/A }
0N/A
0N/A /**
0N/A * Sets the string that goes in the <code>JFileChooser</code> window's
0N/A * title bar.
0N/A *
0N/A * @param dialogTitle the new <code>String</code> for the title bar
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The title of the JFileChooser dialog window.
0N/A *
0N/A * @see #getDialogTitle
0N/A *
0N/A */
0N/A public void setDialogTitle(String dialogTitle) {
0N/A String oldValue = this.dialogTitle;
0N/A this.dialogTitle = dialogTitle;
0N/A if(dialog != null) {
0N/A dialog.setTitle(dialogTitle);
0N/A }
0N/A firePropertyChange(DIALOG_TITLE_CHANGED_PROPERTY, oldValue, dialogTitle);
0N/A }
0N/A
0N/A /**
0N/A * Gets the string that goes in the <code>JFileChooser</code>'s titlebar.
0N/A *
0N/A * @see #setDialogTitle
0N/A */
0N/A public String getDialogTitle() {
0N/A return dialogTitle;
0N/A }
0N/A
0N/A // ************************************
0N/A // ***** JFileChooser View Options *****
0N/A // ************************************
0N/A
0N/A
0N/A
0N/A /**
0N/A * Sets the tooltip text used in the <code>ApproveButton</code>.
0N/A * If <code>null</code>, the UI object will determine the button's text.
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The tooltip text for the ApproveButton.
0N/A *
0N/A * @param toolTipText the tooltip text for the approve button
0N/A * @see #setApproveButtonText
0N/A * @see #setDialogType
0N/A * @see #showDialog
0N/A */
0N/A public void setApproveButtonToolTipText(String toolTipText) {
0N/A if(approveButtonToolTipText == toolTipText) {
0N/A return;
0N/A }
0N/A String oldValue = approveButtonToolTipText;
0N/A approveButtonToolTipText = toolTipText;
0N/A firePropertyChange(APPROVE_BUTTON_TOOL_TIP_TEXT_CHANGED_PROPERTY, oldValue, approveButtonToolTipText);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the tooltip text used in the <code>ApproveButton</code>.
0N/A * If <code>null</code>, the UI object will determine the button's text.
0N/A *
0N/A * @return the tooltip text used for the approve button
0N/A *
0N/A * @see #setApproveButtonText
0N/A * @see #setDialogType
0N/A * @see #showDialog
0N/A */
0N/A public String getApproveButtonToolTipText() {
0N/A return approveButtonToolTipText;
0N/A }
0N/A
0N/A /**
0N/A * Returns the approve button's mnemonic.
0N/A * @return an integer value for the mnemonic key
0N/A *
0N/A * @see #setApproveButtonMnemonic
0N/A */
0N/A public int getApproveButtonMnemonic() {
0N/A return approveButtonMnemonic;
0N/A }
0N/A
0N/A /**
0N/A * Sets the approve button's mnemonic using a numeric keycode.
0N/A *
0N/A * @param mnemonic an integer value for the mnemonic key
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The mnemonic key accelerator for the ApproveButton.
0N/A *
0N/A * @see #getApproveButtonMnemonic
0N/A */
0N/A public void setApproveButtonMnemonic(int mnemonic) {
0N/A if(approveButtonMnemonic == mnemonic) {
0N/A return;
0N/A }
0N/A int oldValue = approveButtonMnemonic;
0N/A approveButtonMnemonic = mnemonic;
0N/A firePropertyChange(APPROVE_BUTTON_MNEMONIC_CHANGED_PROPERTY, oldValue, approveButtonMnemonic);
0N/A }
0N/A
0N/A /**
0N/A * Sets the approve button's mnemonic using a character.
0N/A * @param mnemonic a character value for the mnemonic key
0N/A *
0N/A * @see #getApproveButtonMnemonic
0N/A */
0N/A public void setApproveButtonMnemonic(char mnemonic) {
0N/A int vk = (int) mnemonic;
0N/A if(vk >= 'a' && vk <='z') {
0N/A vk -= ('a' - 'A');
0N/A }
0N/A setApproveButtonMnemonic(vk);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the text used in the <code>ApproveButton</code> in the
0N/A * <code>FileChooserUI</code>.
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: The text that goes in the ApproveButton.
0N/A *
0N/A * @param approveButtonText the text used in the <code>ApproveButton</code>
0N/A *
0N/A * @see #getApproveButtonText
0N/A * @see #setDialogType
0N/A * @see #showDialog
0N/A */
0N/A // PENDING(jeff) - have ui set this on dialog type change
0N/A public void setApproveButtonText(String approveButtonText) {
0N/A if(this.approveButtonText == approveButtonText) {
0N/A return;
0N/A }
0N/A String oldValue = this.approveButtonText;
0N/A this.approveButtonText = approveButtonText;
0N/A firePropertyChange(APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, oldValue, approveButtonText);
0N/A }
0N/A
0N/A /**
0N/A * Returns the text used in the <code>ApproveButton</code> in the
0N/A * <code>FileChooserUI</code>.
0N/A * If <code>null</code>, the UI object will determine the button's text.
0N/A *
0N/A * Typically, this would be "Open" or "Save".
0N/A *
0N/A * @return the text used in the <code>ApproveButton</code>
0N/A *
0N/A * @see #setApproveButtonText
0N/A * @see #setDialogType
0N/A * @see #showDialog
0N/A */
0N/A public String getApproveButtonText() {
0N/A return approveButtonText;
0N/A }
0N/A
0N/A /**
0N/A * Gets the list of user choosable file filters.
0N/A *
0N/A * @return a <code>FileFilter</code> array containing all the choosable
0N/A * file filters
0N/A *
0N/A * @see #addChoosableFileFilter
0N/A * @see #removeChoosableFileFilter
0N/A * @see #resetChoosableFileFilters
0N/A */
0N/A public FileFilter[] getChoosableFileFilters() {
0N/A FileFilter[] filterArray = new FileFilter[filters.size()];
0N/A filters.copyInto(filterArray);
0N/A return filterArray;
0N/A }
0N/A
0N/A /**
0N/A * Adds a filter to the list of user choosable file filters.
0N/A * For information on setting the file selection mode, see
0N/A * {@link #setFileSelectionMode setFileSelectionMode}.
0N/A *
0N/A * @param filter the <code>FileFilter</code> to add to the choosable file
0N/A * filter list
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Adds a filter to the list of user choosable file filters.
0N/A *
0N/A * @see #getChoosableFileFilters
0N/A * @see #removeChoosableFileFilter
0N/A * @see #resetChoosableFileFilters
0N/A * @see #setFileSelectionMode
0N/A */
0N/A public void addChoosableFileFilter(FileFilter filter) {
0N/A if(filter != null && !filters.contains(filter)) {
0N/A FileFilter[] oldValue = getChoosableFileFilters();
0N/A filters.addElement(filter);
0N/A firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
0N/A if (fileFilter == null && filters.size() == 1) {
0N/A setFileFilter(filter);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Removes a filter from the list of user choosable file filters. Returns
0N/A * true if the file filter was removed.
0N/A *
0N/A * @see #addChoosableFileFilter
0N/A * @see #getChoosableFileFilters
0N/A * @see #resetChoosableFileFilters
0N/A */
0N/A public boolean removeChoosableFileFilter(FileFilter f) {
0N/A if(filters.contains(f)) {
0N/A if(getFileFilter() == f) {
0N/A setFileFilter(null);
0N/A }
0N/A FileFilter[] oldValue = getChoosableFileFilters();
0N/A filters.removeElement(f);
0N/A firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
0N/A return true;
0N/A } else {
0N/A return false;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Resets the choosable file filter list to its starting state. Normally,
0N/A * this removes all added file filters while leaving the
0N/A * <code>AcceptAll</code> file filter.
0N/A *
0N/A * @see #addChoosableFileFilter
0N/A * @see #getChoosableFileFilters
0N/A * @see #removeChoosableFileFilter
0N/A */
0N/A public void resetChoosableFileFilters() {
0N/A FileFilter[] oldValue = getChoosableFileFilters();
0N/A setFileFilter(null);
0N/A filters.removeAllElements();
0N/A if(isAcceptAllFileFilterUsed()) {
0N/A addChoosableFileFilter(getAcceptAllFileFilter());
0N/A }
0N/A firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());
0N/A }
0N/A
0N/A /**
0N/A * Returns the <code>AcceptAll</code> file filter.
0N/A * For example, on Microsoft Windows this would be All Files (*.*).
0N/A */
0N/A public FileFilter getAcceptAllFileFilter() {
0N/A FileFilter filter = null;
0N/A if(getUI() != null) {
0N/A filter = getUI().getAcceptAllFileFilter(this);
0N/A }
0N/A return filter;
0N/A }
0N/A
0N/A /**
0N/A * Returns whether the <code>AcceptAll FileFilter</code> is used.
0N/A * @return true if the <code>AcceptAll FileFilter</code> is used
0N/A * @see #setAcceptAllFileFilterUsed
0N/A * @since 1.3
0N/A */
0N/A public boolean isAcceptAllFileFilterUsed() {
0N/A return useAcceptAllFileFilter;
0N/A }
0N/A
0N/A /**
0N/A * Determines whether the <code>AcceptAll FileFilter</code> is used
0N/A * as an available choice in the choosable filter list.
0N/A * If false, the <code>AcceptAll</code> file filter is removed from
0N/A * the list of available file filters.
0N/A * If true, the <code>AcceptAll</code> file filter will become the
0N/A * the actively used file filter.
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.
0N/A *
0N/A * @see #isAcceptAllFileFilterUsed
0N/A * @see #getAcceptAllFileFilter
0N/A * @see #setFileFilter
0N/A * @since 1.3
0N/A */
0N/A public void setAcceptAllFileFilterUsed(boolean b) {
0N/A boolean oldValue = useAcceptAllFileFilter;
0N/A useAcceptAllFileFilter = b;
0N/A if(!b) {
0N/A removeChoosableFileFilter(getAcceptAllFileFilter());
0N/A } else {
0N/A removeChoosableFileFilter(getAcceptAllFileFilter());
0N/A addChoosableFileFilter(getAcceptAllFileFilter());
0N/A }
0N/A firePropertyChange(ACCEPT_ALL_FILE_FILTER_USED_CHANGED_PROPERTY, oldValue, useAcceptAllFileFilter);
0N/A }
0N/A
0N/A /**
0N/A * Returns the accessory component.
0N/A *
0N/A * @return this JFileChooser's accessory component, or null
0N/A * @see #setAccessory
0N/A */
0N/A public JComponent getAccessory() {
0N/A return accessory;
0N/A }
0N/A
0N/A /**
0N/A * Sets the accessory component. An accessory is often used to show a
0N/A * preview image of the selected file; however, it can be used for anything
0N/A * that the programmer wishes, such as extra custom file chooser controls.
0N/A *
0N/A * <p>
0N/A * Note: if there was a previous accessory, you should unregister
0N/A * any listeners that the accessory might have registered with the
0N/A * file chooser.
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Sets the accessory component on the JFileChooser.
0N/A */
0N/A public void setAccessory(JComponent newAccessory) {
0N/A JComponent oldValue = accessory;
0N/A accessory = newAccessory;
0N/A firePropertyChange(ACCESSORY_CHANGED_PROPERTY, oldValue, accessory);
0N/A }
0N/A
0N/A /**
0N/A * Sets the <code>JFileChooser</code> to allow the user to just
0N/A * select files, just select
0N/A * directories, or select both files and directories. The default is
0N/A * <code>JFilesChooser.FILES_ONLY</code>.
0N/A *
0N/A * @param mode the type of files to be displayed:
0N/A * <ul>
0N/A * <li>JFileChooser.FILES_ONLY
0N/A * <li>JFileChooser.DIRECTORIES_ONLY
0N/A * <li>JFileChooser.FILES_AND_DIRECTORIES
0N/A * </ul>
0N/A *
0N/A * @exception IllegalArgumentException if <code>mode</code> is an
0N/A * illegal file selection mode
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Sets the types of files that the JFileChooser can choose.
0N/A * enum: FILES_ONLY JFileChooser.FILES_ONLY
0N/A * DIRECTORIES_ONLY JFileChooser.DIRECTORIES_ONLY
0N/A * FILES_AND_DIRECTORIES JFileChooser.FILES_AND_DIRECTORIES
0N/A *
0N/A *
0N/A * @see #getFileSelectionMode
0N/A */
0N/A public void setFileSelectionMode(int mode) {
0N/A if(fileSelectionMode == mode) {
0N/A return;
0N/A }
0N/A
0N/A if ((mode == FILES_ONLY) || (mode == DIRECTORIES_ONLY) || (mode == FILES_AND_DIRECTORIES)) {
0N/A int oldValue = fileSelectionMode;
0N/A fileSelectionMode = mode;
0N/A firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, oldValue, fileSelectionMode);
0N/A } else {
0N/A throw new IllegalArgumentException("Incorrect Mode for file selection: " + mode);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns the current file-selection mode. The default is
0N/A * <code>JFilesChooser.FILES_ONLY</code>.
0N/A *
0N/A * @return the type of files to be displayed, one of the following:
0N/A * <ul>
0N/A * <li>JFileChooser.FILES_ONLY
0N/A * <li>JFileChooser.DIRECTORIES_ONLY
0N/A * <li>JFileChooser.FILES_AND_DIRECTORIES
0N/A * </ul>
0N/A * @see #setFileSelectionMode
0N/A */
0N/A public int getFileSelectionMode() {
0N/A return fileSelectionMode;
0N/A }
0N/A
0N/A /**
0N/A * Convenience call that determines if files are selectable based on the
0N/A * current file selection mode.
0N/A *
0N/A * @see #setFileSelectionMode
0N/A * @see #getFileSelectionMode
0N/A */
0N/A public boolean isFileSelectionEnabled() {
0N/A return ((fileSelectionMode == FILES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
0N/A }
0N/A
0N/A /**
0N/A * Convenience call that determines if directories are selectable based
0N/A * on the current file selection mode.
0N/A *
0N/A * @see #setFileSelectionMode
0N/A * @see #getFileSelectionMode
0N/A */
0N/A public boolean isDirectorySelectionEnabled() {
0N/A return ((fileSelectionMode == DIRECTORIES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
0N/A }
0N/A
0N/A /**
0N/A * Sets the file chooser to allow multiple file selections.
0N/A *
0N/A * @param b true if multiple files may be selected
0N/A * @beaninfo
0N/A * bound: true
0N/A * description: Sets multiple file selection mode.
0N/A *
0N/A * @see #isMultiSelectionEnabled
0N/A */
0N/A public void setMultiSelectionEnabled(boolean b) {
0N/A if(multiSelectionEnabled == b) {
0N/A return;
0N/A }
0N/A boolean oldValue = multiSelectionEnabled;
0N/A multiSelectionEnabled = b;
0N/A firePropertyChange(MULTI_SELECTION_ENABLED_CHANGED_PROPERTY, oldValue, multiSelectionEnabled);
0N/A }
0N/A
0N/A /**
0N/A * Returns true if multiple files can be selected.
0N/A * @return true if multiple files can be selected
0N/A * @see #setMultiSelectionEnabled
0N/A */
0N/A public boolean isMultiSelectionEnabled() {
0N/A return multiSelectionEnabled;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns true if hidden files are not shown in the file chooser;
0N/A * otherwise, returns false.
0N/A *
0N/A * @return the status of the file hiding property
0N/A * @see #setFileHidingEnabled
0N/A */
0N/A public boolean isFileHidingEnabled() {
0N/A return useFileHiding;
0N/A }
0N/A
0N/A /**
0N/A * Sets file hiding on or off. If true, hidden files are not shown
0N/A * in the file chooser. The job of determining which files are
0N/A * shown is done by the <code>FileView</code>.
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Sets file hiding on or off.
0N/A *
0N/A * @param b the boolean value that determines whether file hiding is
0N/A * turned on
0N/A * @see #isFileHidingEnabled
0N/A */
0N/A public void setFileHidingEnabled(boolean b) {
0N/A // Dump showFilesListener since we'll ignore it from now on
0N/A if (showFilesListener != null) {
0N/A Toolkit.getDefaultToolkit().removePropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
0N/A showFilesListener = null;
0N/A }
0N/A boolean oldValue = useFileHiding;
0N/A useFileHiding = b;
0N/A firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, oldValue, useFileHiding);
0N/A }
0N/A
0N/A /**
0N/A * Sets the current file filter. The file filter is used by the
0N/A * file chooser to filter out files from the user's view.
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Sets the File Filter used to filter out files of type.
0N/A *
0N/A * @param filter the new current file filter to use
0N/A * @see #getFileFilter
0N/A */
0N/A public void setFileFilter(FileFilter filter) {
0N/A FileFilter oldValue = fileFilter;
0N/A fileFilter = filter;
0N/A if (filter != null) {
0N/A if (isMultiSelectionEnabled() && selectedFiles != null && selectedFiles.length > 0) {
625N/A Vector<File> fList = new Vector<File>();
0N/A boolean failed = false;
625N/A for (File file : selectedFiles) {
625N/A if (filter.accept(file)) {
625N/A fList.add(file);
0N/A } else {
0N/A failed = true;
0N/A }
0N/A }
0N/A if (failed) {
625N/A setSelectedFiles((fList.size() == 0) ? null : fList.toArray(new File[fList.size()]));
0N/A }
0N/A } else if (selectedFile != null && !filter.accept(selectedFile)) {
0N/A setSelectedFile(null);
0N/A }
0N/A }
0N/A firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, oldValue, fileFilter);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns the currently selected file filter.
0N/A *
0N/A * @return the current file filter
0N/A * @see #setFileFilter
0N/A * @see #addChoosableFileFilter
0N/A */
0N/A public FileFilter getFileFilter() {
0N/A return fileFilter;
0N/A }
0N/A
0N/A /**
0N/A * Sets the file view to used to retrieve UI information, such as
0N/A * the icon that represents a file or the type description of a file.
0N/A *
0N/A * @beaninfo
0N/A * preferred: true
0N/A * bound: true
0N/A * description: Sets the File View used to get file type information.
0N/A *
0N/A * @see #getFileView
0N/A */
0N/A public void setFileView(FileView fileView) {
0N/A FileView oldValue = this.fileView;
0N/A this.fileView = fileView;
0N/A firePropertyChange(FILE_VIEW_CHANGED_PROPERTY, oldValue, fileView);
0N/A }
0N/A
0N/A /**
0N/A * Returns the current file view.
0N/A *
0N/A * @see #setFileView
0N/A */
0N/A public FileView getFileView() {
0N/A return fileView;
0N/A }
0N/A
0N/A // ******************************
0N/A // *****FileView delegation *****
0N/A // ******************************
0N/A
0N/A // NOTE: all of the following methods attempt to delegate
0N/A // first to the client set fileView, and if <code>null</code> is returned
0N/A // (or there is now client defined fileView) then calls the
0N/A // UI's default fileView.
0N/A
0N/A /**
0N/A * Returns the filename.
0N/A * @param f the <code>File</code>
0N/A * @return the <code>String</code> containing the filename for
0N/A * <code>f</code>
0N/A * @see FileView#getName
0N/A */
0N/A public String getName(File f) {
0N/A String filename = null;
0N/A if(f != null) {
0N/A if(getFileView() != null) {
0N/A filename = getFileView().getName(f);
0N/A }
3372N/A
3372N/A FileView uiFileView = getUI().getFileView(this);
3372N/A
0N/A if(filename == null && uiFileView != null) {
0N/A filename = uiFileView.getName(f);
0N/A }
0N/A }
0N/A return filename;
0N/A }
0N/A
0N/A /**
0N/A * Returns the file description.
0N/A * @param f the <code>File</code>
0N/A * @return the <code>String</code> containing the file description for
0N/A * <code>f</code>
0N/A * @see FileView#getDescription
0N/A */
0N/A public String getDescription(File f) {
0N/A String description = null;
0N/A if(f != null) {
0N/A if(getFileView() != null) {
0N/A description = getFileView().getDescription(f);
0N/A }
3372N/A
3372N/A FileView uiFileView = getUI().getFileView(this);
3372N/A
0N/A if(description == null && uiFileView != null) {
0N/A description = uiFileView.getDescription(f);
0N/A }
0N/A }
0N/A return description;
0N/A }
0N/A
0N/A /**
0N/A * Returns the file type.
0N/A * @param f the <code>File</code>
0N/A * @return the <code>String</code> containing the file type description for
0N/A * <code>f</code>
0N/A * @see FileView#getTypeDescription
0N/A */
0N/A public String getTypeDescription(File f) {
0N/A String typeDescription = null;
0N/A if(f != null) {
0N/A if(getFileView() != null) {
0N/A typeDescription = getFileView().getTypeDescription(f);
0N/A }
3372N/A
3372N/A FileView uiFileView = getUI().getFileView(this);
3372N/A
0N/A if(typeDescription == null && uiFileView != null) {
0N/A typeDescription = uiFileView.getTypeDescription(f);
0N/A }
0N/A }
0N/A return typeDescription;
0N/A }
0N/A
0N/A /**
0N/A * Returns the icon for this file or type of file, depending
0N/A * on the system.
0N/A * @param f the <code>File</code>
0N/A * @return the <code>Icon</code> for this file, or type of file
0N/A * @see FileView#getIcon
0N/A */
0N/A public Icon getIcon(File f) {
0N/A Icon icon = null;
0N/A if (f != null) {
0N/A if(getFileView() != null) {
0N/A icon = getFileView().getIcon(f);
0N/A }
3372N/A
3372N/A FileView uiFileView = getUI().getFileView(this);
3372N/A
0N/A if(icon == null && uiFileView != null) {
0N/A icon = uiFileView.getIcon(f);
0N/A }
0N/A }
0N/A return icon;
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the file (directory) can be visited.
0N/A * Returns false if the directory cannot be traversed.
0N/A * @param f the <code>File</code>
0N/A * @return true if the file/directory can be traversed, otherwise false
0N/A * @see FileView#isTraversable
0N/A */
0N/A public boolean isTraversable(File f) {
0N/A Boolean traversable = null;
0N/A if (f != null) {
0N/A if (getFileView() != null) {
0N/A traversable = getFileView().isTraversable(f);
0N/A }
3372N/A
3372N/A FileView uiFileView = getUI().getFileView(this);
3372N/A
0N/A if (traversable == null && uiFileView != null) {
0N/A traversable = uiFileView.isTraversable(f);
0N/A }
0N/A if (traversable == null) {
0N/A traversable = getFileSystemView().isTraversable(f);
0N/A }
0N/A }
0N/A return (traversable != null && traversable.booleanValue());
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the file should be displayed.
0N/A * @param f the <code>File</code>
0N/A * @return true if the file should be displayed, otherwise false
0N/A * @see FileFilter#accept
0N/A */
0N/A public boolean accept(File f) {
0N/A boolean shown = true;
0N/A if(f != null && fileFilter != null) {
0N/A shown = fileFilter.accept(f);
0N/A }
0N/A return shown;
0N/A }
0N/A
0N/A /**
0N/A * Sets the file system view that the <code>JFileChooser</code> uses for
0N/A * accessing and creating file system resources, such as finding
0N/A * the floppy drive and getting a list of root drives.
0N/A * @param fsv the new <code>FileSystemView</code>
0N/A *
0N/A * @beaninfo
0N/A * expert: true
0N/A * bound: true
0N/A * description: Sets the FileSytemView used to get filesystem information.
0N/A *
0N/A * @see FileSystemView
0N/A */
0N/A public void setFileSystemView(FileSystemView fsv) {
0N/A FileSystemView oldValue = fileSystemView;
0N/A fileSystemView = fsv;
0N/A firePropertyChange(FILE_SYSTEM_VIEW_CHANGED_PROPERTY, oldValue, fileSystemView);
0N/A }
0N/A
0N/A /**
0N/A * Returns the file system view.
0N/A * @return the <code>FileSystemView</code> object
0N/A * @see #setFileSystemView
0N/A */
0N/A public FileSystemView getFileSystemView() {
0N/A return fileSystemView;
0N/A }
0N/A
0N/A // **************************
0N/A // ***** Event Handling *****
0N/A // **************************
0N/A
0N/A /**
0N/A * Called by the UI when the user hits the Approve button
0N/A * (labeled "Open" or "Save", by default). This can also be
0N/A * called by the programmer.
0N/A * This method causes an action event to fire
0N/A * with the command string equal to
0N/A * <code>APPROVE_SELECTION</code>.
0N/A *
0N/A * @see #APPROVE_SELECTION
0N/A */
0N/A public void approveSelection() {
0N/A returnValue = APPROVE_OPTION;
0N/A if(dialog != null) {
0N/A dialog.setVisible(false);
0N/A }
0N/A fireActionPerformed(APPROVE_SELECTION);
0N/A }
0N/A
0N/A /**
0N/A * Called by the UI when the user chooses the Cancel button.
0N/A * This can also be called by the programmer.
0N/A * This method causes an action event to fire
0N/A * with the command string equal to
0N/A * <code>CANCEL_SELECTION</code>.
0N/A *
0N/A * @see #CANCEL_SELECTION
0N/A */
0N/A public void cancelSelection() {
0N/A returnValue = CANCEL_OPTION;
0N/A if(dialog != null) {
0N/A dialog.setVisible(false);
0N/A }
0N/A fireActionPerformed(CANCEL_SELECTION);
0N/A }
0N/A
0N/A /**
0N/A * Adds an <code>ActionListener</code> to the file chooser.
0N/A *
0N/A * @param l the listener to be added
0N/A *
0N/A * @see #approveSelection
0N/A * @see #cancelSelection
0N/A */
0N/A public void addActionListener(ActionListener l) {
0N/A listenerList.add(ActionListener.class, l);
0N/A }
0N/A
0N/A /**
0N/A * Removes an <code>ActionListener</code> from the file chooser.
0N/A *
0N/A * @param l the listener to be removed
0N/A *
0N/A * @see #addActionListener
0N/A */
0N/A public void removeActionListener(ActionListener l) {
0N/A listenerList.remove(ActionListener.class, l);
0N/A }
0N/A
0N/A /**
0N/A * Returns an array of all the action listeners
0N/A * registered on this file chooser.
0N/A *
0N/A * @return all of this file chooser's <code>ActionListener</code>s
0N/A * or an empty
0N/A * array if no action listeners are currently registered
0N/A *
0N/A * @see #addActionListener
0N/A * @see #removeActionListener
0N/A *
0N/A * @since 1.4
0N/A */
0N/A public ActionListener[] getActionListeners() {
625N/A return listenerList.getListeners(ActionListener.class);
0N/A }
0N/A
0N/A /**
0N/A * Notifies all listeners that have registered interest for
0N/A * notification on this event type. The event instance
0N/A * is lazily created using the <code>command</code> parameter.
0N/A *
0N/A * @see EventListenerList
0N/A */
0N/A protected void fireActionPerformed(String command) {
0N/A // Guaranteed to return a non-null array
0N/A Object[] listeners = listenerList.getListenerList();
0N/A long mostRecentEventTime = EventQueue.getMostRecentEventTime();
0N/A int modifiers = 0;
0N/A AWTEvent currentEvent = EventQueue.getCurrentEvent();
0N/A if (currentEvent instanceof InputEvent) {
0N/A modifiers = ((InputEvent)currentEvent).getModifiers();
0N/A } else if (currentEvent instanceof ActionEvent) {
0N/A modifiers = ((ActionEvent)currentEvent).getModifiers();
0N/A }
0N/A ActionEvent e = null;
0N/A // Process the listeners last to first, notifying
0N/A // those that are interested in this event
0N/A for (int i = listeners.length-2; i>=0; i-=2) {
0N/A if (listeners[i]==ActionListener.class) {
0N/A // Lazily create the event:
0N/A if (e == null) {
0N/A e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
0N/A command, mostRecentEventTime,
0N/A modifiers);
0N/A }
0N/A ((ActionListener)listeners[i+1]).actionPerformed(e);
0N/A }
0N/A }
0N/A }
0N/A
0N/A private static class WeakPCL implements PropertyChangeListener {
0N/A WeakReference<JFileChooser> jfcRef;
0N/A
0N/A public WeakPCL(JFileChooser jfc) {
625N/A jfcRef = new WeakReference<JFileChooser>(jfc);
0N/A }
0N/A public void propertyChange(PropertyChangeEvent ev) {
0N/A assert ev.getPropertyName().equals(SHOW_HIDDEN_PROP);
0N/A JFileChooser jfc = jfcRef.get();
0N/A if (jfc == null) {
0N/A // Our JFileChooser is no longer around, so we no longer need to
0N/A // listen for PropertyChangeEvents.
0N/A Toolkit.getDefaultToolkit().removePropertyChangeListener(SHOW_HIDDEN_PROP, this);
0N/A }
0N/A else {
0N/A boolean oldValue = jfc.useFileHiding;
0N/A jfc.useFileHiding = !((Boolean)ev.getNewValue()).booleanValue();
0N/A jfc.firePropertyChange(FILE_HIDING_CHANGED_PROPERTY, oldValue, jfc.useFileHiding);
0N/A }
0N/A }
0N/A }
0N/A
0N/A // *********************************
0N/A // ***** Pluggable L&F methods *****
0N/A // *********************************
0N/A
0N/A /**
0N/A * Resets the UI property to a value from the current look and feel.
0N/A *
0N/A * @see JComponent#updateUI
0N/A */
0N/A public void updateUI() {
0N/A if (isAcceptAllFileFilterUsed()) {
0N/A removeChoosableFileFilter(getAcceptAllFileFilter());
0N/A }
0N/A FileChooserUI ui = ((FileChooserUI)UIManager.getUI(this));
0N/A if (fileSystemView == null) {
0N/A // We were probably deserialized
0N/A setFileSystemView(FileSystemView.getFileSystemView());
0N/A }
0N/A setUI(ui);
0N/A
0N/A if(isAcceptAllFileFilterUsed()) {
0N/A addChoosableFileFilter(getAcceptAllFileFilter());
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a string that specifies the name of the L&F class
0N/A * that renders this component.
0N/A *
0N/A * @return the string "FileChooserUI"
0N/A * @see JComponent#getUIClassID
0N/A * @see UIDefaults#getUI
0N/A * @beaninfo
0N/A * expert: true
0N/A * description: A string that specifies the name of the L&F class.
0N/A */
0N/A public String getUIClassID() {
0N/A return uiClassID;
0N/A }
0N/A
0N/A /**
0N/A * Gets the UI object which implements the L&F for this component.
0N/A *
0N/A * @return the FileChooserUI object that implements the FileChooserUI L&F
0N/A */
0N/A public FileChooserUI getUI() {
0N/A return (FileChooserUI) ui;
0N/A }
0N/A
0N/A /**
0N/A * See <code>readObject</code> and <code>writeObject</code> in
0N/A * <code>JComponent</code> for more
0N/A * information about serialization in Swing.
0N/A */
0N/A private void readObject(java.io.ObjectInputStream in)
0N/A throws IOException, ClassNotFoundException {
0N/A in.defaultReadObject();
0N/A installShowFilesListener();
0N/A }
0N/A
0N/A /**
0N/A * See <code>readObject</code> and <code>writeObject</code> in
0N/A * <code>JComponent</code> for more
0N/A * information about serialization in Swing.
0N/A */
0N/A private void writeObject(ObjectOutputStream s) throws IOException {
0N/A FileSystemView fsv = null;
0N/A
0N/A if (isAcceptAllFileFilterUsed()) {
0N/A //The AcceptAllFileFilter is UI specific, it will be reset by
0N/A //updateUI() after deserialization
0N/A removeChoosableFileFilter(getAcceptAllFileFilter());
0N/A }
0N/A if (fileSystemView.equals(FileSystemView.getFileSystemView())) {
0N/A //The default FileSystemView is platform specific, it will be
0N/A //reset by updateUI() after deserialization
0N/A fsv = fileSystemView;
0N/A fileSystemView = null;
0N/A }
0N/A s.defaultWriteObject();
0N/A if (fsv != null) {
0N/A fileSystemView = fsv;
0N/A }
0N/A if (isAcceptAllFileFilterUsed()) {
0N/A addChoosableFileFilter(getAcceptAllFileFilter());
0N/A }
0N/A if (getUIClassID().equals(uiClassID)) {
0N/A byte count = JComponent.getWriteObjCounter(this);
0N/A JComponent.setWriteObjCounter(this, --count);
0N/A if (count == 0 && ui != null) {
0N/A ui.installUI(this);
0N/A }
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Returns a string representation of this <code>JFileChooser</code>.
0N/A * This method
0N/A * is intended to be used only for debugging purposes, and the
0N/A * content and format of the returned string may vary between
0N/A * implementations. The returned string may be empty but may not
0N/A * be <code>null</code>.
0N/A *
0N/A * @return a string representation of this <code>JFileChooser</code>
0N/A */
0N/A protected String paramString() {
0N/A String approveButtonTextString = (approveButtonText != null ?
0N/A approveButtonText: "");
0N/A String dialogTitleString = (dialogTitle != null ?
0N/A dialogTitle: "");
0N/A String dialogTypeString;
0N/A if (dialogType == OPEN_DIALOG) {
0N/A dialogTypeString = "OPEN_DIALOG";
0N/A } else if (dialogType == SAVE_DIALOG) {
0N/A dialogTypeString = "SAVE_DIALOG";
0N/A } else if (dialogType == CUSTOM_DIALOG) {
0N/A dialogTypeString = "CUSTOM_DIALOG";
0N/A } else dialogTypeString = "";
0N/A String returnValueString;
0N/A if (returnValue == CANCEL_OPTION) {
0N/A returnValueString = "CANCEL_OPTION";
0N/A } else if (returnValue == APPROVE_OPTION) {
0N/A returnValueString = "APPROVE_OPTION";
0N/A } else if (returnValue == ERROR_OPTION) {
0N/A returnValueString = "ERROR_OPTION";
0N/A } else returnValueString = "";
0N/A String useFileHidingString = (useFileHiding ?
0N/A "true" : "false");
0N/A String fileSelectionModeString;
0N/A if (fileSelectionMode == FILES_ONLY) {
0N/A fileSelectionModeString = "FILES_ONLY";
0N/A } else if (fileSelectionMode == DIRECTORIES_ONLY) {
0N/A fileSelectionModeString = "DIRECTORIES_ONLY";
0N/A } else if (fileSelectionMode == FILES_AND_DIRECTORIES) {
0N/A fileSelectionModeString = "FILES_AND_DIRECTORIES";
0N/A } else fileSelectionModeString = "";
0N/A String currentDirectoryString = (currentDirectory != null ?
0N/A currentDirectory.toString() : "");
0N/A String selectedFileString = (selectedFile != null ?
0N/A selectedFile.toString() : "");
0N/A
0N/A return super.paramString() +
0N/A ",approveButtonText=" + approveButtonTextString +
0N/A ",currentDirectory=" + currentDirectoryString +
0N/A ",dialogTitle=" + dialogTitleString +
0N/A ",dialogType=" + dialogTypeString +
0N/A ",fileSelectionMode=" + fileSelectionModeString +
0N/A ",returnValue=" + returnValueString +
0N/A ",selectedFile=" + selectedFileString +
0N/A ",useFileHiding=" + useFileHidingString;
0N/A }
0N/A
0N/A/////////////////
0N/A// Accessibility support
0N/A////////////////
0N/A
0N/A protected AccessibleContext accessibleContext = null;
0N/A
0N/A /**
0N/A * Gets the AccessibleContext associated with this JFileChooser.
0N/A * For file choosers, the AccessibleContext takes the form of an
0N/A * AccessibleJFileChooser.
0N/A * A new AccessibleJFileChooser instance is created if necessary.
0N/A *
0N/A * @return an AccessibleJFileChooser that serves as the
0N/A * AccessibleContext of this JFileChooser
0N/A */
0N/A public AccessibleContext getAccessibleContext() {
0N/A if (accessibleContext == null) {
0N/A accessibleContext = new AccessibleJFileChooser();
0N/A }
0N/A return accessibleContext;
0N/A }
0N/A
0N/A /**
0N/A * This class implements accessibility support for the
0N/A * <code>JFileChooser</code> class. It provides an implementation of the
0N/A * Java Accessibility API appropriate to file chooser user-interface
0N/A * elements.
0N/A */
0N/A protected class AccessibleJFileChooser extends AccessibleJComponent {
0N/A
0N/A /**
0N/A * Gets the role of this object.
0N/A *
0N/A * @return an instance of AccessibleRole describing the role of the
0N/A * object
0N/A * @see AccessibleRole
0N/A */
0N/A public AccessibleRole getAccessibleRole() {
0N/A return AccessibleRole.FILE_CHOOSER;
0N/A }
0N/A
0N/A } // inner class AccessibleJFileChooser
0N/A
0N/A}