Здравствуйте, уважаемые.
Встал вопрос с отображением иконки типа файла, в инете нашел более-менее нормальное решение:
Маленькая иконка
| Код | File file = null; String extension = "doc";
try { //Create a temporary file with the specified extension file = File.createTempFile("icon", "." + extension); FileSystemView view = FileSystemView.getFileSystemView(); Icon icon = view.getSystemIcon(file);
//Delete the temporary file file.delete(); } catch (IOException ioe) { }
|
Большая иконка.
| Код |
File file = null; String extension = "doc";
try { //Create a temporary file with the specified extension file = File.createTempFile("icon", "." + extension); sun.awt.shell.ShellFolder shellFolder = sun.awt.shell.ShellFolder.getShellFolder(file); Icon icon = new ImageIcon(shellFolder.getIcon(true));
//Delete the temporary file file.delete(); } catch (Exception e) { }
|
раборает! Но 1). Меня пугает класс sun.awt.shell.ShellFolder, насколько он распространен? Есть ли он в jre для Линукса? Сам задал вопрос сам отвечаю:
http://www.onjava.com/pub/a/onjava/2005/08/10/swinghacks.html?page=last
| Цитата | Get Large File Icons
Not to leave Windows lonely, here is an undocumented class that will let you obtain large desktop icons and other file information. The FileSystemView only provides access to file icons of a "default" size, which usually means 16 by 16 pixels. If you look at your operating system desktop, however, you may see icons that are much bigger, with more detail. There is no standardized way of getting to the larger icons, but on Windows you can use the hidden class called sun.awt.shell.ShellFolder to retrieve larger (32 by 32) desktop file icons. This class is only available in Sun's JVM, so it won't work with other vendors, or on other platforms.
|
2). Постоянно создавать и удалять файл, чтоб определить тип - это не тема. Выход конечно прост: сделать кеш в виде 2-х Map<String, Icon> |