 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.gui.mapimagecache;
22 import java.awt.Image;
24 import java.io.IOException;
25 import java.lang.ref.SoftReference;
26 import java.util.Collection;
27 import java.util.EnumMap;
28 import java.util.HashMap;
30 import java.util.concurrent.CopyOnWriteArrayList;
42 import org.jetbrains.annotations.NotNull;
43 import org.jetbrains.annotations.Nullable;
86 private final Collection<MapImageCacheListener<G, A, R>>
listenerList =
new CopyOnWriteArrayList<>();
93 private final Map<ImageType, MapImageCacheEntry>
entries =
new EnumMap<>(
ImageType.class);
107 final MapFile mapFile = mapControl.getMapModel().getMapFile();
108 assert mapFile !=
null;
109 final File file = mapFile.
getFile();
139 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
167 public void flush(@NotNull
final File mapFile) {
169 entries.get(imageType).flush(mapFile);
180 public Image
getIcon(@NotNull
final File mapFile) {
257 }
catch (
final IOException ignored) {
261 return entries.get(imageType).getDefaultImage();
279 }
catch (
final OutOfMemoryError ignored) {
280 return entries.get(imageType).getDefaultImage();
282 final Image[] images =
new Image[2];
286 if (mapFile !=
null) {
288 listener.iconChanged(mapControl);
304 final MapRenderer tmpMapRenderer = mapRendererReference ==
null ? null : mapRendererReference.get();
306 if (tmpMapRenderer ==
null) {
310 mapRenderer = tmpMapRenderer;
340 final MapFile mapFile = mapControl.getMapModel().getMapFile();
341 if (mapFile !=
null) {
342 final Image image =
entries.get(imageType).lookupCache(mapFile.
getFile());
361 if (mapFile.isDirectory()) {
365 final Image image =
entries.get(imageType).lookupCache(mapFile);
366 return image ==
null ?
updateCaches(mapFile, imageType) : image;
final Map< ImageType, MapImageCacheEntry > entries
The cache entries.
A MapManager manages all opened maps.
Image getOrCreateIcon(@NotNull final MapControl< G, A, R > mapControl)
Returns an icon Image for a given map.
Base package of all Gridarta classes.
Image getOrCreatePreview(@NotNull final MapControl< G, A, R > mapControl)
Returns a preview Image for a given map.
Interface for listeners listening to MapManager changes.
MapRenderer newSimpleMapRenderer(@NotNull MapModel< G, A, R > mapModel)
Creates a new map renderer instance which paints only squares but no grid, cursor,...
final Map< MapControl< G, A, R >, SoftReference< MapRenderer > > mapRendererReferences
Maps MapControl instance to MapRenderer which is only used to get images.
void addMapManagerListener(@NotNull MapManagerListener< G, A, R > listener)
Adds a MapManagerListener to be notified.
Reflects a game object (object on a map).
static final int ICON_HEIGHT
The height of icons in pixels.
PREVIEW
The preview is a large thumbnail.
Graphical User Interface of Gridarta.
Image getOrCreate(@NotNull final File mapFile, @NotNull final ImageType imageType)
Returns a preview Image for a given map file.
Image getIcon(@NotNull final File mapFile)
Returns the icon Image for a given map file.
Caches icon and preview images for map files.
GameObjects are the objects based on Archetypes found on maps.
Image getOrCreateIcon(@NotNull final File mapFile)
Returns an icon Image for a given map file.
void removeMapImageCacheListener(@NotNull final MapImageCacheListener< G, A, R > listener)
Removes a MapControlListener to be notified.
final RendererFactory< G, A, R > rendererFactory
The RendererFactory for creating renderers.
void flush(@NotNull final File mapFile)
Removes the cached images for a map file.
final MapControlListener< G, A, R > mapControlListener
The MapControlListener attached to all MapControls.
final Collection< MapImageCacheListener< G, A, R > > listenerList
The registered event listeners.
Interface for MapArchObjects.
Image updateCaches(@NotNull final File mapFile, final ImageType imageType)
Updates the cached icon and preview Images for one map file.
Image getOrCreatePreview(@NotNull final File mapFile)
Returns a preview Image for a given map file.
File getFile()
Returns a File for this map file.
MapControl< G, A, R > openMapFile(@NotNull MapFile mapFile, boolean interactive)
Loads a map file.
MapImageCache(@NotNull final MapManager< G, A, R > mapManager, @NotNull final Image defaultIcon, @NotNull final Image defaultPreview, @NotNull final RendererFactory< G, A, R > rendererFactory, @NotNull final CacheFiles cacheFiles)
Creates a new instance.
void addMapImageCacheListener(@NotNull final MapImageCacheListener< G, A, R > listener)
Adds a MapImageCacheListener to be notified.
final MapManager< G, A, R > mapManager
The MapManager for loading maps.
The location of a map file with a map directory.
Reading and writing of maps, handling of paths.
static final int PREVIEW_SCALE
The scale factor for preview images.
void release(@NotNull MapControl< G, A, R > mapControl)
Releases a MapControl instance.
The types of images that are cached.
MapRenderer getRenderer(@NotNull final MapControl< G, A, R > mapControl)
Returns a MapRenderer for a map.
Image getPreview(@NotNull final File mapFile)
Returns a preview Image for a given map file.
Image getOrCreate(@NotNull final MapControl< G, A, R > mapControl, @NotNull final ImageType imageType)
Returns an icon or preview Image for a given map.
static final int ICON_WIDTH
The width of icons in pixels.
Factory for creating MapRenderer instances.
Base classes for rendering maps.
An image cache entry for one ImageType.
Currently nothing more than a marker interface for unification.
Interface for listeners listening on changes in MapControl instances.
ICON
The icon is a small thumbnail usable as icon in file browsers.
BufferedImage getFullImage()
Returns an image of the entire map view.
Creates derived files for caching files.
Image updateCaches(@Nullable final File mapFile, @NotNull final MapControl< G, A, R > mapControl, final ImageType imageType)
Updates the cached icon and preview Images for one map file.
Common interface for renderers of map control instances.