Class ImageProvider
- java.lang.Object
-
- org.openstreetmap.josm.tools.ImageProvider
-
public class ImageProvider extends java.lang.Object
Helper class to support the application with images.How to use:
ImageIcon icon = new ImageProvider(name).setMaxSize(ImageSizes.MAP).get();(there are more options, see below)short form:
ImageIcon icon = ImageProvider.get(name);
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classImageProvider.ImageLocationsstatic classImageProvider.ImageSizesSupported image sizesstatic classImageProvider.ImageTypeSupported image types
-
Field Summary
Fields Modifier and Type Field Description protected java.io.Filearchivearchive file to take image fromprivate static java.util.Map<java.lang.String,ImageResource>cacheThe icon cacheprivate static java.awt.PointCROSSHAIR_HOTSPOTprotected static intCURSOR_SIZE_HOTSPOT_IS_RELATIVE_TOThe cursor hotspot constantsDEFAULT_HOTSPOTandCROSSHAIR_HOTSPOTare relative to this cursor sizeprivate static java.util.regex.PatterndataUrlPatterndata:[<mediatype>][;base64],<data>private static java.awt.PointDEFAULT_HOTSPOTprotected java.util.Collection<java.lang.String>dirsdirectories in which images are searchedprivate static java.lang.StringHTTP_PROTOCOLprivate static java.lang.StringHTTPS_PROTOCOLprotected java.lang.Stringidcaching identifierprivate static java.util.concurrent.ExecutorServiceIMAGE_FETCHERprotected java.lang.StringinArchiveDirdirectory inside the archiveprotected booleanisDisabledtrueif icon must be grayed outprotected booleanmultiResolutiontrueif multi-resolution image is requestedprotected java.lang.Stringnameimage file nameprotected booleanoptionalIn case of errors do not throw exception but returnnullfor missing imageprivate static java.util.Map<OsmPrimitiveType,javax.swing.ImageIcon>osmPrimitiveTypeCachesmall cache of critical images used in many parts of the applicationprotected java.util.List<ImageOverlay>overlayInfoordered list of overlay imagesstatic java.lang.StringPROP_TRANSPARENCY_COLORProperty set onBufferedImagereturned byread(java.io.File, boolean, boolean)if metadata is required.static java.lang.StringPROP_TRANSPARENCY_FORCEDProperty set onBufferedImagereturned bymakeImageTransparent(java.awt.image.BufferedImage, java.awt.Color).protected java.lang.Stringsubdirsub directory the image can be found inprotected booleansuppressWarningstrueif warnings should be suppressedprivate static com.kitfox.svg.SVGUniversesvgUniverseprotected intvirtualHeightvirtual height of the resulting image, -1 when original image data should be usedprotected intvirtualMaxHeightvirtual maximum height of the resulting image, -1 for no restrictionprotected intvirtualMaxWidthvirtual maximum width of the resulting image, -1 for no restrictionprotected intvirtualWidthvirtual width of the resulting image, -1 when original image data should be usedprivate static java.lang.StringWIKI_PROTOCOL
-
Constructor Summary
Constructors Constructor Description ImageProvider(java.lang.String name)Constructs a newImageProviderfrom a filename.ImageProvider(java.lang.String subdir, java.lang.String name)Constructs a newImageProviderfrom a filename in a given directory.ImageProvider(ImageProvider image)Constructs a newImageProviderfrom an existing one.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ImageProvideraddOverlay(ImageOverlay overlay)Add an overlay over the image.static voidclearCache()Clears the internal image caches.static javax.swing.ImageIconcreateBlankIcon(ImageProvider.ImageSizes size)Creates a blank icon of the given size.static java.awt.ImagecreateBoundedImage(java.awt.Image img, int maxSize)Creates a scaled down version of the input image to fit maximum dimensions.(package private) static java.awt.image.BufferedImagecreateImageFromSvg(com.kitfox.svg.SVGDiagram svg, java.awt.Dimension dim, ImageResizeMode resizeMode)Constructs an image from the given SVG data.private static javax.imageio.stream.ImageInputStreamcreateImageInputStream(java.lang.Object input)static java.awt.image.BufferedImagecreateScaledImage(java.awt.image.BufferedImage img, int targetWidth, int targetHeight, java.lang.Object hint)Returns a scaled instance of the providedBufferedImage.javax.swing.ImageIconget()Execute the image request and scale result.static javax.swing.ImageIconget(java.lang.String name)Load an image with a given file name.static javax.swing.ImageIconget(java.lang.String subdir, java.lang.String name)Load an image with a given file name.static javax.swing.ImageIconget(java.lang.String subdir, java.lang.String name, ImageProvider.ImageSizes size)Load an image from directory with a given file name and size.static javax.swing.ImageIconget(java.lang.String name, ImageProvider.ImageSizes size)Load an image with a given file name and size.static javax.swing.ImageIconget(OsmPrimitiveType type)Replies the icon for an OSM primitive typejava.util.concurrent.CompletableFuture<java.lang.Void>getAsync(java.util.function.Consumer<? super javax.swing.ImageIcon> action)Load the image in a background thread.static java.awt.CursorgetCursor(java.lang.String name, java.lang.String overlay)Load a cursor with a given file name, optionally decorated with an overlay image.(package private) static java.awt.ImagegetCursorImage(java.lang.String name, java.lang.String overlay, java.util.function.UnaryOperator<java.awt.Dimension> bestCursorSizeFunction, java.awt.Point hotSpot)Load a cursor image with a given file name, optionally decorated with an overlay imagejava.lang.StringgetDataURL()Execute the image request and scale result.static javax.swing.ImageIcongetEmpty(ImageProvider.ImageSizes size)Load an empty image with a given size.static javax.swing.ImageIcongetIfAvailable(java.lang.String name)Load an image with a given file name, but do not throw an exception when the image cannot be found.static javax.swing.ImageIcongetIfAvailable(java.lang.String subdir, java.lang.String name)Load an image with a given file name, but do not throw an exception when the image cannot be found.private static ImageResourcegetIfAvailableDataUrl(java.lang.String url)Internal implementation of the image request for inline images (data: urls).private static ImageResourcegetIfAvailableHttp(java.lang.String url, ImageProvider.ImageType type)Internal implementation of the image request for URL's.private ImageResourcegetIfAvailableImpl()Internal implementation of the image request.private static ImageResourcegetIfAvailableLocalURL(java.net.URL path, ImageProvider.ImageType type)Internal implementation of the image request for local images.private static ImageResourcegetIfAvailableWiki(java.lang.String name, ImageProvider.ImageType type)Internal implementation of the image request for wiki images.private static ImageResourcegetIfAvailableZip(java.lang.String fullName, java.io.File archive, java.lang.String inArchiveDir, ImageProvider.ImageType type)Internal implementation of the image request for images in Zip archives.private java.net.URLgetImageUrl(java.lang.String imageName)private static java.net.URLgetImageUrl(java.lang.String path, java.lang.String name)private static java.lang.StringgetImgUrlFromWikiInfoPage(java.lang.String base, java.lang.String fn)Reads the wiki page on a certain file in html format in order to find the real image URL.static javax.swing.ImageIcongetPadded(OsmPrimitive primitive, java.awt.Dimension iconSize)Returns anImageIconfor the given OSM object, at the specified size.ImageResourcegetResource()Execute the image request.java.util.concurrent.CompletableFuture<java.lang.Void>getResourceAsync(java.util.function.Consumer<? super ImageResource> action)Load the image in a background thread.private static com.kitfox.svg.SVGUniversegetSvgUniverse()static java.awt.ColorgetTransparentColor(java.awt.image.ColorModel model, javax.imageio.ImageReader reader)Returns theTransparentColordefined in image reader metadata.static booleanhasTransparentColor(java.awt.image.BufferedImage bi)Determines if the givenBufferedImagehas a transparent color determined by a previous call toread(java.io.File, boolean, boolean).booleanisRemote()Determines if this icon is located on a remote location (http, https, wiki).static booleanisTransparencyForced(java.awt.image.BufferedImage bi)Determines if the transparency of the givenBufferedImagehas been enforced by a previous call tomakeImageTransparent(java.awt.image.BufferedImage, java.awt.Color).static java.awt.image.BufferedImagemakeImageTransparent(java.awt.image.BufferedImage bi, java.awt.Color color)Returns a transparent version of the given image, based on the given transparent color.private static java.awt.ColorparseRGB(java.lang.String... s)static java.awt.image.BufferedImageread(java.io.File input, boolean readMetadata, boolean enforceTransparency)Returns aBufferedImageas the result of decoding a suppliedFilewith anImageReaderchosen automatically from among those currently registered.static java.awt.image.BufferedImageread(java.io.InputStream input, boolean readMetadata, boolean enforceTransparency)Returns aBufferedImageas the result of decoding a suppliedInputStreamwith anImageReaderchosen automatically from among those currently registered.static java.awt.image.BufferedImageread(java.net.URL input, boolean readMetadata, boolean enforceTransparency)Returns aBufferedImageas the result of decoding a suppliedURLwith anImageReaderchosen automatically from among those currently registered.static java.awt.image.BufferedImageread(java.net.URL input, boolean readMetadata, boolean enforceTransparency, java.util.function.Function<javax.imageio.ImageReader,javax.imageio.ImageReadParam> readParamFunction)Returns aBufferedImageas the result of decoding a suppliedURLwith anImageReaderchosen automatically from among those currently registered.static java.awt.image.BufferedImageread(javax.imageio.stream.ImageInputStream stream, boolean readMetadata, boolean enforceTransparency)Returns aBufferedImageas the result of decoding a suppliedImageInputStreamwith anImageReaderchosen automatically from among those currently registered.private static java.awt.image.BufferedImageread(javax.imageio.stream.ImageInputStream stream, boolean readMetadata, boolean enforceTransparency, java.util.function.Function<javax.imageio.ImageReader,javax.imageio.ImageReadParam> readParamFunction)ImageProviderresetMaxSize(java.awt.Dimension maxSize)Limit the maximum size of the image.ImageProvidersetArchive(java.io.File archive)Specify a zip file where the image is located.ImageProvidersetDirs(java.util.Collection<java.lang.String> dirs)Directories to look for the image.ImageProvidersetDisabled(boolean disabled)Set, if image must be filtered to grayscale so it will look like disabled icon.ImageProvidersetHeight(int height)Set image heightImageProvidersetId(java.lang.String id)Set an id used for caching.ImageProvidersetInArchiveDir(java.lang.String inArchiveDir)Specify a base path inside the zip file.ImageProvidersetMaxHeight(int maxHeight)Limit the maximum height of the image.ImageProvidersetMaxSize(int maxSize)Convenience method, seesetMaxSize(Dimension).ImageProvidersetMaxSize(java.awt.Dimension maxSize)Limit the maximum size of the image.ImageProvidersetMaxSize(ImageProvider.ImageSizes size)Limit the maximum size of the image.ImageProvidersetMaxWidth(int maxWidth)Limit the maximum width of the image.ImageProvidersetMultiResolution(boolean multiResolution)Decide, if multi-resolution image is requested (defaulttrue).ImageProvidersetOptional(boolean optional)Decide, if an exception should be thrown, when the image cannot be located.ImageProvidersetSize(int width, int height)Set the dimensions of the image.ImageProvidersetSize(java.awt.Dimension size)Set the dimensions of the image.ImageProvidersetSize(ImageProvider.ImageSizes size)Set the dimensions of the image.ImageProvidersetSuppressWarnings(boolean suppressWarnings)Suppresses warning on the command line in case the image cannot be found.ImageProvidersetWidth(int width)Set image widthstatic voidshutdown(boolean now)Shutdown background image fetcher.static java.awt.image.BufferedImagetoBufferedImage(java.awt.Image image)Converts anImageto aBufferedImageinstance.static java.awt.image.BufferedImagetoBufferedImage(java.awt.Image image, java.awt.Rectangle cropArea)Converts anRectanglearea ofImageto aBufferedImageinstance.java.lang.StringtoString()
-
-
-
Field Detail
-
HTTP_PROTOCOL
private static final java.lang.String HTTP_PROTOCOL
- See Also:
- Constant Field Values
-
HTTPS_PROTOCOL
private static final java.lang.String HTTPS_PROTOCOL
- See Also:
- Constant Field Values
-
WIKI_PROTOCOL
private static final java.lang.String WIKI_PROTOCOL
- See Also:
- Constant Field Values
-
PROP_TRANSPARENCY_FORCED
public static final java.lang.String PROP_TRANSPARENCY_FORCED
Property set onBufferedImagereturned bymakeImageTransparent(java.awt.image.BufferedImage, java.awt.Color).- Since:
- 7132
- See Also:
- Constant Field Values
-
PROP_TRANSPARENCY_COLOR
public static final java.lang.String PROP_TRANSPARENCY_COLOR
Property set onBufferedImagereturned byread(java.io.File, boolean, boolean)if metadata is required.- Since:
- 7132
- See Also:
- Constant Field Values
-
dirs
protected java.util.Collection<java.lang.String> dirs
directories in which images are searched
-
id
protected java.lang.String id
caching identifier
-
subdir
protected java.lang.String subdir
sub directory the image can be found in
-
name
protected final java.lang.String name
image file name
-
archive
protected java.io.File archive
archive file to take image from
-
inArchiveDir
protected java.lang.String inArchiveDir
directory inside the archive
-
virtualWidth
protected int virtualWidth
virtual width of the resulting image, -1 when original image data should be used
-
virtualHeight
protected int virtualHeight
virtual height of the resulting image, -1 when original image data should be used
-
virtualMaxWidth
protected int virtualMaxWidth
virtual maximum width of the resulting image, -1 for no restriction
-
virtualMaxHeight
protected int virtualMaxHeight
virtual maximum height of the resulting image, -1 for no restriction
-
optional
protected boolean optional
In case of errors do not throw exception but returnnullfor missing image
-
suppressWarnings
protected boolean suppressWarnings
trueif warnings should be suppressed
-
overlayInfo
protected java.util.List<ImageOverlay> overlayInfo
ordered list of overlay images
-
isDisabled
protected boolean isDisabled
trueif icon must be grayed out
-
multiResolution
protected boolean multiResolution
trueif multi-resolution image is requested
-
svgUniverse
private static com.kitfox.svg.SVGUniverse svgUniverse
-
cache
private static final java.util.Map<java.lang.String,ImageResource> cache
The icon cache
-
osmPrimitiveTypeCache
private static final java.util.Map<OsmPrimitiveType,javax.swing.ImageIcon> osmPrimitiveTypeCache
small cache of critical images used in many parts of the application
-
IMAGE_FETCHER
private static final java.util.concurrent.ExecutorService IMAGE_FETCHER
-
dataUrlPattern
private static final java.util.regex.Pattern dataUrlPattern
data:[<mediatype>][;base64],<data>- See Also:
- RFC2397
-
CURSOR_SIZE_HOTSPOT_IS_RELATIVE_TO
protected static final int CURSOR_SIZE_HOTSPOT_IS_RELATIVE_TO
The cursor hotspot constantsDEFAULT_HOTSPOTandCROSSHAIR_HOTSPOTare relative to this cursor size- See Also:
- Constant Field Values
-
DEFAULT_HOTSPOT
private static final java.awt.Point DEFAULT_HOTSPOT
-
CROSSHAIR_HOTSPOT
private static final java.awt.Point CROSSHAIR_HOTSPOT
-
-
Constructor Detail
-
ImageProvider
public ImageProvider(java.lang.String subdir, java.lang.String name)
Constructs a newImageProviderfrom a filename in a given directory.- Parameters:
subdir- subdirectory the image lies inname- the name of the image. If it does not end with '.png' or '.svg', both extensions are tried.- Throws:
java.lang.NullPointerException- if name is null
-
ImageProvider
public ImageProvider(java.lang.String name)
Constructs a newImageProviderfrom a filename.- Parameters:
name- the name of the image. If it does not end with '.png' or '.svg', both extensions are tried.- Throws:
java.lang.NullPointerException- if name is null
-
ImageProvider
public ImageProvider(ImageProvider image)
Constructs a newImageProviderfrom an existing one.- Parameters:
image- the existing image provider to be copied- Since:
- 8095
-
-
Method Detail
-
setDirs
public ImageProvider setDirs(java.util.Collection<java.lang.String> dirs)
Directories to look for the image.- Parameters:
dirs- The directories to look for.- Returns:
- the current object, for convenience
-
setId
public ImageProvider setId(java.lang.String id)
Set an id used for caching. If name starts withhttp://Id is not used for the cache. (A URL is unique anyway.)- Parameters:
id- the id for the cached image- Returns:
- the current object, for convenience
-
setArchive
public ImageProvider setArchive(java.io.File archive)
Specify a zip file where the image is located.(optional)
- Parameters:
archive- zip file where the image is located- Returns:
- the current object, for convenience
-
setInArchiveDir
public ImageProvider setInArchiveDir(java.lang.String inArchiveDir)
Specify a base path inside the zip file.The subdir and name will be relative to this path.
(optional)
- Parameters:
inArchiveDir- path inside the archive- Returns:
- the current object, for convenience
-
addOverlay
public ImageProvider addOverlay(ImageOverlay overlay)
Add an overlay over the image. Multiple overlays are possible.- Parameters:
overlay- overlay image and placement specification- Returns:
- the current object, for convenience
- Since:
- 8095
-
setSize
public ImageProvider setSize(java.awt.Dimension size)
Set the dimensions of the image.If not specified, the original size of the image is used. The width part of the dimension can be -1. Then it will only set the height but keep the aspect ratio. (And the other way around.)
- Parameters:
size- final dimensions of the image- Returns:
- the current object, for convenience
-
setSize
public ImageProvider setSize(ImageProvider.ImageSizes size)
Set the dimensions of the image.If not specified, the original size of the image is used.
- Parameters:
size- final dimensions of the image- Returns:
- the current object, for convenience
- Since:
- 7687
-
setSize
public ImageProvider setSize(int width, int height)
Set the dimensions of the image.- Parameters:
width- final width of the imageheight- final height of the image- Returns:
- the current object, for convenience
- Since:
- 10358
-
setWidth
public ImageProvider setWidth(int width)
Set image width- Parameters:
width- final width of the image- Returns:
- the current object, for convenience
- See Also:
setSize(java.awt.Dimension)
-
setHeight
public ImageProvider setHeight(int height)
Set image height- Parameters:
height- final height of the image- Returns:
- the current object, for convenience
- See Also:
setSize(java.awt.Dimension)
-
setMaxSize
public ImageProvider setMaxSize(java.awt.Dimension maxSize)
Limit the maximum size of the image.It will shrink the image if necessary, but keep the aspect ratio. The given width or height can be -1 which means this direction is not bounded.
'size' and 'maxSize' are not compatible, you should set only one of them.
- Parameters:
maxSize- maximum image size- Returns:
- the current object, for convenience
-
resetMaxSize
public ImageProvider resetMaxSize(java.awt.Dimension maxSize)
Limit the maximum size of the image.It will shrink the image if necessary, but keep the aspect ratio. The given width or height can be -1 which means this direction is not bounded.
This function sets value using the most restrictive of the new or existing set of values.
- Parameters:
maxSize- maximum image size- Returns:
- the current object, for convenience
- See Also:
setMaxSize(Dimension)
-
setMaxSize
public ImageProvider setMaxSize(ImageProvider.ImageSizes size)
Limit the maximum size of the image.It will shrink the image if necessary, but keep the aspect ratio. The given width or height can be -1 which means this direction is not bounded.
'size' and 'maxSize' are not compatible, you should set only one of them.
- Parameters:
size- maximum image size- Returns:
- the current object, for convenience
- Since:
- 7687
-
setMaxSize
public ImageProvider setMaxSize(int maxSize)
Convenience method, seesetMaxSize(Dimension).- Parameters:
maxSize- maximum image size- Returns:
- the current object, for convenience
-
setMaxWidth
public ImageProvider setMaxWidth(int maxWidth)
Limit the maximum width of the image.- Parameters:
maxWidth- maximum image width- Returns:
- the current object, for convenience
- See Also:
setMaxSize(java.awt.Dimension)
-
setMaxHeight
public ImageProvider setMaxHeight(int maxHeight)
Limit the maximum height of the image.- Parameters:
maxHeight- maximum image height- Returns:
- the current object, for convenience
- See Also:
setMaxSize(java.awt.Dimension)
-
setOptional
public ImageProvider setOptional(boolean optional)
Decide, if an exception should be thrown, when the image cannot be located.Set to true, when the image URL comes from user data and the image may be missing.
- Parameters:
optional- true, if JOSM should not throw a RuntimeException in case the image cannot be located.- Returns:
- the current object, for convenience
-
setSuppressWarnings
public ImageProvider setSuppressWarnings(boolean suppressWarnings)
Suppresses warning on the command line in case the image cannot be found.In combination with setOptional(true);
- Parameters:
suppressWarnings- iftruewarnings are suppressed- Returns:
- the current object, for convenience
-
setDisabled
public ImageProvider setDisabled(boolean disabled)
Set, if image must be filtered to grayscale so it will look like disabled icon.- Parameters:
disabled- true, if image must be grayed out for disabled state- Returns:
- the current object, for convenience
- Since:
- 10428
-
setMultiResolution
public ImageProvider setMultiResolution(boolean multiResolution)
Decide, if multi-resolution image is requested (defaulttrue).A
java.awt.image.MultiResolutionImageis a Java 9Imageimplementation, which adds support for HiDPI displays. The effect will be that in HiDPI mode, when GUI elements are scaled by a factor 1.5, 2.0, etc., the images are not just up-scaled, but a higher resolution version of the image is rendered instead.Use
HiDPISupport.getBaseImage(java.awt.Image)to extract the original image from a multi-resolution image.See
HiDPISupport.processMRImage(java.awt.Image, java.util.function.UnaryOperator<java.awt.Image>)for how to process the image without removing the multi-resolution magic.- Parameters:
multiResolution- true, if multi-resolution image is requested- Returns:
- the current object, for convenience
-
isRemote
public boolean isRemote()
Determines if this icon is located on a remote location (http, https, wiki).- Returns:
trueif this icon is located on a remote location (http, https, wiki)- Since:
- 13250
-
get
public javax.swing.ImageIcon get()
Execute the image request and scale result.- Returns:
- the requested image or null if the request failed
-
getDataURL
public java.lang.String getDataURL()
Execute the image request and scale result.- Returns:
- the requested image as data: URL or null if the request failed
- Since:
- 16872
-
getAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> getAsync(java.util.function.Consumer<? super javax.swing.ImageIcon> action)
Load the image in a background thread.This method returns immediately and runs the image request asynchronously.
- Parameters:
action- the action that will deal with the image- Returns:
- the future of the requested image
- Since:
- 13252
-
getResource
public ImageResource getResource()
Execute the image request.- Returns:
- the requested image or null if the request failed
- Since:
- 7693
-
getResourceAsync
public java.util.concurrent.CompletableFuture<java.lang.Void> getResourceAsync(java.util.function.Consumer<? super ImageResource> action)
Load the image in a background thread.This method returns immediately and runs the image request asynchronously.
- Parameters:
action- the action that will deal with the image- Returns:
- the future of the requested image
- Since:
- 13252
-
get
public static javax.swing.ImageIcon get(java.lang.String subdir, java.lang.String name)
Load an image with a given file name.- Parameters:
subdir- subdirectory the image lies inname- The icon name (base name with or without '.png' or '.svg' extension)- Returns:
- The requested Image.
- Throws:
java.lang.RuntimeException- if the image cannot be located
-
get
public static javax.swing.ImageIcon get(java.lang.String name)
Load an image with a given file name.- Parameters:
name- The icon name (base name with or without '.png' or '.svg' extension)- Returns:
- the requested image or null if the request failed
- See Also:
get(String, String)
-
get
public static javax.swing.ImageIcon get(java.lang.String subdir, java.lang.String name, ImageProvider.ImageSizes size)
Load an image from directory with a given file name and size.- Parameters:
subdir- subdirectory the image lies inname- The icon name (base name with or without '.png' or '.svg' extension)size- Target icon size- Returns:
- The requested Image.
- Throws:
java.lang.RuntimeException- if the image cannot be located- Since:
- 10428
-
getEmpty
public static javax.swing.ImageIcon getEmpty(ImageProvider.ImageSizes size)
Load an empty image with a given size.- Parameters:
size- Target icon size- Returns:
- The requested Image.
- Since:
- 10358
-
getIfAvailable
public static javax.swing.ImageIcon getIfAvailable(java.lang.String subdir, java.lang.String name)
Load an image with a given file name, but do not throw an exception when the image cannot be found.- Parameters:
subdir- subdirectory the image lies inname- The icon name (base name with or without '.png' or '.svg' extension)- Returns:
- the requested image or null if the request failed
- See Also:
get(String, String)
-
get
public static javax.swing.ImageIcon get(java.lang.String name, ImageProvider.ImageSizes size)
Load an image with a given file name and size.- Parameters:
name- The icon name (base name with or without '.png' or '.svg' extension)size- Target icon size- Returns:
- the requested image or null if the request failed
- Since:
- 10428
- See Also:
get(String, String)
-
getIfAvailable
public static javax.swing.ImageIcon getIfAvailable(java.lang.String name)
Load an image with a given file name, but do not throw an exception when the image cannot be found.- Parameters:
name- The icon name (base name with or without '.png' or '.svg' extension)- Returns:
- the requested image or null if the request failed
- See Also:
getIfAvailable(String, String)
-
clearCache
public static void clearCache()
Clears the internal image caches.- Since:
- 11021
-
getIfAvailableImpl
private ImageResource getIfAvailableImpl()
Internal implementation of the image request.- Returns:
- the requested image or null if the request failed
-
getIfAvailableHttp
private static ImageResource getIfAvailableHttp(java.lang.String url, ImageProvider.ImageType type)
Internal implementation of the image request for URL's.- Parameters:
url- URL of the imagetype- data type of the image- Returns:
- the requested image or null if the request failed
-
getIfAvailableDataUrl
private static ImageResource getIfAvailableDataUrl(java.lang.String url)
Internal implementation of the image request for inline images (data: urls).- Parameters:
url- the data URL for image extraction- Returns:
- the requested image or null if the request failed
-
getIfAvailableWiki
private static ImageResource getIfAvailableWiki(java.lang.String name, ImageProvider.ImageType type)
Internal implementation of the image request for wiki images.- Parameters:
name- image file nametype- data type of the image- Returns:
- the requested image or null if the request failed
-
getIfAvailableZip
private static ImageResource getIfAvailableZip(java.lang.String fullName, java.io.File archive, java.lang.String inArchiveDir, ImageProvider.ImageType type)
Internal implementation of the image request for images in Zip archives.- Parameters:
fullName- image file namearchive- the archive to get image frominArchiveDir- directory of the image inside the archive ornulltype- data type of the image- Returns:
- the requested image or null if the request failed
-
getIfAvailableLocalURL
private static ImageResource getIfAvailableLocalURL(java.net.URL path, ImageProvider.ImageType type)
Internal implementation of the image request for local images.- Parameters:
path- image file pathtype- data type of the image- Returns:
- the requested image or null if the request failed
-
getImageUrl
private static java.net.URL getImageUrl(java.lang.String path, java.lang.String name)
-
getImageUrl
private java.net.URL getImageUrl(java.lang.String imageName)
-
getImgUrlFromWikiInfoPage
private static java.lang.String getImgUrlFromWikiInfoPage(java.lang.String base, java.lang.String fn)
Reads the wiki page on a certain file in html format in order to find the real image URL.- Parameters:
base- base URL for Wiki imagefn- filename of the Wiki image- Returns:
- image URL for a Wiki image or null in case of error
-
getCursor
public static java.awt.Cursor getCursor(java.lang.String name, java.lang.String overlay)
Load a cursor with a given file name, optionally decorated with an overlay image.- Parameters:
name- the cursor image filename in "cursor" directoryoverlay- optional overlay image- Returns:
- cursor with a given file name, optionally decorated with an overlay image
-
getCursorImage
static java.awt.Image getCursorImage(java.lang.String name, java.lang.String overlay, java.util.function.UnaryOperator<java.awt.Dimension> bestCursorSizeFunction, java.awt.Point hotSpot)
Load a cursor image with a given file name, optionally decorated with an overlay image- Parameters:
name- the cursor image filename in "cursor" directoryoverlay- optional overlay imagebestCursorSizeFunction- computes the best cursor size, seeToolkit.getBestCursorSize(int, int)hotSpot- will be set to the properly scaled hotspot of the cursor- Returns:
- cursor with a given file name, optionally decorated with an overlay image
-
createBoundedImage
public static java.awt.Image createBoundedImage(java.awt.Image img, int maxSize)
Creates a scaled down version of the input image to fit maximum dimensions. (Keeps aspect ratio)- Parameters:
img- the image to be scaled down.maxSize- the maximum size in pixels (both for width and height)- Returns:
- the image after scaling.
- Since:
- 6172
-
createScaledImage
public static java.awt.image.BufferedImage createScaledImage(java.awt.image.BufferedImage img, int targetWidth, int targetHeight, java.lang.Object hint)
Returns a scaled instance of the providedBufferedImage. This method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in downscaling cases, wheretargetWidthortargetHeightis smaller than the original dimensions, and generally only when theBILINEARhint is specified).- Parameters:
img- the original image to be scaledtargetWidth- the desired width of the scaled instance, in pixelstargetHeight- the desired height of the scaled instance, in pixelshint- one of the rendering hints that corresponds toRenderingHints.KEY_INTERPOLATION(e.g.RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR,RenderingHints.VALUE_INTERPOLATION_BILINEAR,RenderingHints.VALUE_INTERPOLATION_BICUBIC)- Returns:
- a scaled version of the original
BufferedImage - Since:
- 13038
-
get
public static javax.swing.ImageIcon get(OsmPrimitiveType type)
Replies the icon for an OSM primitive type- Parameters:
type- the type- Returns:
- the icon
-
getPadded
public static javax.swing.ImageIcon getPadded(OsmPrimitive primitive, java.awt.Dimension iconSize)
Returns anImageIconfor the given OSM object, at the specified size. This is a slow operation.- Parameters:
primitive- Object for which an icon shall be fetched. The icon is chosen based on tags.iconSize- Target size of icon. Icon is padded if required.- Returns:
- Icon for
primitivethat fits in cell. - Since:
- 8903
-
createImageFromSvg
static java.awt.image.BufferedImage createImageFromSvg(com.kitfox.svg.SVGDiagram svg, java.awt.Dimension dim, ImageResizeMode resizeMode)
Constructs an image from the given SVG data.- Parameters:
svg- the SVG datadim- the desired image dimensionresizeMode- how to size/resize the image- Returns:
- an image from the given SVG data at the desired dimension.
-
getSvgUniverse
private static com.kitfox.svg.SVGUniverse getSvgUniverse()
-
read
public static java.awt.image.BufferedImage read(java.io.File input, boolean readMetadata, boolean enforceTransparency) throws java.io.IOException
Returns aBufferedImageas the result of decoding a suppliedFilewith anImageReaderchosen automatically from among those currently registered. TheFileis wrapped in anImageInputStream. If no registeredImageReaderclaims to be able to read the resulting stream,nullis returned.The current cache settings from
getUseCacheandgetCacheDirectorywill be used to control caching in theImageInputStreamthat is created.Note that there is no
readmethod that takes a filename as aString; use this method instead after creating aFilefrom the filename.This method does not attempt to locate
ImageReaders that can read directly from aFile; that may be accomplished usingIIORegistryandImageReaderSpi.- Parameters:
input- aFileto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color.- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
java.lang.IllegalArgumentException- ifinputisnull.java.io.IOException- if an error occurs during reading.- Since:
- 7132
- See Also:
BufferedImage.getProperty(java.lang.String, java.awt.image.ImageObserver)
-
read
public static java.awt.image.BufferedImage read(java.io.InputStream input, boolean readMetadata, boolean enforceTransparency) throws java.io.IOException
Returns aBufferedImageas the result of decoding a suppliedInputStreamwith anImageReaderchosen automatically from among those currently registered. TheInputStreamis wrapped in anImageInputStream. If no registeredImageReaderclaims to be able to read the resulting stream,nullis returned.The current cache settings from
getUseCacheandgetCacheDirectorywill be used to control caching in theImageInputStreamthat is created.This method does not attempt to locate
ImageReaders that can read directly from anInputStream; that may be accomplished usingIIORegistryandImageReaderSpi.This method does not close the provided
InputStreamafter the read operation has completed; it is the responsibility of the caller to close the stream, if desired.- Parameters:
input- anInputStreamto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color for non translucent images, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color.- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
java.lang.IllegalArgumentException- ifinputisnull.java.io.IOException- if an error occurs during reading.- Since:
- 7132
-
read
public static java.awt.image.BufferedImage read(java.net.URL input, boolean readMetadata, boolean enforceTransparency) throws java.io.IOException
Returns aBufferedImageas the result of decoding a suppliedURLwith anImageReaderchosen automatically from among those currently registered. AnInputStreamis obtained from theURL, which is wrapped in anImageInputStream. If no registeredImageReaderclaims to be able to read the resulting stream,nullis returned.The current cache settings from
getUseCacheandgetCacheDirectorywill be used to control caching in theImageInputStreamthat is created.This method does not attempt to locate
ImageReaders that can read directly from aURL; that may be accomplished usingIIORegistryandImageReaderSpi.- Parameters:
input- aURLto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color for non translucent images, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color.- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
java.lang.IllegalArgumentException- ifinputisnull.java.io.IOException- if an error occurs during reading.- Since:
- 7132
-
read
public static java.awt.image.BufferedImage read(java.net.URL input, boolean readMetadata, boolean enforceTransparency, java.util.function.Function<javax.imageio.ImageReader,javax.imageio.ImageReadParam> readParamFunction) throws java.io.IOException
Returns aBufferedImageas the result of decoding a suppliedURLwith anImageReaderchosen automatically from among those currently registered. AnInputStreamis obtained from theURL, which is wrapped in anImageInputStream. If no registeredImageReaderclaims to be able to read the resulting stream,nullis returned.The current cache settings from
getUseCacheandgetCacheDirectorywill be used to control caching in theImageInputStreamthat is created.This method does not attempt to locate
ImageReaders that can read directly from aURL; that may be accomplished usingIIORegistryandImageReaderSpi.- Parameters:
input- aURLto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color for non translucent images, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color.readParamFunction- a function to compute the read parameters from the image reader- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
java.lang.IllegalArgumentException- ifinputisnull.java.io.IOException- if an error occurs during reading.- Since:
- 17880
-
read
public static java.awt.image.BufferedImage read(javax.imageio.stream.ImageInputStream stream, boolean readMetadata, boolean enforceTransparency) throws java.io.IOException
Returns aBufferedImageas the result of decoding a suppliedImageInputStreamwith anImageReaderchosen automatically from among those currently registered. If no registeredImageReaderclaims to be able to read the stream,nullis returned.Unlike most other methods in this class, this method does close the provided
ImageInputStreamafter the read operation has completed, unlessnullis returned, in which case this method does not close the stream.- Parameters:
stream- anImageInputStreamto read from.readMetadata- iftrue, makes sure to read image metadata to detect transparency color for non translucent images, if any. In that case the color can be retrieved later throughPROP_TRANSPARENCY_COLOR. Always consideredtrueifenforceTransparencyis alsotrueenforceTransparency- iftrue, makes sure to read image metadata and, if the image does not provide an alpha channel but defines aTransparentColormetadata node, that the resulting image has a transparency set toTRANSLUCENTand uses the correct transparent color. For Java < 11 only.- Returns:
- a
BufferedImagecontaining the decoded contents of the input, ornull. - Throws:
java.lang.IllegalArgumentException- ifstreamisnull.java.io.IOException- if an error occurs during reading.- Since:
- 7132
-
read
private static java.awt.image.BufferedImage read(javax.imageio.stream.ImageInputStream stream, boolean readMetadata, boolean enforceTransparency, java.util.function.Function<javax.imageio.ImageReader,javax.imageio.ImageReadParam> readParamFunction) throws java.io.IOException
- Throws:
java.io.IOException
-
getTransparentColor
public static java.awt.Color getTransparentColor(java.awt.image.ColorModel model, javax.imageio.ImageReader reader) throws java.io.IOException
Returns theTransparentColordefined in image reader metadata.- Parameters:
model- The image color modelreader- The image reader- Returns:
- the
TransparentColordefined in image reader metadata, ornull - Throws:
java.io.IOException- if an error occurs during reading- Since:
- 7499
- See Also:
- javax_imageio_1.0 metadata
-
parseRGB
private static java.awt.Color parseRGB(java.lang.String... s)
-
makeImageTransparent
public static java.awt.image.BufferedImage makeImageTransparent(java.awt.image.BufferedImage bi, java.awt.Color color)
Returns a transparent version of the given image, based on the given transparent color.- Parameters:
bi- The image to convertcolor- The transparent color- Returns:
- The same image as
biwhere all pixels of the given color are transparent. This resulting image has also the special propertyPROP_TRANSPARENCY_FORCEDset tocolor - Since:
- 7132
- See Also:
BufferedImage.getProperty(java.lang.String, java.awt.image.ImageObserver),isTransparencyForced(java.awt.image.BufferedImage)
-
isTransparencyForced
public static boolean isTransparencyForced(java.awt.image.BufferedImage bi)
Determines if the transparency of the givenBufferedImagehas been enforced by a previous call tomakeImageTransparent(java.awt.image.BufferedImage, java.awt.Color).- Parameters:
bi- TheBufferedImageto test- Returns:
trueif the transparency ofbihas been enforced by a previous call tomakeImageTransparent.- Since:
- 7132
- See Also:
makeImageTransparent(java.awt.image.BufferedImage, java.awt.Color)
-
hasTransparentColor
public static boolean hasTransparentColor(java.awt.image.BufferedImage bi)
Determines if the givenBufferedImagehas a transparent color determined by a previous call toread(java.io.File, boolean, boolean).- Parameters:
bi- TheBufferedImageto test- Returns:
trueifbihas a transparent color determined by a previous call toread.- Since:
- 7132
- See Also:
read(java.io.File, boolean, boolean)
-
shutdown
public static void shutdown(boolean now)
Shutdown background image fetcher.- Parameters:
now- iftrue, attempts to stop all actively executing tasks, halts the processing of waiting tasks. iffalse, initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted- Since:
- 8412
-
toBufferedImage
public static java.awt.image.BufferedImage toBufferedImage(java.awt.Image image)
Converts anImageto aBufferedImageinstance.- Parameters:
image- image to convert- Returns:
- a
BufferedImageinstance for the givenImage. - Since:
- 13038
-
toBufferedImage
public static java.awt.image.BufferedImage toBufferedImage(java.awt.Image image, java.awt.Rectangle cropArea)
Converts anRectanglearea ofImageto aBufferedImageinstance.- Parameters:
image- image to convertcropArea- rectangle to crop image with- Returns:
- a
BufferedImageinstance for the cropped area ofImage. - Since:
- 13127
-
createImageInputStream
private static javax.imageio.stream.ImageInputStream createImageInputStream(java.lang.Object input) throws java.io.IOException
- Throws:
java.io.IOException
-
createBlankIcon
public static javax.swing.ImageIcon createBlankIcon(ImageProvider.ImageSizes size)
Creates a blank icon of the given size.- Parameters:
size- image size- Returns:
- a blank icon of the given size
- Since:
- 13984
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-