private Component addDimensionsControl(final Dictionary<String, Object> dictionary,
final String key, Form.Section section) {
Dimensions dimensions = (Dimensions)dictionary.get(key);
BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
section.add(boxPane);
Form.setLabel(boxPane, key);
FlowPane flowPane = new FlowPane();
flowPane.getStyles().put("alignToBaseline", true);
flowPane.getStyles().put("horizontalSpacing", 5);
boxPane.add(flowPane);
TextInput textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(5);
textInput.setValidator(new IntValidator());
textInput.setText(String.valueOf(dimensions.width));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener.Adapter() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInput = (TextInput)component;
Dimensions dimensions = (Dimensions)dictionary.get(key);
try {
int width = Integer.parseInt(textInput.getText());
dictionary.put(key, new Dimensions(width, dimensions.height));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInput.setText(String.valueOf(dimensions.width));
}
}
}
});
Label label = new Label("width");
label.getStyles().put("font", "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put("alignToBaseline", true);
flowPane.getStyles().put("horizontalSpacing", 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(4);
textInput.setMaximumLength(5);
textInput.setValidator(new IntValidator());