Search in sources :

Example 11 with VisValidatableTextField

use of com.kotcrab.vis.ui.widget.VisValidatableTextField in project vis-ui by kotcrab.

the class SimpleFormValidator method validate.

/**
 * Performs full check of this form, typically there is no need to call this method manually since form will be automatically
 * validated upon field content change. However calling this might be required when change made to field state does not
 * cause change event to be fired. For example disabling or enabling field.
 */
public void validate() {
    formInvalid = false;
    errorMsgText = null;
    for (CheckedButtonWrapper wrapper : buttons) {
        if (wrapper.button.isChecked() != wrapper.mustBeChecked) {
            wrapper.setButtonStateInvalid(true);
        } else {
            wrapper.setButtonStateInvalid(false);
        }
    }
    for (CheckedButtonWrapper wrapper : buttons) {
        if (treatDisabledFieldsAsValid && wrapper.button.isDisabled()) {
            continue;
        }
        if (wrapper.button.isChecked() != wrapper.mustBeChecked) {
            errorMsgText = wrapper.errorMsg;
            formInvalid = true;
            break;
        }
    }
    for (VisValidatableTextField field : fields) {
        field.validateInput();
    }
    for (VisValidatableTextField field : fields) {
        if (treatDisabledFieldsAsValid && field.isDisabled()) {
            continue;
        }
        if (field.isInputValid() == false) {
            Array<InputValidator> validators = field.getValidators();
            for (InputValidator v : validators) {
                if (v instanceof FormInputValidator == false) {
                    throw new IllegalStateException("Fields validated by FormValidator cannot have validators not added using FormValidator methods. " + "Are you adding validators to field manually?");
                }
                FormInputValidator validator = (FormInputValidator) v;
                if (validator.getLastResult() == false) {
                    if (!(validator.isHideErrorOnEmptyInput() && field.getText().equals(""))) {
                        errorMsgText = validator.getErrorMsg();
                    }
                    formInvalid = true;
                    break;
                }
            }
            break;
        }
    }
    updateWidgets();
}
Also used : InputValidator(com.kotcrab.vis.ui.util.InputValidator) VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Example 12 with VisValidatableTextField

use of com.kotcrab.vis.ui.widget.VisValidatableTextField in project gdx-graph by MarcinSc.

the class Vector3BoxPart method createInput.

private VisValidatableTextField createInput(InputValidator inputValidator, float defaultValue) {
    final VisValidatableTextField result;
    if (inputValidator != null) {
        result = new VisValidatableTextField(Validators.FLOATS, inputValidator) {

            @Override
            public float getPrefWidth() {
                return 50;
            }
        };
    } else
        result = new VisValidatableTextField(Validators.FLOATS) {

            @Override
            public float getPrefWidth() {
                return 50;
            }
        };
    result.setText(String.valueOf(defaultValue));
    result.setAlignment(Align.right);
    result.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            result.fire(new GraphChangedEvent(false, true));
        }
    });
    return result;
}
Also used : GraphChangedEvent(com.gempukku.libgdx.graph.ui.graph.GraphChangedEvent) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Example 13 with VisValidatableTextField

use of com.kotcrab.vis.ui.widget.VisValidatableTextField in project gdx-graph by MarcinSc.

the class Vector2BoxPart method createInput.

private VisValidatableTextField createInput(InputValidator inputValidator, float defaultValue) {
    final VisValidatableTextField result;
    if (inputValidator != null) {
        result = new VisValidatableTextField(Validators.FLOATS, inputValidator) {

            @Override
            public float getPrefWidth() {
                return 50;
            }
        };
    } else
        result = new VisValidatableTextField(Validators.FLOATS) {

            @Override
            public float getPrefWidth() {
                return 50;
            }
        };
    result.setText(String.valueOf(defaultValue));
    result.setAlignment(Align.right);
    result.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            result.fire(new GraphChangedEvent(false, true));
        }
    });
    return result;
}
Also used : GraphChangedEvent(com.gempukku.libgdx.graph.ui.graph.GraphChangedEvent) Actor(com.badlogic.gdx.scenes.scene2d.Actor) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Example 14 with VisValidatableTextField

use of com.kotcrab.vis.ui.widget.VisValidatableTextField in project gdx-graph by MarcinSc.

the class ValueVector3BoxProducer method createValuePart.

private GraphBoxPartImpl createValuePart(float v1, float v2, float v3) {
    final VisValidatableTextField v1Input = new VisValidatableTextField(Validators.FLOATS) {

        @Override
        public float getPrefWidth() {
            return 50;
        }
    };
    v1Input.setText(String.valueOf(v1));
    v1Input.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            v1Input.fire(new GraphChangedEvent(false, true));
        }
    });
    final VisValidatableTextField v2Input = new VisValidatableTextField(Validators.FLOATS) {

        @Override
        public float getPrefWidth() {
            return 50;
        }
    };
    v2Input.setText(String.valueOf(v2));
    v2Input.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            v2Input.fire(new GraphChangedEvent(false, true));
        }
    });
    final VisValidatableTextField v3Input = new VisValidatableTextField(Validators.FLOATS) {

        @Override
        public float getPrefWidth() {
            return 50;
        }
    };
    v3Input.setText(String.valueOf(v3));
    v3Input.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            v3Input.fire(new GraphChangedEvent(false, true));
        }
    });
    HorizontalGroup horizontalGroup = new HorizontalGroup();
    horizontalGroup.addActor(new VisLabel("x"));
    horizontalGroup.addActor(v1Input);
    horizontalGroup.addActor(new VisLabel("y"));
    horizontalGroup.addActor(v2Input);
    horizontalGroup.addActor(new VisLabel("z"));
    horizontalGroup.addActor(v3Input);
    GraphBoxPartImpl colorPart = new GraphBoxPartImpl(horizontalGroup, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            object.addChild("v1", new JsonValue(Float.parseFloat(v1Input.getText())));
            object.addChild("v2", new JsonValue(Float.parseFloat(v2Input.getText())));
            object.addChild("v3", new JsonValue(Float.parseFloat(v3Input.getText())));
        }
    });
    colorPart.setOutputConnector(GraphBoxOutputConnector.Side.Right, configuration.getNodeOutputs().get("value"));
    return colorPart;
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) JsonValue(com.badlogic.gdx.utils.JsonValue) VisLabel(com.kotcrab.vis.ui.widget.VisLabel) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Example 15 with VisValidatableTextField

use of com.kotcrab.vis.ui.widget.VisValidatableTextField in project gdx-graph by MarcinSc.

the class ValueVector2BoxProducer method createValuePart.

private GraphBoxPartImpl createValuePart(float v1, float v2) {
    final VisValidatableTextField v1Input = new VisValidatableTextField(Validators.FLOATS) {

        @Override
        public float getPrefWidth() {
            return 50;
        }
    };
    v1Input.setText(String.valueOf(v1));
    v1Input.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            v1Input.fire(new GraphChangedEvent(false, true));
        }
    });
    final VisValidatableTextField v2Input = new VisValidatableTextField(Validators.FLOATS) {

        @Override
        public float getPrefWidth() {
            return 50;
        }
    };
    v2Input.setText(String.valueOf(v2));
    v2Input.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            v2Input.fire(new GraphChangedEvent(false, true));
        }
    });
    HorizontalGroup horizontalGroup = new HorizontalGroup();
    horizontalGroup.addActor(new VisLabel("x"));
    horizontalGroup.addActor(v1Input);
    horizontalGroup.addActor(new VisLabel("y"));
    horizontalGroup.addActor(v2Input);
    GraphBoxPartImpl colorPart = new GraphBoxPartImpl(horizontalGroup, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            object.addChild("v1", new JsonValue(Float.parseFloat(v1Input.getText())));
            object.addChild("v2", new JsonValue(Float.parseFloat(v2Input.getText())));
        }
    });
    colorPart.setOutputConnector(GraphBoxOutputConnector.Side.Right, configuration.getNodeOutputs().get("value"));
    return colorPart;
}
Also used : Actor(com.badlogic.gdx.scenes.scene2d.Actor) JsonValue(com.badlogic.gdx.utils.JsonValue) VisLabel(com.kotcrab.vis.ui.widget.VisLabel) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) HorizontalGroup(com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup) VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Aggregations

VisValidatableTextField (com.kotcrab.vis.ui.widget.VisValidatableTextField)15 Actor (com.badlogic.gdx.scenes.scene2d.Actor)11 ChangeListener (com.badlogic.gdx.scenes.scene2d.utils.ChangeListener)11 HorizontalGroup (com.badlogic.gdx.scenes.scene2d.ui.HorizontalGroup)7 Label (com.badlogic.gdx.scenes.scene2d.ui.Label)4 VisLabel (com.kotcrab.vis.ui.widget.VisLabel)4 JsonValue (com.badlogic.gdx.utils.JsonValue)3 GraphChangedEvent (com.gempukku.libgdx.graph.ui.graph.GraphChangedEvent)3 StringNameValidator (games.rednblack.editor.view.ui.validator.StringNameValidator)2 InputValidator (com.kotcrab.vis.ui.util.InputValidator)1 IntDigitsOnlyFilter (com.kotcrab.vis.ui.util.IntDigitsOnlyFilter)1 VisTable (com.kotcrab.vis.ui.widget.VisTable)1 VisTextField (com.kotcrab.vis.ui.widget.VisTextField)1 TextFieldFilter (com.kotcrab.vis.ui.widget.VisTextField.TextFieldFilter)1