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 paintedFlatSVGIcon.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
FlatSVGIconColorFilter can be retrieved using thegetInstance()method.
-
-
Constructor Summary
Constructors Constructor Description ColorFilter()Creates an empty color filter.ColorFilter(BiFunction<Component,Color,Color> mapperEx)Creates a color modifying function that changes painted colors.ColorFilter(Function<Color,Color> mapper)Creates a color filter with a color modifying function that changes painted colors.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FlatSVGIcon.ColorFilteradd(Color from, Color to)Adds a color mapping.FlatSVGIcon.ColorFilteradd(Color from, Color toLight, Color toDark)Adds a color mapping, which has different colors for light and dark themes.FlatSVGIcon.ColorFilteraddAll(Map<Color,Color> from2toMap)Adds color mappings.FlatSVGIcon.ColorFilteraddAll(Map<Color,Color> from2toLightMap, Map<Color,Color> from2toDarkMap)Adds a color mappings, which has different colors for light and dark themes.static Function<Color,Color>createRGBImageFilterFunction(RGBImageFilter rgbImageFilter)Creates a color modifying function that usesRGBImageFilter.filterRGB(int, int, int).Colorfilter(Color color)Colorfilter(Component c, Color color)Map<Color,Color>getDarkColorMap()Returns the color mappings used for dark themes.static FlatSVGIcon.ColorFiltergetInstance()Returns the global ColorFilter that is applied to all icons.Map<Color,Color>getLightColorMap()Returns the color mappings used for light themes.Function<Color,Color>getMapper()Returns a color modifying function ornullBiFunction<Component,Color,Color>getMapperEx()Returns a color modifying function ornullComponentgetPaintingComponent()Returns the component passed toFlatSVGIcon.paintIcon(Component, Graphics, int, int).FlatSVGIcon.ColorFilterremove(Color from)Removes a specific color mapping.FlatSVGIcon.ColorFilterremoveAll()Removes all color mappings.voidsetMapper(Function<Color,Color> mapper)Sets a color modifying function that changes painted colors.voidsetMapperEx(BiFunction<Component,Color,Color> mapperEx)Sets a color modifying function that changes painted colors.
-
-
-
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. TheFunctiongets 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. TheBiFunctiongets 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 ornull- Since:
- 1.2
-
setMapper
public void setMapper(Function<Color,Color> mapper)
Sets a color modifying function that changes painted colors. TheFunctiongets 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)
-
getMapperEx
public BiFunction<Component,Color,Color> getMapperEx()
Returns a color modifying function ornull- Since:
- 3.6
-
setMapperEx
public void setMapperEx(BiFunction<Component,Color,Color> mapperEx)
Sets a color modifying function that changes painted colors. TheBiFunctiongets 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
-
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
-
getPaintingComponent
public Component getPaintingComponent()
Returns the component passed toFlatSVGIcon.paintIcon(Component, Graphics, int, int). This allows color mapping depend on component state (e.g. enabled, selected, hover, etc).- Since:
- 3.6
-
createRGBImageFilterFunction
public static Function<Color,Color> createRGBImageFilterFunction(RGBImageFilter rgbImageFilter)
Creates a color modifying function that usesRGBImageFilter.filterRGB(int, int, int). Can be set to aFlatSVGIcon.ColorFilterusingsetMapper(Function).- Since:
- 1.2
- See Also:
GrayFilter
-
-