use of org.apache.pivot.wtk.ComponentStateListener in project pivot by apache.
the class ComponentInspectorSkin method addSpanControl.
private static Component addSpanControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
Span span = (Span) dictionary.get(key);
BoxPane boxPane = new BoxPane(Orientation.VERTICAL);
section.add(boxPane);
Form.setLabel(boxPane, key);
FlowPane flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
TextInput textInput = new TextInput();
textInput.setTextSize(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(span == null ? "" : String.valueOf(span.start));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Span spanLocal = (Span) dictionary.get(key);
try {
int start = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Span(start, spanLocal == null ? start : spanLocal.end));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(spanLocal == null ? "" : String.valueOf(spanLocal.start));
}
}
}
});
Label label = new Label("start");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
flowPane = new FlowPane();
flowPane.getStyles().put(Style.alignToBaseline, true);
flowPane.getStyles().put(Style.horizontalSpacing, 5);
boxPane.add(flowPane);
textInput = new TextInput();
textInput.setTextSize(10);
textInput.setMaximumLength(10);
textInput.setValidator(new IntValidator());
textInput.setText(span == null ? "" : String.valueOf(span.end));
flowPane.add(textInput);
textInput.getComponentStateListeners().add(new ComponentStateListener() {
@Override
public void focusedChanged(Component component, Component obverseComponent) {
if (!component.isFocused()) {
TextInput textInputLocal = (TextInput) component;
Span spanLocal = (Span) dictionary.get(key);
try {
int end = Integer.parseInt(textInputLocal.getText());
dictionary.put(key, new Span(spanLocal == null ? end : spanLocal.start, end));
} catch (Exception exception) {
displayErrorMessage(exception, component.getWindow());
textInputLocal.setText(spanLocal == null ? "" : String.valueOf(spanLocal.end));
}
}
}
});
label = new Label("end");
label.getStyles().put(Style.font, "{italic:true}");
flowPane.add(label);
return boxPane;
}
Aggregations