Class BaseMultiResolutionImage

java.lang.Object
java.awt.Image
java.awt.image.AbstractMultiResolutionImage
io.github.stanio.xbrz.awt.util.BaseMultiResolutionImage
All Implemented Interfaces:
MultiResolutionImage
Direct Known Subclasses:
MultiResolutionCachedImage

public abstract class BaseMultiResolutionImage extends AbstractMultiResolutionImage
Convenience base MultiResolutionImage implementation...
  • Field Details

    • baseWidth

      protected final int baseWidth
    • baseHeight

      protected final int baseHeight
  • Constructor Details

    • BaseMultiResolutionImage

      protected BaseMultiResolutionImage(int baseWidth, int baseHeight)
      Initializes a BaseMultiResolutionImage with the given base width and height properties.
      Parameters:
      baseWidth - the user-space logical with of the image
      baseHeight - the user-space logical height of the image
  • Method Details

    • withProducer

      public static BaseMultiResolutionImage withProducer(int baseWidth, int baseHeight, BiFunction<Integer,Integer,Image> variantProducer)
      Returns a BaseMultiResolutionImage delegating to the given resolution variantProducer.

      The returned MultiResolutionImage implementation will return the last produced variant if request for the same destination width and height, as at the time the variant has been created, is received. That is it won't continuously request creation of the same variant in succession.

      Parameters:
      baseWidth - ...
      baseHeight - ...
      variantProducer - ...
      Returns:
      A MultiResolutionImage ...
    • getWidth

      public int getWidth(ImageObserver observer)
      Returns the baseWidth specified during the initialization.
      Overrides:
      getWidth in class AbstractMultiResolutionImage
      Parameters:
      observer - an object waiting for the image to be loaded.
      Returns:
      the width of the base image, or -1 if the width is not yet known
      See Also:
    • getHeight

      public int getHeight(ImageObserver observer)
      Returns the baseHeight specified during the initialization.
      Overrides:
      getHeight in class AbstractMultiResolutionImage
      Parameters:
      observer - an object waiting for the image to be loaded.
      Returns:
      the height of the base image, or -1 if the height is not yet known
      See Also:
    • getBaseImage

      protected Image getBaseImage()
      This implementation delegates to getResolutionVariant(baseWidth, baseHeight).
      Specified by:
      getBaseImage in class AbstractMultiResolutionImage
      Returns:
      the base image of the set of multi-resolution images
    • getProperty

      public Object getProperty(String name, ImageObserver observer)
      This implementation returns UndefinedProperty.
      Overrides:
      getProperty in class AbstractMultiResolutionImage
      Parameters:
      name - a property name.
      observer - an object waiting for this image to be loaded.
      Returns:
      the value of the named property in the base image
      See Also:
    • getScaledInstance

      public Image getScaledInstance(int width, int height, int hints)
      This implementation delegates to getResolutionVariant(width, height).
      Overrides:
      getScaledInstance in class Image
      Parameters:
      width - the width to which to scale the image.
      height - the height to which to scale the image.
      hints - flags to indicate the type of algorithm to use for image resampling.
      Returns:
      a scaled version of the image.
      See Also:
    • getResolutionVariants

      public List<Image> getResolutionVariants()
      This implementation returns a singleton list containing the baseImage.
      Returns:
      list of resolution variants.
    • getResolutionVariant

      public abstract Image getResolutionVariant(double destWidth, double destHeight)
      Description copied from interface: java.awt.image.MultiResolutionImage
      Gets a specific image that is the best variant to represent this logical image at the indicated size.
      Parameters:
      destWidth - the width of the destination image, in pixels.
      destHeight - the height of the destination image, in pixels.
      Returns:
      image resolution variant.
    • preloadDimensions

      protected static Image preloadDimensions(Image image)
      Preload dimensions of Toolkit images. This is crucial for the Java 2D drawing pipeline. If dimensions are not immediately available, a getResolutionVariant() request for the base width and height is made, that could trigger unexpected internal loops, depending on the actual implementation.