I am implementing the enum class which I will use to retrieve some background in application, a current implementation of this class is here:
public enum Painters{
/**
* Available painters.
*/
Background(getBackgroundPainter()),
InactiveBackground(getInactiveBackgroundPainter()),
DesktopBackground(getBackgroundPainter());
/**
* The background painter.
*/
private Painter<Component> _painter;
/**
* Constructor will initialize the object.
*/
Painters(Painter<Component> painter){
_painter = painter;
}
/**
* Will return a current painter.
* @return instance of Painter<Component>
*/
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 each time I trying to get a painter but I prefer just to write the type of the painter instead. I thought that if I can to extend the Painter by my enum then probably I will get the right functionality, but it looks that it is not possible in java.
public enum Painters extends Painter<Component>
Do you know any solution for this problem???
Currently I am using it in this way:
Painters.Background.painter();
but I need:
Painters.Background;