Class 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 using Class.getResource(String), so icon name should follow that notation.

    • Constructor Summary

      Constructors 
      Constructor Description
      IconsFactory()  
    • Constructor Detail

      • IconsFactory

        public IconsFactory()
    • 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 class
        name - 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 class
        name - 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 name
        silent - 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 class
        name - icon name
        silent - 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 - url
        size - 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 - url
        size - 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 icon
        data - 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 - uri
        data - an array of icon data
        size - 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 uri
        data - 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 uri
        data - an array of icon data
        size - 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 with ImageIcon.
        Parameters:
        url - icon url
        Returns:
        icon