Class EnumImageStorage<T extends Enum<?>>

java.lang.Object
jfxutils.images.EnumImageStorage<T>
Type Parameters:
T - an enum whose constants are represented by PNG images
All Implemented Interfaces:
ImageStorage<T>

public class EnumImageStorage<T extends Enum<?>> extends Object implements ImageStorage<T>
An implementation of the ImageStorage interface that associates PNG images with the constants of an enum. The images representing the constants of the enum specified are loaded via the classloader when an instance of the class is created.

Consider, for example, the following enum:

package chess.puzzle;
enum Piece {
    WHITE_KNIGHT,
    BLACK_KNIGHT
}
The code new EnumImageStorage(Piece.class) will search for white_knight.png and black_knight.png in the chess.puzzle package, respectively. Thus, in the case of an Apache Maven project, the images should be kept under the src/main/resources/chess/puzzle directory. It is not needed to have an image for each of the enum constants.
  • Constructor Summary

    Constructors
    Constructor
    Description
    EnumImageStorage(Class<T> enumClass)
    Creates an EnumImageStorage instance for the enum specified.
  • Method Summary

    Modifier and Type
    Method
    Description
    Optional<javafx.scene.image.Image>
    get(T constant)
    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

    • EnumImageStorage

      public EnumImageStorage(Class<T> enumClass)
      Creates an EnumImageStorage instance for the enum specified.
      Parameters:
      enumClass - a Class object representing an enum
  • Method Details

    • get

      public Optional<javafx.scene.image.Image> get(T constant)
      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<T extends Enum<?>>
      Parameters:
      constant - the constant 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