Added IconUtil utility class
This commit is contained in:
		
							
								
								
									
										31
									
								
								src/main/java/envoy/client/ui/IconUtil.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/main/java/envoy/client/ui/IconUtil.java
									
									
									
									
									
										Normal 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; | ||||||
|  | 	} | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user