From 6873c136c30dc8653f7b760b9bb0ad5fbc9ed99d Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Mon, 16 Mar 2020 14:30:14 +0100 Subject: [PATCH] Added IconUtil utility class --- src/main/java/envoy/client/ui/IconUtil.java | 31 +++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/main/java/envoy/client/ui/IconUtil.java diff --git a/src/main/java/envoy/client/ui/IconUtil.java b/src/main/java/envoy/client/ui/IconUtil.java new file mode 100644 index 0000000..457a977 --- /dev/null +++ b/src/main/java/envoy/client/ui/IconUtil.java @@ -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: envoy-client + * File: IconUtil.java + * Created: 16.03.2020 + * + * @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 > EnumMap loadByEnum(Class enumClass) throws IOException { + var icons = new EnumMap(enumClass); + var path = "/icons/" + enumClass.getSimpleName().toLowerCase() + "/"; + for (var e : EnumSet.allOf(enumClass)) + icons.put(e, load(path + e.toString().toLowerCase() + ".png")); + return icons; + } +}