< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 205     }
 206 
 207     /**
 208      * Type description for a file, directory, or folder as it would be displayed in
 209      * a system file browser. Example from Windows: the "Desktop" folder
 210      * is described as "Desktop".
 211      *
 212      * Override for platforms with native ShellFolder implementations.
 213      *
 214      * @param f a <code>File</code> object
 215      * @return the file type description as it would be displayed by a native file chooser
 216      * or null if no native information is available.
 217      * @see JFileChooser#getTypeDescription
 218      * @since 1.4
 219      */
 220     public String getSystemTypeDescription(File f) {
 221         return null;
 222     }
 223 
 224     /**
 225      * Icon for a file, directory, or folder as it would be displayed in
 226      * a system file browser. Example from Windows: the "M:\" directory
 227      * displays a CD-ROM icon.
 228      *
 229      * The default implementation gets information from the ShellFolder class.
 230      *
 231      * @param f a <code>File</code> object
 232      * @return an icon as it would be displayed by a native file chooser
 233      * @see JFileChooser#getIcon
 234      * @since 1.4
 235      */
 236     public Icon getSystemIcon(File f) {
 237         if (f == null) {
 238             return null;
 239         }
 240 
 241         ShellFolder sf;
 242 
 243         try {
 244             sf = getShellFolder(f);
 245         } catch (FileNotFoundException e) {
 246             return null;
 247         }
 248 
 249         Image img = sf.getIcon(false);
 250 




































 251         if (img != null) {
 252             return new ImageIcon(img, sf.getFolderType());
 253         } else {
 254             return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
 255         }
 256     }
 257 
 258     /**
 259      * On Windows, a file can appear in multiple folders, other than its
 260      * parent directory in the filesystem. Folder could for example be the
 261      * "Desktop" folder which is not the same as file.getParentFile().
 262      *
 263      * @param folder a <code>File</code> object representing a directory or special folder
 264      * @param file a <code>File</code> object
 265      * @return <code>true</code> if <code>folder</code> is a directory or special folder and contains <code>file</code>.
 266      * @since 1.4
 267      */
 268     public boolean isParent(File folder, File file) {
 269         if (folder == null || file == null) {
 270             return false;


   1 /*
   2  * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 205     }
 206 
 207     /**
 208      * Type description for a file, directory, or folder as it would be displayed in
 209      * a system file browser. Example from Windows: the "Desktop" folder
 210      * is described as "Desktop".
 211      *
 212      * Override for platforms with native ShellFolder implementations.
 213      *
 214      * @param f a <code>File</code> object
 215      * @return the file type description as it would be displayed by a native file chooser
 216      * or null if no native information is available.
 217      * @see JFileChooser#getTypeDescription
 218      * @since 1.4
 219      */
 220     public String getSystemTypeDescription(File f) {
 221         return null;
 222     }
 223 
 224     /**
 225      * Returns icon for a file, directory, or folder as it would be displayed in
 226      * a system file browser. Example from Windows: the "M:\" directory
 227      * displays a CD-ROM icon.
 228      *


 229      * @param f a <code>File</code> object
 230      * @return an icon as it would be displayed by a native file chooser
 231      * @see JFileChooser#getIcon
 232      * @since 1.4
 233      */
 234     public Icon getSystemIcon(File f) {
 235         if (f == null) {
 236             return null;
 237         }
 238 
 239         ShellFolder sf;
 240 
 241         try {
 242             sf = getShellFolder(f);
 243         } catch (FileNotFoundException e) {
 244             return null;
 245         }
 246 
 247         Image img = sf.getIcon(false);
 248 
 249         if (img != null) {
 250             return new ImageIcon(img, sf.getFolderType());
 251         } else {
 252             return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
 253         }
 254     }
 255 
 256     /**
 257      * Icon for a file, directory, or folder as it would be displayed in
 258      * a system file browser for the requested size.
 259      *
 260      * The default implementation gets information from the ShellFolder class.
 261      *
 262      * @param f a <code>File</code> object
 263      * @param size width and height of the icon in pixels to be scaled(valid range: 1 to 256)
 264      * @return an icon as it would be displayed by a native file chooser
 265      * @see JFileChooser#getIcon
 266      * @since 12
 267      */
 268     protected Icon getSystemIcon(File f, int size) {
 269         if (f == null) {
 270             return null;
 271         }
 272 
 273         if (size > 256 || size < 1) {
 274             return null;
 275         }
 276 
 277         ShellFolder sf;
 278         try {
 279             sf = getShellFolder(f);
 280         } catch (FileNotFoundException e) {
 281             return null;
 282         }
 283 
 284         Image img = sf.getIcon(size);
 285         if (img != null) {
 286             return new ImageIcon(img, sf.getFolderType());
 287         } else {
 288             return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
 289         }
 290     }
 291 
 292     /**
 293      * On Windows, a file can appear in multiple folders, other than its
 294      * parent directory in the filesystem. Folder could for example be the
 295      * "Desktop" folder which is not the same as file.getParentFile().
 296      *
 297      * @param folder a <code>File</code> object representing a directory or special folder
 298      * @param file a <code>File</code> object
 299      * @return <code>true</code> if <code>folder</code> is a directory or special folder and contains <code>file</code>.
 300      * @since 1.4
 301      */
 302     public boolean isParent(File folder, File file) {
 303         if (folder == null || file == null) {
 304             return false;


< prev index next >