I have a class called ColorConstants which is simply a class that defines a number of public static final Color fields used throughout my application – making it easy to change color schemes etc. What I would like to do is have two schemes: inverted, not-inverted. I’d like to set this class up so that the same field names may be references to different colors depending on the scheme / theme. Rather than to check / get the necessary color everytime.
I’ve never used an enum before, and was just wondering if it’s suited for this?
Alternatively I’d just make the fields non-final and use a setAll(int theme) approach.
I wouldn’t use enum here.
I would create a class containing all the color fields (non-final), but without value. And create extending classes that define all the colors in the constructor.
And now create an implementation of the ColorScheme:
Now, you can use your color schemes like this:
From now on you can create extra color schemes and simply use in the line above the new colorscheme and everything should work dynamically.