Search in sources :

Example 1 with TextInput

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

the class ComponentInspectorSkin method addScopeControl.

private static Component addScopeControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    Scope scope = (Scope) 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(scope == null ? "" : String.valueOf(scope.start));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Scope scopeLocal = (Scope) dictionary.get(key);
                try {
                    int start = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Scope(start, scopeLocal == null ? start : scopeLocal.end, scopeLocal == null ? start : scopeLocal.extent));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(scopeLocal == null ? "" : String.valueOf(scopeLocal.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(scope == null ? "" : String.valueOf(scope.end));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Scope scopeLocal = (Scope) dictionary.get(key);
                try {
                    int end = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Scope(scopeLocal == null ? end : scopeLocal.start, end, scopeLocal == null ? end : scopeLocal.extent));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(scopeLocal == null ? "" : String.valueOf(scopeLocal.end));
                }
            }
        }
    });
    label = new Label("end");
    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(scope == null ? "" : String.valueOf(scope.extent));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Scope scopeLocal = (Scope) dictionary.get(key);
                try {
                    int extent = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Scope(scopeLocal == null ? extent : scopeLocal.start, scopeLocal == null ? extent : scopeLocal.end, extent));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(scopeLocal == null ? "" : String.valueOf(scopeLocal.extent));
                }
            }
        }
    });
    label = new Label("extent");
    label.getStyles().put(Style.font, "{italic:true}");
    flowPane.add(label);
    return boxPane;
}
Also used : IntValidator(org.apache.pivot.wtk.validation.IntValidator) Scope(org.apache.pivot.wtk.ScrollBar.Scope) 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 2 with TextInput

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

the class ComponentInspectorSkin method addStringControl.

private static Component addStringControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    String value = (String) dictionary.get(key);
    TextInput textInput = new TextInput();
    textInput.setText(value == null ? "" : 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, textInputLocal.getText());
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    String valueLocal = (String) dictionary.get(key);
                    textInputLocal.setText(valueLocal == null ? "" : valueLocal);
                }
            }
        }
    });
    return textInput;
}
Also used : TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 3 with TextInput

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

the class ComponentInspectorSkin method addDoubleControl.

private static Component addDoubleControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    double value = (Double) dictionary.get(key);
    TextInput textInput = new TextInput();
    textInput.setTextSize(14);
    textInput.setValidator(new DoubleValidator());
    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, Double.parseDouble(textInputLocal.getText()));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    double valueLocal = (Double) dictionary.get(key);
                    textInputLocal.setText(String.valueOf(valueLocal));
                }
            }
        }
    });
    return textInput;
}
Also used : DoubleValidator(org.apache.pivot.wtk.validation.DoubleValidator) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 4 with TextInput

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

the class ComponentInspectorSkin method addDimensionsControl.

private static 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(Style.alignToBaseline, true);
    flowPane.getStyles().put(Style.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() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Dimensions dimensionsLocal = (Dimensions) dictionary.get(key);
                try {
                    int width = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Dimensions(width, dimensionsLocal.height));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(String.valueOf(dimensionsLocal.width));
                }
            }
        }
    });
    Label label = new Label("width");
    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(4);
    textInput.setMaximumLength(5);
    textInput.setValidator(new IntValidator());
    textInput.setText(String.valueOf(dimensions.height));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                Dimensions dimensionsLocal = (Dimensions) dictionary.get(key);
                try {
                    int height = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new Dimensions(dimensionsLocal.width, height));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(String.valueOf(dimensionsLocal.height));
                }
            }
        }
    });
    label = new Label("height");
    label.getStyles().put(Style.font, "{italic:true}");
    flowPane.add(label);
    return boxPane;
}
Also used : IntValidator(org.apache.pivot.wtk.validation.IntValidator) BoxPane(org.apache.pivot.wtk.BoxPane) Label(org.apache.pivot.wtk.Label) Dimensions(org.apache.pivot.wtk.Dimensions) 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 5 with TextInput

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

the class ComponentInspectorSkin method updateFloatControl.

private void updateFloatControl(Dictionary<String, Object> dictionary, String key) {
    TextInput textInput = (TextInput) controls.get(key);
    if (textInput != null) {
        float value = (Float) dictionary.get(key);
        textInput.setText(String.valueOf(value));
    }
}
Also used : 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