I am implementing an enum class that I will use to get some background in the application, the current implementation of this class is here:
public enum Painters{
Background(getBackgroundPainter()),
InactiveBackground(getInactiveBackgroundPainter()),
DesktopBackground(getBackgroundPainter());
private Painter<Component> _painter;
Painters(Painter<Component> painter){
_painter = painter;
}
public Painter<Component> painter(){
return _painter;
}
private static Painter<Component> getBackgroundPainter(){
MattePainter mp = new MattePainter(Colors.White.alpha(1f));
PinstripePainter pp = new PinstripePainter(Colors.Gray.alpha(0.2f),45d);
return (new CompoundPainter<Component>(mp, pp));
}
private static Painter<Component> getInactiveBackgroundPainter(){
MattePainter mp = new MattePainter(Colors.White.alpha(1f));
GlossPainter gp = new GlossPainter(Colors.Gray.alpha(0.1f), GlossPainter.GlossPosition.BOTTOM);
PinstripePainter pp = new PinstripePainter(Colors.Gray.alpha(0.2f), 45d);
return (new CompoundPainter<Component>(mp, pp, gp));
}
}
My problem is that I need to call the painter () method every time I try to get an artist, but I prefer to just write the type of artist. I thought that if I can extend the Painter by my enumeration, then I will probably get the necessary functionality, but it seems that this is not possible in java.
public enum Painters extends Painter<Component>
Do you know any solution to this problem ???
I am currently using it as follows:
Painters.Background.painter();
but I need:
Painters.Background;
source
share