Class ImageResource

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<java.net.URI> alternativeLocators  
      private static java.util.Comparator<java.awt.image.BufferedImage> biComp
      Comparator to compare buffered images by ascending size.
      private java.awt.image.BufferedImage image  
      private java.util.List<java.awt.image.BufferedImage> loadedImages  
      private static java.util.logging.Logger logger  
      private java.util.List<ImageResource> variations  
    • Constructor Summary

      Constructors 
      Constructor Description
      ImageResource​(java.lang.String primaryKey, java.net.URI resourceLocator)
      Do not use directly.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addAlternativeResourceLocator​(java.net.URI uri)
      Adds another URI for loading a differently sized version of the image.
      void addAlternativeResourceLocators​(java.util.List<java.net.URI> uris)
      Adds another URIs for loading a differently sized version of the image.
      void addVariation​(ImageResource imageResource)  
      private static boolean canUseBitmask​(java.net.URI uri)  
      void clean()
      Clean the caches inside the resource.
      private java.awt.image.BufferedImage findLoadedImage​(java.util.function.Predicate<java.awt.image.BufferedImage> pred)
      Find the loaded image that satisfies a predicate.
      private java.awt.image.BufferedImage getColorImage​(java.awt.Dimension siz)
      Gets the image using the specified dimension.
      private java.awt.image.BufferedImage getGrayscaleImage​(java.awt.Dimension siz)
      Gets a grayscale version of the image of the given size.
      java.awt.image.BufferedImage getImage()
      Gets the Image represented by this resource.
      java.awt.image.BufferedImage getImage​(int variation, java.awt.Dimension d, boolean grayscale)
      Gets the image using the specified dimension and choice of grayscale.
      java.awt.image.BufferedImage getImage​(java.awt.Dimension d, boolean grayscale)
      Gets the image using the specified dimension and choice of grayscale.
      ImageResource getVariation​(int variationNumber)  
      int getVariationNumberForSeed​(int seed)  
      int getVariationNumberForTick​(long ticks)  
      private boolean haveAlternatives()  
      private static java.awt.image.BufferedImage loadImage​(java.net.URI uri)
      Load an image from a URI.
      void preload()
      Preload the resource if possible/meaningful.
      • Methods inherited from class java.lang.Object

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

      • logger

        private static final java.util.logging.Logger logger
      • biComp

        private static final java.util.Comparator<java.awt.image.BufferedImage> biComp
        Comparator to compare buffered images by ascending size.
      • image

        private volatile java.awt.image.BufferedImage image
      • alternativeLocators

        private java.util.List<java.net.URI> alternativeLocators
      • loadedImages

        private java.util.List<java.awt.image.BufferedImage> loadedImages
    • Constructor Detail

      • ImageResource

        public ImageResource​(java.lang.String primaryKey,
                             java.net.URI resourceLocator)
        Do not use directly.
        Parameters:
        primaryKey - The primary key.
        resourceLocator - The URI used when loading this resource.
    • Method Detail

      • addAlternativeResourceLocator

        public void addAlternativeResourceLocator​(java.net.URI uri)
        Adds another URI for loading a differently sized version of the image. Only use before preload got called!
        Parameters:
        uri - The URI used when loading.
      • addVariation

        public void addVariation​(ImageResource imageResource)
      • addAlternativeResourceLocators

        public void addAlternativeResourceLocators​(java.util.List<java.net.URI> uris)
        Adds another URIs for loading a differently sized version of the image. Only use before preload got called!
        Parameters:
        uris - A List of URIs used when loading.
      • getImage

        public java.awt.image.BufferedImage getImage()
        Gets the Image represented by this resource.
        Returns:
        The image in its original size and color.
      • getVariationNumberForSeed

        public int getVariationNumberForSeed​(int seed)
      • getVariationNumberForTick

        public int getVariationNumberForTick​(long ticks)
      • getVariation

        public ImageResource getVariation​(int variationNumber)
      • getImage

        public java.awt.image.BufferedImage getImage​(int variation,
                                                     java.awt.Dimension d,
                                                     boolean grayscale)
        Gets the image using the specified dimension and choice of grayscale.
        Parameters:
        variation - The image variation.
        d - The Dimension of the requested image.
        grayscale - If true return a grayscale image.
        Returns:
        The scaled BufferedImage.
      • getImage

        public java.awt.image.BufferedImage getImage​(java.awt.Dimension d,
                                                     boolean grayscale)
        Gets the image using the specified dimension and choice of grayscale.
        Parameters:
        d - The Dimension of the requested image.
        grayscale - If true return a grayscale image.
        Returns:
        The scaled BufferedImage.
      • findLoadedImage

        private java.awt.image.BufferedImage findLoadedImage​(java.util.function.Predicate<java.awt.image.BufferedImage> pred)
        Find the loaded image that satisfies a predicate.
        Parameters:
        pred - The Predicate to satisfy.
        Returns:
        The BufferedImage found, or if not found, the one at the end of the loaded images list.
      • haveAlternatives

        private boolean haveAlternatives()
      • getColorImage

        private java.awt.image.BufferedImage getColorImage​(java.awt.Dimension siz)
        Gets the image using the specified dimension. Rescaling will be performed if necessary.
        Parameters:
        siz - The Dimension of the requested image.
        Returns:
        The BufferedImage with the required dimension.
      • getGrayscaleImage

        private java.awt.image.BufferedImage getGrayscaleImage​(java.awt.Dimension siz)
        Gets a grayscale version of the image of the given size.
        Parameters:
        siz - The Dimension of the requested image.
        Returns:
        The BufferedImage.
      • preload

        public void preload()
        Preload the resource if possible/meaningful.
        Specified by:
        preload in class Resource
      • loadImage

        private static java.awt.image.BufferedImage loadImage​(java.net.URI uri)
        Load an image from a URI.
        Parameters:
        uri - The URI to load from.
        Returns:
        The loaded BufferedImage, or null on error.
      • canUseBitmask

        private static boolean canUseBitmask​(java.net.URI uri)