< prev index next >

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

Print this page




  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) {


 237     public Icon getSystemIcon(File f) {
 238         if (f == null) {
 239             return null;
 240         }
 241 
 242         ShellFolder sf;
 243 
 244         try {
 245             sf = getShellFolder(f);
 246         } catch (FileNotFoundException e) {
 247             return null;
 248         }
 249 
 250         Image img = sf.getIcon(false);
 251 
 252         if (img != null) {
 253             return new ImageIcon(img, sf.getFolderType());
 254         } else {
 255             return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
 256         }










































 257     }
 258 
 259     /**
 260      * On Windows, a file can appear in multiple folders, other than its
 261      * parent directory in the filesystem. Folder could for example be the
 262      * "Desktop" folder which is not the same as file.getParentFile().
 263      *
 264      * @param folder a <code>File</code> object representing a directory or special folder
 265      * @param file a <code>File</code> object
 266      * @return <code>true</code> if <code>folder</code> is a directory or special folder and contains <code>file</code>.
 267      * @since 1.4
 268      */
 269     public boolean isParent(File folder, File file) {
 270         if (folder == null || file == null) {
 271             return false;
 272         } else if (folder instanceof ShellFolder) {
 273                 File parent = file.getParentFile();
 274                 if (parent != null && parent.equals(folder)) {
 275                     return true;
 276                 }




  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      * An icon image query option that requests the small file icon.
  78      *
  79      * @since 10
  80      */
  81     public static final int FILE_ICON_SMALL = -1;
  82 
  83     /**
  84      * An icon image query option that requests the large file icon.
  85      *
  86      * @since 10
  87      */
  88     public static final int FILE_ICON_LARGE = -2;
  89 
  90     /**
  91      * Returns the file system view.
  92      * @return the file system view
  93      */
  94     public static FileSystemView getFileSystemView() {
  95         if(File.separatorChar == '\\') {
  96             if(windowsFileSystemView == null) {
  97                 windowsFileSystemView = new WindowsFileSystemView();
  98             }
  99             return windowsFileSystemView;
 100         }
 101 
 102         if(File.separatorChar == '/') {
 103             if(unixFileSystemView == null) {
 104                 unixFileSystemView = new UnixFileSystemView();
 105             }
 106             return unixFileSystemView;
 107         }
 108 
 109         // if(File.separatorChar == ':') {
 110         //    if(macFileSystemView == null) {


 251     public Icon getSystemIcon(File f) {
 252         if (f == null) {
 253             return null;
 254         }
 255 
 256         ShellFolder sf;
 257 
 258         try {
 259             sf = getShellFolder(f);
 260         } catch (FileNotFoundException e) {
 261             return null;
 262         }
 263 
 264         Image img = sf.getIcon(false);
 265 
 266         if (img != null) {
 267             return new ImageIcon(img, sf.getFolderType());
 268         } else {
 269             return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
 270         }
 271     }
 272 
 273     /**
 274      * Returns icon image if it is associated with the specified file or
 275      * {@code null} otherwise. Depending on the passed {@code size} different
 276      * sizes of file icon may be queried. If value of the {@code size} argument
 277      * equals to {@code #FILE_ICON_SMALL} or {@code #FILE_ICON_LARGE} then
 278      * the small or large file icon variant is returned correspondingly.
 279      * For any positive size value the exact file icon size is queried.
 280      *
 281      * @param file a file
 282      * @param size size to query
 283      * @return file icon
 284      * @throws NullPointerException if {@code file} equals {@code null}
 285      * @see #FILE_ICON_SMALL
 286      * @see #FILE_ICON_LARGE
 287      * @since 10
 288      */
 289     public ImageIcon getSystemIcon(File file, int size) {
 290         if (file == null) {
 291             throw new NullPointerException("file is null");
 292         }
 293         ShellFolder sf;
 294         try {
 295             sf = ShellFolder.getShellFolder(file);
 296         } catch (FileNotFoundException e) {
 297             return null;
 298         }
 299         Image img = null;
 300         if (size == FILE_ICON_SMALL) {
 301             img = sf.getIcon(false);
 302         } else if (size == FILE_ICON_LARGE) {
 303             img = sf.getIcon(true);
 304         } else if (size > 0) {
 305             img = sf.getIcon(size);
 306         } else {
 307             throw new IllegalArgumentException("Wrong size value +" + size);
 308         }
 309         if (img != null) {
 310             return new ImageIcon(img, sf.getFolderType());
 311         }
 312         return null;
 313     }
 314 
 315     /**
 316      * On Windows, a file can appear in multiple folders, other than its
 317      * parent directory in the filesystem. Folder could for example be the
 318      * "Desktop" folder which is not the same as file.getParentFile().
 319      *
 320      * @param folder a <code>File</code> object representing a directory or special folder
 321      * @param file a <code>File</code> object
 322      * @return <code>true</code> if <code>folder</code> is a directory or special folder and contains <code>file</code>.
 323      * @since 1.4
 324      */
 325     public boolean isParent(File folder, File file) {
 326         if (folder == null || file == null) {
 327             return false;
 328         } else if (folder instanceof ShellFolder) {
 329                 File parent = file.getParentFile();
 330                 if (parent != null && parent.equals(folder)) {
 331                     return true;
 332                 }


< prev index next >