22 package com.realtime.crossfire.jxclient.skin.io;
27 import java.awt.Color;
28 import java.awt.Image;
29 import java.awt.image.BufferedImage;
30 import java.io.IOException;
31 import java.io.InputStream;
32 import javax.imageio.ImageIO;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
67 definedImages.
clear();
78 public Image
getImage(@Nullable
final Color color, @NotNull
final String name)
throws IOException {
80 return color == null ?
getImage(name) : null;
90 public BufferedImage
getImage(@NotNull
final String name)
throws IOException {
92 return definedImages.
lookup(name);
97 final String filename =
"pictures/"+name+
".png";
98 final BufferedImage image;
99 try (
final InputStream inputStream = skinSource.
getInputStream(filename)) {
100 image = ImageIO.read(inputStream);
103 throw new IOException(
"image '"+skinSource.
getURI(filename)+
"' does not exist");
106 definedImages.
insert(name, image);
108 throw new AssertionError(ex);
String getURI(@NotNull String name)
Returns a description of the location of a resource name.
InputStream getInputStream(@NotNull String name)
Returns an InputStream for a resource name.
Image getImage(@Nullable final Color color, @NotNull final String name)
Optionally loads an image by base file name.
void insert(@NotNull final String name, @NotNull final T t)
Adds a new element to the cache.
Interface for providers of JXCSkin sources.
void clear()
Forgets all cached elements.
ImageParser(@NotNull final JXCSkinSource skinSource)
Creates a new instance.
Implements a cache for elements identified by name.
Exception thrown if a skin related problem occurs.
void clear()
Forgets all defined images.
final JXCSkinCache< BufferedImage > definedImages
All defined images.
BufferedImage getImage(@NotNull final String name)
Loads an image by base file name.
T lookup(@NotNull final String name)
Looks up an element by name.
Creates BufferedImage instances from string representations.
final JXCSkinSource skinSource
The JXCSkinSource for loading resources.