Package net.sf.freecol.common.resources
Class ImageResource
- java.lang.Object
-
- net.sf.freecol.common.resources.Resource
-
- net.sf.freecol.common.resources.ImageResource
-
- All Implemented Interfaces:
Resource.Cleanable
public class ImageResource extends Resource implements Resource.Cleanable
AResource
wrapping anImage
.- See Also:
Resource
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.freecol.common.resources.Resource
Resource.Cleanable
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<java.net.URI>
alternativeLocators
private static java.util.Comparator<java.awt.image.BufferedImage>
biComp
Comparator to compare buffered images by ascending size.private java.awt.image.BufferedImage
image
private java.util.List<java.awt.image.BufferedImage>
loadedImages
private static java.util.logging.Logger
logger
private java.util.List<ImageResource>
variations
-
Constructor Summary
Constructors Constructor Description ImageResource(java.lang.String primaryKey, java.net.URI resourceLocator)
Do not use directly.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAlternativeResourceLocator(java.net.URI uri)
Adds another URI for loading a differently sized version of the image.void
addAlternativeResourceLocators(java.util.List<java.net.URI> uris)
Adds another URIs for loading a differently sized version of the image.void
addVariation(ImageResource imageResource)
private static boolean
canUseBitmask(java.net.URI uri)
void
clean()
Clean the caches inside the resource.private java.awt.image.BufferedImage
findLoadedImage(java.util.function.Predicate<java.awt.image.BufferedImage> pred)
Find the loaded image that satisfies a predicate.private java.awt.image.BufferedImage
getColorImage(java.awt.Dimension siz)
Gets the image using the specified dimension.private java.awt.image.BufferedImage
getGrayscaleImage(java.awt.Dimension siz)
Gets a grayscale version of the image of the given size.java.awt.image.BufferedImage
getImage()
Gets theImage
represented by this resource.java.awt.image.BufferedImage
getImage(int variation, java.awt.Dimension d, boolean grayscale)
Gets the image using the specified dimension and choice of grayscale.java.awt.image.BufferedImage
getImage(java.awt.Dimension d, boolean grayscale)
Gets the image using the specified dimension and choice of grayscale.ImageResource
getVariation(int variationNumber)
int
getVariationNumberForSeed(int seed)
int
getVariationNumberForTick(long ticks)
private boolean
haveAlternatives()
private static java.awt.image.BufferedImage
loadImage(java.net.URI uri)
Load an image from a URI.void
preload()
Preload the resource if possible/meaningful.-
Methods inherited from class net.sf.freecol.common.resources.Resource
getPrimaryKey, getResourceLocator
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
biComp
private static final java.util.Comparator<java.awt.image.BufferedImage> biComp
Comparator to compare buffered images by ascending size.
-
image
private volatile java.awt.image.BufferedImage image
-
alternativeLocators
private java.util.List<java.net.URI> alternativeLocators
-
loadedImages
private java.util.List<java.awt.image.BufferedImage> loadedImages
-
variations
private java.util.List<ImageResource> variations
-
-
Method Detail
-
addAlternativeResourceLocator
public void addAlternativeResourceLocator(java.net.URI uri)
Adds another URI for loading a differently sized version of the image. Only use before preload got called!- Parameters:
uri
- TheURI
used when loading.
-
addVariation
public void addVariation(ImageResource imageResource)
-
addAlternativeResourceLocators
public void addAlternativeResourceLocators(java.util.List<java.net.URI> uris)
Adds another URIs for loading a differently sized version of the image. Only use before preload got called!- Parameters:
uris
- AList
ofURI
s used when loading.
-
getImage
public java.awt.image.BufferedImage getImage()
Gets theImage
represented by this resource.- Returns:
- The image in its original size and color.
-
getVariationNumberForSeed
public int getVariationNumberForSeed(int seed)
-
getVariationNumberForTick
public int getVariationNumberForTick(long ticks)
-
getVariation
public ImageResource getVariation(int variationNumber)
-
getImage
public java.awt.image.BufferedImage getImage(int variation, java.awt.Dimension d, boolean grayscale)
Gets the image using the specified dimension and choice of grayscale.- Parameters:
variation
- The image variation.d
- TheDimension
of the requested image.grayscale
- If true return a grayscale image.- Returns:
- The scaled
BufferedImage
.
-
getImage
public java.awt.image.BufferedImage getImage(java.awt.Dimension d, boolean grayscale)
Gets the image using the specified dimension and choice of grayscale.- Parameters:
d
- TheDimension
of the requested image.grayscale
- If true return a grayscale image.- Returns:
- The scaled
BufferedImage
.
-
findLoadedImage
private java.awt.image.BufferedImage findLoadedImage(java.util.function.Predicate<java.awt.image.BufferedImage> pred)
Find the loaded image that satisfies a predicate.- Parameters:
pred
- ThePredicate
to satisfy.- Returns:
- The
BufferedImage
found, or if not found, the one at the end of the loaded images list.
-
haveAlternatives
private boolean haveAlternatives()
-
getColorImage
private java.awt.image.BufferedImage getColorImage(java.awt.Dimension siz)
Gets the image using the specified dimension. Rescaling will be performed if necessary.- Parameters:
siz
- TheDimension
of the requested image.- Returns:
- The
BufferedImage
with the required dimension.
-
getGrayscaleImage
private java.awt.image.BufferedImage getGrayscaleImage(java.awt.Dimension siz)
Gets a grayscale version of the image of the given size.- Parameters:
siz
- TheDimension
of the requested image.- Returns:
- The
BufferedImage
.
-
preload
public void preload()
Preload the resource if possible/meaningful.
-
loadImage
private static java.awt.image.BufferedImage loadImage(java.net.URI uri)
Load an image from a URI.- Parameters:
uri
- TheURI
to load from.- Returns:
- The loaded
BufferedImage
, or null on error.
-
clean
public void clean()
Description copied from interface:Resource.Cleanable
Clean the caches inside the resource.- Specified by:
clean
in interfaceResource.Cleanable
-
canUseBitmask
private static boolean canUseBitmask(java.net.URI uri)
-
-