< prev index next >

src/java.desktop/share/classes/javax/swing/filechooser/FileSystemView.java

Print this page




  56  * Java Licensees may want to provide a different implementation of
  57  * FileSystemView to better handle a given operating system.
  58  *
  59  * @author Jeff Dinkins
  60  */
  61 
  62 // PENDING(jeff) - need to provide a specification for
  63 // how Mac/OS2/BeOS/etc file systems can modify FileSystemView
  64 // to handle their particular type of file system.
  65 
  66 public abstract class FileSystemView {
  67 
  68     static FileSystemView windowsFileSystemView = null;
  69     static FileSystemView unixFileSystemView = null;
  70     //static FileSystemView macFileSystemView = null;
  71     static FileSystemView genericFileSystemView = null;
  72 
  73     private boolean useSystemExtensionHiding =
  74             UIManager.getDefaults().getBoolean("FileChooser.useSystemExtensionHiding");
  75 




  76     public static FileSystemView getFileSystemView() {
  77         if(File.separatorChar == '\\') {
  78             if(windowsFileSystemView == null) {
  79                 windowsFileSystemView = new WindowsFileSystemView();
  80             }
  81             return windowsFileSystemView;
  82         }
  83 
  84         if(File.separatorChar == '/') {
  85             if(unixFileSystemView == null) {
  86                 unixFileSystemView = new UnixFileSystemView();
  87             }
  88             return unixFileSystemView;
  89         }
  90 
  91         // if(File.separatorChar == ':') {
  92         //    if(macFileSystemView == null) {
  93         //      macFileSystemView = new MacFileSystemView();
  94         //    }
  95         //    return macFileSystemView;
  96         //}
  97 
  98         if(genericFileSystemView == null) {
  99             genericFileSystemView = new GenericFileSystemView();
 100         }
 101         return genericFileSystemView;
 102     }
 103 



 104     public FileSystemView() {
 105         final WeakReference<FileSystemView> weakReference = new WeakReference<FileSystemView>(this);
 106 
 107         UIManager.addPropertyChangeListener(new PropertyChangeListener() {
 108             public void propertyChange(PropertyChangeEvent evt) {
 109                 FileSystemView fileSystemView = weakReference.get();
 110 
 111                 if (fileSystemView == null) {
 112                     // FileSystemView was destroyed
 113                     UIManager.removePropertyChangeListener(this);
 114                 } else {
 115                     if (evt.getPropertyName().equals("lookAndFeel")) {
 116                         fileSystemView.useSystemExtensionHiding =
 117                                 UIManager.getDefaults().getBoolean("FileChooser.useSystemExtensionHiding");
 118                     }
 119                 }
 120             }
 121         });
 122     }
 123 


 407      *         on this system
 408      */
 409     public File[] getRoots() {
 410         // Don't cache this array, because filesystem might change
 411         File[] roots = (File[])ShellFolder.get("roots");
 412 
 413         for (int i = 0; i < roots.length; i++) {
 414             if (isFileSystemRoot(roots[i])) {
 415                 roots[i] = createFileSystemRoot(roots[i]);
 416             }
 417         }
 418         return roots;
 419     }
 420 
 421 
 422     // Providing default implementations for the remaining methods
 423     // because most OS file systems will likely be able to use this
 424     // code. If a given OS can't, override these methods in its
 425     // implementation.
 426 




 427     public File getHomeDirectory() {
 428         return createFileObject(System.getProperty("user.home"));
 429     }
 430 
 431     /**
 432      * Return the user's default starting directory for the file chooser.
 433      *
 434      * @return a <code>File</code> object representing the default
 435      *         starting folder
 436      * @since 1.4
 437      */
 438     public File getDefaultDirectory() {
 439         File f = (File)ShellFolder.get("fileChooserDefaultFolder");
 440         if (isFileSystemRoot(f)) {
 441             f = createFileSystemRoot(f);
 442         }
 443         return f;
 444     }
 445 
 446     /**




  56  * Java Licensees may want to provide a different implementation of
  57  * FileSystemView to better handle a given operating system.
  58  *
  59  * @author Jeff Dinkins
  60  */
  61 
  62 // PENDING(jeff) - need to provide a specification for
  63 // how Mac/OS2/BeOS/etc file systems can modify FileSystemView
  64 // to handle their particular type of file system.
  65 
  66 public abstract class FileSystemView {
  67 
  68     static FileSystemView windowsFileSystemView = null;
  69     static FileSystemView unixFileSystemView = null;
  70     //static FileSystemView macFileSystemView = null;
  71     static FileSystemView genericFileSystemView = null;
  72 
  73     private boolean useSystemExtensionHiding =
  74             UIManager.getDefaults().getBoolean("FileChooser.useSystemExtensionHiding");
  75 
  76     /**
  77      * Returns the file system view.
  78      * @return the file system view
  79      */
  80     public static FileSystemView getFileSystemView() {
  81         if(File.separatorChar == '\\') {
  82             if(windowsFileSystemView == null) {
  83                 windowsFileSystemView = new WindowsFileSystemView();
  84             }
  85             return windowsFileSystemView;
  86         }
  87 
  88         if(File.separatorChar == '/') {
  89             if(unixFileSystemView == null) {
  90                 unixFileSystemView = new UnixFileSystemView();
  91             }
  92             return unixFileSystemView;
  93         }
  94 
  95         // if(File.separatorChar == ':') {
  96         //    if(macFileSystemView == null) {
  97         //      macFileSystemView = new MacFileSystemView();
  98         //    }
  99         //    return macFileSystemView;
 100         //}
 101 
 102         if(genericFileSystemView == null) {
 103             genericFileSystemView = new GenericFileSystemView();
 104         }
 105         return genericFileSystemView;
 106     }
 107 
 108     /**
 109      * Constructs a FileSystemView.
 110      */
 111     public FileSystemView() {
 112         final WeakReference<FileSystemView> weakReference = new WeakReference<FileSystemView>(this);
 113 
 114         UIManager.addPropertyChangeListener(new PropertyChangeListener() {
 115             public void propertyChange(PropertyChangeEvent evt) {
 116                 FileSystemView fileSystemView = weakReference.get();
 117 
 118                 if (fileSystemView == null) {
 119                     // FileSystemView was destroyed
 120                     UIManager.removePropertyChangeListener(this);
 121                 } else {
 122                     if (evt.getPropertyName().equals("lookAndFeel")) {
 123                         fileSystemView.useSystemExtensionHiding =
 124                                 UIManager.getDefaults().getBoolean("FileChooser.useSystemExtensionHiding");
 125                     }
 126                 }
 127             }
 128         });
 129     }
 130 


 414      *         on this system
 415      */
 416     public File[] getRoots() {
 417         // Don't cache this array, because filesystem might change
 418         File[] roots = (File[])ShellFolder.get("roots");
 419 
 420         for (int i = 0; i < roots.length; i++) {
 421             if (isFileSystemRoot(roots[i])) {
 422                 roots[i] = createFileSystemRoot(roots[i]);
 423             }
 424         }
 425         return roots;
 426     }
 427 
 428 
 429     // Providing default implementations for the remaining methods
 430     // because most OS file systems will likely be able to use this
 431     // code. If a given OS can't, override these methods in its
 432     // implementation.
 433 
 434     /**
 435      * Returns the home directory.
 436      * @return the home directory
 437      */
 438     public File getHomeDirectory() {
 439         return createFileObject(System.getProperty("user.home"));
 440     }
 441 
 442     /**
 443      * Return the user's default starting directory for the file chooser.
 444      *
 445      * @return a <code>File</code> object representing the default
 446      *         starting folder
 447      * @since 1.4
 448      */
 449     public File getDefaultDirectory() {
 450         File f = (File)ShellFolder.get("fileChooserDefaultFolder");
 451         if (isFileSystemRoot(f)) {
 452             f = createFileSystemRoot(f);
 453         }
 454         return f;
 455     }
 456 
 457     /**


< prev index next >