public abstract class CachedHiDPIIcon extends Object implements Icon
Icon
implementations that need to cache scaled bitmap
representations for HiDPI displays. Bitmaps for multiple HiDPI scaling factors can be cached at
the same time, e.g. for multi-monitor setups. Thread-safe.Modifier | Constructor and Description |
---|---|
protected |
CachedHiDPIIcon(int width,
int height)
Constructor to be used by subclasses.
|
Modifier and Type | Method and Description |
---|---|
protected abstract Image |
createAndPaintImage(Component c,
ColorModel colorModel,
int deviceWidth,
int deviceHeight,
double scale)
Create a scaled image containing the graphics of this icon.
|
protected static BufferedImage |
createBufferedImage(ColorModel colorModel,
int deviceWidth,
int deviceHeight)
Utility method to create a compatible
BufferedImage from the parameters passed to
CachedHiDPIIcon.createAndPaintImage(Component, ColorModel, int, int, double) . |
int |
getIconHeight() |
int |
getIconWidth() |
void |
paintIcon(Component c,
Graphics g0,
int x,
int y) |
protected CachedHiDPIIcon(int width, int height)
width
- the width of the iconheight
- the height of the iconpublic final int getIconWidth()
getIconWidth
in interface Icon
public final int getIconHeight()
getIconHeight
in interface Icon
protected abstract Image createAndPaintImage(Component c, ColorModel colorModel, int deviceWidth, int deviceHeight, double scale)
c
- the component that was passed to Icon.paintIcon(Component,Graphics,int,int)
.
The cache will not be invalidated if c
or its state changes, so
subclasses should avoid depending on it if possible. This parameter exists mainly to
ensure compatibility with existing Icon implementations that may be used as delegates.
Future implementations might also elect to simply pass a dummy Component instance
here.colorModel
- the ColorModel
of the surface on which the image will be painted
(may be passed to CachedHiDPIIcon.createBufferedImage(ColorModel, int, int)
in the common
case)deviceWidth
- the required width of the image, in device pixels (>=1)deviceHeight
- the required height of the image, in device pixels (>=1)scale
- the HiDPI scaling factor detected in graphicsConfiguration
protected static final BufferedImage createBufferedImage(ColorModel colorModel, int deviceWidth, int deviceHeight)
BufferedImage
from the parameters passed to
CachedHiDPIIcon.createAndPaintImage(Component, ColorModel, int, int, double)
. May be called by
implementors of the latter to create a surface to draw on and return.colorModel
- the required ColorModel
deviceWidth
- the required width of the image, in device pixels (>=1)deviceHeight
- the required height of the image, in device pixels (>=1)