Added IconUtil utility class

This commit is contained in:
Kai S. K. Engelbart 2020-03-16 14:30:14 +01:00
parent 98b82d74d0
commit 6873c136c3

View File

@ -0,0 +1,31 @@
package envoy.client.ui;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.EnumMap;
import java.util.EnumSet;
import javax.imageio.ImageIO;
/**
* Project: <strong>envoy-client</strong>
* File: <strong>IconUtil.java</strong>
* Created: <strong>16.03.2020</strong>
*
* @author Kai S. K. Engelbart
* @since Envoy v0.1-beta
*/
public class IconUtil {
private IconUtil() {}
public BufferedImage load(String path) throws IOException { return ImageIO.read(IconUtil.class.getResourceAsStream(path)); }
public <T extends Enum<T>> EnumMap<T, BufferedImage> loadByEnum(Class<T> enumClass) throws IOException {
var icons = new EnumMap<T, BufferedImage>(enumClass);
var path = "/icons/" + enumClass.getSimpleName().toLowerCase() + "/";
for (var e : EnumSet.allOf(enumClass))
icons.put(e, load(path + e.toString().toLowerCase() + ".png"));
return icons;
}
}