Search in sources :

Example 6 with TextInput

use of org.apache.pivot.wtk.TextInput in project pivot by apache.

the class ComponentInspectorSkin method addLimitsControl.

private static Component addLimitsControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    Limits limits = (Limits) 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(String.valueOf(limits.minimum));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Limits limitsLocal = (Limits) dictionary.get(key);
                try {
                    int min = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Limits(min, limitsLocal.maximum));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(String.valueOf(limitsLocal.minimum));
                }
            }
        }
    });
    Label label = new Label("min");
    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(String.valueOf(limits.maximum));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Limits limitsLocal = (Limits) dictionary.get(key);
                try {
                    int max = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Limits(limitsLocal.minimum, max));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(String.valueOf(limitsLocal.maximum));
                }
            }
        }
    });
    label = new Label("max");
    label.getStyles().put(Style.font, "{italic:true}");
    flowPane.add(label);
    return boxPane;
}
Also used : Limits(org.apache.pivot.wtk.Limits) IntValidator(org.apache.pivot.wtk.validation.IntValidator) BoxPane(org.apache.pivot.wtk.BoxPane) Label(org.apache.pivot.wtk.Label) FlowPane(org.apache.pivot.wtk.FlowPane) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 7 with TextInput

use of org.apache.pivot.wtk.TextInput in project pivot by apache.

the class ComponentInspectorSkin method addFloatControl.

private static Component addFloatControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    float value = (Float) dictionary.get(key);
    TextInput textInput = new TextInput();
    textInput.setTextSize(10);
    textInput.setValidator(new FloatValidator());
    textInput.setText(String.valueOf(value));
    section.add(textInput);
    Form.setLabel(textInput, key);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                try {
                    dictionary.put(key, Float.parseFloat(textInputLocal.getText()));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    float valueLocal = (Float) dictionary.get(key);
                    textInputLocal.setText(String.valueOf(valueLocal));
                }
            }
        }
    });
    return textInput;
}
Also used : FloatValidator(org.apache.pivot.wtk.validation.FloatValidator) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 8 with TextInput

use of org.apache.pivot.wtk.TextInput in project pivot by apache.

the class ComponentInspectorSkin method updateStringControl.

private void updateStringControl(Dictionary<String, Object> dictionary, String key) {
    TextInput textInput = (TextInput) controls.get(key);
    if (textInput != null) {
        String value = (String) dictionary.get(key);
        textInput.setText(value == null ? "" : value);
    }
}
Also used : TextInput(org.apache.pivot.wtk.TextInput)

Example 9 with TextInput

use of org.apache.pivot.wtk.TextInput in project pivot by apache.

the class ComponentInspectorSkin method updateDimensionsControl.

private void updateDimensionsControl(Dictionary<String, Object> dictionary, String key) {
    BoxPane boxPane = (BoxPane) controls.get(key);
    if (boxPane != null) {
        Dimensions dimensions = (Dimensions) dictionary.get(key);
        TextInput widthTextInput = (TextInput) ((FlowPane) boxPane.get(0)).get(0);
        TextInput heightTextInput = (TextInput) ((FlowPane) boxPane.get(1)).get(0);
        widthTextInput.setText(String.valueOf(dimensions.width));
        heightTextInput.setText(String.valueOf(dimensions.height));
    }
}
Also used : BoxPane(org.apache.pivot.wtk.BoxPane) Dimensions(org.apache.pivot.wtk.Dimensions) TextInput(org.apache.pivot.wtk.TextInput)

Example 10 with TextInput

use of org.apache.pivot.wtk.TextInput in project pivot by apache.

the class ComponentInspectorSkin method updateLimitsControl.

private void updateLimitsControl(Dictionary<String, Object> dictionary, String key) {
    BoxPane boxPane = (BoxPane) controls.get(key);
    if (boxPane != null) {
        Limits limits = (Limits) dictionary.get(key);
        TextInput minTextInput = (TextInput) ((FlowPane) boxPane.get(0)).get(0);
        TextInput maxTextInput = (TextInput) ((FlowPane) boxPane.get(1)).get(0);
        minTextInput.setText(String.valueOf(limits.minimum));
        maxTextInput.setText(String.valueOf(limits.maximum));
    }
}
Also used : Limits(org.apache.pivot.wtk.Limits) BoxPane(org.apache.pivot.wtk.BoxPane) TextInput(org.apache.pivot.wtk.TextInput)

Aggregations

TextInput (org.apache.pivot.wtk.TextInput)51 Component (org.apache.pivot.wtk.Component)21 BoxPane (org.apache.pivot.wtk.BoxPane)15 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)11 TextInputContentListener (org.apache.pivot.wtk.TextInputContentListener)9 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)8 Label (org.apache.pivot.wtk.Label)8 Point (org.apache.pivot.wtk.Point)8 IntValidator (org.apache.pivot.wtk.validation.IntValidator)8 FlowPane (org.apache.pivot.wtk.FlowPane)7 ArrayList (org.apache.pivot.collections.ArrayList)6 IOException (java.io.IOException)5 Button (org.apache.pivot.wtk.Button)5 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)5 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)5 Keyboard (org.apache.pivot.wtk.Keyboard)5 Mouse (org.apache.pivot.wtk.Mouse)5 Sequence (org.apache.pivot.collections.Sequence)4 SerializationException (org.apache.pivot.serialization.SerializationException)4 ComponentKeyListener (org.apache.pivot.wtk.ComponentKeyListener)4