use of org.terasology.rendering.nui.databinding.Binding in project Terasology by MovingBlocks.
the class NUIEditorMenuTreeBuilder method getFieldValue.
private Object getFieldValue(Field field, Class clazz) throws IllegalAccessException, InstantiationException {
if (Enum.class.isAssignableFrom(field.getType())) {
return field.getType().getEnumConstants()[0].toString();
} else {
Object value;
if (Binding.class.isAssignableFrom(field.getType())) {
if (AbstractWidget.class.isAssignableFrom(clazz) && Objects.equals(field.getName(), "family")) {
// The default - and acceptable - value for the AbstractWidget.family binding is null, but a user
// most likely wants to use a custom family. Therefore, the default is set to an empty string instead.
value = "";
} else {
Binding binding = (Binding) field.get(newInstance(clazz));
value = binding.get();
}
} else if (Optional.class.isAssignableFrom(field.getType())) {
value = newInstance((Class) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]);
} else {
value = field.get(newInstance(clazz));
}
if (value != null && value instanceof Boolean) {
value = !(Boolean) value;
}
return (value != null || Binding.class.isAssignableFrom(field.getType())) ? value : newInstance(field.getType());
}
}
use of org.terasology.rendering.nui.databinding.Binding in project Terasology by MovingBlocks.
the class BenchmarkScreen method initialise.
@Override
public void initialise() {
textArea = find("textArea", UIText.class);
dropdown = find("dropdown", UIDropdownScrollable.class);
if (dropdown != null) {
dropdown.bindSelection(new Binding() {
@Override
public Object get() {
return selectedBenchmarkType;
}
@Override
public void set(Object value) {
selectedBenchmarkType = (BenchmarkType) value;
if (runningBenchmark != null) {
runningBenchmark = null;
}
textArea.setText(selectedBenchmarkType.getDescription());
}
});
dropdown.setOptions(Arrays.asList(BenchmarkType.values()));
}
closeButton = find("closeButton", UIButton.class);
if (closeButton != null) {
closeButton.subscribe(this::onCloseButton);
}
startStopButton = find("startStopButton", UIButton.class);
if (startStopButton != null) {
startStopButton.subscribe(this::onStartStopButton);
}
}
Aggregations