Class FlatSVGIcon.ColorFilter

java.lang.Object
com.formdev.flatlaf.extras.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.

  • Field Details

  • Constructor Details

    • 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
  • Method Details

    • 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
    • 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
    • addAll

      public FlatSVGIcon.ColorFilter addAll(Map<Color,Color> from2toMap)
      Adds color mappings. Used for light and dark themes.
    • addAll

      public FlatSVGIcon.ColorFilter addAll(Map<Color,Color> from2toLightMap, Map<Color,Color> from2toDarkMap)
      Adds a color mappings, which has different colors for light and dark themes.
      Since:
      1.2
    • add

      public FlatSVGIcon.ColorFilter add(Color from, Color to)
      Adds a color mapping. Used for light and dark themes.
    • add

      public FlatSVGIcon.ColorFilter add(Color from, Color toLight, Color toDark)
      Adds a color mapping, which has different colors for light and dark themes.
      Since:
      1.2
    • remove

      public FlatSVGIcon.ColorFilter remove(Color from)
      Removes a specific color mapping.
    • removeAll

      public FlatSVGIcon.ColorFilter removeAll()
      Removes all color mappings.
      Since:
      1.2
    • ensureColorMap

      private void ensureColorMap()
    • ensureDarkColorMap

      private void ensureDarkColorMap()
    • filter

      public Color filter(Color color)
    • applyMappings

      private Color applyMappings(Color color)
    • createRGBImageFilterFunction

      public static Function<Color,Color> createRGBImageFilterFunction(RGBImageFilter rgbImageFilter)
      Creates a color modifying function that uses RGBImageFilter.filterRGB(int, int, int). Can be set to a FlatSVGIcon.ColorFilter using setMapper(Function).
      Since:
      1.2
      See Also: