Search in sources :

Example 6 with IntValidator

use of org.apache.pivot.wtk.validation.IntValidator in project pivot by apache.

the class ComponentInspectorSkin method addCornerRadiiControl.

private static Component addCornerRadiiControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    CornerRadii cornerRadii = (CornerRadii) 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(4);
    textInput.setValidator(new IntValidator());
    textInput.setText(String.valueOf(cornerRadii.topLeft));
    flowPane.add(textInput);
    textInput.getComponentStateListeners().add(new ComponentStateListener() {

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

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

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

        @Override
        public void focusedChanged(Component component, Component obverseComponent) {
            if (!component.isFocused()) {
                TextInput textInputLocal = (TextInput) component;
                CornerRadii cornerRadiiLocal = (CornerRadii) dictionary.get(key);
                try {
                    int bottomRight = Integer.parseInt(textInputLocal.getText());
                    dictionary.put(key, new CornerRadii(cornerRadiiLocal.topLeft, cornerRadiiLocal.topRight, cornerRadiiLocal.bottomLeft, bottomRight));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    textInputLocal.setText(String.valueOf(cornerRadiiLocal.bottomRight));
                }
            }
        }
    });
    label = new Label("bottomRight");
    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) FlowPane(org.apache.pivot.wtk.FlowPane) CornerRadii(org.apache.pivot.wtk.CornerRadii) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 7 with IntValidator

use of org.apache.pivot.wtk.validation.IntValidator in project pivot by apache.

the class ComponentInspectorSkin method addIntControl.

private static Component addIntControl(final Dictionary<String, Object> dictionary, final String key, Form.Section section) {
    int value = dictionary.getInt(key);
    TextInput textInput = new TextInput();
    textInput.setTextSize(10);
    textInput.setMaximumLength(10);
    textInput.setValidator(new IntValidator());
    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, Integer.parseInt(textInputLocal.getText()));
                } catch (Exception exception) {
                    displayErrorMessage(exception, component.getWindow());
                    int valueLocal = dictionary.getInt(key);
                    textInputLocal.setText(String.valueOf(valueLocal));
                }
            }
        }
    });
    return textInput;
}
Also used : IntValidator(org.apache.pivot.wtk.validation.IntValidator) TextInput(org.apache.pivot.wtk.TextInput) Component(org.apache.pivot.wtk.Component) Point(org.apache.pivot.wtk.Point) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Example 8 with IntValidator

use of org.apache.pivot.wtk.validation.IntValidator 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;
}
Also used : 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) Span(org.apache.pivot.wtk.Span) ComponentStateListener(org.apache.pivot.wtk.ComponentStateListener)

Aggregations

Component (org.apache.pivot.wtk.Component)8 ComponentStateListener (org.apache.pivot.wtk.ComponentStateListener)8 TextInput (org.apache.pivot.wtk.TextInput)8 IntValidator (org.apache.pivot.wtk.validation.IntValidator)8 BoxPane (org.apache.pivot.wtk.BoxPane)7 FlowPane (org.apache.pivot.wtk.FlowPane)7 Label (org.apache.pivot.wtk.Label)7 Point (org.apache.pivot.wtk.Point)2 CornerRadii (org.apache.pivot.wtk.CornerRadii)1 Dimensions (org.apache.pivot.wtk.Dimensions)1 Insets (org.apache.pivot.wtk.Insets)1 Limits (org.apache.pivot.wtk.Limits)1 Scope (org.apache.pivot.wtk.ScrollBar.Scope)1 Span (org.apache.pivot.wtk.Span)1