Package ca.cgjennings.ui.theme
Class ThemedImageIcon
- java.lang.Object
-
- ca.cgjennings.ui.theme.AbstractThemedIcon
-
- ca.cgjennings.ui.theme.ThemedImageIcon
-
- All Implemented Interfaces:
ThemedIcon
,javax.swing.Icon
public class ThemedImageIcon extends AbstractThemedIcon
An icon that whose image can change according to the installedTheme
. Supports multi-resolution images using file name suffixes (such asmyicon@2x.png
).- 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 ThemedImageIcon(java.awt.image.BufferedImage... images)
Creates a new themed icon directly from one or images.ThemedImageIcon(java.awt.image.MultiResolutionImage image, int width, int height)
Creates a themed icon from a multiresolution image source.ThemedImageIcon(java.lang.String resource)
Creates a new themed icon from an image resource.ThemedImageIcon(java.lang.String resource, boolean deferLoading)
Creates a new themed icon from an image resource.ThemedImageIcon(java.lang.String resource, int size)
Creates a new themed icon with the specified size.ThemedImageIcon(java.lang.String resource, int iconWidth, int iconHeight)
Creates a new themed icon with the specified size.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ThemedImageIcon
derive(int newWidth, int newHeight)
Returns an icon with the same base image as this icon, but which renders with a different nominal size or state.ThemedImageIcon
disabled()
Returns a new icon that renders the same image as this icon, but as if for a permanently disabled component.int
getIconHeight()
int
getIconWidth()
java.awt.image.AbstractMultiResolutionImage
getMultiResolutionImage()
Returns an image that can be used to render the icon's image at multiple resolutions.java.lang.String
getResource()
Returns the resource identifier for this icon.void
paintIcon(java.awt.Component c, java.awt.Graphics2D g, int x, int y)
java.lang.String
toString()
-
Methods inherited from class ca.cgjennings.ui.theme.AbstractThemedIcon
paintIcon
-
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
-
ThemedImageIcon
public ThemedImageIcon(java.lang.String resource)
Creates a new themed icon from an image resource.- Parameters:
resource
- the non-null image resource, e.g.,"res://path/image.png"
-
ThemedImageIcon
public ThemedImageIcon(java.lang.String resource, boolean deferLoading)
Creates a new themed icon from an image resource. IfdeferLoading
istrue
, then it will not be loaded until the first time it is used. Otherwise, the image may start loading immediately in a background thread.- Parameters:
resource
- the the non-null image resource, e.g.,"res://path/image.png"
deferLoading
- iftrue
, the image is loaded lazily- See Also:
Theme#applyThemeToImage(java.lang.String)
-
ThemedImageIcon
public ThemedImageIcon(java.lang.String resource, int size)
Creates a new themed icon with the specified size. This is a cover for creating an icon of equal width and height.- Parameters:
resource
- the the non-null image resource, e.g.,"res://path/image.png"
size
- the desired icon width and height
-
ThemedImageIcon
public ThemedImageIcon(java.lang.String resource, int iconWidth, int iconHeight)
Creates a new themed icon with the specified size.- Parameters:
resource
- the the non-null image resource, e.g.,"res://path/image.png"
iconWidth
- the desired icon width (for 1:1 displays)iconHeight
- the desired icon height (for 1:1 displays)
-
ThemedImageIcon
public ThemedImageIcon(java.awt.image.MultiResolutionImage image, int width, int height)
Creates a themed icon from a multiresolution image source.- Parameters:
image
- the non-null image to use as a base for the iconwidth
- the icon widthheight
- the icon height
-
ThemedImageIcon
public ThemedImageIcon(java.awt.image.BufferedImage... images)
Creates a new themed icon directly from one or images. Each image should be a different version of the same graphic, but scaled for a different size or resolution. The initial size of the icon will be taken from the size of the first image; this can be changed by callingderive(int,int)
.If only one source image is available, it is recommended to use
ThemedSingleImageIcon
instead, as this will generally produce a higher quality image.- Parameters:
images
- a non-null array of at least one image
-
-
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
-
getMultiResolutionImage
public final java.awt.image.AbstractMultiResolutionImage getMultiResolutionImage()
Returns an image that can be used to render the icon's image at multiple resolutions.- Returns:
- a multi-resolution version of the source image
-
derive
public final ThemedImageIcon derive(int newWidth, int newHeight)
Returns an icon with the same base image as this icon, but which renders with a different nominal size or state.- Parameters:
newWidth
- the new width (on 1:1 displays)newHeight
- the new height (on 1:1 displays)- Returns:
- an icon for the new size
-
disabled
public final ThemedImageIcon disabled()
Description copied from interface:ThemedIcon
Returns a new icon that renders the same image as this icon, but as if for a permanently disabled component.- Specified by:
disabled
in interfaceThemedIcon
- Overrides:
disabled
in classAbstractThemedIcon
- Returns:
- a disabled verison of the icon
-
getIconWidth
public int getIconWidth()
- Specified by:
getIconWidth
in interfacejavax.swing.Icon
- Overrides:
getIconWidth
in classAbstractThemedIcon
-
getIconHeight
public int getIconHeight()
- Specified by:
getIconHeight
in interfacejavax.swing.Icon
- Overrides:
getIconHeight
in classAbstractThemedIcon
-
paintIcon
public void paintIcon(java.awt.Component c, java.awt.Graphics2D g, int x, int y)
- Specified by:
paintIcon
in classAbstractThemedIcon
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractThemedIcon
-
-