Package org.openhab.core.ui.icon
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 [-].", 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.
InputStream
.
The resources are expected to follow the naming convention "- Author:
- Kai Kreuzer - Initial contribution
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription@Nullable InputStream
getIcon
(String category, String iconSetId, @Nullable String state, IconSet.Format format) retrieves theInputStream
of an iconReturns a set of icon set definitions (meta-data) which this provider defines.protected abstract Integer
Provides the priority of this provider.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.@Nullable Integer
hasIcon
(String category, String iconSetId, IconSet.Format format) determines whether this provider can deliver an icon for a given nameprotected abstract boolean
hasResource
(String iconSetId, String resourceName) Checks whether a certain resource exists for a given icon set.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.openhab.core.ui.icon.IconProvider
getIconSets
-
Field Details
-
i18nProvider
-
-
Constructor Details
-
AbstractResourceIconProvider
-
-
Method Details
-
getIconSets
Description copied from interface:IconProvider
Returns a set of icon set definitions (meta-data) which this provider defines.- Specified by:
getIconSets
in interfaceIconProvider
- Returns:
- a set of icon sets in the default locale
-
hasIcon
Description copied from interface:IconProvider
determines whether this provider can deliver an icon for a given name- Specified by:
hasIcon
in interfaceIconProvider
- Parameters:
category
- the icon categoryiconSetId
- the id of the icon set for which the icon is requestedformat
- 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 theInputStream
of an icon- Specified by:
getIcon
in interfaceIconProvider
- Parameters:
category
- the icon categoryiconSetId
- the id of the icon set for which the icon is requestedstate
- 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
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
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 requestedresourceName
- the name of the resource- Returns:
- the content as a stream or null, if the resource does not exist
-
hasResource
Checks whether a certain resource exists for a given icon set.- Parameters:
iconSetId
- the id of the icon set for which the resource is requestedresourceName
- the name of the resource- Returns:
- true, if the resource exists, false otherwise
-