com.mucommander.file.icon
Interface CacheableFileIconProvider

All Superinterfaces:
FileIconProvider

public interface CacheableFileIconProvider
extends FileIconProvider

CacheableFileIconProvider is an interface to be implemented by file icon providers that wish to use some icon caching to improve performance. This interface is to be used in conjunction with CachedFileIconProvider to form a functional cached provider.

Author:
Maxence Bernard

Method Summary
 void addToCache(AbstractFile file, javax.swing.Icon icon, java.awt.Dimension preferredResolution)
          This method is called by CachedFileIconProvider.getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) to give implementations a chance to cache an icon fetched with FileIconProvider.getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) and have it returned later by lookupCache(com.mucommander.file.AbstractFile, java.awt.Dimension).
 boolean isCacheable(AbstractFile file, java.awt.Dimension preferredResolution)
          Returns true if the icon cache can be used for the specified file and preferred resolution.
 javax.swing.Icon lookupCache(AbstractFile file, java.awt.Dimension preferredResolution)
          This method is called by CachedFileIconProvider.getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) to perform a cache lookup and give implementations a chance to re-use a cached icon.
 
Methods inherited from interface com.mucommander.file.icon.FileIconProvider
getFileIcon
 

Method Detail

isCacheable

boolean isCacheable(AbstractFile file,
                    java.awt.Dimension preferredResolution)
Returns true if the icon cache can be used for the specified file and preferred resolution. This method allows the icon cache to be used only for certain types of files and/or preferred resolutions.

This method is called by CachedFileIconProvider.getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) each time an icon is requested. If true is returned, the icon cache will be looked up with lookupCache(com.mucommander.file.AbstractFile, java.awt.Dimension) and if the cache did not return an icon, the icon will be be added to the cache with addToCache(com.mucommander.file.AbstractFile, javax.swing.Icon, java.awt.Dimension).
On the other hand, if false is returned, FileIconProvider.getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) will simply be called, without querying or adding to the cache.

Parameters:
file - the file for which to retrieve an icon
preferredResolution - the preferred resolution for the icon
Returns:
true if the icon cache can be used with the specified file

lookupCache

javax.swing.Icon lookupCache(AbstractFile file,
                             java.awt.Dimension preferredResolution)
This method is called by CachedFileIconProvider.getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) to perform a cache lookup and give implementations a chance to re-use a cached icon. If a non-null value is returned, the returned icon will be used.
On the other hand, if null is returned, the icon will be fetched using FileIconProvider.getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) followed by a call to addToCache(com.mucommander.file.AbstractFile, javax.swing.Icon,java.awt.Dimension) to add the freshly-retrieved icon to the cache.

This method is called only if the prior call to isCacheable(com.mucommander.file.AbstractFile, java.awt.Dimension) returned true.

.

Parameters:
file - the file for which to look for a previously cached icon
preferredResolution - the preferred resolution for the icon
Returns:
a cached icon to re-use, null if there is none

addToCache

void addToCache(AbstractFile file,
                javax.swing.Icon icon,
                java.awt.Dimension preferredResolution)
This method is called by CachedFileIconProvider.getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) to give implementations a chance to cache an icon fetched with FileIconProvider.getFileIcon(com.mucommander.file.AbstractFile, java.awt.Dimension) and have it returned later by lookupCache(com.mucommander.file.AbstractFile, java.awt.Dimension).
There is no obligation for this method to cache the given icon, implementations may freely choose whether to cache certain icons only.

This method is called only if the prior call to isCacheable(com.mucommander.file.AbstractFile, java.awt.Dimension) returned true.

.

Parameters:
file - the file that corresponds to the given icon
icon - the icon to add to the cache
preferredResolution - the preferred icon resolution that was originally requested


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