Added Javadoc to IconUtil
This commit is contained in:
parent
1e11948e10
commit
8bc8507feb
@ -9,6 +9,9 @@ import javax.imageio.ImageIO;
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
/**
|
||||
* Provides static utility methods for loading icons from the resource
|
||||
* folder.<br>
|
||||
* <br>
|
||||
* Project: <strong>envoy-client</strong>
|
||||
* File: <strong>IconUtil.java</strong>
|
||||
* Created: <strong>16.03.2020</strong>
|
||||
@ -20,10 +23,34 @@ public class IconUtil {
|
||||
|
||||
private IconUtil() {}
|
||||
|
||||
/**
|
||||
* Loads an icon from resource folder and scales it to a given size.
|
||||
*
|
||||
* @param path the path to the icon inside the resource folder
|
||||
* @param size the size to scale the icon to
|
||||
* @return the scaled icon
|
||||
* @throws IOException if the loading process failed
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
public static ImageIcon load(String path, int size) throws IOException {
|
||||
return new ImageIcon(ImageIO.read(IconUtil.class.getResourceAsStream(path)).getScaledInstance(size, size, Image.SCALE_SMOOTH));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Loads icons specified by an enum. The images have to be named like the
|
||||
* lowercase enum constants with {@code .png} extension and be located inside a
|
||||
* folder with the lowercase name of the enum, which must be contained inside
|
||||
* the {@code /icons} folder.
|
||||
*
|
||||
* @param <T> the enum that specifies the icons to load
|
||||
* @param enumClass the class of the enum
|
||||
* @param size the size to scale the icons to
|
||||
* @return a map containing the loaded icons with the corresponding enum
|
||||
* constants as keys
|
||||
* @throws IOException if the loading process failed
|
||||
* @since Envoy v0.1-beta
|
||||
*/
|
||||
public static <T extends Enum<T>> EnumMap<T, ImageIcon> loadByEnum(Class<T> enumClass, int size) throws IOException {
|
||||
var icons = new EnumMap<T, ImageIcon>(enumClass);
|
||||
var path = "/icons/" + enumClass.getSimpleName().toLowerCase() + "/";
|
||||
|
Reference in New Issue
Block a user