Gridarta Editor
net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry Class Reference

An image cache entry for one ImageType. More...

+ Collaboration diagram for net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry:

Public Member Functions

void flush (@NotNull final File mapFile)
 Removes the cached image for a map file. More...
 
Image getDefaultImage ()
 Returns the default image. More...
 
Image lookupCache (@NotNull final File mapFile)
 Looks up an image from the cache. More...
 
 MapImageCacheEntry (@NotNull final CacheFiles cacheFiles, @NotNull final Image defaultImage, @NotNull final String prefix)
 Creates a new instance. More...
 
Image scaleImage (@Nullable final File mapFile, @NotNull final Image image, final int width, final int height)
 Scales an Image to the given size and updates the cache. More...
 

Private Member Functions

Image getImageIcon (@NotNull final File mapFile)
 Returns the Image for a given map file. More...
 
Image loadImageFile (@NotNull final File mapFile)
 Loads an image file from disk. More...
 
void saveImageFile (@NotNull final File mapFile, @NotNull final Image image)
 Saves an PNG image file for a map file. More...
 

Static Private Member Functions

static void deleteCacheFile (@NotNull final File cacheFile)
 Deletes a cache file if it exists. More...
 

Private Attributes

final CacheFiles cacheFiles
 The CacheFiles for generating files for cached icons and previews. More...
 
final Image defaultImage
 The default image. More...
 
final Map< File, WeakReference< Image > > images = new HashMap<>()
 The cached icons. More...
 
final String prefix
 The directory prefix name for the cache directory. More...
 
final Map< File, Long > timestamps = new HashMap<>()
 The timestamps of the cached icons. More...
 

Static Private Attributes

static final Category LOG = Logger.getLogger(MapImageCacheEntry.class)
 The logger for printing log messages. More...
 

Detailed Description

An image cache entry for one ImageType.

Author
Andreas Kirschbaum

Definition at line 42 of file MapImageCacheEntry.java.

Constructor & Destructor Documentation

◆ MapImageCacheEntry()

net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.MapImageCacheEntry ( @NotNull final CacheFiles  cacheFiles,
@NotNull final Image  defaultImage,
@NotNull final String  prefix 
)

Creates a new instance.

Parameters
cacheFilesthe cache files for generating files for caching icons and previews
defaultImagethe default image
prefixthe directory prefix for the cache directory

Definition at line 87 of file MapImageCacheEntry.java.

References net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.cacheFiles, net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.defaultImage, and net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.prefix.

Member Function Documentation

◆ deleteCacheFile()

static void net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.deleteCacheFile ( @NotNull final File  cacheFile)
staticprivate

Deletes a cache file if it exists.

Logs a warning message if the file cannot be deleted.

Parameters
cacheFilethe cache file to delete

Definition at line 109 of file MapImageCacheEntry.java.

Referenced by net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.flush(), and net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.loadImageFile().

+ Here is the caller graph for this function:

◆ flush()

void net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.flush ( @NotNull final File  mapFile)

Removes the cached image for a map file.

Both in-memory and on-disk cache are purged.

Parameters
mapFilethe map file to flush

Definition at line 98 of file MapImageCacheEntry.java.

References net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.deleteCacheFile(), and net.sf.gridarta.model.io.CacheFiles.getCacheFile().

+ Here is the call graph for this function:

◆ getDefaultImage()

Image net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.getDefaultImage ( )

Returns the default image.

Returns
the default image

Definition at line 250 of file MapImageCacheEntry.java.

References net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.defaultImage.

◆ getImageIcon()

Image net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.getImageIcon ( @NotNull final File  mapFile)
private

Returns the Image for a given map file.

Parameters
mapFilethe map file
Returns
the image icon or
null
if no image is available

Definition at line 121 of file MapImageCacheEntry.java.

Referenced by net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.lookupCache().

+ Here is the caller graph for this function:

◆ loadImageFile()

Image net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.loadImageFile ( @NotNull final File  mapFile)
private

Loads an image file from disk.

If the file does not exists, cannot be loaded, or is outdated, return

null

.

Parameters
mapFilethe map file name
Returns
the image file, or
null

Definition at line 179 of file MapImageCacheEntry.java.

References net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.deleteCacheFile(), and net.sf.gridarta.model.io.CacheFiles.getCacheFile().

Referenced by net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.lookupCache().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupCache()

Image net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.lookupCache ( @NotNull final File  mapFile)

Looks up an image from the cache.

Parameters
mapFilethe map file to look up
Returns
the image, or
null
if the cache does not contain an entry for
mapFile
or if the entry is outdated

Definition at line 223 of file MapImageCacheEntry.java.

References net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.getImageIcon(), and net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.loadImageFile().

+ Here is the call graph for this function:

◆ saveImageFile()

void net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.saveImageFile ( @NotNull final File  mapFile,
@NotNull final Image  image 
)
private

Saves an PNG image file for a map file.

Parameters
mapFilethe map file to save the image of
imagethe image to save

Definition at line 140 of file MapImageCacheEntry.java.

References net.sf.gridarta.model.io.CacheFiles.getCacheFile().

Referenced by net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.scaleImage().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ scaleImage()

Image net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.scaleImage ( @Nullable final File  mapFile,
@NotNull final Image  image,
final int  width,
final int  height 
)

Scales an Image to the given size and updates the cache.

If an out of memory error occurs the default image is returned.

Parameters
mapFilethe map file for the image
imagethe image to scale
widththe scaled width
heightthe scaled height
Returns
the scaled image

Definition at line 264 of file MapImageCacheEntry.java.

References net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.defaultImage, net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.saveImageFile(), and net.sf.gridarta.utils.ImageUtils.scaleImage().

+ Here is the call graph for this function:

Member Data Documentation

◆ cacheFiles

final CacheFiles net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.cacheFiles
private

The CacheFiles for generating files for cached icons and previews.

Definition at line 55 of file MapImageCacheEntry.java.

Referenced by net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.MapImageCacheEntry().

◆ defaultImage

final Image net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.defaultImage
private

◆ images

final Map<File, WeakReference<Image> > net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.images = new HashMap<>()
private

The cached icons.

Maps map file to Image.

Definition at line 72 of file MapImageCacheEntry.java.

◆ LOG

final Category net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.LOG = Logger.getLogger(MapImageCacheEntry.class)
staticprivate

The logger for printing log messages.

Definition at line 48 of file MapImageCacheEntry.java.

◆ prefix

final String net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.prefix
private

The directory prefix name for the cache directory.

Definition at line 66 of file MapImageCacheEntry.java.

Referenced by net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.MapImageCacheEntry().

◆ timestamps

final Map<File, Long> net.sf.gridarta.gui.mapimagecache.MapImageCacheEntry.timestamps = new HashMap<>()
private

The timestamps of the cached icons.

Maps map file to timestamp.

Definition at line 78 of file MapImageCacheEntry.java.


The documentation for this class was generated from the following file: