I'm trying to make custom forms with annotations. My idea is that given an annotated class, my code could generate a FX GUI form to edit objects of that class. It should be clearer in the code:
@...
@interface Form {
String label() default "";
}
@Form
class SomeData {
@Form(label="Name")
String name;
@Form(label="Age")
int age;
...
}
class FormBuilder {
Pane makeForm(Class annotated) {
Pane pane = ... ;
for (/*each annotated field*/) {
Label label = new Label(/*field's annotated label*/));
Control field = generateControl(/*annotated field's type*/));
...
pane.getChildren().addAll(label, field);
}
return pane;
}
Control generateControl(Class type) {
// returns the control that matches with the type
// its everything OK here
}
main(...) {
Pane someDataForm = makeForm(SomeData.class);
...
}
}
I am starting in custom annotations now, and didn't get yet how to:
- Iterate over annotated fields of an annotated class
- Get its annotated data (label:String)
- Get annotated field's type (name:String and age:Integer in this case)
in order to implement the method makeForm