< prev index next >

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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -220,16 +220,14 @@
     public String getSystemTypeDescription(File f) {
         return null;
     }
 
     /**
-     * Icon for a file, directory, or folder as it would be displayed in
+     * Returns icon for a file, directory, or folder as it would be displayed in
      * a system file browser. Example from Windows: the "M:\" directory
      * displays a CD-ROM icon.
      *
-     * The default implementation gets information from the ShellFolder class.
-     *
      * @param f a <code>File</code> object
      * @return an icon as it would be displayed by a native file chooser
      * @see JFileChooser#getIcon
      * @since 1.4
      */

@@ -251,10 +249,46 @@
         if (img != null) {
             return new ImageIcon(img, sf.getFolderType());
         } else {
             return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
         }
+    }
+
+    /**
+     * Icon for a file, directory, or folder as it would be displayed in
+     * a system file browser for the requested size.
+     *
+     * The default implementation gets information from the ShellFolder class.
+     *
+     * @param f a <code>File</code> object
+     * @param size width and height of the icon in pixels to be scaled(valid range: 1 to 256)
+     * @return an icon as it would be displayed by a native file chooser
+     * @see JFileChooser#getIcon
+     * @since 12
+     */
+    protected Icon getSystemIcon(File f, int size) {
+        if (f == null) {
+            return null;
+        }
+
+        if (size > 256 || size < 1) {
+            return null;
+        }
+
+        ShellFolder sf;
+        try {
+            sf = getShellFolder(f);
+        } catch (FileNotFoundException e) {
+            return null;
+        }
+
+        Image img = sf.getIcon(size);
+        if (img != null) {
+            return new ImageIcon(img, sf.getFolderType());
+        } else {
+            return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon");
+        }
     }
 
     /**
      * On Windows, a file can appear in multiple folders, other than its
      * parent directory in the filesystem. Folder could for example be the
< prev index next >