Class ImageResource


  • public class ImageResource
    extends Object
    Holds data for one particular image. It can be backed by a svg or raster image. In the first case, svg is not null and in the latter case, baseImage is not null.
    Since:
    4271
    • Constructor Detail

      • ImageResource

        public ImageResource​(Image img)
        Constructs a new ImageResource from an image.
        Parameters:
        img - the image
      • ImageResource

        public ImageResource​(com.kitfox.svg.SVGDiagram svg)
        Constructs a new ImageResource from SVG data.
        Parameters:
        svg - SVG data
      • ImageResource

        public ImageResource​(ImageResource res,
                             List<ImageOverlay> overlayInfo)
        Constructs a new ImageResource from another one and sets overlays.
        Parameters:
        res - the existing resource
        overlayInfo - the overlay to apply
        Since:
        8095
    • Method Detail

      • setDisabled

        public ImageResource setDisabled​(boolean disabled)
        Set, if image must be filtered to grayscale so it will look like disabled icon.
        Parameters:
        disabled - true, if image must be grayed out for disabled state
        Returns:
        the current object, for convenience
        Since:
        10428
      • attachImageIcon

        public void attachImageIcon​(AbstractAction a)
        Set both icons of an Action
        Parameters:
        a - The action for the icons
        Since:
        10369
      • attachImageIcon

        public void attachImageIcon​(AbstractAction a,
                                    boolean attachImageResource)
        Set both icons of an Action
        Parameters:
        a - The action for the icons
        attachImageResource - Adds an resource named "ImageResource" if true
        Since:
        10369
      • getAttachedImageResource

        public static ImageResource getAttachedImageResource​(Action a)
        Returns the ImageResource attached to the given action, if any.
        Parameters:
        a - action
        Returns:
        the ImageResource attached to the given action, or null
        Since:
        18099
      • getImageIcon

        public ImageIcon getImageIcon()
        Returns the image icon at default dimension.
        Returns:
        the image icon at default dimension
      • getImageIcon

        public ImageIcon getImageIcon​(Dimension dim)
        Get an ImageIcon object for the image of this resource.

        Will return a multi-resolution image by default (if possible).

        Parameters:
        dim - The requested dimensions. Use (-1,-1) for the original size and (width, -1) to set the width, but otherwise scale the image proportionally.
        Returns:
        ImageIcon object for the image of this resource, scaled according to dim
        See Also:
        getImageIconBounded(java.awt.Dimension)
      • getImageIcon

        ImageIcon getImageIcon​(Dimension dim,
                               boolean multiResolution,
                               ImageResizeMode resizeMode)
        Get an ImageIcon object for the image of this resource.
        Parameters:
        dim - The requested dimensions. Use (-1,-1) for the original size and (width, -1) to set the width, but otherwise scale the image proportionally.
        multiResolution - If true, return a multi-resolution image (java.awt.image.MultiResolutionImage in Java 9), otherwise a plain BufferedImage. When running Java 8, this flag has no effect and a plain image will be returned in any case.
        resizeMode - how to size/resize the image
        Returns:
        ImageIcon object for the image of this resource, scaled according to dim
        Since:
        12722
      • getImageIconAlreadyScaled

        ImageIcon getImageIconAlreadyScaled​(Dimension dim,
                                            boolean multiResolution,
                                            boolean highResolution,
                                            ImageResizeMode resizeMode)
        Get an ImageIcon object for the image of this resource. A potential UI scaling is assumed to be already taken care of, so dim is already scaled accordingly.
        Parameters:
        dim - The requested dimensions. Use (-1,-1) for the original size and (width, -1) to set the width, but otherwise scale the image proportionally.
        multiResolution - If true, return a multi-resolution image (java.awt.image.MultiResolutionImage in Java 9), otherwise a plain BufferedImage. When running Java 8, this flag has no effect and a plain image will be returned in any case.
        highResolution - whether the high resolution variant should be used for overlays
        resizeMode - how to size/resize the image
        Returns:
        ImageIcon object for the image of this resource, scaled according to dim
      • getImageIconBounded

        public ImageIcon getImageIconBounded​(Dimension maxSize)
        Get image icon with a certain maximum size. The image is scaled down to fit maximum dimensions. (Keeps aspect ratio)

        Will return a multi-resolution image by default (if possible).

        Parameters:
        maxSize - The maximum size. One of the dimensions (width or height) can be -1, which means it is not bounded.
        Returns:
        ImageIcon object for the image of this resource, scaled down if needed, according to maxSize
      • getPaddedIcon

        public ImageIcon getPaddedIcon​(Dimension iconSize)
        Returns an ImageIcon for the given map image, at the specified size. Uses a cache to improve performance.
        Parameters:
        iconSize - size in pixels
        Returns:
        an ImageIcon for the given map image, at the specified size