Class AbstractResourceIconProvider

java.lang.Object
org.openhab.core.ui.icon.AbstractResourceIconProvider
All Implemented Interfaces:
IconProvider

@NonNullByDefault public abstract class AbstractResourceIconProvider extends Object implements IconProvider
This is an abstract base class for implementing icon providers that serve icons from file resources. These files could be read from the file system, directly from the bundle itself or from somewhere else that can provide an InputStream. The resources are expected to follow the naming convention "[-].", e.g. "alarm.png" or "alarm-on.svg". Resource names must be all lower case. Whether an icon is provided or not is determined by the existence of a resource without a state postfix. If a specific resource for a state is available, it will be used. If not, the default icon without a state postfix is used. If the state is a decimal number between 0 and 100, the implementation will look for a resource with the next smaller state postfix available. Example: For category "Light" and state 84, it will check for the resources light-82.png, light-81.png, light-80.png and return the first one it can find.
Author:
Kai Kreuzer - Initial contribution
  • Field Details

  • Constructor Details

    • AbstractResourceIconProvider

      protected AbstractResourceIconProvider(TranslationProvider i18nProvider)
  • Method Details

    • getIconSets

      public Set<IconSet> getIconSets()
      Description copied from interface: IconProvider
      Returns a set of icon set definitions (meta-data) which this provider defines.
      Specified by:
      getIconSets in interface IconProvider
      Returns:
      a set of icon sets in the default locale
    • hasIcon

      public @Nullable Integer hasIcon(String category, String iconSetId, IconSet.Format format)
      Description copied from interface: IconProvider
      determines whether this provider can deliver an icon for a given name
      Specified by:
      hasIcon in interface IconProvider
      Parameters:
      category - the icon category
      iconSetId - the id of the icon set for which the icon is requested
      format - the format of the stream (usually either png or svg)
      Returns:
      a non-negative Integer value defining the priority (higher is more important) or null, if this provider cannot deliver an icon. Default for full icon sets should be 0, so that others have the chance to override icons.
    • getIcon

      public @Nullable InputStream getIcon(String category, String iconSetId, @Nullable String state, IconSet.Format format)
      Description copied from interface: IconProvider
      retrieves the InputStream of an icon
      Specified by:
      getIcon in interface IconProvider
      Parameters:
      category - the icon category
      iconSetId - the id of the icon set for which the icon is requested
      state - the string representation of the state (for the case that the icon differs for different states)
      format - the format of the stream (usually either png or svg)
      Returns:
      a byte stream of the icon in the given format or null, if no icon exists
    • getPriority

      protected abstract Integer getPriority()
      Provides the priority of this provider. A higher value will give this provider a precedence over others.
      Returns:
      the priority as a positive integer
    • getResource

      protected abstract @Nullable InputStream getResource(String iconSetId, String resourceName)
      Provides the content of a resource for a certain icon set as a stream or null, if the resource does not exist.
      Parameters:
      iconSetId - the id of the icon set for which the resource is requested
      resourceName - the name of the resource
      Returns:
      the content as a stream or null, if the resource does not exist
    • hasResource

      protected abstract boolean hasResource(String iconSetId, String resourceName)
      Checks whether a certain resource exists for a given icon set.
      Parameters:
      iconSetId - the id of the icon set for which the resource is requested
      resourceName - the name of the resource
      Returns:
      true, if the resource exists, false otherwise