Package com.nomagic.magicdraw.icons
Class IconsFactory
- java.lang.Object
-
- com.nomagic.magicdraw.icons.IconsFactory
-
@OpenApiAll public class IconsFactory extends java.lang.Object
Utility class to load icons from MagicDraw icons package or other locations. All loaded icons are cached, so second attempt to load same icon will take it from a cache. Icons are loader usingClass.getResource(String)
, so icon name should follow that notation.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
NO_SCALE_KEY
-
Constructor Summary
Constructors Constructor Description IconsFactory()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ResizableIcon
getIcon(java.lang.Class clazz, java.lang.String name)
Load icon from a given resourcestatic ResizableIcon
getIcon(java.lang.Class clazz, java.lang.String name, boolean silent)
Load icon from a given resource.static ResizableIcon
getIcon(java.lang.String name)
Load icon from a given resourcestatic ResizableIcon
getIcon(java.lang.String name, boolean silent)
Load icon from a given resource.static ResizableIcon
getIcon(java.net.URI uri, byte[] data)
Load icon from given bytes.static ResizableIcon
getIcon(java.net.URI uri, byte[] data, int size)
Load icon from given bytes.static ResizableIcon
getIcon(java.net.URL url)
Load icon from a given url.static ResizableIcon
getIcon(java.net.URL url, int size)
Load icon from a given url.static byte[]
getIconData(java.io.File file)
Reads icon data from a given file.static byte[]
getIconData(java.io.InputStream input)
Reads icon data from a given stream.static byte[]
getIconData(java.net.URL url)
Reads icon data from a given url.static ResizableIcon
getNotScaledIcon(java.lang.Class clazz, java.lang.String name)
Load icon from a given resource.static ResizableIcon
getNotScaledIcon(java.lang.String name)
Load icon from a given resource.static ResizableIcon
getNotScaledIcon(java.net.URI uri, byte[] data)
Load icon from given bytes.static ResizableIcon
getNotScaledIcon(java.net.URI uri, byte[] data, int size)
Load icon from given bytes.static ResizableIcon
getNotScaledIcon(java.net.URL url)
Load icon from a given url.static ResizableIcon
getNotScaledIcon(java.net.URL url, int size)
Load icon from a given url.static java.lang.String
getQualifiedResourceName(java.lang.String resourceName)
Resolves given resource name to a qualified name in this package.static java.net.URL
getResource(java.lang.String name)
Provide URL to a resource in this packagestatic java.io.InputStream
getResourceAsStream(java.lang.String name)
Provide stream to a resource in this packagestatic ResizableIcon
getSvgIcon(java.net.URL url)
Load SVG icon from a given url.
-
-
-
Field Detail
-
NO_SCALE_KEY
private static final java.lang.String NO_SCALE_KEY
- See Also:
- Constant Field Values
-
-
Method Detail
-
getIcon
public static ResizableIcon getIcon(java.lang.String name)
Load icon from a given resource- Parameters:
name
- icon name- Returns:
- icon
- See Also:
Class.getResource(java.lang.String)
-
getIcon
public static ResizableIcon getIcon(java.lang.Class clazz, java.lang.String name)
Load icon from a given resource- Parameters:
clazz
- icon resource classname
- icon name- Returns:
- icon
- See Also:
Class.getResource(java.lang.String)
-
getNotScaledIcon
public static ResizableIcon getNotScaledIcon(java.lang.String name)
Load icon from a given resource. Does not scale icon by screen dpi.- Parameters:
name
- icon name- Returns:
- icon
- See Also:
Class.getResource(java.lang.String)
-
getNotScaledIcon
public static ResizableIcon getNotScaledIcon(java.lang.Class clazz, java.lang.String name)
Load icon from a given resource. Does not scale icon by screen dpi.- Parameters:
clazz
- icon resource classname
- icon name- Returns:
- icon
- See Also:
Class.getResource(java.lang.String)
-
getIcon
public static ResizableIcon getIcon(java.lang.String name, boolean silent)
Load icon from a given resource.- Parameters:
name
- icon namesilent
- true if missing icon should not be reported to a log file- Returns:
- icon
- See Also:
Class.getResource(java.lang.String)
-
getIcon
public static ResizableIcon getIcon(java.lang.Class clazz, java.lang.String name, boolean silent)
Load icon from a given resource.- Parameters:
clazz
- icon resource classname
- icon namesilent
- true if missing icon should not be reported to a log file- Returns:
- icon
- See Also:
Class.getResource(java.lang.String)
-
getResourceAsStream
public static java.io.InputStream getResourceAsStream(java.lang.String name)
Provide stream to a resource in this package- Parameters:
name
- resource name- Returns:
- icon
- See Also:
Class.getResourceAsStream(String)
-
getResource
public static java.net.URL getResource(java.lang.String name)
Provide URL to a resource in this package- Parameters:
name
- resource name- Returns:
- icon
- See Also:
Class.getResource(java.lang.String)
-
getQualifiedResourceName
public static java.lang.String getQualifiedResourceName(java.lang.String resourceName)
Resolves given resource name to a qualified name in this package. If resource name is already qualified (starts with "/"), returns it.- Parameters:
resourceName
- resource name- Returns:
- qualified resource name in this package
-
getIcon
public static ResizableIcon getIcon(java.net.URL url)
Load icon from a given url.- Parameters:
url
- url- Returns:
- icon
-
getIcon
public static ResizableIcon getIcon(java.net.URL url, int size)
Load icon from a given url. Scales icon to a box of given size.- Parameters:
url
- urlsize
- icon box size. -1 if scaling is not needed- Returns:
- icon
-
getNotScaledIcon
public static ResizableIcon getNotScaledIcon(java.net.URL url)
Load icon from a given url. Does not scale icon by screen dpi.- Parameters:
url
- url- Returns:
- icon
-
getNotScaledIcon
public static ResizableIcon getNotScaledIcon(java.net.URL url, int size)
Load icon from a given url. Scales icon to a box of given size. Does not scale icon by screen dpi.- Parameters:
url
- urlsize
- icon box size. -1 if scaling is not needed- Returns:
- icon
-
getIcon
public static ResizableIcon getIcon(java.net.URI uri, byte[] data)
Load icon from given bytes.- Parameters:
uri
- uri describing the location (or format) of the icondata
- an array of icon data bytes- Returns:
- icon
-
getIcon
public static ResizableIcon getIcon(java.net.URI uri, byte[] data, int size)
Load icon from given bytes. Scales icon to a box of given size. Does not scale icon by screen dpi.- Parameters:
uri
- uridata
- an array of icon datasize
- icon box size. Icon will be scaled to this box. -1 if scaling is not needed- Returns:
- icon
- See Also:
HiDPIScaleUtilities.scaleIcon(int)
-
getNotScaledIcon
public static ResizableIcon getNotScaledIcon(java.net.URI uri, byte[] data)
Load icon from given bytes. Scales icon to a box of given size. Does not scale icon by screen dpi.- Parameters:
uri
- icon uridata
- an array of icon data- Returns:
- icon
-
getNotScaledIcon
public static ResizableIcon getNotScaledIcon(java.net.URI uri, byte[] data, int size)
Load icon from given bytes. Scales icon to a box of given size. Does not scale icon by screen dpi.- Parameters:
uri
- icon uridata
- an array of icon datasize
- icon box size. Icon will be scaled to this box. -1 if scaling is not needed- Returns:
- icon
-
getIconData
@CheckForNull public static byte[] getIconData(java.io.File file)
Reads icon data from a given file.- Parameters:
file
- an icon file- Returns:
- icon data from given file
-
getIconData
@CheckForNull public static byte[] getIconData(java.net.URL url)
Reads icon data from a given url.- Parameters:
url
- icon url- Returns:
- icon data from given url
-
getIconData
@CheckForNull public static byte[] getIconData(java.io.InputStream input)
Reads icon data from a given stream.- Parameters:
input
- input stream- Returns:
- icon data
-
getSvgIcon
@CheckForNull public static ResizableIcon getSvgIcon(java.net.URL url)
Load SVG icon from a given url. Other getIcon(...) methods in this class also can read SVG icons, but this one does not return icon compatible withImageIcon
.- Parameters:
url
- icon url- Returns:
- icon
-
-