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>
An implementation of the
The code
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
}
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
ConstructorsConstructorDescriptionEnumImageStorage
(Class<T> enumClass) Creates anEnumImageStorage
instance for the enum specified. -
Method Summary
-
Constructor Details
-
EnumImageStorage
-
-
Method Details
-
get
Returns anOptional
describing the image associated with the key specified, or an empty optional if no image is associated with the key.- Specified by:
get
in interfaceImageStorage<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
-