- java.lang.Object
-
- org.jorigin.swing.IconLoader
-
public class IconLoader extends Object
A class dedicated to SWING icon loading. It is possible to specify where the icon loader has to search for icons by setting the "org.jorigin.icon.dir" system property.- Since:
- 1.0.0
- Version:
- "1.0.14" - b202111241200L
- Author:
- Julien SEINTURIER - Université de Toulon / CNRS LIS umr 7020 - github.com/jorigin/jcommon (contact@jorigin.org)
-
-
Field Summary
Fields Modifier and Type Field Description static StringICON_LOADER_DIRSpecify where the icon loader has to search for icons (default empty string "").static intPATH_TYPE_EMBEDDED_JARThis flag identifies a jar type for the resource path.static intPATH_TYPE_EMBEDDED_ZIPThis flag identifies a zup type for the resource path.static intPATH_TYPE_FILESYSTEMThis flag identifies an filesystem type (absolute) for the resource path.static intPATH_TYPE_UNKNOWNThis flag identifies an unknown type for the resource path.static intPATH_TYPE_URLThis flag identifies an URL type (HTTP, HTTPS, FTP, SFTP) for the resource path.
-
Constructor Summary
Constructors Constructor Description IconLoader()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ImageIcongetIcon(String path)Get aniconfrom the givenpath.static StringgetIconDirectory()Get the directory to use as root for the icon search.static ImagegetImage(String path)Get animagefrom the givenpath.static ImageIcongetScaledIcon(String name, double width, double height)Get an icon and scale it to the desired size given in millimeters.static ImageIcongetScaledIcon(String name, Dimension dimension)Get an icon and scale it to the desired size given in millimeters.static voidsetIconDirectory(String path)Set the path to use as root for the icon search.
-
-
-
Field Detail
-
ICON_LOADER_DIR
public static final String ICON_LOADER_DIR
Specify where the icon loader has to search for icons (default empty string "").- See Also:
- Constant Field Values
-
PATH_TYPE_UNKNOWN
public static int PATH_TYPE_UNKNOWN
This flag identifies an unknown type for the resource path.
-
PATH_TYPE_FILESYSTEM
public static int PATH_TYPE_FILESYSTEM
This flag identifies an filesystem type (absolute) for the resource path.
-
PATH_TYPE_URL
public static int PATH_TYPE_URL
This flag identifies an URL type (HTTP, HTTPS, FTP, SFTP) for the resource path.
-
PATH_TYPE_EMBEDDED_JAR
public static int PATH_TYPE_EMBEDDED_JAR
This flag identifies a jar type for the resource path.
-
PATH_TYPE_EMBEDDED_ZIP
public static int PATH_TYPE_EMBEDDED_ZIP
This flag identifies a zup type for the resource path.
-
-
Method Detail
-
getIcon
public static ImageIcon getIcon(String path)
Get aniconfrom the givenpath. If the iconpathis relative, a complete path is created by concatenating theicon root pathand the given one. If the iconpathis absolute, the icon is directly loaded.- Parameters:
path- the path to the icon. Can be relative or absolute.- Returns:
- the loaded icon or
nullif no icon was found.
-
getImage
public static Image getImage(String path)
Get animagefrom the givenpath. If the imagepathis relative, a complete path is created by concatenating theicon root pathand the given one. If the imagepathis absolute, the image is directly loaded.- Parameters:
path- the path to the image. Can be relative or absolute.- Returns:
- the loaded image or
nullif no image was found.
-
getScaledIcon
public static ImageIcon getScaledIcon(String name, Dimension dimension)
Get an icon and scale it to the desired size given in millimeters.- Parameters:
name- the name of the icon to load.dimension- the dimension in millimeters of the icon.- Returns:
- a scaled image that represents the desired icon.
-
getScaledIcon
public static ImageIcon getScaledIcon(String name, double width, double height)
Get an icon and scale it to the desired size given in millimeters.- Parameters:
name- the name of the icon to load.width- the expected width in millimeter (mm)height- the expected height in millimeter (mm)- Returns:
- a scaled image that represents the desired icon
- See Also:
getScaledIcon(String, Dimension)
-
getIconDirectory
public static String getIconDirectory()
Get the directory to use as root for the icon search. The icon path can be a system directory, a string that represents an URL or a string that represents an embedded (zip, jar, ...) directory.- Returns:
- the path to use as root for the icon search.
- See Also:
setIconDirectory(String)
-
setIconDirectory
public static void setIconDirectory(String path)
Set the path to use as root for the icon search. The icon path can be a system directory, a string that represents an URL or a string that represents an embedded (zip, jar, ...) directory.- Parameters:
path- the path to use as root for the icon search.- See Also:
getIconDirectory()
-
-