com.mucommander.ui.icon
Class FileIcons

java.lang.Object
  extended by com.mucommander.ui.icon.FileIcons

public class FileIcons
extends java.lang.Object

FileIcons provides several methods to retrieve file icons for a given file:

Icons can be requested indifferently for any type of AbstractFile files: local files, remote files, archives entries... The

It is important to note that not all platforms have proper support for system file icons. The hasProperSystemIcons() method can be used to determine if the current platform properly supports system icons. Non-supported platforms may return no icon (null values), or icons that do not resemble the system ones.

Author:
Maxence Bernard

Field Summary
static float DEFAULT_SCALE_FACTOR
          Default icon scale factor (no rescaling)
static java.lang.String DEFAULT_SYSTEM_ICONS_POLICY
          Default policy for system icons
static java.lang.String USE_SYSTEM_ICONS_ALWAYS
          Always use system file icons
static java.lang.String USE_SYSTEM_ICONS_APPLICATIONS
          Use system file icons only for applications
static java.lang.String USE_SYSTEM_ICONS_NEVER
          Never use system file icons
 
Constructor Summary
FileIcons()
           
 
Method Summary
static javax.swing.Icon getCustomFileIcon(AbstractFile file)
          Shorthand for getCustomFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) called with the icon dimension returned by getIconDimension().
static javax.swing.Icon getCustomFileIcon(AbstractFile file, java.awt.Dimension iconDimension)
          Returns an icon of the specified dimension for the given file.
static FileIconProvider getCustomFileIconProvider()
          Returns the FileIconProvider instance that provides 'custom' file icons.
static javax.swing.Icon getFileIcon(AbstractFile file)
          Shorthand for getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) called with the icon dimension returned by getIconDimension().
static javax.swing.Icon getFileIcon(AbstractFile file, java.awt.Dimension iconDimension)
          Returns an icon for the given file and of the specified dimension.
static java.awt.Dimension getIconDimension()
          Returns the dimension of file icons currently returned by this class, which is the base icon dimension (16x16) multiplied by the current scale factor.
static float getScaleFactor()
          Returns the current icon scale factor, initialized by default to DEFAULT_SCALE_FACTOR.
static javax.swing.Icon getSystemFileIcon(AbstractFile file)
          Shorthand for getSystemFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) called with the icon dimension returned by getIconDimension().
static javax.swing.Icon getSystemFileIcon(AbstractFile file, java.awt.Dimension iconDimension)
          Returns an icon of the specified dimension for the given file.
static FileIconProvider getSystemFileIconProvider()
          Returns the FileIconProvider instance that provides 'system' file icons.
static java.lang.String getSystemIconsPolicy()
          Returns the current system icons policy, controlling when system file icons should be used instead of custom file icons, see constant fields for possible values.
static boolean hasProperSystemIcons()
          Returns true if the current platform is able to retrieve system icons that match the ones used in the OS's default file manager.
static void setCustomFileIconProvider(FileIconProvider fip)
          Sets the FileIconProvider instance that provides 'custom' file icons.
static void setScaleFactor(float factor)
          Sets the current icon scale factor.
static void setSystemFileIconProvider(FileIconProvider fip)
          Sets the FileIconProvider instance that provides 'custom' file icons.
static void setSystemIconsPolicy(java.lang.String policy)
          Sets the system icons policy, controlling when system file icons should be used instead of custom file icons.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

USE_SYSTEM_ICONS_NEVER

public static final java.lang.String USE_SYSTEM_ICONS_NEVER
Never use system file icons

See Also:
Constant Field Values

USE_SYSTEM_ICONS_APPLICATIONS

public static final java.lang.String USE_SYSTEM_ICONS_APPLICATIONS
Use system file icons only for applications

See Also:
Constant Field Values

USE_SYSTEM_ICONS_ALWAYS

public static final java.lang.String USE_SYSTEM_ICONS_ALWAYS
Always use system file icons

See Also:
Constant Field Values

DEFAULT_SYSTEM_ICONS_POLICY

public static final java.lang.String DEFAULT_SYSTEM_ICONS_POLICY
Default policy for system icons

See Also:
Constant Field Values

DEFAULT_SCALE_FACTOR

public static final float DEFAULT_SCALE_FACTOR
Default icon scale factor (no rescaling)

See Also:
Constant Field Values
Constructor Detail

FileIcons

public FileIcons()
Method Detail

getFileIcon

public static javax.swing.Icon getFileIcon(AbstractFile file)
Shorthand for getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) called with the icon dimension returned by getIconDimension().

Parameters:
file - the AbstractFile instance for which an icon will be returned
Returns:
an icon for the given file
See Also:
getSystemIconsPolicy()

getFileIcon

public static javax.swing.Icon getFileIcon(AbstractFile file,
                                           java.awt.Dimension iconDimension)
Returns an icon for the given file and of the specified dimension. The returned icon will either be a system icon, or one from the custom icon set, depending on the current system icons policy. Returns null if the icon couldn't be retrieved, either because the file doesn't exist or for any other reason.

Parameters:
file - the AbstractFile instance for which an icon will be returned
iconDimension - the icon's dimension
Returns:
an icon for the given file
See Also:
getSystemIconsPolicy()

getCustomFileIcon

public static javax.swing.Icon getCustomFileIcon(AbstractFile file)
Shorthand for getCustomFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) called with the icon dimension returned by getIconDimension().

Parameters:
file - the file for which an icon is to be returned
Returns:
a custom icon for the given file

getCustomFileIcon

public static javax.swing.Icon getCustomFileIcon(AbstractFile file,
                                                 java.awt.Dimension iconDimension)
Returns an icon of the specified dimension for the given file. The icon is provided by the custom file icon provider. Returns null if the icon couldn't be retrieved, either because the file doesn't exist or for any other reason.

Parameters:
file - the file for which an icon is to be returned
iconDimension - the icon's dimension
Returns:
a custom icon for the given file
See Also:
getCustomFileIconProvider()

getSystemFileIcon

public static javax.swing.Icon getSystemFileIcon(AbstractFile file)
Shorthand for getSystemFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) called with the icon dimension returned by getIconDimension().

Parameters:
file - the file for which an icon is to be returned
Returns:
a system icon for the given file

getSystemFileIcon

public static javax.swing.Icon getSystemFileIcon(AbstractFile file,
                                                 java.awt.Dimension iconDimension)
Returns an icon of the specified dimension for the given file. The returned icon is provided by the underlying OS/desktop manager, using the FileIconProvider currently set. Returns null if the icon couldn't be retrieved, either because the file doesn't exist or for any other reason.

Parameters:
file - the file for which an icon is to be returned
iconDimension - the icon's dimension
Returns:
a system icon for the given file

getCustomFileIconProvider

public static FileIconProvider getCustomFileIconProvider()
Returns the FileIconProvider instance that provides 'custom' file icons.

Returns:
the FileIconProvider instance that provides 'custom' file icons.

setCustomFileIconProvider

public static void setCustomFileIconProvider(FileIconProvider fip)
Sets the FileIconProvider instance that provides 'custom' file icons.

Parameters:
fip - the FileIconProvider instance that provides 'custom' file icons

getSystemFileIconProvider

public static FileIconProvider getSystemFileIconProvider()
Returns the FileIconProvider instance that provides 'system' file icons.

Returns:
the FileIconProvider instance that provides 'custom' file icons.

setSystemFileIconProvider

public static void setSystemFileIconProvider(FileIconProvider fip)
Sets the FileIconProvider instance that provides 'custom' file icons.

Parameters:
fip - the FileIconProvider instance that provides 'custom' file icons

getIconDimension

public static java.awt.Dimension getIconDimension()
Returns the dimension of file icons currently returned by this class, which is the base icon dimension (16x16) multiplied by the current scale factor.

Returns:
the dimension of file icons currently returned by this class

getScaleFactor

public static float getScaleFactor()
Returns the current icon scale factor, initialized by default to DEFAULT_SCALE_FACTOR.

Returns:
the current icon scale factor

setScaleFactor

public static void setScaleFactor(float factor)
Sets the current icon scale factor. The given value must be greater than 0.

Parameters:
factor - the new icon scale factor to use
Throws:
java.lang.IllegalArgumentException - if factor is lower or equal to 0

getSystemIconsPolicy

public static java.lang.String getSystemIconsPolicy()
Returns the current system icons policy, controlling when system file icons should be used instead of custom file icons, see constant fields for possible values. The system icons policy is by default initialized to DEFAULT_SYSTEM_ICONS_POLICY.

Returns:
the current system icons policy

setSystemIconsPolicy

public static void setSystemIconsPolicy(java.lang.String policy)
Sets the system icons policy, controlling when system file icons should be used instead of custom file icons. See constants fields for allowed values.

Parameters:
policy - the new system icons policy to use

hasProperSystemIcons

public static boolean hasProperSystemIcons()
Returns true if the current platform is able to retrieve system icons that match the ones used in the OS's default file manager. If false is returned and getSystemFileIcon(com.mucommander.file.AbstractFile) is used or getFileIcon(com.mucommander.file.AbstractFile) together with a system policy different from USE_SYSTEM_ICONS_NEVER, the returned icon will probably look very bad.

Returns:
true if the current platform is able to retrieve system icons that match the ones used in the OS's default file manager


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard