Class MapImageCache<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
- java.lang.Object
-
- net.sf.gridarta.gui.mapimagecache.MapImageCache<G,A,R>
-
public class MapImageCache<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>> extends java.lang.ObjectCaches icon and preview images for map files. Cached images are cached both on disk and in memory using weak references. Icons have a fixed size (ICON_WIDTHxICON_HEIGHTpixels); previews are scaled down from the normal size by the factorPREVIEW_SCALE.
-
-
Constructor Summary
Constructors Constructor Description MapImageCache(@NotNull MapManager<G,A,R> mapManager, @NotNull java.awt.Image defaultIcon, @NotNull java.awt.Image defaultPreview, @NotNull RendererFactory<G,A,R> rendererFactory, @NotNull CacheFiles cacheFiles)Creates a new instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMapImageCacheListener(@NotNull MapImageCacheListener<G,A,R> listener)Adds aMapImageCacheListenerto be notified.voidflush(@NotNull java.io.File mapFile)Removes the cached images for a map file.@Nullable java.awt.ImagegetIcon(@NotNull java.io.File mapFile)Returns the iconImagefor a given map file.@Nullable java.awt.ImagegetOrCreateIcon(@NotNull java.io.File mapFile)Returns an iconImagefor a given map file.@NotNull java.awt.ImagegetOrCreateIcon(@NotNull MapControl<G,A,R> mapControl)Returns an iconImagefor a given map.@Nullable java.awt.ImagegetOrCreatePreview(@NotNull java.io.File mapFile)Returns a previewImagefor a given map file.@NotNull java.awt.ImagegetOrCreatePreview(@NotNull MapControl<G,A,R> mapControl)Returns a previewImagefor a given map.@Nullable java.awt.ImagegetPreview(@NotNull java.io.File mapFile)Returns a previewImagefor a given map file.voidremoveMapImageCacheListener(@NotNull MapImageCacheListener<G,A,R> listener)Removes aMapControlListenerto be notified.
-
-
-
Constructor Detail
-
MapImageCache
public MapImageCache(@NotNull @NotNull MapManager<G,A,R> mapManager, @NotNull @NotNull java.awt.Image defaultIcon, @NotNull @NotNull java.awt.Image defaultPreview, @NotNull @NotNull RendererFactory<G,A,R> rendererFactory, @NotNull @NotNull CacheFiles cacheFiles)Creates a new instance.- Parameters:
mapManager- the map manager for loading mapsdefaultIcon- the default icon to return if no icon can be created for a mapdefaultPreview- the default preview image to return if no preview can be created for a maprendererFactory- the renderer factory for creating rendererscacheFiles- the cache files for generating files for cached icons and previews
-
-
Method Detail
-
flush
public void flush(@NotNull @NotNull java.io.File mapFile)Removes the cached images for a map file.- Parameters:
mapFile- the map file to purge
-
getIcon
@Nullable public @Nullable java.awt.Image getIcon(@NotNull @NotNull java.io.File mapFile)Returns the iconImagefor a given map file. If no image is cached (or if the cached image is outdated), returnsnull.- Parameters:
mapFile- the map file- Returns:
- the icon image or
null
-
getOrCreateIcon
@Nullable public @Nullable java.awt.Image getOrCreateIcon(@NotNull @NotNull java.io.File mapFile)Returns an iconImagefor a given map file. If no image is cached (or if the cached image is outdated), loads the map and creates the icon.- Parameters:
mapFile- the map file- Returns:
- the icon image or
nullfor directories
-
getOrCreateIcon
@NotNull public @NotNull java.awt.Image getOrCreateIcon(@NotNull @NotNull MapControl<G,A,R> mapControl)Returns an iconImagefor a given map. If no image is cached (or if the cached image is outdated), (re-)creates it.- Parameters:
mapControl- the map- Returns:
- the icon image
-
getPreview
@Nullable public @Nullable java.awt.Image getPreview(@NotNull @NotNull java.io.File mapFile)Returns a previewImagefor a given map file. If no image is cached (or if the cached image is outdated), returnsnull.- Parameters:
mapFile- the map file- Returns:
- the preview image or
null
-
getOrCreatePreview
@Nullable public @Nullable java.awt.Image getOrCreatePreview(@NotNull @NotNull java.io.File mapFile)Returns a previewImagefor a given map file. If no image is cached (or if the cached image is outdated), loads the map and creates the image.- Parameters:
mapFile- the map file- Returns:
- the preview image or
nullfor directories
-
getOrCreatePreview
@NotNull public @NotNull java.awt.Image getOrCreatePreview(@NotNull @NotNull MapControl<G,A,R> mapControl)Returns a previewImagefor a given map. If no image is cached (or if the cached image is outdated), (re-)creates the image.- Parameters:
mapControl- the map- Returns:
- the preview image
-
addMapImageCacheListener
public void addMapImageCacheListener(@NotNull @NotNull MapImageCacheListener<G,A,R> listener)Adds aMapImageCacheListenerto be notified.- Parameters:
listener- the listener to add
-
removeMapImageCacheListener
public void removeMapImageCacheListener(@NotNull @NotNull MapImageCacheListener<G,A,R> listener)Removes aMapControlListenerto be notified.- Parameters:
listener- the listener to remove
-
-