How to make IntelliJ color preview recognize a custom Color class?

Viewed 107

In IntelliJ there's a feature where you can preview colors in the gutter for regular rgb colors using the Color class. However, there are some cases where I prefer the HSL color model, which Java doesn't have, so I made my own class that extends Color. Colors instantiated through the custom class don't have previews; is there any way I can tell IntelliJ how to extract a preview from my class?

Example of what I'm talking about

Here's a short preview of the HSLColor class:

public class HSLColor extends Color
{
    private float[] hsl;
    private float alpha;
    
    public HSLColor(float h, float s, float l, float a)
    {
        this(toRGB(h, s, l, a));
        hsl = new float[]{h, s, l};
        alpha = a;
    }
    
    private HSLColor(float[] rgba)
    {
        super(rgba[0], rgba[1], rgba[2], rgba[3]);
    }
}
1 Answers
Related