Package ca.cgjennings.ui.theme
Class ThemedSingleImageIcon
- java.lang.Object
-
- ca.cgjennings.ui.theme.AbstractThemedIcon
-
- ca.cgjennings.ui.theme.ThemedSingleImageIcon
-
- All Implemented Interfaces:
ThemedIcon
,javax.swing.Icon
public final class ThemedSingleImageIcon extends AbstractThemedIcon
An image icon that scales the source image appropriately for high DPI displays. This is a simpler alternative toThemedImageIcon
that is preferable when it is known that only one source image is available. Where aThemedImageIcon
chooses an image from one or more possible representations, this class will cache a high-quality pre-scaled image adjusted for the desktop scale.- Since:
- 3.4
- Author:
- Chris Jennings
-
-
Field Summary
-
Fields inherited from class ca.cgjennings.ui.theme.AbstractThemedIcon
disabled, height, width
-
Fields inherited from interface ca.cgjennings.ui.theme.ThemedIcon
GIGANTIC, LARGE, MEDIUM, MEDIUM_LARGE, MEDIUM_SMALL, SMALL, TINY, VERY_LARGE
-
-
Constructor Summary
Constructors Constructor Description ThemedSingleImageIcon(java.awt.image.BufferedImage sourceImage)
Creates a new, small icon from the specified image.ThemedSingleImageIcon(java.awt.image.BufferedImage sourceImage, int size)
Creates a new icon from the specified image.ThemedSingleImageIcon(java.awt.image.BufferedImage sourceImage, int iconWidth, int iconHeight)
Creates a new icon from the specified image.ThemedSingleImageIcon(java.lang.String imageResource)
Creates a new, small icon from the specified image resource identifier.ThemedSingleImageIcon(java.lang.String imageResource, int size)
Creates a new icon from the specified image resource identifier.ThemedSingleImageIcon(java.lang.String imageResource, int iconWidth, int iconHeight)
Creates a new icon from the specified image resource identifier.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThemedIcon
derive(int newWidth, int newHeight)
Returns a new icon that renders the same image as this icon, but at a different size.java.awt.image.BufferedImage
getImage()
Returns the source image that this icon will use as a basis for drawing.java.lang.String
getResource()
Returns the resource identifier for this icon.protected void
paintIcon(java.awt.Component c, java.awt.Graphics2D g, int x, int y)
-
Methods inherited from class ca.cgjennings.ui.theme.AbstractThemedIcon
disabled, getIconHeight, getIconWidth, paintIcon, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ca.cgjennings.ui.theme.ThemedIcon
derive, gigantic, large, medium, mediumLarge, mediumSmall, small, tiny, veryLarge
-
-
-
-
Constructor Detail
-
ThemedSingleImageIcon
public ThemedSingleImageIcon(java.lang.String imageResource)
Creates a new, small icon from the specified image resource identifier.- Parameters:
imageResource
- the non-null image resource, e.g.,"res://path/image.png"
-
ThemedSingleImageIcon
public ThemedSingleImageIcon(java.lang.String imageResource, int size)
Creates a new icon from the specified image resource identifier. This is a cover for creating an icon of equal width and height.- Parameters:
imageResource
- the non-null image resource, e.g.,"res://path/image.png"
size
- the desired icon width and height
-
ThemedSingleImageIcon
public ThemedSingleImageIcon(java.lang.String imageResource, int iconWidth, int iconHeight)
Creates a new icon from the specified image resource identifier. The width and height should be given as if the desktop is not being scaled.- Parameters:
imageResource
- the non-null image resource, e.g.,"res://path/image.png"
iconWidth
- the desired icon widthiconHeight
- the desired icon height
-
ThemedSingleImageIcon
public ThemedSingleImageIcon(java.awt.image.BufferedImage sourceImage)
Creates a new, small icon from the specified image.- Parameters:
sourceImage
- the non-null image
-
ThemedSingleImageIcon
public ThemedSingleImageIcon(java.awt.image.BufferedImage sourceImage, int size)
Creates a new icon from the specified image. This is a cover for creating an icon of equal width and height.- Parameters:
sourceImage
- the non-null imagesize
- the desired icon width and height
-
ThemedSingleImageIcon
public ThemedSingleImageIcon(java.awt.image.BufferedImage sourceImage, int iconWidth, int iconHeight)
Creates a new icon from the specified image. The width and height should be given as if the desktop is not being scaled.- Parameters:
sourceImage
- the non-null imageiconWidth
- the desired icon widthiconHeight
- the desired icon height
-
-
Method Detail
-
getResource
public java.lang.String getResource()
Returns the resource identifier for this icon. This will be null if the icon was not created from a resource identifier.- Returns:
- the image resource
-
getImage
public java.awt.image.BufferedImage getImage()
Returns the source image that this icon will use as a basis for drawing.- Returns:
- the non-null source image
-
paintIcon
protected void paintIcon(java.awt.Component c, java.awt.Graphics2D g, int x, int y)
- Specified by:
paintIcon
in classAbstractThemedIcon
-
derive
public ThemedIcon derive(int newWidth, int newHeight)
Description copied from interface:ThemedIcon
Returns a new icon that renders the same image as this icon, but at a different size.- Parameters:
newWidth
- the new width ≥ 1newHeight
- the new height ≥ 1- Returns:
- an icon with the revised dimensions
-
-