public class ImageProvider extends Object
ImageIcon icon = new ImageProvider(name).setMaxWidth(24).setMaxHeight(24).get();
(there are more options, see below)
short form:
ImageIcon icon = ImageProvider.get(name);
Modifier and Type | Class and Description |
---|---|
static interface |
ImageProvider.ImageCallback |
static class |
ImageProvider.ImageType
Supported image types
|
static class |
ImageProvider.OverlayPosition
Position of an overlay icon
|
Modifier and Type | Field and Description |
---|---|
protected Collection<ClassLoader> |
additionalClassLoaders |
protected File |
archive |
private static Map<String,ImageResource> |
cache
The icon cache
|
private static Pattern |
dataUrlPattern
data:[<mediatype>][;base64],<data> |
(package private) static double |
DEGREE_90
90 degrees in radians units
|
protected Collection<String> |
dirs |
protected int |
height |
protected String |
id |
private static ExecutorService |
IMAGE_FETCHER |
protected String |
inArchiveDir |
protected int |
maxHeight |
protected int |
maxWidth |
protected String |
name |
protected boolean |
optional |
private static Map<Image,Map<Long,ImageResource>> |
ROTATE_CACHE
Caches the image data for rotated versions of the same image.
|
protected String |
subdir |
protected boolean |
suppressWarnings |
private static SVGUniverse |
svgUniverse |
protected int |
width |
Constructor and Description |
---|
ImageProvider(String name)
Constructs a new
ImageProvider from a filename. |
ImageProvider(String subdir,
String name)
Constructs a new
ImageProvider from a filename in a given directory. |
Modifier and Type | Method and Description |
---|---|
static Image |
createBoundedImage(Image img,
int maxSize)
Creates a scaled down version of the input image to fit maximum dimensions.
|
static BufferedImage |
createImageFromSvg(SVGDiagram svg,
Dimension dim) |
static Image |
createRotatedImage(Image img,
double rotatedAngle)
Creates a rotated version of the input image.
|
static Image |
createRotatedImage(Image img,
double rotatedAngle,
Dimension dimension)
Creates a rotated version of the input image, scaled to the given dimension.
|
ImageIcon |
get()
Execute the image request.
|
static ImageIcon |
get(OsmPrimitiveType type)
Replies the icon for an OSM primitive type
|
static ImageIcon |
get(String name) |
static ImageIcon |
get(String subdir,
String name)
Load an image with a given file name.
|
static Cursor |
getCursor(String name,
String overlay) |
static ImageIcon |
getIfAvailable(String name) |
static ImageIcon |
getIfAvailable(String subdir,
String name)
Load an image with a given file name, but do not throw an exception
when the image cannot be found.
|
private static ImageResource |
getIfAvailableHttp(String url,
ImageProvider.ImageType type) |
private ImageResource |
getIfAvailableImpl(Collection<ClassLoader> additionalClassLoaders) |
private static ImageResource |
getIfAvailableLocalURL(URL path,
ImageProvider.ImageType type) |
private static ImageResource |
getIfAvailableWiki(String name,
ImageProvider.ImageType type) |
private static ImageResource |
getIfAvailableZip(String full_name,
File archive,
String inArchiveDir,
ImageProvider.ImageType type) |
private static URL |
getImageUrl(String imageName,
Collection<String> dirs,
Collection<ClassLoader> additionalClassLoaders) |
private static URL |
getImageUrl(String path,
String name,
Collection<ClassLoader> additionalClassLoaders) |
private static String |
getImgUrlFromWikiInfoPage(String base,
String fn)
Reads the wiki page on a certain file in html format in order to find the real image URL.
|
void |
getInBackground(ImageProvider.ImageCallback callback)
Load the image in a background thread.
|
private static SVGUniverse |
getSvgUniverse() |
static ImageIcon |
overlay(Icon ground,
Icon overlay,
ImageProvider.OverlayPosition pos)
Decorate one icon with an overlay icon.
|
ImageProvider |
setAdditionalClassLoaders(Collection<ClassLoader> additionalClassLoaders)
Add a collection of additional class loaders to search image for.
|
ImageProvider |
setArchive(File archive)
Specify a zip file where the image is located.
|
ImageProvider |
setDirs(Collection<String> dirs)
Directories to look for the image.
|
ImageProvider |
setHeight(int height) |
ImageProvider |
setId(String id)
Set an id used for caching.
|
ImageProvider |
setInArchiveDir(String inArchiveDir)
Specify a base path inside the zip file.
|
ImageProvider |
setMaxHeight(int maxHeight) |
ImageProvider |
setMaxSize(Dimension maxSize)
Limit the maximum size of the image.
|
ImageProvider |
setMaxSize(int maxSize)
Convenience method, see
setMaxSize(Dimension) . |
ImageProvider |
setMaxWidth(int maxWidth) |
ImageProvider |
setOptional(boolean optional)
Decide, if an exception should be thrown, when the image cannot be located.
|
ImageProvider |
setSize(Dimension size)
Set the dimensions of the image.
|
ImageProvider |
setSuppressWarnings(boolean suppressWarnings)
Suppresses warning on the command line in case the image cannot be found.
|
ImageProvider |
setWidth(int width) |
protected Collection<String> dirs
protected String inArchiveDir
protected int width
protected int height
protected int maxWidth
protected int maxHeight
protected boolean optional
protected boolean suppressWarnings
protected Collection<ClassLoader> additionalClassLoaders
private static SVGUniverse svgUniverse
private static final Map<String,ImageResource> cache
private static final Map<Image,Map<Long,ImageResource>> ROTATE_CACHE
private static final ExecutorService IMAGE_FETCHER
private static final Pattern dataUrlPattern
data:[<mediatype>][;base64],<data>
static final double DEGREE_90
public ImageProvider(String subdir, String name)
ImageProvider
from a filename in a given directory.subdir
- subdirectory the image lies inname
- the name of the image. If it does not end with '.png' or '.svg',
both extensions are tried.public ImageProvider(String name)
ImageProvider
from a filename.name
- the name of the image. If it does not end with '.png' or '.svg',
both extensions are tried.public ImageProvider setDirs(Collection<String> dirs)
dirs
- The directories to look for.public ImageProvider setId(String id)
public ImageProvider setArchive(File archive)
public ImageProvider setInArchiveDir(String inArchiveDir)
public ImageProvider setSize(Dimension size)
public ImageProvider setWidth(int width)
setSize(java.awt.Dimension)
public ImageProvider setHeight(int height)
setSize(java.awt.Dimension)
public ImageProvider setMaxSize(Dimension maxSize)
public ImageProvider setMaxSize(int maxSize)
setMaxSize(Dimension)
.public ImageProvider setMaxWidth(int maxWidth)
setMaxSize(java.awt.Dimension)
public ImageProvider setMaxHeight(int maxHeight)
setMaxSize(java.awt.Dimension)
public ImageProvider setOptional(boolean optional)
optional
- true, if JOSM should not throw a RuntimeException
in case the image cannot be located.public ImageProvider setSuppressWarnings(boolean suppressWarnings)
public ImageProvider setAdditionalClassLoaders(Collection<ClassLoader> additionalClassLoaders)
public ImageIcon get()
public void getInBackground(ImageProvider.ImageCallback callback)
callback
- a callback. It is called, when the image is ready.
This can happen before the call to this method returns or it may be
invoked some time (seconds) later. If no image is available, a null
value is returned to callback (just like get()
).public static ImageIcon get(String subdir, String name)
subdir
- subdirectory the image lies inname
- The icon name (base name with or without '.png' or '.svg' extension)RuntimeException
- if the image cannot be locatedpublic static ImageIcon get(String name)
get(java.lang.String, java.lang.String)
public static ImageIcon getIfAvailable(String subdir, String name)
get(java.lang.String, java.lang.String)
public static ImageIcon getIfAvailable(String name)
private ImageResource getIfAvailableImpl(Collection<ClassLoader> additionalClassLoaders)
private static ImageResource getIfAvailableHttp(String url, ImageProvider.ImageType type)
private static ImageResource getIfAvailableWiki(String name, ImageProvider.ImageType type)
private static ImageResource getIfAvailableZip(String full_name, File archive, String inArchiveDir, ImageProvider.ImageType type)
private static ImageResource getIfAvailableLocalURL(URL path, ImageProvider.ImageType type)
private static URL getImageUrl(String path, String name, Collection<ClassLoader> additionalClassLoaders)
private static URL getImageUrl(String imageName, Collection<String> dirs, Collection<ClassLoader> additionalClassLoaders)
private static String getImgUrlFromWikiInfoPage(String base, String fn)
public static ImageIcon overlay(Icon ground, Icon overlay, ImageProvider.OverlayPosition pos)
ground
- the base imageoverlay
- the overlay image (can be smaller than the base image)pos
- position of the overlay image inside the base image (positioned
in one of the corners)public static Image createRotatedImage(Image img, double rotatedAngle)
img
- the image to be rotated.rotatedAngle
- the rotated angle, in degree, clockwise. It could be any double but we
will mod it with 360 before using it. More over for caching performance, it will be rounded to
an entire value between 0 and 360.public static Image createRotatedImage(Image img, double rotatedAngle, Dimension dimension)
img
- the image to be rotated.rotatedAngle
- the rotated angle, in degree, clockwise. It could be any double but we
will mod it with 360 before using it. More over for caching performance, it will be rounded to
an entire value between 0 and 360.dimension
- The requested dimensions. Use (-1,-1) for the original size
and (width, -1) to set the width, but otherwise scale the image proportionally.public static Image createBoundedImage(Image img, int maxSize)
img
- the image to be scaled down.maxSize
- the maximum size in pixels (both for width and height)public static ImageIcon get(OsmPrimitiveType type)
type
- the typepublic static BufferedImage createImageFromSvg(SVGDiagram svg, Dimension dim)
private static SVGUniverse getSvgUniverse()