Package org.openstreetmap.josm.tools
Class ImageResource
- java.lang.Object
-
- org.openstreetmap.josm.tools.ImageResource
-
public class ImageResource extends java.lang.Object
Holds data for one particular image. It can be backed by a svg or raster image. In the first case,svg
is notnull
and in the latter case,baseImage
is notnull
.- Since:
- 4271
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Image
baseImage
The base raster image for the final outputstatic java.awt.Dimension
DEFAULT_DIMENSION
Use this dimension to request original file dimension.private java.util.Map<java.lang.Integer,java.awt.image.BufferedImage>
imgCache
Caches the image data for resized versions of the same image.protected boolean
isDisabled
true
if icon must be grayed outprotected java.util.List<ImageOverlay>
overlayInfo
ordered list of overlay imagesprivate com.kitfox.svg.SVGDiagram
svg
SVG diagram information in case of SVG vector image.
-
Constructor Summary
Constructors Constructor Description ImageResource(com.kitfox.svg.SVGDiagram svg)
Constructs a newImageResource
from SVG data.ImageResource(java.awt.Image img)
Constructs a newImageResource
from an image.ImageResource(ImageResource res, java.util.List<ImageOverlay> overlayInfo)
Constructs a newImageResource
from another one and sets overlays.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
attachImageIcon(javax.swing.AbstractAction a)
Set both icons of an Actionvoid
attachImageIcon(javax.swing.AbstractAction a, boolean attachImageResource)
Set both icons of an Actionstatic ImageResource
getAttachedImageResource(javax.swing.Action a)
Returns theImageResource
attached to the given action, if any.javax.swing.ImageIcon
getImageIcon()
Returns the image icon at default dimension.javax.swing.ImageIcon
getImageIcon(java.awt.Dimension dim)
Get an ImageIcon object for the image of this resource.(package private) javax.swing.ImageIcon
getImageIcon(java.awt.Dimension dim, boolean multiResolution, ImageResizeMode resizeMode)
Get an ImageIcon object for the image of this resource.(package private) javax.swing.ImageIcon
getImageIconAlreadyScaled(java.awt.Dimension dim, boolean multiResolution, boolean highResolution, ImageResizeMode resizeMode)
Get an ImageIcon object for the image of this resource.javax.swing.ImageIcon
getImageIconBounded(java.awt.Dimension maxSize)
Get image icon with a certain maximum size.javax.swing.ImageIcon
getPaddedIcon(java.awt.Dimension iconSize)
Returns anImageIcon
for the given map image, at the specified size.ImageResource
setDisabled(boolean disabled)
Set, if image must be filtered to grayscale so it will look like disabled icon.java.lang.String
toString()
-
-
-
Field Detail
-
imgCache
private final java.util.Map<java.lang.Integer,java.awt.image.BufferedImage> imgCache
Caches the image data for resized versions of the same image. The key is obtained usingImageResizeMode.cacheKey(Dimension)
.
-
svg
private com.kitfox.svg.SVGDiagram svg
SVG diagram information in case of SVG vector image.
-
DEFAULT_DIMENSION
public static final java.awt.Dimension DEFAULT_DIMENSION
Use this dimension to request original file dimension.
-
overlayInfo
protected java.util.List<ImageOverlay> overlayInfo
ordered list of overlay images
-
isDisabled
protected boolean isDisabled
true
if icon must be grayed out
-
baseImage
private java.awt.Image baseImage
The base raster image for the final output
-
-
Constructor Detail
-
ImageResource
public ImageResource(java.awt.Image img)
Constructs a newImageResource
from an image.- Parameters:
img
- the image
-
ImageResource
public ImageResource(com.kitfox.svg.SVGDiagram svg)
Constructs a newImageResource
from SVG data.- Parameters:
svg
- SVG data
-
ImageResource
public ImageResource(ImageResource res, java.util.List<ImageOverlay> overlayInfo)
Constructs a newImageResource
from another one and sets overlays.- Parameters:
res
- the existing resourceoverlayInfo
- the overlay to apply- Since:
- 8095
-
-
Method Detail
-
setDisabled
public ImageResource 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
-
attachImageIcon
public void attachImageIcon(javax.swing.AbstractAction a)
Set both icons of an Action- Parameters:
a
- The action for the icons- Since:
- 10369
-
attachImageIcon
public void attachImageIcon(javax.swing.AbstractAction a, boolean attachImageResource)
Set both icons of an Action- Parameters:
a
- The action for the iconsattachImageResource
- Adds an resource named "ImageResource" iftrue
- Since:
- 10369
-
getAttachedImageResource
public static ImageResource getAttachedImageResource(javax.swing.Action a)
Returns theImageResource
attached to the given action, if any.- Parameters:
a
- action- Returns:
- the
ImageResource
attached to the given action, ornull
- Since:
- 18099
-
getImageIcon
public javax.swing.ImageIcon getImageIcon()
Returns the image icon at default dimension.- Returns:
- the image icon at default dimension
-
getImageIcon
public javax.swing.ImageIcon getImageIcon(java.awt.Dimension dim)
Get an ImageIcon object for the image of this resource.Will return a multi-resolution image by default (if possible).
- Parameters:
dim
- The requested dimensions. Use (-1,-1) for the original size and (width, -1) to set the width, but otherwise scale the image proportionally.- Returns:
- ImageIcon object for the image of this resource, scaled according to dim
- See Also:
getImageIconBounded(java.awt.Dimension)
-
getImageIcon
javax.swing.ImageIcon getImageIcon(java.awt.Dimension dim, boolean multiResolution, ImageResizeMode resizeMode)
Get an ImageIcon object for the image of this resource.- Parameters:
dim
- The requested dimensions. Use (-1,-1) for the original size and (width, -1) to set the width, but otherwise scale the image proportionally.multiResolution
- If true, return a multi-resolution image (java.awt.image.MultiResolutionImage in Java 9), otherwise a plainBufferedImage
. When running Java 8, this flag has no effect and a plain image will be returned in any case.resizeMode
- how to size/resize the image- Returns:
- ImageIcon object for the image of this resource, scaled according to dim
- Since:
- 12722
-
getImageIconAlreadyScaled
javax.swing.ImageIcon getImageIconAlreadyScaled(java.awt.Dimension dim, boolean multiResolution, boolean highResolution, ImageResizeMode resizeMode)
Get an ImageIcon object for the image of this resource. A potential UI scaling is assumed to be already taken care of, so dim is already scaled accordingly.- Parameters:
dim
- The requested dimensions. Use (-1,-1) for the original size and (width, -1) to set the width, but otherwise scale the image proportionally.multiResolution
- If true, return a multi-resolution image (java.awt.image.MultiResolutionImage in Java 9), otherwise a plainBufferedImage
. When running Java 8, this flag has no effect and a plain image will be returned in any case.highResolution
- whether the high resolution variant should be used for overlaysresizeMode
- how to size/resize the image- Returns:
- ImageIcon object for the image of this resource, scaled according to dim
-
getImageIconBounded
public javax.swing.ImageIcon getImageIconBounded(java.awt.Dimension maxSize)
Get image icon with a certain maximum size. The image is scaled down to fit maximum dimensions. (Keeps aspect ratio)Will return a multi-resolution image by default (if possible).
- Parameters:
maxSize
- The maximum size. One of the dimensions (width or height) can be -1, which means it is not bounded.- Returns:
- ImageIcon object for the image of this resource, scaled down if needed, according to maxSize
-
getPaddedIcon
public javax.swing.ImageIcon getPaddedIcon(java.awt.Dimension iconSize)
Returns anImageIcon
for the given map image, at the specified size. Uses a cache to improve performance.- Parameters:
iconSize
- size in pixels- Returns:
- an
ImageIcon
for the given map image, at the specified size
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-