diff --git a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/extras/ExtrasPanel.java b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/extras/ExtrasPanel.java
index 84dec7e3..e3501e7c 100644
--- a/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/extras/ExtrasPanel.java
+++ b/flatlaf-demo/src/main/java/com/formdev/flatlaf/demo/extras/ExtrasPanel.java
@@ -20,7 +20,6 @@ import javax.swing.*;
import com.formdev.flatlaf.extras.*;
import com.formdev.flatlaf.extras.FlatSVGIcon.ColorFilter;
import com.formdev.flatlaf.extras.components.FlatTriStateCheckBox;
-import com.formdev.flatlaf.util.GrayFilter;
import net.miginfocom.swing.*;
import java.awt.*;
@@ -159,9 +158,9 @@ public class ExtrasPanel
// ---- toggleButton1 ----
toggleButton1.addActionListener( (e) -> {
if (toggleButton1.isSelected())
- FlatSVGIcon.ColorFilter.getInstance().setFilter( color -> color.brighter().brighter() );
+ FlatSVGIcon.ColorFilter.getInstance().setMapper( color -> color.brighter() );
else
- FlatSVGIcon.ColorFilter.getInstance().setFilter( null );
+ FlatSVGIcon.ColorFilter.getInstance().setMapper( null );
SwingUtilities.getRootPane( toggleButton1 ).repaint();
} );
@@ -170,7 +169,7 @@ public class ExtrasPanel
private JLabel createRainbowIcon(String name) {
FlatSVGIcon rainbowIcon = new FlatSVGIcon( "com/formdev/flatlaf/demo/extras/svg/" + name);
- rainbowIcon.setFilter( new ColorFilter( (color) -> {
+ rainbowIcon.setColorFilter( new ColorFilter( (color) -> {
counter+=1;
counter%=255;
return Color.getHSBColor(counter/255f, 1, 1);
diff --git a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatSVGIcon.java b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatSVGIcon.java
index 850ba5de..3cfb418f 100644
--- a/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatSVGIcon.java
+++ b/flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatSVGIcon.java
@@ -66,7 +66,7 @@ public class FlatSVGIcon
private final boolean disabled;
private final ClassLoader classLoader;
- private ColorFilter userColorFilter = null;
+ private ColorFilter colorFilter;
private SVGDiagram diagram;
private boolean dark;
@@ -163,37 +163,11 @@ public class FlatSVGIcon
protected FlatSVGIcon( String name, int width, int height, float scale, boolean disabled, ClassLoader classLoader ) {
this.name = name;
- this.classLoader = classLoader;
this.width = width;
this.height = height;
this.scale = scale;
this.disabled = disabled;
- }
-
- /**
- * Sets a color filter that can freely modify colors of this icon during painting.
- *
- * This method accepts a {@link ColorFilter}. Usually you would want to use a ColorFilter created using the
- * {@link ColorFilter#ColorFilter(Function)} constructor.
- *
- * This can be used to brighten colors of the icon:
- *
icon.setFilter( new FlatSVGIcon.ColorFilter( color -> color.brighter() ) );
icon.setFilter( new FlatSVGIcon.ColorFilter( color -> Color.RED ) );
+ * This method accepts a {@link ColorFilter}. Usually you would want to use a ColorFilter created using the + * {@link ColorFilter#ColorFilter(Function)} constructor. + *
+ * This can be used to brighten colors of the icon: + *
icon.setColorFilter( new FlatSVGIcon.ColorFilter( color -> color.brighter() ) );+ *
+ * Using a filter, icons can also be turned monochrome (painted with a single color): + *
icon.setColorFilter( new FlatSVGIcon.ColorFilter( color -> Color.RED ) );+ *
+ * Note: If a filter is already set, it will be replaced.
+ *
+ * @param colorFilter The color filter
+ * @since 1.2
+ */
+ public void setColorFilter( ColorFilter colorFilter ) {
+ this.colorFilter = colorFilter;
+ }
+
private void update() {
if( dark == isDarkLaf() && diagram != null )
return;
@@ -331,7 +335,7 @@ public class FlatSVGIcon
: GrayFilter.createDisabledIconFilter( dark );
}
- Graphics2D g2 = new GraphicsFilter( (Graphics2D) g.create(), ColorFilter.getInstance(), this.userColorFilter, grayFilter );
+ Graphics2D g2 = new GraphicsFilter( (Graphics2D) g.create(), colorFilter, ColorFilter.getInstance(), grayFilter );
try {
FlatUIUtils.setRenderingHints( g2 );
@@ -430,93 +434,91 @@ public class FlatSVGIcon
//---- class ColorFilter --------------------------------------------------
/**
- * A color filter that can modify colors of a painted {@link FlatSVGIcon}.
- *
- * The ColorFilter modifes color in two ways.
- * Either using a color map, where specific colors are mapped to different ones.
- * And/or by modifying the colors directly, applying a modification to their rgba values.
- *
- * When filtering a color. Mappings are applied first, then an rgb color filter is applied.
- *
+ * A color filter that can modify colors of a painted {@link 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 {@link FlatSVGIcon} ColorFilter can be retrieved using the {@link ColorFilter#getInstance()} method.
- *
- * @see ColorFilter#ColorFilter(Function)
- * @see ColorFilter#ColorFilter(boolean)
*/
public static class ColorFilter
{
private static ColorFilter instance;
- //Color maps
private final Map
* Examples:
* A ColorFilter can be used to brighten colors of the icon:
*
* Using a ColorFilter, icons can also be turned monochrome (painted with a single color):
*
* Examples:
* A ColorFilter can be used to brighten colors of the icon:
- *
* Using a ColorFilter, icons can also be turned monochrome (painted with a single color):
- *
+ * Creates a color filter with a color modifying function that changes painted colors.
* The {@link Function} gets passed the original color and returns a modified one.
- *
+ * new ColorFilter( color -> color.brighter() );
- *
+ * new ColorFilter( color -> Color.RED );
- *
- * @param filter The color filter function
+ *
+ * @param mapper The color mapper function
+ * @since 1.2
*/
- public ColorFilter(Function
+ * Returns a color modifying function or {@code null}
+ *
+ * @since 1.2
+ */
+ public Function
+ * filter.setFilter( color -> color.brighter() );
- *
+ * filter.setMapper( color -> color.brighter() );
+ * filter.setFilter( color -> Color.RED );
- *
- * @param filter The color filter function
+ * filter.setMapper( color -> Color.RED );
+ *
+ * @param mapper The color mapper function
+ * @since 1.2
*/
- public void setFilter(Function