@OpenApiAll public class ScalableImageIcon extends javax.swing.ImageIcon implements ResizableIcon
This class dynamically chooses a right image by current screen dpi and/or scaling factor defined in the system (Retina and etc). If scaling is needed and svg icon with the same name is available at given location, svg icon will be used instead of a bitmap icon.
Dynamic choosing will work only if two icons are provided at the same location. For example:
ScalableImageIcon(Product.class, "/com/product/icons/a.png") will load a.png on a regular dpi monitor, but a.svg will be loaded on HiDPI monitor. Keep in mind that svg icon size can be any. Svg icon will be resized according to the size of a.png icon and scaling factor. For example if size of a.png is 16x16 and scaling factor is 2, loaded svg icon will be resized to 32x32 if needed.
Original icon will be loaded and scaled if svg icon is not provided, but HiDPI with scaling is used.
Icon image loading is lazy. Image will be loaded only if icon is painted, getImage() is called or icon width/height is retrieved.
Modifier and Type | Class and Description |
---|---|
(package private) class |
ScalableImageIcon.AbstractImageLoader |
Constructor and Description |
---|
ScalableImageIcon() |
ScalableImageIcon(byte[] imageData)
Load icon from given bytes.
|
ScalableImageIcon(byte[] imageData,
java.net.URI uri)
Load icon from given bytes.
|
ScalableImageIcon(java.lang.Class clazz,
java.lang.String location)
Load icon from a resources of given class.
|
ScalableImageIcon(java.lang.Class clazz,
java.lang.String location,
boolean silent)
Load icon from a resources of given class.
|
ScalableImageIcon(java.awt.Image image)
Wrap given image and use it for painting.
|
ScalableImageIcon(java.awt.Image image,
ResizableIcon icon)
Create icon with given image and give icon to be used for painting
|
ScalableImageIcon(java.net.URL url)
Load icon from a given url.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Returns cloned instance of this icon.
|
static ScalableImageIcon |
create(java.lang.String fileName)
Load icon from a file.
|
void |
doNotScale()
Do not scale this icon by screen dpi.
|
int |
getIconHeight() |
int |
getIconWidth() |
java.awt.Image |
getImage() |
java.lang.String |
getLocation() |
java.net.URL |
getURL() |
(package private) ResizableIcon |
internalGetIcon() |
(package private) void |
internalSetLoader(ScalableImageIcon.AbstractImageLoader loader) |
(package private) java.awt.Image |
internalSuperGetImage() |
void |
paintIcon(java.awt.Component c,
java.awt.Graphics g,
int x,
int y) |
void |
paintIcon(java.awt.Component c,
java.awt.Graphics g,
int x,
int y,
int w,
int h)
Draw the icon in the given bounds.
|
void |
setImage(java.awt.Image image) |
static ScalableImageIcon |
toImageIcon(javax.swing.Icon icon)
Convert given icon to a ImageIcon.
|
static ScalableImageIcon |
toImageIcon(ResizableIcon icon)
Convert given icon to a ImageIcon.
|
static ScalableImageIcon |
toImageIcon(ResizableIcon icon,
int width,
int height)
Convert given icon to a ImageIcon of given width and height.
|
ScalableImageIcon()
ScalableImageIcon(java.awt.Image image, ResizableIcon icon)
image
- icon imageicon
- icon for paintingpublic ScalableImageIcon(java.awt.Image image)
image
- imagepublic ScalableImageIcon(byte[] imageData)
imageData
- image bytespublic ScalableImageIcon(byte[] imageData, java.net.URI uri)
imageData
- image bytesuri
- uri describing the bytes (format and etc)public ScalableImageIcon(java.net.URL url)
url
- urlpublic ScalableImageIcon(java.lang.Class clazz, java.lang.String location)
clazz
- classlocation
- resources location relative to a given classpublic ScalableImageIcon(java.lang.Class clazz, java.lang.String location, boolean silent)
clazz
- classlocation
- resources location relative to a given classsilent
- if true, does not report to log file about missing icon at given location@CheckForNull public static ScalableImageIcon create(java.lang.String fileName)
fileName
- file namepublic void paintIcon(java.awt.Component c, java.awt.Graphics g, int x, int y)
paintIcon
in interface javax.swing.Icon
paintIcon
in class javax.swing.ImageIcon
public void paintIcon(@CheckForNull java.awt.Component c, java.awt.Graphics g, int x, int y, int w, int h)
ResizableIcon
paintIcon
in interface ResizableIcon
c
- the given component.g
- the graphics to paint on.x
- x coordinate.y
- y coordinate.w
- width to paint.h
- height to paint.public int getIconHeight()
getIconHeight
in interface javax.swing.Icon
getIconHeight
in class javax.swing.ImageIcon
public int getIconWidth()
getIconWidth
in interface javax.swing.Icon
getIconWidth
in class javax.swing.ImageIcon
ResizableIcon internalGetIcon()
void internalSetLoader(ScalableImageIcon.AbstractImageLoader loader)
public void setImage(@CheckForNull java.awt.Image image)
setImage
in class javax.swing.ImageIcon
public java.awt.Image getImage()
getImage
in class javax.swing.ImageIcon
java.awt.Image internalSuperGetImage()
public java.lang.String getLocation()
public java.net.URL getURL()
public java.lang.Object clone()
ResizableIcon
clone
in interface ResizableIcon
clone
in class java.lang.Object
public void doNotScale()
@CheckForNull public static ScalableImageIcon toImageIcon(@CheckForNull ResizableIcon icon, int width, int height)
icon
- icon to convertwidth
- icon widthheight
- icon height@CheckForNull public static ScalableImageIcon toImageIcon(@CheckForNull javax.swing.Icon icon)
icon
- icon to convert@CheckForNull public static ScalableImageIcon toImageIcon(@CheckForNull ResizableIcon icon)
icon
- icon to convert