001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.osm.visitor.paint; 003 004import java.awt.Image; 005 006import jakarta.annotation.Nullable; 007 008/** 009 * A record for keeping the image information for a tile. Used in conjunction with {@link TileZXY} for 010 * {@link org.openstreetmap.josm.data.cache.JCSCacheManager}. 011 * @since 19176 012 */ 013public final class ImageCache { 014 private final boolean isDirty; 015 private final StyledTiledMapRenderer.TileLoader imageFuture; 016 private final Image image; 017 /** 018 * Create a new {@link ImageCache} object 019 * @param image The image to paint (optional; either this or {@link #imageFuture} must be specified) 020 * @param imageFuture The future for the image (optional; either this or {@link #image} must be specified) 021 * @param isDirty {@code true} if the tile needs to be repainted 022 */ 023 ImageCache(Image image, StyledTiledMapRenderer.TileLoader imageFuture, boolean isDirty) { 024 this.image = image; 025 this.imageFuture = imageFuture; 026 this.isDirty = isDirty; 027 if (image == null && imageFuture == null) { 028 throw new IllegalArgumentException("Either image or imageFuture must be non-null"); 029 } 030 } 031 032 /** 033 * Check if this tile is dirty 034 * @return {@code true} if this is a dirty tile 035 */ 036 public boolean isDirty() { 037 return this.isDirty; 038 } 039 040 /** 041 * Mark this tile as dirty 042 * @return The tile to put in the cache 043 */ 044 public ImageCache becomeDirty() { 045 if (this.isDirty) { 046 return this; 047 } 048 return new ImageCache(this.image, this.imageFuture, true); 049 } 050 051 /** 052 * Get the image to paint 053 * @return The image (may be {@code null}) 054 */ 055 @Nullable 056 public Image image() { 057 return this.image; 058 } 059 060 /** 061 * Get the image future 062 * @return The image future (may be {@code null}) 063 */ 064 @Nullable 065 StyledTiledMapRenderer.TileLoader imageFuture() { 066 return this.imageFuture; 067 } 068}