public class TLcdImageIcon extends Object implements ILcdIcon
java.awt.Image
, or ILcdIcon
.
The LuciadLightspeed distribution comes with many example images. luciadlightspeed.jar
file, in the directory images/icons
.
// 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:
image@3x.png
,image@2x.png
,image.png
.TLcdIconFactory
,
Serialized FormConstructor and Description |
---|
TLcdImageIcon()
Constructs an icon with a default image.
|
TLcdImageIcon(Image aImage)
Constructs an icon for the specified image.
|
TLcdImageIcon(String aSourceName)
Constructs an icon with the image at the given location.
|
TLcdImageIcon(TLcdImageIcon aIcon)
Constructs an icon with the same image as the icon passed.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Makes
Object.clone() public. |
static TLcdImageIcon |
createCachedIcon(ILcdIcon aIcon)
Creates an image-based cached rendering of the given icon.
|
boolean |
equals(Object aObject) |
int |
getIconHeight()
The height of the image painted by the icon.
|
int |
getIconWidth()
The width of the image painted by the icon.
|
static Image |
getImage(short aIndex)
Deprecated.
Do not use this method.
|
static Image |
getImage(String aImageName)
Reads an Image from the given file
|
short |
getIndex()
Deprecated.
The index is an internal variable.
|
String |
getSourceName()
Returns the location of the image painted in this icon.
|
int |
hashCode() |
void |
paintIcon(Component aComponent,
Graphics aGraphics,
int aX,
int aY)
Paints the image at the given location.
|
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.
|
String |
toString() |
public TLcdImageIcon()
TLcdGUIIcon
.public TLcdImageIcon(Image aImage)
aImage
- The image to use.public TLcdImageIcon(TLcdImageIcon aIcon)
aIcon
- the icon to copy.public TLcdImageIcon(String aSourceName)
aSourceName
- the location of the image. If the location is not given with an absolute
path, the classpath is searched for the file.public static TLcdImageIcon createCachedIcon(ILcdIcon aIcon)
aIcon
- the icon to cache, not nullpublic String getSourceName()
@Deprecated public short getIndex()
public int getIconWidth()
getIconWidth
in interface ILcdIcon
public int getIconHeight()
getIconHeight
in interface ILcdIcon
public void paintIcon(Component aComponent, Graphics aGraphics, int aX, int aY)
paintIcon
in interface ILcdIcon
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.public void paintIcon(int aWidth, int aHeight, Component aComponent, Graphics aGraphics, int aX, int aY)
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.public Object clone()
ILcdCloneable
Makes Object.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 );
}
}
clone
in interface ILcdCloneable
clone
in class Object
Object.clone()
@Deprecated public static Image getImage(short aIndex)
aIndex
- the index of the image.public static Image getImage(String aImageName)
aImageName
- a location that is accessible from the file system or classpath