Thank you @wezrule, that pattern totally helped me… not sure if I implemented it correctly, but it sure pointed me towards a way to do it good enough for me.
So, the aim was to easily display parameters of whatever object, and get back either a new object of that class filled with the new values or update an instance of that class with the new values on demand.
Basically:
- create an adaptee class for that type, implementing the needed methods to get the params, a method to create a new instance and a method to update an instance.
- a generic adapter that interrogates the adaptee to get the data and hand it over in an easy to use way; is also the link between the adaptee and the tonegodGUI adapter.
- a tonegodGUI adapter that deals with the tonegodGUI specifics and returning a list of elements to display, with the needed data; also deals with recuperating the data from the UI.
- the screen UI is responsible for positioning/dimensioning and such stuff
Currently:
- creates a selectBox when passed an enum
- creates a checkbox when passed a boolean
- creates textField for other cases
- deterministic naming in case of UI specifics
- provides type / min / max values to allow validation on the UI side
- sets default values or passes adapted values
It uses my “enriched” (yes, bad name lol) tonegodGUI controls.
Could be quickly modified to use the standard lib controls, but not sure how to add event handling then, while with my controls, the screenEventListener works the same way for generated and directly typed-in controls.
Thinking of adding support for tooltips, sliders and classes to validate content. Maybe dials too.
Interface the adaptees need to implement:
[java]
public interface ControlAdaptee {
public enum ParamType{
STRING, FLOAT, DOUBLE, INTEGER, ENUM, BOOLEAN
}
public List<String> getParamNames();
public List<ParamType> getParamTypes();
public List<String> getParamDefaultValues();
public List<Class <? extends Enum>> getParamEnums();
public List<String> getParamMin();
public List<String> getParamMax();
public Object getNewAdapted(List<Object> values);
public Object getUpdatedAdapted(List<Object> values, Object adapted);
}
[/java]
Getting the controls to be displayed:
[java]
ControlAdapterTonegodGUI controlAdapter2D = new ControlAdapterTonegodGUI(new ControlAdapter());
List<? extends Element> list = controlAdapter2D.getParametersControls(UIDPrefix, screen, screenEventListener, new SpotLightAdaptee());
[/java]
Getting the controls to be displayed with default values filled by the adapted values:
[java]
List<? extends Element> list = controlAdapter2D.getParametersControls(UIDPrefix, screen, screenEventListener, new SpotLightAdaptee(), spotLight);
[/java]
Getting a new adapted back with it’s new values:
[java]
SpotLight adapted = (SpotLight)controlAdapter2D.getNewAdapted(UIDPrefix, screen, new SpotLightAdaptee());
[/java]
Updating an adapted with the new values:
[java]
spotLight = (SpotLight)getUpdatedAdapted(UIDPrefix, screen, new SpotLightAdaptee(), spotLight);
[/java]
If anybody is curious, I can post the code.
Anyway, thx a lot for your help!