Skip to content
Permalink
Browse files
8182043: Access to Windows Large Icons
Reviewed-by: aivanov, azvegint, prr
  • Loading branch information
Alexander Zuev committed May 27, 2021
1 parent 8a31c07 commit 7f52c50ba32eecf5f379f8db30ac6a5cc50b3b66
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2021, 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
@@ -26,6 +26,7 @@
package javax.swing.filechooser;

import java.awt.Image;
import java.awt.image.AbstractMultiResolutionImage;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FileNotFoundException;
@@ -225,7 +226,7 @@ public String getSystemTypeDescription(File f) {
* 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.
*
* <p>
* The default implementation gets information from the ShellFolder class.
*
* @param f a <code>File</code> object
@@ -255,6 +256,67 @@ public Icon getSystemIcon(File f) {
}
}

/**
* Returns an icon for a file, directory, or folder as it would be displayed
* in a system file browser for the requested size.
* <p>
* Example: <pre>
* FileSystemView fsv = FileSystemView.getFileSystemView();
* Icon icon = fsv.getSystemIcon(new File("application.exe"), 64, 64);
* JLabel label = new JLabel(icon);
* </pre>
*
* @implSpec The available icons may be platform specific and so the
* available sizes determined by the platform. Therefore an exact match
* for the requested size may not be possible.
*
* The icon returned may be a multi-resolution icon image,
* which allows better support for High DPI environments
* with different scaling factors.
*
* @param f a {@code File} object for which the icon will be retrieved
* @param width width of the icon in user coordinate system.
* @param height height of the icon in user coordinate system.
* @return an icon as it would be displayed by a native file chooser
* or null for a non-existent or inaccessible file.
* @throws IllegalArgumentException if an invalid parameter such
* as a negative size or a null file reference is passed.
* @see JFileChooser#getIcon
* @see AbstractMultiResolutionImage
* @see FileSystemView#getSystemIcon(File)
* @since 17
*/
public Icon getSystemIcon(File f, int width, int height) {
if (height < 1 || width < 1) {
throw new IllegalArgumentException("Icon size can not be below 1");
}

if (f == null) {
throw new IllegalArgumentException("The file reference should not be null");
}

if(!f.exists()) {
return null;
}

ShellFolder sf;

try {
sf = ShellFolder.getShellFolder(f);
} catch (FileNotFoundException e) {
return null;
}

Image img = sf.getIcon(width, height);

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
@@ -207,6 +207,16 @@ public Image getIcon(boolean getLargeIcon) {
return null;
}

/**
* Returns the icon of the specified size used to display this shell folder.
*
* @param width width of the icon > 0
* @param height height of the icon > 0
* @return The icon of the specified size used to display this shell folder
*/
public Image getIcon(int width, int height) {
return null;
}

// Static

1 comment on commit 7f52c50

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 7f52c50 May 27, 2021

Please sign in to comment.