Class IconsFactory

java.lang.Object
com.nomagic.magicdraw.icons.IconsFactory

@OpenApiAll public class IconsFactory extends 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 Details

    • IconsFactory

      public IconsFactory()
  • Method Details

    • getIcon

      public static ResizableIcon getIcon(String name)
      Load icon from a given resource
      Parameters:
      name - icon name
      Returns:
      icon
      See Also:
    • getIcon

      public static ResizableIcon getIcon(Class clazz, String name)
      Load icon from a given resource
      Parameters:
      clazz - icon resource class
      name - icon name
      Returns:
      icon
      See Also:
    • getNotScaledIcon

      public static ResizableIcon getNotScaledIcon(String name)
      Load icon from a given resource. Does not scale icon by screen dpi.
      Parameters:
      name - icon name
      Returns:
      icon
      See Also:
    • getNotScaledIcon

      public static ResizableIcon getNotScaledIcon(Class clazz, 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:
    • getIcon

      public static ResizableIcon getIcon(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:
    • getIcon

      public static ResizableIcon getIcon(Class clazz, 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:
    • getResourceAsStream

      public static InputStream getResourceAsStream(String name)
      Provide stream to a resource in this package
      Parameters:
      name - resource name
      Returns:
      icon
      See Also:
    • getResource

      public static URL getResource(String name)
      Provide URL to a resource in this package
      Parameters:
      name - resource name
      Returns:
      icon
      See Also:
    • getQualifiedResourceName

      public static String getQualifiedResourceName(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(URL url)
      Load icon from a given url.
      Parameters:
      url - url
      Returns:
      icon
    • getIcon

      public static ResizableIcon getIcon(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(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(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(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(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:
    • getNotScaledIcon

      public static ResizableIcon getNotScaledIcon(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(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(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(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(InputStream input)
      Reads icon data from a given stream.
      Parameters:
      input - input stream
      Returns:
      icon data
    • getSvgIcon

      @CheckForNull public static ResizableIcon getSvgIcon(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