Class TLcdImageIcon

java.lang.Object
com.luciad.gui.TLcdImageIcon
All Implemented Interfaces:
ILcdIcon, ILcdCloneable, Serializable, Cloneable

public class TLcdImageIcon extends Object implements ILcdIcon
Icon that uses an image from a file name, 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 Details

    • TLcdImageIcon

      public TLcdImageIcon()
      Constructs an icon with a default image. This image is the same as the image loaded for the default TLcdGUIIcon.
    • TLcdImageIcon

      public TLcdImageIcon(Image aImage)
      Constructs an icon for the specified image.
      Parameters:
      aImage - The image to use.
    • TLcdImageIcon

      public TLcdImageIcon(TLcdImageIcon aIcon)
      Constructs an icon with the same image as the icon passed.
      Parameters:
      aIcon - the icon to copy.
    • TLcdImageIcon

      public TLcdImageIcon(String aSourceName)
      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

      public static TLcdImageIcon createCachedIcon(ILcdIcon aIcon)
      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

      public String getSourceName()
      Returns the location of the image painted in this icon.
      Returns:
      the location of the image painted in this icon.
    • getIndex

      @Deprecated public short 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 interface ILcdIcon
      Returns:
      the fixed width of the icon.
    • getIconHeight

      public int getIconHeight()
      The height of the image painted by the icon.
      Specified by:
      getIconHeight in interface ILcdIcon
      Returns:
      height of the image painted by the icon.
    • paintIcon

      public void paintIcon(Component aComponent, Graphics aGraphics, int aX, int aY)
      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 interface ILcdIcon
      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

      public String toString()
      Overrides:
      toString in class Object
    • clone

      public Object clone()
      Description copied from interface: ILcdCloneable

      Makes Object.clone() public.

      When for example extending from 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 interface ILcdCloneable
      Overrides:
      clone in class Object
      See Also:
    • getImage

      @Deprecated public static Image getImage(short aIndex)
      Deprecated.
      Do not use this method.
      Parameters:
      aIndex - the index of the image.
      Returns:
      the image at the given index.
    • getImage

      public static Image getImage(String aImageName)
      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

      public boolean equals(Object aObject)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object