Class FlatSVGIcon.ColorFilter

  • Enclosing class:
    FlatSVGIcon

    public static class FlatSVGIcon.ColorFilter
    extends Object
    A color filter that can modify colors of a painted FlatSVGIcon.

    The ColorFilter modifies color in two ways. Either using a color map, where specific colors are mapped to different ones. And/or by modifying the colors in a mapper function.

    When filtering a color, mappings are applied first, then the mapper function is applied.

    Global FlatSVGIcon ColorFilter can be retrieved using the getInstance() method.

    • Constructor Detail

      • ColorFilter

        public ColorFilter()
        Creates an empty color filter.
      • ColorFilter

        public ColorFilter​(Function<Color,​Color> mapper)
        Creates a color filter with a color modifying function that changes painted colors. The Function gets passed the original color and returns a modified one.

        Examples: A ColorFilter can be used to brighten colors of the icon:

        new ColorFilter( color -> color.brighter() );

        Using a ColorFilter, icons can also be turned monochrome (painted with a single color):

        new ColorFilter( color -> Color.RED );
        Parameters:
        mapper - The color mapper function
        Since:
        1.2
      • ColorFilter

        public ColorFilter​(BiFunction<Component,​Color,​Color> mapperEx)
        Creates a color modifying function that changes painted colors. The BiFunction gets passed the component and the original color and returns a modified one.

        Examples: A ColorFilter can be used to brighten colors of the icon (depending on component state if desired):

        new ColorFilter( (c, color) -> c.isEnabled() ? color.brighter() : color );
        Parameters:
        mapperEx - The color mapper function
        Since:
        3.6
    • Method Detail

      • getInstance

        public static FlatSVGIcon.ColorFilter getInstance()
        Returns the global ColorFilter that is applied to all icons.
      • getMapper

        public Function<Color,​Color> getMapper()
        Returns a color modifying function or null
        Since:
        1.2
      • setMapper

        public void setMapper​(Function<Color,​Color> mapper)
        Sets a color modifying function that changes painted colors. The Function gets passed the original color and returns a modified one.

        Examples: A ColorFilter can be used to brighten colors of the icon:

        filter.setMapper( color -> color.brighter() );

        Using a ColorFilter, icons can also be turned monochrome (painted with a single color):

        filter.setMapper( color -> Color.RED );
        Parameters:
        mapper - The color mapper function
        Since:
        1.2
        See Also:
        setMapperEx(BiFunction)
      • setMapperEx

        public void setMapperEx​(BiFunction<Component,​Color,​Color> mapperEx)
        Sets a color modifying function that changes painted colors. The BiFunction gets passed the component and the original color and returns a modified one.

        Examples: A ColorFilter can be used to brighten colors of the icon (depending on component state if desired):

        filter.setMapperEx( (c, color) -> c.isEnabled() ? color.brighter() : color );
        Parameters:
        mapperEx - The color mapper function
        Since:
        3.6
        See Also:
        setMapper(Function)
      • getLightColorMap

        public Map<Color,​Color> getLightColorMap()
        Returns the color mappings used for light themes.
        Since:
        1.2
      • getDarkColorMap

        public Map<Color,​Color> getDarkColorMap()
        Returns the color mappings used for dark themes.
        Since:
        1.2