< prev index next >

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

Print this page

        

*** 72,81 **** --- 72,95 ---- private boolean useSystemExtensionHiding = UIManager.getDefaults().getBoolean("FileChooser.useSystemExtensionHiding"); /** + * An icon image query option that requests the small file icon. + * + * @since 10 + */ + public static final int FILE_ICON_SMALL = -1; + + /** + * An icon image query option that requests the large file icon. + * + * @since 10 + */ + public static final int FILE_ICON_LARGE = -2; + + /** * Returns the file system view. * @return the file system view */ public static FileSystemView getFileSystemView() { if(File.separatorChar == '\\') {
*** 255,264 **** --- 269,320 ---- return UIManager.getIcon(f.isDirectory() ? "FileView.directoryIcon" : "FileView.fileIcon"); } } /** + * Returns icon image if it is associated with the specified file or + * {@code null} otherwise. Depending on the passed {@code size} different + * sizes of file icon may be queried. If value of the {@code size} argument + * equals to {@code #FILE_ICON_SMALL} or {@code #FILE_ICON_LARGE} then + * the small or large file icon variant is returned correspondingly. + * For any positive size value the exact file icon size is queried. + * + * @param file a file + * @param size size to query + * @return file icon + * @throws NullPointerException if {@code file} equals {@code null} + * @see #FILE_ICON_SMALL + * @see #FILE_ICON_LARGE + * @since 10 + */ + public ImageIcon getSystemIcon(File file, int size) { + if (file == null) { + throw new NullPointerException("file is null"); + } + ShellFolder sf; + try { + sf = ShellFolder.getShellFolder(file); + } catch (FileNotFoundException e) { + return null; + } + Image img = null; + if (size == FILE_ICON_SMALL) { + img = sf.getIcon(false); + } else if (size == FILE_ICON_LARGE) { + img = sf.getIcon(true); + } else if (size > 0) { + img = sf.getIcon(size); + } else { + throw new IllegalArgumentException("Wrong size value +" + size); + } + if (img != null) { + return new ImageIcon(img, sf.getFolderType()); + } + return null; + } + + /** * On Windows, a file can appear in multiple folders, other than its * parent directory in the filesystem. Folder could for example be the * "Desktop" folder which is not the same as file.getParentFile(). * * @param folder a <code>File</code> object representing a directory or special folder
< prev index next >