Template Pattern
What's Template Pattern
How to apply this method
Create a enum
└── src
└── main
└── java
└── com.your_company_name.your_name_app
.
.
.
└── controller
└── Template.javapublic enum Template {
/*
H1 to H4 will be used to stylize the controls with a font, bold style,
font size and forecolor and will be changed between those enum only your fontsize.
The parameters of the getFont () method are String font_name,
boolean boldStyle, int size in example h1 we have then:
"Graviola Soft-Bold": font
false: boldStyle
24: Font size
0x363D86: forecolor
*/
H1(Font.getFont("Graviola Soft-Bold", false, 24), 0x363D86),
H2(Font.getFont("Graviola Soft-Bold", false, 20), 0x363D86),
H3(Font.getFont("Graviola Soft-Bold", false, 18), 0x363D86),
H4(Font.getFont("OpenSans-Bold", false, 12), 0x363D86),
private final Font font;
private final Integer forecolor;
Template(Font font, Integer forecolor) {
this.font = font;
this.forecolor = forecolor;
}
public <T extends Control> T apply(T c) {
if (forecolor != null) {
c.setForeColor(forecolor);
}
if (font != null) {
if (c instanceof Icon) {
c.setFont(Font.getFont(c.getFont().name, false, font.size));
} else {
c.setFont(font);
}
}
return c;
}
To use the template
Last updated
Was this helpful?