jdk/src/share/classes/javax/swing/JFileChooser.java

Print this page

        

@@ -20,11 +20,10 @@
  *
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
-
 package javax.swing;
 
 import javax.swing.event.*;
 import javax.swing.filechooser.*;
 import javax.swing.plaf.FileChooserUI;

@@ -46,10 +45,12 @@
 import java.awt.GraphicsEnvironment;
 import java.awt.HeadlessException;
 import java.awt.EventQueue;
 import java.awt.Toolkit;
 import java.awt.event.*;
+import java.beans.JavaBean;
+import java.beans.BeanProperty;
 import java.beans.PropertyChangeListener;
 import java.beans.PropertyChangeEvent;
 import java.io.InvalidObjectException;
 import java.io.ObjectInputStream;
 import java.lang.ref.WeakReference;

@@ -81,17 +82,15 @@
  * <strong>Warning:</strong> Swing is not thread safe. For more
  * information see <a
  * href="package-summary.html#threading">Swing's Threading
  * Policy</a>.
  *
- * @beaninfo
- *   attribute: isContainer false
- * description: A component which allows for the interactive selection of a file.
- *
  * @author Jeff Dinkins
  * @since 1.2
  */
+@JavaBean(defaultProperty = "UI", description = "A component which allows for the interactive selection of a file.")
+@SwingContainer(false)
 @SuppressWarnings("serial") // Superclass is not serializable across versions
 public class JFileChooser extends JComponent implements Accessible {
 
     /**
      * @see #getUIClassID

@@ -454,15 +453,13 @@
      * @see java.awt.GraphicsEnvironment#isHeadless
      * @see #getDragEnabled
      * @see #setTransferHandler
      * @see TransferHandler
      * @since 1.4
-     *
-     * @beaninfo
-     *  description: determines whether automatic drag handling is enabled
-     *        bound: false
      */
+    @BeanProperty(bound = false, description
+            = "determines whether automatic drag handling is enabled")
     public void setDragEnabled(boolean b) {
         checkDragEnabled(b);
         dragEnabled = b;
     }
 

@@ -503,18 +500,15 @@
     /**
      * 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.
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     *
      * @see #getSelectedFile
      *
      * @param file the selected file
      */
+    @BeanProperty(preferred = true)
     public void setSelectedFile(File file) {
         File oldValue = selectedFile;
         selectedFile = file;
         if(selectedFile != null) {
             if (file.isAbsolute() && !getFileSystemView().isParent(getCurrentDirectory(), selectedFile)) {

@@ -544,14 +538,13 @@
     /**
      * Sets the list of selected files if the file chooser is
      * set to allow multiple selection.
      *
      * @param selectedFiles an array {@code File}s to be selected
-     * @beaninfo
-     *       bound: true
-     * description: The list of selected files if the chooser is in multiple selection mode.
      */
+    @BeanProperty(description
+            = "The list of selected files if the chooser is in multiple selection mode.")
     public void setSelectedFiles(File[] selectedFiles) {
         File[] oldValue = this.selectedFiles;
         if (selectedFiles == null || selectedFiles.length == 0) {
             selectedFiles = null;
             this.selectedFiles = null;

@@ -584,18 +577,15 @@
      * 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.
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: The directory that the JFileChooser is showing files of.
-     *
      * @param dir the current directory to point to
      * @see #getCurrentDirectory
      */
+    @BeanProperty(preferred = true, description
+            = "The directory that the JFileChooser is showing files of.")
     public void setCurrentDirectory(File dir) {
         File oldValue = currentDirectory;
 
         if (dir != null && !dir.exists()) {
             dir = currentDirectory;

@@ -878,19 +868,16 @@
      * as the name of the property.
      *
      * @param b <code>false</code> if control buttons should not be
      *    shown; otherwise, <code>true</code>
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: Sets whether the approve &amp; cancel buttons are shown.
-     *
      * @see #getControlButtonsAreShown
      * @see #CONTROL_BUTTONS_ARE_SHOWN_CHANGED_PROPERTY
      * @since 1.3
      */
+    @BeanProperty(preferred = true, description
+            = "Sets whether the approve &amp; cancel buttons are shown.")
     public void setControlButtonsAreShown(boolean b) {
         if(controlsShown == b) {
             return;
         }
         boolean oldValue = controlsShown;

@@ -936,23 +923,20 @@
      * <li>JFileChooser.CUSTOM_DIALOG
      * </ul>
      *
      * @exception IllegalArgumentException if <code>dialogType</code> is
      *                          not legal
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: The type (open, save, custom) of the JFileChooser.
-     *        enum:
-     *              OPEN_DIALOG JFileChooser.OPEN_DIALOG
-     *              SAVE_DIALOG JFileChooser.SAVE_DIALOG
-     *              CUSTOM_DIALOG JFileChooser.CUSTOM_DIALOG
      *
      * @see #getDialogType
      * @see #setApproveButtonText
      */
     // PENDING(jeff) - fire button text change property
+    @BeanProperty(preferred = true, enumerationValues = {
+            "JFileChooser.OPEN_DIALOG",
+            "JFileChooser.SAVE_DIALOG",
+            "JFileChooser.CUSTOM_DIALOG"}, description
+            = "The type (open, save, custom) of the JFileChooser.")
     public void setDialogType(int dialogType) {
         if(this.dialogType == dialogType) {
             return;
         }
         checkDialogType(dialogType);

@@ -976,18 +960,15 @@
      * Sets the string that goes in the <code>JFileChooser</code> window's
      * title bar.
      *
      * @param dialogTitle the new <code>String</code> for the title bar
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: The title of the JFileChooser dialog window.
-     *
      * @see #getDialogTitle
      *
      */
+    @BeanProperty(preferred = true, description
+            = "The title of the JFileChooser dialog window.")
     public void setDialogTitle(String dialogTitle) {
         String oldValue = this.dialogTitle;
         this.dialogTitle = dialogTitle;
         if(dialog != null) {
             dialog.setTitle(dialogTitle);

@@ -1013,20 +994,17 @@
 
     /**
      * Sets the tooltip text used in the <code>ApproveButton</code>.
      * If <code>null</code>, the UI object will determine the button's text.
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: The tooltip text for the ApproveButton.
-     *
      * @param toolTipText the tooltip text for the approve button
      * @see #setApproveButtonText
      * @see #setDialogType
      * @see #showDialog
      */
+    @BeanProperty(preferred = true, description
+            = "The tooltip text for the ApproveButton.")
     public void setApproveButtonToolTipText(String toolTipText) {
         if(approveButtonToolTipText == toolTipText) {
             return;
         }
         String oldValue = approveButtonToolTipText;

@@ -1062,17 +1040,14 @@
     /**
      * Sets the approve button's mnemonic using a numeric keycode.
      *
      * @param mnemonic  an integer value for the mnemonic key
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: The mnemonic key accelerator for the ApproveButton.
-     *
      * @see #getApproveButtonMnemonic
      */
+    @BeanProperty(preferred = true, description
+            = "The mnemonic key accelerator for the ApproveButton.")
     public void setApproveButtonMnemonic(int mnemonic) {
         if(approveButtonMnemonic == mnemonic) {
            return;
         }
         int oldValue = approveButtonMnemonic;

@@ -1097,22 +1072,19 @@
 
     /**
      * Sets the text used in the <code>ApproveButton</code> in the
      * <code>FileChooserUI</code>.
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: The text that goes in the ApproveButton.
-     *
      * @param approveButtonText the text used in the <code>ApproveButton</code>
      *
      * @see #getApproveButtonText
      * @see #setDialogType
      * @see #showDialog
      */
     // PENDING(jeff) - have ui set this on dialog type change
+    @BeanProperty(preferred = true, description
+            = "The text that goes in the ApproveButton.")
     public void setApproveButtonText(String approveButtonText) {
         if(this.approveButtonText == approveButtonText) {
             return;
         }
         String oldValue = this.approveButtonText;

@@ -1145,10 +1117,11 @@
      *
      * @see #addChoosableFileFilter
      * @see #removeChoosableFileFilter
      * @see #resetChoosableFileFilters
      */
+    @BeanProperty(bound = false)
     public FileFilter[] getChoosableFileFilters() {
         FileFilter[] filterArray = new FileFilter[filters.size()];
         filters.copyInto(filterArray);
         return filterArray;
     }

@@ -1159,20 +1132,17 @@
      * {@link #setFileSelectionMode setFileSelectionMode}.
      *
      * @param filter the <code>FileFilter</code> to add to the choosable file
      *               filter list
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: Adds a filter to the list of user choosable file filters.
-     *
      * @see #getChoosableFileFilters
      * @see #removeChoosableFileFilter
      * @see #resetChoosableFileFilters
      * @see #setFileSelectionMode
      */
+    @BeanProperty(preferred = true, description
+            = "Adds a filter to the list of user choosable file filters.")
     public void addChoosableFileFilter(FileFilter filter) {
         if(filter != null && !filters.contains(filter)) {
             FileFilter[] oldValue = getChoosableFileFilters();
             filters.addElement(filter);
             firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY, oldValue, getChoosableFileFilters());

@@ -1246,10 +1216,11 @@
      * Returns the <code>AcceptAll</code> file filter.
      * For example, on Microsoft Windows this would be All Files (*.*).
      *
      * @return the {@code AcceptAll} file filter
      */
+    @BeanProperty(bound = false)
     public FileFilter getAcceptAllFileFilter() {
         FileFilter filter = null;
         if(getUI() != null) {
             filter = getUI().getAcceptAllFileFilter(this);
         }

@@ -1274,20 +1245,18 @@
     * If true, the <code>AcceptAll</code> file filter will become the
     * actively used file filter.
     *
     * @param b a {@code boolean} which determines whether the {@code AcceptAll}
     *          file filter is an available choice in the choosable filter list
-    * @beaninfo
-    *   preferred: true
-    *       bound: true
-    * description: Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.
     *
     * @see #isAcceptAllFileFilterUsed
     * @see #getAcceptAllFileFilter
     * @see #setFileFilter
     * @since 1.3
     */
+    @BeanProperty(preferred = true, description
+            = "Sets whether the AcceptAll FileFilter is used as an available choice in the choosable filter list.")
     public void setAcceptAllFileFilterUsed(boolean b) {
         boolean oldValue = useAcceptAllFileFilter;
         useAcceptAllFileFilter = b;
         if(!b) {
             removeChoosableFileFilter(getAcceptAllFileFilter());

@@ -1317,15 +1286,13 @@
      * Note: if there was a previous accessory, you should unregister
      * any listeners that the accessory might have registered with the
      * file chooser.
      *
      * @param newAccessory the accessory component to be set
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: Sets the accessory component on the JFileChooser.
      */
+    @BeanProperty(preferred = true, description
+            = "Sets the accessory component on the JFileChooser.")
     public void setAccessory(JComponent newAccessory) {
         JComponent oldValue = accessory;
         accessory = newAccessory;
         firePropertyChange(ACCESSORY_CHANGED_PROPERTY, oldValue, accessory);
     }

@@ -1343,21 +1310,18 @@
      * <li>JFileChooser.FILES_AND_DIRECTORIES
      * </ul>
      *
      * @exception IllegalArgumentException  if <code>mode</code> is an
      *                          illegal file selection mode
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: Sets the types of files that the JFileChooser can choose.
-     *        enum: FILES_ONLY JFileChooser.FILES_ONLY
-     *              DIRECTORIES_ONLY JFileChooser.DIRECTORIES_ONLY
-     *              FILES_AND_DIRECTORIES JFileChooser.FILES_AND_DIRECTORIES
-     *
      *
      * @see #getFileSelectionMode
      */
+    @BeanProperty(preferred = true, enumerationValues = {
+            "JFileChooser.FILES_ONLY",
+            "JFileChooser.DIRECTORIES_ONLY",
+            "JFileChooser.FILES_AND_DIRECTORIES"}, description
+            = "Sets the types of files that the JFileChooser can choose.")
     public void setFileSelectionMode(int mode) {
         if(fileSelectionMode == mode) {
             return;
         }
 

@@ -1397,10 +1361,11 @@
      *
      * @return true if files are selectable, false otherwise
      * @see #setFileSelectionMode
      * @see #getFileSelectionMode
      */
+    @BeanProperty(bound = false)
     public boolean isFileSelectionEnabled() {
         return ((fileSelectionMode == FILES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
     }
 
     /**

@@ -1409,24 +1374,24 @@
      *
      * @return true if directories are selectable, false otherwise
      * @see #setFileSelectionMode
      * @see #getFileSelectionMode
      */
+    @BeanProperty(bound = false)
     public boolean isDirectorySelectionEnabled() {
         return ((fileSelectionMode == DIRECTORIES_ONLY) || (fileSelectionMode == FILES_AND_DIRECTORIES));
     }
 
     /**
      * Sets the file chooser to allow multiple file selections.
      *
      * @param b true if multiple files may be selected
-     * @beaninfo
-     *       bound: true
-     * description: Sets multiple file selection mode.
      *
      * @see #isMultiSelectionEnabled
      */
+    @BeanProperty(description
+            = "Sets multiple file selection mode.")
     public void setMultiSelectionEnabled(boolean b) {
         if(multiSelectionEnabled == b) {
             return;
         }
         boolean oldValue = multiSelectionEnabled;

@@ -1458,19 +1423,16 @@
     /**
      * 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 <code>FileView</code>.
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: Sets file hiding on or off.
-     *
      * @param b the boolean value that determines whether file hiding is
      *          turned on
      * @see #isFileHidingEnabled
      */
+    @BeanProperty(preferred = true, description
+            = "Sets file hiding on or off.")
     public void setFileHidingEnabled(boolean b) {
         // Dump showFilesListener since we'll ignore it from now on
         if (showFilesListener != null) {
             Toolkit.getDefaultToolkit().removePropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
             showFilesListener = null;

@@ -1482,18 +1444,15 @@
 
     /**
      * Sets the current file filter. The file filter is used by the
      * file chooser to filter out files from the user's view.
      *
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: Sets the File Filter used to filter out files of type.
-     *
      * @param filter the new current file filter to use
      * @see #getFileFilter
      */
+    @BeanProperty(preferred = true, description
+            = "Sets the File Filter used to filter out files of type.")
     public void setFileFilter(FileFilter filter) {
         FileFilter oldValue = fileFilter;
         fileFilter = filter;
         if (filter != null) {
             if (isMultiSelectionEnabled() && selectedFiles != null && selectedFiles.length > 0) {

@@ -1531,17 +1490,15 @@
     /**
      * Sets the file view to be used to retrieve UI information, such as
      * the icon that represents a file or the type description of a file.
      *
      * @param fileView a {@code FileView} to be used to retrieve UI information
-     * @beaninfo
-     *   preferred: true
-     *       bound: true
-     * description: Sets the File View used to get file type information.
      *
      * @see #getFileView
      */
+    @BeanProperty(preferred = true, description
+            = "Sets the File View used to get file type information.")
     public void setFileView(FileView fileView) {
         FileView oldValue = this.fileView;
         this.fileView = fileView;
         firePropertyChange(FILE_VIEW_CHANGED_PROPERTY, oldValue, fileView);
     }

@@ -1701,17 +1658,14 @@
      * Sets the file system view that the <code>JFileChooser</code> uses for
      * accessing and creating file system resources, such as finding
      * the floppy drive and getting a list of root drives.
      * @param fsv  the new <code>FileSystemView</code>
      *
-     * @beaninfo
-     *      expert: true
-     *       bound: true
-     * description: Sets the FileSytemView used to get filesystem information.
-     *
      * @see FileSystemView
      */
+    @BeanProperty(expert = true, description
+            = "Sets the FileSytemView used to get filesystem information.")
     public void setFileSystemView(FileSystemView fsv) {
         FileSystemView oldValue = fileSystemView;
         fileSystemView = fsv;
         firePropertyChange(FILE_SYSTEM_VIEW_CHANGED_PROPERTY, oldValue, fileSystemView);
     }

@@ -1798,10 +1752,11 @@
      * @see #addActionListener
      * @see #removeActionListener
      *
      * @since 1.4
      */
+    @BeanProperty(bound = false)
     public ActionListener[] getActionListeners() {
         return listenerList.getListeners(ActionListener.class);
     }
 
     /**

@@ -1892,23 +1847,23 @@
      * that renders this component.
      *
      * @return the string "FileChooserUI"
      * @see JComponent#getUIClassID
      * @see UIDefaults#getUI
-     * @beaninfo
-     *        expert: true
-     *   description: A string that specifies the name of the L&amp;F class.
      */
+    @BeanProperty(bound = false, expert = true, description
+            = "A string that specifies the name of the L&amp;F class.")
     public String getUIClassID() {
         return uiClassID;
     }
 
     /**
      * Gets the UI object which implements the L&amp;F for this component.
      *
      * @return the FileChooserUI object that implements the FileChooserUI L&amp;F
      */
+    @BeanProperty(bound = false)
     public FileChooserUI getUI() {
         return (FileChooserUI) ui;
     }
 
     /**

@@ -2067,10 +2022,11 @@
      * A new AccessibleJFileChooser instance is created if necessary.
      *
      * @return an AccessibleJFileChooser that serves as the
      *         AccessibleContext of this JFileChooser
      */
+    @BeanProperty(bound = false)
     public AccessibleContext getAccessibleContext() {
         if (accessibleContext == null) {
             accessibleContext = new AccessibleJFileChooser();
         }
         return accessibleContext;