public class MapImageCache<G extends GameObject<G,A,R>,A extends MapArchObject<A>,R extends Archetype<G,A,R>>
extends java.lang.Object
ICON_WIDTH
xICON_HEIGHT
pixels); previews are scaled down from the
normal size by the factor PREVIEW_SCALE
.Constructor and Description |
---|
MapImageCache(MapManager<G,A,R> mapManager,
java.awt.Image defaultIcon,
java.awt.Image defaultPreview,
RendererFactory<G,A,R> rendererFactory,
CacheFiles cacheFiles)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
void |
addMapImageCacheListener(MapImageCacheListener<G,A,R> listener)
Adds a
MapImageCacheListener to be notified. |
void |
flush(java.io.File mapFile)
Removes the cached images for a map file.
|
java.awt.Image |
getIcon(java.io.File mapFile)
Returns the icon
Image for a given map file. |
java.awt.Image |
getOrCreateIcon(java.io.File mapFile)
Returns an icon
Image for a given map file. |
java.awt.Image |
getOrCreateIcon(MapControl<G,A,R> mapControl)
Returns an icon
Image for a given map. |
java.awt.Image |
getOrCreatePreview(java.io.File mapFile)
Returns a preview
Image for a given map file. |
java.awt.Image |
getOrCreatePreview(MapControl<G,A,R> mapControl)
Returns a preview
Image for a given map. |
java.awt.Image |
getPreview(java.io.File mapFile)
Returns a preview
Image for a given map file. |
void |
removeMapImageCacheListener(MapImageCacheListener<G,A,R> listener)
Removes a
MapControlListener to be notified. |
public 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)
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 previewspublic void flush(@NotNull java.io.File mapFile)
mapFile
- the map file to purge@Nullable public java.awt.Image getIcon(@NotNull java.io.File mapFile)
Image
for a given map file. If no image is
cached (or if the cached image is outdated), returns null
.mapFile
- the map filenull
@Nullable public java.awt.Image getOrCreateIcon(@NotNull java.io.File mapFile)
Image
for a given map file. If no image is cached
(or if the cached image is outdated), loads the map and creates the
icon.mapFile
- the map filenull
for directories@NotNull public java.awt.Image getOrCreateIcon(@NotNull MapControl<G,A,R> mapControl)
Image
for a given map. If no image is cached (or
if the cached image is outdated), (re-)creates it.mapControl
- the map@Nullable public java.awt.Image getPreview(@NotNull java.io.File mapFile)
Image
for a given map file. If no image is
cached (or if the cached image is outdated), returns null
.mapFile
- the map filenull
@Nullable public java.awt.Image getOrCreatePreview(@NotNull java.io.File mapFile)
Image
for a given map file. If no image is
cached (or if the cached image is outdated), loads the map and creates
the image.mapFile
- the map filenull
for directories@NotNull public java.awt.Image getOrCreatePreview(@NotNull MapControl<G,A,R> mapControl)
Image
for a given map. If no image is cached
(or if the cached image is outdated), (re-)creates the image.mapControl
- the mappublic void addMapImageCacheListener(@NotNull MapImageCacheListener<G,A,R> listener)
MapImageCacheListener
to be notified.listener
- the listener to addpublic void removeMapImageCacheListener(@NotNull MapImageCacheListener<G,A,R> listener)
MapControlListener
to be notified.listener
- the listener to remove