Class PictureImageIcon

  • All Implemented Interfaces:
    javax.swing.Icon

    public class PictureImageIcon
    extends java.lang.Object
    implements javax.swing.Icon
    Adapter class that makes a Picture usable as an Icon, suitable for use in a pixel (non-vector) context. Rendering is done to an off-screen volatile image for performance. This rendered image is optionally cached for subsequent use.
    Since:
    25 Jan 2012
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Constructor Description
      PictureImageIcon​(Picture picture, boolean caching)
      Constructs an icon with default transparency.
      PictureImageIcon​(Picture picture, boolean caching, int transparency)
      Constructs an icon with specific transparency characteristics.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void cacheImage​(java.awt.GraphicsConfiguration gc, java.awt.Color bg)
      Forces creation of a cached image for display.
      static java.awt.image.BufferedImage createImage​(Picture picture, java.awt.GraphicsConfiguration gc, java.awt.Color bg, java.lang.Integer transparency)
      Creates an image containing the graphic content of this icon, suitable for caching or painting to a graphics context.
      int getIconHeight()  
      int getIconWidth()  
      void paintIcon​(java.awt.Component c, java.awt.Graphics g, int x, int y)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PictureImageIcon

        public PictureImageIcon​(Picture picture,
                                boolean caching,
                                int transparency)
        Constructs an icon with specific transparency characteristics.
        Parameters:
        picture - picture to paint
        caching - true iff painted image is cached rather than just drawn off-screen every time
        transparency - transparency mode
        See Also:
        Transparency.OPAQUE, Transparency.BITMASK, Transparency.TRANSLUCENT
      • PictureImageIcon

        public PictureImageIcon​(Picture picture,
                                boolean caching)
        Constructs an icon with default transparency.
        Parameters:
        picture - picture to paint
        caching - true iff painted image is cached rather than just drawn off-screen every time
    • Method Detail

      • getIconWidth

        public int getIconWidth()
        Specified by:
        getIconWidth in interface javax.swing.Icon
      • getIconHeight

        public int getIconHeight()
        Specified by:
        getIconHeight in interface javax.swing.Icon
      • paintIcon

        public void paintIcon​(java.awt.Component c,
                              java.awt.Graphics g,
                              int x,
                              int y)
        Specified by:
        paintIcon in interface javax.swing.Icon
      • cacheImage

        public void cacheImage​(java.awt.GraphicsConfiguration gc,
                               java.awt.Color bg)
        Forces creation of a cached image for display. If this is not called explicitly then in caching mode a cached image will be created when this icon is first painted.
        Parameters:
        gc - graphics config in which this icon will be displayed
        bg - background colour for image; null is legal but may lead to unpredictable effects.
      • createImage

        public static java.awt.image.BufferedImage createImage​(Picture picture,
                                                               java.awt.GraphicsConfiguration gc,
                                                               java.awt.Color bg,
                                                               java.lang.Integer transparency)
        Creates an image containing the graphic content of this icon, suitable for caching or painting to a graphics context.
        Parameters:
        picture - picture to paint on the image
        gc - graphics config in which this icon will be displayed
        bg - background colour for image; null is legal but may lead to unpredictable effects.
        transparency - integer value of Transparency code, or null
        Returns:
        image containing picture graphics