Class MapImageCache<G extends GameObject<G,​A,​R>,​A extends MapArchObject<A>,​R extends Archetype<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.Object
    Caches 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_HEIGHT pixels); previews are scaled down from the normal size by the factor PREVIEW_SCALE.
    • 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 maps
        defaultIcon - the default icon to return if no icon can be created for a map
        defaultPreview - the default preview image to return if no preview can be created for a map
        rendererFactory - the renderer factory for creating renderers
        cacheFiles - 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 icon Image for a given map file. If no image is cached (or if the cached image is outdated), returns null.
        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 icon 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.
        Parameters:
        mapFile - the map file
        Returns:
        the icon image or null for directories
      • getOrCreateIcon

        @NotNull
        public @NotNull java.awt.Image getOrCreateIcon​(@NotNull
                                                       @NotNull MapControl<G,​A,​R> mapControl)
        Returns an icon Image for 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 preview Image for a given map file. If no image is cached (or if the cached image is outdated), returns null.
        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 preview 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.
        Parameters:
        mapFile - the map file
        Returns:
        the preview image or null for directories
      • getOrCreatePreview

        @NotNull
        public @NotNull java.awt.Image getOrCreatePreview​(@NotNull
                                                          @NotNull MapControl<G,​A,​R> mapControl)
        Returns a preview Image for 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
      • removeMapImageCacheListener

        public void removeMapImageCacheListener​(@NotNull
                                                @NotNull MapImageCacheListener<G,​A,​R> listener)
        Removes a MapControlListener to be notified.
        Parameters:
        listener - the listener to remove