Class OrdinalImageStorage

java.lang.Object
jfxutils.images.OrdinalImageStorage
All Implemented Interfaces:
ImageStorage<Integer>

public class OrdinalImageStorage extends Object implements ImageStorage<Integer>
An implementation of the ImageStorage interface that associates PNG images with a consecutive sequence of ints starting from 0. The images representing the integers are loaded via the classloader of the class specified.

Consider, for example, the following code:

ImageStorage<Integer> imageStorage = new OrdinalImageStorage(chess.game.PuzzleState.class,
    "none.png",
    "white_knight.png",
    "black_knight.png"
);
The code will search for none.png, white_knight.png, and black_knight.png in the chess.game package, respectively. Thus, in the case of an Apache Maven project, the images should be kept under the src/main/resources/chess/game directory.
  • Constructor Summary

    Constructors
    Constructor
    Description
    OrdinalImageStorage(Class<?> c, String... resourceNames)
    Creates a OrdinalImageStorage instance to associate the image resources specified with the integers 0, 1, 2, ….
  • Method Summary

    Modifier and Type
    Method
    Description
    Optional<javafx.scene.image.Image>
    get(Integer index)
    Returns an Optional describing the image associated with the key specified, or an empty optional if no image is associated with the key.

    Methods inherited from class java.lang.Object

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

    • OrdinalImageStorage

      public OrdinalImageStorage(Class<?> c, String... resourceNames)
      Creates a OrdinalImageStorage instance to associate the image resources specified with the integers 0, 1, 2, ….
      Parameters:
      c - the class whose classloader is used to load the images
      resourceNames - the resource names of the images
  • Method Details

    • get

      public Optional<javafx.scene.image.Image> get(Integer index)
      Description copied from interface: ImageStorage
      Returns an Optional describing the image associated with the key specified, or an empty optional if no image is associated with the key.
      Specified by:
      get in interface ImageStorage<Integer>
      Parameters:
      index - a key for which the associated image should be returned
      Returns:
      an Optional describing the image associated with the key specified, or an empty optional if no image is associated with the key