jdk/src/java.desktop/share/classes/javax/swing/JFileChooser.java
changeset 26037 508779ce6619
parent 26001 991e1be0b235
parent 25859 3317bb8137f4
child 28231 b608ffcaed74
equal deleted inserted replaced
25992:e9b05e933ddd 26037:508779ce6619
    48 import java.awt.EventQueue;
    48 import java.awt.EventQueue;
    49 import java.awt.Toolkit;
    49 import java.awt.Toolkit;
    50 import java.awt.event.*;
    50 import java.awt.event.*;
    51 import java.beans.PropertyChangeListener;
    51 import java.beans.PropertyChangeListener;
    52 import java.beans.PropertyChangeEvent;
    52 import java.beans.PropertyChangeEvent;
       
    53 import java.io.InvalidObjectException;
       
    54 import java.io.ObjectInputStream;
    53 import java.lang.ref.WeakReference;
    55 import java.lang.ref.WeakReference;
    54 
    56 
    55 /**
    57 /**
    56  * <code>JFileChooser</code> provides a simple mechanism for the user to
    58  * <code>JFileChooser</code> provides a simple mechanism for the user to
    57  * choose a file.
    59  * choose a file.
   458      * @beaninfo
   460      * @beaninfo
   459      *  description: determines whether automatic drag handling is enabled
   461      *  description: determines whether automatic drag handling is enabled
   460      *        bound: false
   462      *        bound: false
   461      */
   463      */
   462     public void setDragEnabled(boolean b) {
   464     public void setDragEnabled(boolean b) {
       
   465         checkDragEnabled(b);
       
   466         dragEnabled = b;
       
   467     }
       
   468 
       
   469     private static void checkDragEnabled(boolean b) {
   463         if (b && GraphicsEnvironment.isHeadless()) {
   470         if (b && GraphicsEnvironment.isHeadless()) {
   464             throw new HeadlessException();
   471             throw new HeadlessException();
   465         }
   472         }
   466         dragEnabled = b;
       
   467     }
   473     }
   468 
   474 
   469     /**
   475     /**
   470      * Gets the value of the <code>dragEnabled</code> property.
   476      * Gets the value of the <code>dragEnabled</code> property.
   471      *
   477      *
   947     // PENDING(jeff) - fire button text change property
   953     // PENDING(jeff) - fire button text change property
   948     public void setDialogType(int dialogType) {
   954     public void setDialogType(int dialogType) {
   949         if(this.dialogType == dialogType) {
   955         if(this.dialogType == dialogType) {
   950             return;
   956             return;
   951         }
   957         }
   952         if(!(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG || dialogType == CUSTOM_DIALOG)) {
   958         checkDialogType(dialogType);
   953             throw new IllegalArgumentException("Incorrect Dialog Type: " + dialogType);
       
   954         }
       
   955         int oldValue = this.dialogType;
   959         int oldValue = this.dialogType;
   956         this.dialogType = dialogType;
   960         this.dialogType = dialogType;
   957         if(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG) {
   961         if(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG) {
   958             setApproveButtonText(null);
   962             setApproveButtonText(null);
   959         }
   963         }
   960         firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, oldValue, dialogType);
   964         firePropertyChange(DIALOG_TYPE_CHANGED_PROPERTY, oldValue, dialogType);
       
   965     }
       
   966 
       
   967     private static void checkDialogType(int dialogType) {
       
   968         if (!(dialogType == OPEN_DIALOG || dialogType == SAVE_DIALOG
       
   969                 || dialogType == CUSTOM_DIALOG)) {
       
   970             throw new IllegalArgumentException(
       
   971                     "Incorrect Dialog Type: " + dialogType);
       
   972         }
   961     }
   973     }
   962 
   974 
   963     /**
   975     /**
   964      * Sets the string that goes in the <code>JFileChooser</code> window's
   976      * Sets the string that goes in the <code>JFileChooser</code> window's
   965      * title bar.
   977      * title bar.
  1347     public void setFileSelectionMode(int mode) {
  1359     public void setFileSelectionMode(int mode) {
  1348         if(fileSelectionMode == mode) {
  1360         if(fileSelectionMode == mode) {
  1349             return;
  1361             return;
  1350         }
  1362         }
  1351 
  1363 
  1352         if ((mode == FILES_ONLY) || (mode == DIRECTORIES_ONLY) || (mode == FILES_AND_DIRECTORIES)) {
  1364         checkFileSelectionMode(mode);
  1353            int oldValue = fileSelectionMode;
  1365            int oldValue = fileSelectionMode;
  1354            fileSelectionMode = mode;
  1366            fileSelectionMode = mode;
  1355            firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, oldValue, fileSelectionMode);
  1367            firePropertyChange(FILE_SELECTION_MODE_CHANGED_PROPERTY, oldValue, fileSelectionMode);
  1356         } else {
  1368     }
  1357            throw new IllegalArgumentException("Incorrect Mode for file selection: " + mode);
  1369 
       
  1370     private static void checkFileSelectionMode(int mode) {
       
  1371         if ((mode != FILES_ONLY) && (mode != DIRECTORIES_ONLY)
       
  1372                 && (mode != FILES_AND_DIRECTORIES)) {
       
  1373             throw new IllegalArgumentException(
       
  1374                     "Incorrect Mode for file selection: " + mode);
  1358         }
  1375         }
  1359     }
  1376     }
  1360 
  1377 
  1361     /**
  1378     /**
  1362      * Returns the current file-selection mode.  The default is
  1379      * Returns the current file-selection mode.  The default is
  1899      * <code>JComponent</code> for more
  1916      * <code>JComponent</code> for more
  1900      * information about serialization in Swing.
  1917      * information about serialization in Swing.
  1901      */
  1918      */
  1902     private void readObject(java.io.ObjectInputStream in)
  1919     private void readObject(java.io.ObjectInputStream in)
  1903             throws IOException, ClassNotFoundException {
  1920             throws IOException, ClassNotFoundException {
  1904         in.defaultReadObject();
  1921         ObjectInputStream.GetField f = in.readFields();
       
  1922 
       
  1923         dialogTitle = (String) f.get("dialogTitle", null);
       
  1924         approveButtonText = (String) f.get("approveButtonText", null);
       
  1925         approveButtonToolTipText =
       
  1926                 (String) f.get("approveButtonToolTipText", null);
       
  1927         approveButtonMnemonic = f.get("approveButtonMnemonic", 0);
       
  1928         @SuppressWarnings("unchecked")
       
  1929         Vector<FileFilter> newFilters = (Vector<FileFilter>) f.get("filters", null);
       
  1930         if (newFilters == null) {
       
  1931             throw new InvalidObjectException("Null filters");
       
  1932         }
       
  1933         filters = newFilters;
       
  1934         dialog = (JDialog) f.get("dialog", null);
       
  1935         int newDialogType = f.get("dialogType", OPEN_DIALOG);
       
  1936         checkDialogType(newDialogType);
       
  1937         dialogType = newDialogType;
       
  1938         returnValue = f.get("returnValue", 0);
       
  1939         accessory = (JComponent) f.get("accessory", null);
       
  1940         fileView = (FileView) f.get("fileView", null);
       
  1941         controlsShown = f.get("controlsShown", false);
       
  1942         useFileHiding = f.get("useFileHiding", false);
       
  1943         int newFileSelectionMode = f.get("fileSelectionMode", FILES_ONLY);
       
  1944         checkFileSelectionMode(newFileSelectionMode);
       
  1945         fileSelectionMode = newFileSelectionMode;
       
  1946         multiSelectionEnabled = f.get("multiSelectionEnabled", false);
       
  1947         useAcceptAllFileFilter = f.get("useAcceptAllFileFilter", false);
       
  1948         boolean newDragEnabled = f.get("dragEnabled", false);
       
  1949         checkDragEnabled(newDragEnabled);
       
  1950         dragEnabled = newDragEnabled;
       
  1951         fileFilter = (FileFilter) f.get("fileFilter", null);
       
  1952         fileSystemView = (FileSystemView) f.get("fileSystemView", null);
       
  1953         currentDirectory = (File) f.get("currentDirectory", null);
       
  1954         selectedFile = (File) f.get("selectedFile", null);
       
  1955         selectedFiles = (File[]) f.get("selectedFiles", null);
       
  1956         accessibleContext = (AccessibleContext) f.get("accessibleContext", null);
       
  1957 
  1905         installShowFilesListener();
  1958         installShowFilesListener();
  1906     }
  1959     }
  1907 
  1960 
  1908     /**
  1961     /**
  1909      * See <code>readObject</code> and <code>writeObject</code> in
  1962      * See <code>readObject</code> and <code>writeObject</code> in