< prev index next >

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

Print this page




 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;
 271         } else if (folder instanceof ShellFolder) {
 272                 File parent = file.getParentFile();
 273                 if (parent != null && parent.equals(folder)) {
 274                     return true;
 275                 }
 276             File[] children = getFiles(folder, false);
 277             for (File child : children) {
 278                 if (file.equals(child)) {




 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      * Icon for a file, directory, or folder as it would be displayed in
 260      * a system file browser for the requested size.
 261      *
 262      * The default implementation gets information from the ShellFolder class.
 263      *
 264      * @param f a <code>File</code> object
 265      * @param size width and height of the icon in pixels to be scaled(valid range: 1 to 256)
 266      * @return an icon as it would be displayed by a native file chooser
 267      * @see JFileChooser#getIcon
 268      * @since 12
 269      */
 270     protected Icon getSystemIcon(File f, int size) {
 271         if (f == null) {
 272             return null;
 273         }
 274 
 275         if (size > 256 || size < 1) {
 276             return null;
 277         }
 278 
 279         ShellFolder sf;
 280         try {
 281             sf = getShellFolder(f);
 282         } catch (FileNotFoundException e) {
 283             return null;
 284         }
 285 
 286         Image img = sf.getIcon(size);
 287         if (img != null) {
 288             return new ImageIcon(img, sf.getFolderType());
 289         } else {
 290             return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
 291         }
 292     }
 293 
 294     /**
 295      * On Windows, a file can appear in multiple folders, other than its
 296      * parent directory in the filesystem. Folder could for example be the
 297      * "Desktop" folder which is not the same as file.getParentFile().
 298      *
 299      * @param folder a <code>File</code> object representing a directory or special folder
 300      * @param file a <code>File</code> object
 301      * @return <code>true</code> if <code>folder</code> is a directory or special folder and contains <code>file</code>.
 302      * @since 1.4
 303      */
 304     public boolean isParent(File folder, File file) {
 305         if (folder == null || file == null) {
 306             return false;
 307         } else if (folder instanceof ShellFolder) {
 308                 File parent = file.getParentFile();
 309                 if (parent != null && parent.equals(folder)) {
 310                     return true;
 311                 }
 312             File[] children = getFiles(folder, false);
 313             for (File child : children) {
 314                 if (file.equals(child)) {


< prev index next >