Another thing that popped into my mind...
This proposal also opens the possibility of
internationalizing/translating bean class and property/styles names
via simple alias classes. Styles can be exposed as bean properties to
simplify things even further as demonstrated below.
The following example of a simplified Chinese translation (according
to Google translate) is possible with a little hack to make
BXMLSerializer think that the first character of '文字输入' is a capital
letter, and therefore represents a class to be instantiated.
Hopefully Google hasn't suggested any offensive terms when it translated :)
BXML
<!-- TextInput, text property, color style in simplified Chinese/zh-CN -->
<文字输入 文字="Text for the TextInput" 的颜色="#ff0000" />
Java
// 文字输入 - text input
// 文字 - text
// 的颜色 - color
public class 文字输入 implements Transformable<TextInput> {
private TextInput textInput = new TextInput();
// 'text' property
private String text = "";
public String get文字() {
return text;
}
public void set文字(String text) {
this.text = text;
}
// 'color' style
private Color color = (Color) textInput.getStyles().get("color");
public Color get的颜色() {
return color;
}
public void set的颜色(String color) {
this.color = Color.decode(color);
}
@Override
public Collection<TextInput> transform() {
textInput.setText(text);
textInput.getStyles().put("color", color);
return Arrays.asList(textInput);
}
}
The class above has hard coded 'translations' but it shouldn't be
difficult to write a base AbstractTranslator class (implementing
Dictionary) that would read the translations and 'style to property'
mappings from a resource file.
The alias classes could even be automatically generated from the resource files.
Chris