Strongly-Typed Colors for Java – Because `"#ff00cc"` is not a color

Been guilty of stuffing color strings all over your Java code like it’s JavaScript? Yeah, me too and I have hated myself for it. So I finally snapped and wrote a proper color library.

:point_right: GitHub - viritin/color: A lightweight and zero-dependency Java domain objects for "css colors".

  • Fully typed color values (because Java’s type system deserves better). Immutable, based on records, but e.g. HSL colors contain some handy functions for generating derived values.
  • Vaadin-agnostic – but handy in Vaadin apps, add-ons, whatever. Types can be used as such, but toString() creates CSS compatible string representations.
  • Already in use in 4 of my other add-ons, behaving surprisingly well.
  • Jackson configuration → in case e.g. some JSON config uses those plain CSS strings, you can use types directly in your Java model.

Thinking of pitching the classes to Vaadin core at some point (Style, Charts…), but would love feedback before I go knocking on that door.

Try it. Break it. Complain. PRs welcome.

5 Likes