Package com.luciad.gui
Class TLcdImageIcon
java.lang.Object
com.luciad.gui.TLcdImageIcon
- All Implemented Interfaces:
ILcdIcon
,ILcdCloneable
,Serializable
,Cloneable
Icon that uses an image from a file name,
The images can be found in the
For example:
java.awt.Image
, or ILcdIcon
.
The LuciadLightspeed distribution comes with many example images. The images can be found in the
luciadlightspeed.jar
file, in the directory images/icons
.For example:
// creates an ILcdIcon showing the hint_16.png image
ILcdIcon hintIcon = new TLcdImageIcon("images/icons/hint_16.png");
// assigns the icon to a Swing JButton
JButton hintButton = new JButton(new TLcdSWIcon(hintIcon));
This icon implementation supports high DPI rendering by adopting the
@2x naming convention.
This convention relies on having multiple versions of an icon for different resolutions in order to use/visualize the proper one according to the resolution of the Graphics
.
For instance, assume an image called image.png
and a DPI scale factor of 3.0:
- if there are 2x and 3x scales images available, the image path is
image@3x.png
, - if there is a 2x scale image available, the image path is
image@2x.png
, - if there are no scaled images available, the image path is
image.png
.
- See Also:
-
Constructor Summary
ConstructorDescriptionConstructs an icon with a default image.TLcdImageIcon
(TLcdImageIcon aIcon) Constructs an icon with the same image as the icon passed.TLcdImageIcon
(Image aImage) Constructs an icon for the specified image.TLcdImageIcon
(String aSourceName) Constructs an icon with the image at the given location. -
Method Summary
Modifier and TypeMethodDescriptionclone()
MakesObject.clone()
public.static TLcdImageIcon
createCachedIcon
(ILcdIcon aIcon) Creates an image-based cached rendering of the given icon.boolean
int
The height of the image painted by the icon.int
The width of the image painted by the icon.static Image
getImage
(short aIndex) Deprecated.Do not use this method.static Image
Reads an Image from the given fileshort
getIndex()
Deprecated.The index is an internal variable.Returns the location of the image painted in this icon.int
hashCode()
void
Paints a scaled version of the image at the given location so that it fits into the given width and height.void
Paints the image at the given location.toString()
-
Constructor Details
-
TLcdImageIcon
public TLcdImageIcon()Constructs an icon with a default image. This image is the same as the image loaded for the defaultTLcdGUIIcon
. -
TLcdImageIcon
Constructs an icon for the specified image.- Parameters:
aImage
- The image to use.
-
TLcdImageIcon
Constructs an icon with the same image as the icon passed.- Parameters:
aIcon
- the icon to copy.
-
TLcdImageIcon
Constructs an icon with the image at the given location.- Parameters:
aSourceName
- the location of the image. If the location is not given with an absolute path, the classpath is searched for the file.
-
-
Method Details
-
createCachedIcon
Creates an image-based cached rendering of the given icon. This can be useful if icon painting is slow. The cache image will be automatically scaled according to the current display scale.- Parameters:
aIcon
- the icon to cache, not null- Returns:
- the TLcdImageIcon that will cache a rasterized rendering of the given icon
- Since:
- 2021.0
-
getSourceName
Returns the location of the image painted in this icon.- Returns:
- the location of the image painted in this icon.
-
getIndex
Deprecated.The index is an internal variable.Returns the index of the image of this icon.- Returns:
- the index of the image of this icon.
-
getIconWidth
public int getIconWidth()The width of the image painted by the icon.- Specified by:
getIconWidth
in interfaceILcdIcon
- Returns:
- the fixed width of the icon.
-
getIconHeight
public int getIconHeight()The height of the image painted by the icon.- Specified by:
getIconHeight
in interfaceILcdIcon
- Returns:
- height of the image painted by the icon.
-
paintIcon
Paints the image at the given location. The image is drawn with its top-left corner at(aX,aY) in this graphics context's coordinate space.- Specified by:
paintIcon
in interfaceILcdIcon
- Parameters:
aComponent
- the Component on which the image is painted.aGraphics
- the Graphics on which the image is painted.aX
- the location on the X-axis where the top left point of the icon shall be painted.aY
- the location on the Y-axis where the top left point of the icon shall be painted.
-
paintIcon
public void paintIcon(int aWidth, int aHeight, Component aComponent, Graphics aGraphics, int aX, int aY) Paints a scaled version of the image at the given location so that it fits into the given width and height. The image is drawn with its top-left corner at(aX,aY) in this graphics context's coordinate space.- Parameters:
aWidth
- the width the painted image shall be scaled to.aHeight
- the height the painted image shall be scaled to.aComponent
- the Component on which the image is painted.aGraphics
- the Graphics on which the image is painted.aX
- the location on the X-axis where the top left point of the icon shall be painted.aY
- the location on the Y-axis where the top left point of the icon shall be painted.
-
toString
-
clone
Description copied from interface:ILcdCloneable
Makes
When for example extending fromObject.clone()
public.java.lang.Object
, it can be implemented like this:public Object clone() { try { return super.clone(); } catch ( CloneNotSupportedException e ) { // Cannot happen: extends from Object and implements Cloneable (see also Object.clone) throw new RuntimeException( e ); } }
- Specified by:
clone
in interfaceILcdCloneable
- Overrides:
clone
in classObject
- See Also:
-
getImage
Deprecated.Do not use this method.- Parameters:
aIndex
- the index of the image.- Returns:
- the image at the given index.
-
getImage
Reads an Image from the given file- Parameters:
aImageName
- a location that is accessible from the file system or classpath- Returns:
- the Image representing the given file, or a fallback image if the file could not be accessed
-
equals
-
hashCode
public int hashCode()
-