Dismissed rethrowing of image loading error
Additionally cleaned up Javadoc A LOT in IconUtil and banned the word "icon" from appearing in Javadoc there (it returns an Image, not an Icon).
This commit is contained in:
parent
9d5c430fe0
commit
e14d5da997
@ -25,81 +25,72 @@ public class IconUtil {
|
|||||||
private IconUtil() {}
|
private IconUtil() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an icon from the resource folder.
|
* Loads an image from the resource folder.
|
||||||
*
|
*
|
||||||
* @param path the path to the icon inside the resource folder
|
* @param path the path to the icon inside the resource folder
|
||||||
* @return the icon
|
* @return the loaded image
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
*/
|
*/
|
||||||
public static Image load(String path) {
|
public static Image load(String path) {
|
||||||
Image image;
|
Image image = null;
|
||||||
try {
|
try {
|
||||||
image = new Image(IconUtil.class.getResource(path).toExternalForm());
|
image = new Image(IconUtil.class.getResource(path).toExternalForm());
|
||||||
} catch (final NullPointerException e) {
|
} catch (final NullPointerException e) {
|
||||||
EnvoyLog.getLogger(IconUtil.class).log(Level.WARNING, String.format("Could not load image at path %s: ", path), e);
|
EnvoyLog.getLogger(IconUtil.class).log(Level.WARNING, String.format("Could not load image at path %s: ", path), e);
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an icon from the resource folder and scales it to a given size.
|
* Loads an image from the resource folder and scales it to the given size.
|
||||||
*
|
*
|
||||||
* @param path the path to the icon inside the resource folder
|
* @param path the path to the icon inside the resource folder
|
||||||
* @param size the size to scale the icon to
|
* @param size the size to scale the icon to
|
||||||
* @return the scaled icon
|
* @return the scaled image
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
*/
|
*/
|
||||||
public static Image load(String path, int size) {
|
public static Image load(String path, int size) {
|
||||||
Image image;
|
Image image = null;
|
||||||
try {
|
try {
|
||||||
image = new Image(IconUtil.class.getResource(path).toExternalForm(), size, size, true, true);
|
image = new Image(IconUtil.class.getResource(path).toExternalForm(), size, size, true, true);
|
||||||
} catch (final NullPointerException e) {
|
} catch (final NullPointerException e) {
|
||||||
EnvoyLog.getLogger(IconUtil.class).log(Level.WARNING, String.format("Could not load image at path %s: ", path), e);
|
EnvoyLog.getLogger(IconUtil.class).log(Level.WARNING, String.format("Could not load image at path %s: ", path), e);
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a {@code .png} icon from the sub-folder {@code /icons/} of the resource
|
* Loads a {@code .png} image from the sub-folder {@code /icons/} of the
|
||||||
* folder and scales it to 16px.<br>
|
* resource folder.<br>
|
||||||
* The suffix {@code .png} is automatically appended.
|
* The suffix {@code .png} is automatically appended.
|
||||||
*
|
*
|
||||||
* @param name the image name without the .png suffix
|
* @param name the image name without the .png suffix
|
||||||
* @return the loaded image
|
* @return the loaded image
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
* @apiNote let's take a sample image {@code abc.png} in the folder
|
* @apiNote let's load a sample image {@code /icons/abc.png}.<br>
|
||||||
* {@code /icons/}.
|
* To do that, we only have to call {@code IconUtil.loadIcon("abc")}
|
||||||
* <br>
|
|
||||||
* To do that, we only have to call
|
|
||||||
* {@code IconUtil.loadIcon("abc")}
|
|
||||||
*/
|
*/
|
||||||
public static Image loadIcon(String name) { return load("/icons/" + name + ".png"); }
|
public static Image loadIcon(String name) { return load("/icons/" + name + ".png"); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a {@code .png} icon from the sub-folder {@code /icons/} of the resource
|
* Loads a {@code .png} image from the sub-folder {@code /icons/} of the
|
||||||
* folder and scales it to a given size.<br>
|
* resource folder and scales it to the given size.<br>
|
||||||
* The suffix {@code .png} is automatically appended.
|
* The suffix {@code .png} is automatically appended.
|
||||||
*
|
*
|
||||||
* @param name the image name without the .png suffix
|
* @param name the image name without the .png suffix
|
||||||
* @param size the size of the image to scale to
|
* @param size the size of the image to scale to
|
||||||
* @return the loaded image
|
* @return the loaded image
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
* @apiNote let's take a sample image {@code abc.png} in the folder
|
* @apiNote let's load a sample image {@code /icons/abc.png} in size 16.<br>
|
||||||
* {@code /icons/} and load it in size 16.
|
|
||||||
* <br>
|
|
||||||
* To do that, we only have to call
|
* To do that, we only have to call
|
||||||
* {@code IconUtil.loadIcon("abc", 16)}
|
* {@code IconUtil.loadIcon("abc", 16)}
|
||||||
*/
|
*/
|
||||||
public static Image loadIcon(String name, int size) { return load("/icons/" + name + ".png", size); }
|
public static Image loadIcon(String name, int size) { return load("/icons/" + name + ".png", size); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a {@code .png} icon whose design depends on the currently active theme
|
* Loads a {@code .png} image whose design depends on the currently active theme
|
||||||
* from the sub-folder {@code /icons/} of the resource folder.
|
* from the sub-folder {@code /icons/dark/} or {@code /icons/light/} of the
|
||||||
* <p>
|
* resource folder.
|
||||||
* In case of the dark theme, the suffix {@code "white"} will be appended, else
|
|
||||||
* the suffix {@code "black"} will be appended.
|
|
||||||
* <p>
|
* <p>
|
||||||
* The suffix {@code .png} is automatically appended.
|
* The suffix {@code .png} is automatically appended.
|
||||||
*
|
*
|
||||||
@ -107,21 +98,17 @@ public class IconUtil {
|
|||||||
* the .png suffix
|
* the .png suffix
|
||||||
* @return the loaded image
|
* @return the loaded image
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
* @apiNote let's take two sample images {@code abc_black.png} and
|
* @apiNote let's take two sample images {@code /icons/dark/abc.png} and
|
||||||
* {@code abc_white.png} in the folder {@code /icons/} and load them.
|
* {@code /icons/light/abc.png}, and load one of them.<br>
|
||||||
* <br>
|
* To do that theme sensitive, we only have to call
|
||||||
* To do that theme sensitve, we only have to call
|
* {@code IconUtil.loadIconThemeSensitive("abc")}
|
||||||
* {@code IconUtil.loadIconThemeSensitive("abc_")}
|
|
||||||
*/
|
*/
|
||||||
public static Image loadIconThemeSensitive(String name) { return loadIcon(themeSpecificSubFolder() + name); }
|
public static Image loadIconThemeSensitive(String name) { return loadIcon(themeSpecificSubFolder() + name); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads a {@code .png} icon whose design depends on the currently active theme
|
* Loads a {@code .png} image whose design depends on the currently active theme
|
||||||
* from the sub-folder {@code /icons/} of the resource
|
* from the sub-folder {@code /icons/dark/} or {@code /icons/light/} of the
|
||||||
* folder and scales it to the given size.
|
* resource folder and scales it to the given size.
|
||||||
* <p>
|
|
||||||
* In case of the dark theme, the suffix {@code "white"} will be appended, else
|
|
||||||
* the suffix {@code "black"} will be appended.
|
|
||||||
* <p>
|
* <p>
|
||||||
* The suffix {@code .png} is automatically appended.
|
* The suffix {@code .png} is automatically appended.
|
||||||
*
|
*
|
||||||
@ -129,26 +116,24 @@ public class IconUtil {
|
|||||||
* @param size the size of the image to scale to
|
* @param size the size of the image to scale to
|
||||||
* @return the loaded image
|
* @return the loaded image
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
* @apiNote let's take two sample images {@code abc_black.png} and
|
* @apiNote let's take two sample images {@code /icons/dark/abc.png} and
|
||||||
* {@code abc_white.png} in the folder {@code /icons/} and load it in
|
* {@code /icons/light/abc.png}, and load one of them in size 16.<br>
|
||||||
* size 16.
|
* To do that theme sensitive, we only have to call
|
||||||
* <br>
|
* {@code IconUtil.loadIconThemeSensitive("abc", 16)}
|
||||||
* To do that theme sensitve, we only have to call
|
|
||||||
* {@code IconUtil.loadIconThemeSensitive("abc_", 16)}
|
|
||||||
*/
|
*/
|
||||||
public static Image loadIconThemeSensitive(String name, int size) { return loadIcon(themeSpecificSubFolder() + name, size); }
|
public static Image loadIconThemeSensitive(String name, int size) { return loadIcon(themeSpecificSubFolder() + name, size); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Loads icons specified by an enum. The images have to be named like the
|
* Loads images specified by an enum. The images have to be named like the
|
||||||
* lowercase enum constants with {@code .png} extension and be located inside a
|
* 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
|
* folder with the lowercase name of the enum, which must be contained inside
|
||||||
* the {@code /icons} folder.
|
* the {@code /icons/} folder.
|
||||||
*
|
*
|
||||||
* @param <T> the enum that specifies the icons to load
|
* @param <T> the enum that specifies the images to load
|
||||||
* @param enumClass the class of the enum
|
* @param enumClass the class of the enum
|
||||||
* @param size the size to scale the icons to
|
* @param size the size to scale the images to
|
||||||
* @return a map containing the loaded icons with the corresponding enum
|
* @return a map containing the loaded images with the corresponding enum
|
||||||
* constants as keys
|
* constants as keys
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
*/
|
*/
|
||||||
@ -161,10 +146,10 @@ public class IconUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method should be called if the display of an icon depends upon the
|
* This method should be called if the display of an image depends upon the
|
||||||
* currently active theme.<br>
|
* currently active theme.<br>
|
||||||
* In case of a default theme, the string returned will be
|
* In case of a default theme, the string returned will be
|
||||||
* returned ({@code dark/} or {@code light/}), else it will be empty.
|
* ({@code dark/} or {@code light/}), otherwise it will be empty.
|
||||||
*
|
*
|
||||||
* @return the theme specific folder
|
* @return the theme specific folder
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.1-beta
|
||||||
|
Reference in New Issue
Block a user