com.realtime.crossfire.jxclient.faces
Class FileCache

java.lang.Object
  extended by com.realtime.crossfire.jxclient.faces.FileCache
All Implemented Interfaces:
ImageCache

public class FileCache
extends java.lang.Object
implements ImageCache

A disk based cache for image files.


Field Summary
private  java.io.File cacheDir
          The directory where the images are saved.
 
Constructor Summary
FileCache(java.io.File cacheDir)
          Creates a new instance.
 
Method Summary
private  java.io.File getImageFileName(java.lang.String faceName, int faceChecksum)
          Calculates a hashed image name to be used as a file name.
 javax.swing.ImageIcon load(Face face)
          Retrieves an image from the cache.
private  javax.swing.ImageIcon load(java.lang.String faceName, int faceChecksum)
          Retrieves an image from the cache.
 void save(Face face, javax.swing.ImageIcon imageIcon)
          Stores an ImageIcon into the cache.
 void save(java.lang.String faceName, int faceChecksum, javax.swing.Icon imageIcon)
          Stores an ImageIcon into the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cacheDir

@NotNull
private final java.io.File cacheDir
The directory where the images are saved.

Constructor Detail

FileCache

public FileCache(@NotNull
                 java.io.File cacheDir)
Creates a new instance.

Parameters:
cacheDir - the directory where the images are saved
Method Detail

getImageFileName

@NotNull
private java.io.File getImageFileName(@NotNull
                                              java.lang.String faceName,
                                              int faceChecksum)
Calculates a hashed image name to be used as a file name.

Parameters:
faceName - the image name to hash
faceChecksum - the checksum to hash
Returns:
the hashed image name

load

@Nullable
public javax.swing.ImageIcon load(@NotNull
                                           Face face)
Retrieves an image from the cache.

Specified by:
load in interface ImageCache
Parameters:
face - the face to retrieve
Returns:
the image icon, or null if the cache does not contain the image

load

@Nullable
private javax.swing.ImageIcon load(@NotNull
                                            java.lang.String faceName,
                                            int faceChecksum)
Retrieves an image from the cache.

Parameters:
faceName - the image name to retrieve
faceChecksum - the checksum to retrieve
Returns:
the image icon, or null if the cache does not contain the image

save

public void save(@NotNull
                 Face face,
                 @NotNull
                 javax.swing.ImageIcon imageIcon)
Stores an ImageIcon into the cache.

Specified by:
save in interface ImageCache
Parameters:
face - the face to save
imageIcon - the image icon to store

save

public void save(@NotNull
                 java.lang.String faceName,
                 int faceChecksum,
                 @NotNull
                 javax.swing.Icon imageIcon)
Stores an ImageIcon into the cache.

Parameters:
faceName - the image name to save
faceChecksum - the checksum to save
imageIcon - the image icon to store