Search in sources :

Example 6 with VisValidatableTextField

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

the class ValueFloatBoxProducer method createValuePart.

private GraphBoxPartImpl createValuePart(float v1) {
    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));
        }
    });
    HorizontalGroup horizontalGroup = new HorizontalGroup();
    horizontalGroup.addActor(new VisLabel("x"));
    horizontalGroup.addActor(v1Input);
    GraphBoxPartImpl colorPart = new GraphBoxPartImpl(horizontalGroup, new GraphBoxPartImpl.Callback() {

        @Override
        public void serialize(JsonValue object) {
            float value;
            try {
                value = Float.parseFloat(v1Input.getText());
            } catch (NumberFormatException exp) {
                value = 0f;
            }
            object.addChild("v1", new JsonValue(value));
        }
    });
    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 7 with VisValidatableTextField

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

the class FloatSpinnerModel method setScale.

private void setScale(final int scale, boolean notifySpinner) {
    if (scale < 0)
        throw new IllegalStateException("Scale can't be < 0");
    this.scale = scale;
    current = current.setScale(scale, BigDecimal.ROUND_HALF_UP);
    VisValidatableTextField valueText = spinner.getTextField();
    valueText.getValidators().clear();
    // Both need the bounds check
    valueText.addValidator(boundsValidator);
    if (scale == 0) {
        valueText.addValidator(Validators.INTEGERS);
        valueText.setTextFieldFilter(textFieldFilter = new IntDigitsOnlyFilter(true));
    } else {
        valueText.addValidator(Validators.FLOATS);
        valueText.addValidator(new InputValidator() {

            @Override
            public boolean validateInput(String input) {
                int dotIndex = input.indexOf('.');
                if (dotIndex == -1)
                    return true;
                return input.length() - input.indexOf('.') - 1 <= scale;
            }
        });
        valueText.setTextFieldFilter(textFieldFilter = new FloatDigitsOnlyFilter(true));
    }
    textFieldFilter.setUseFieldCursorPosition(true);
    if (min.compareTo(BigDecimal.ZERO) >= 0) {
        textFieldFilter.setAcceptNegativeValues(false);
    } else {
        textFieldFilter.setAcceptNegativeValues(true);
    }
    if (notifySpinner) {
        spinner.notifyValueChanged(spinner.isProgrammaticChangeEvents());
    }
}
Also used : VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Example 8 with VisValidatableTextField

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

the class SimpleFloatSpinnerModel method setPrecision.

private void setPrecision(final int precision, boolean notifySpinner) {
    if (precision < 0)
        throw new IllegalStateException("Precision can't be < 0");
    this.precision = precision;
    VisValidatableTextField valueText = spinner.getTextField();
    valueText.getValidators().clear();
    // Both need the bounds check
    valueText.addValidator(boundsValidator);
    if (precision == 0) {
        valueText.addValidator(Validators.INTEGERS);
        valueText.setTextFieldFilter(textFieldFilter = new IntDigitsOnlyFilter(true));
    } else {
        valueText.addValidator(Validators.FLOATS);
        valueText.addValidator(new InputValidator() {

            @Override
            public boolean validateInput(String input) {
                int dotIndex = input.indexOf('.');
                if (dotIndex == -1)
                    return true;
                return input.length() - input.indexOf('.') - 1 <= precision;
            }
        });
        valueText.setTextFieldFilter(textFieldFilter = new FloatDigitsOnlyFilter(true));
    }
    textFieldFilter.setUseFieldCursorPosition(true);
    if (min >= 0) {
        textFieldFilter.setAcceptNegativeValues(false);
    } else {
        textFieldFilter.setAcceptNegativeValues(true);
    }
    if (notifySpinner) {
        spinner.notifyValueChanged(spinner.isProgrammaticChangeEvents());
    }
}
Also used : VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Example 9 with VisValidatableTextField

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

the class IntSpinnerModel method bind.

@Override
public void bind(Spinner spinner) {
    super.bind(spinner);
    VisValidatableTextField valueText = spinner.getTextField();
    valueText.getValidators().clear();
    valueText.addValidator(boundsValidator);
    valueText.addValidator(Validators.INTEGERS);
    valueText.setTextFieldFilter(textFieldFilter = new IntDigitsOnlyFilter(true));
    textFieldFilter.setUseFieldCursorPosition(true);
    if (min >= 0) {
        textFieldFilter.setAcceptNegativeValues(false);
    } else {
        textFieldFilter.setAcceptNegativeValues(true);
    }
    spinner.notifyValueChanged(true);
}
Also used : IntDigitsOnlyFilter(com.kotcrab.vis.ui.util.IntDigitsOnlyFilter) VisValidatableTextField(com.kotcrab.vis.ui.widget.VisValidatableTextField)

Example 10 with VisValidatableTextField

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

the class BasicColorPicker method createHexTable.

private VisTable createHexTable() {
    VisTable table = new VisTable(true);
    table.add(new VisLabel(HEX.get()));
    table.add(hexField = new VisValidatableTextField("00000000")).width(HEX_FIELD_WIDTH * sizes.scaleFactor);
    table.row();
    hexField.setMaxLength(HEX_COLOR_LENGTH);
    hexField.setProgrammaticChangeEvents(false);
    hexField.setTextFieldFilter(new TextFieldFilter() {

        @Override
        public boolean acceptChar(VisTextField textField, char c) {
            return Character.isDigit(c) || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
        }
    });
    hexField.addListener(new ChangeListener() {

        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (hexField.getText().length() == (allowAlphaEdit ? HEX_COLOR_LENGTH_WITH_ALPHA : HEX_COLOR_LENGTH)) {
                setColor(Color.valueOf(hexField.getText()), false);
            }
        }
    });
    return table;
}
Also used : VisTextField(com.kotcrab.vis.ui.widget.VisTextField) VisTable(com.kotcrab.vis.ui.widget.VisTable) Actor(com.badlogic.gdx.scenes.scene2d.Actor) TextFieldFilter(com.kotcrab.vis.ui.widget.VisTextField.TextFieldFilter) VisLabel(com.kotcrab.vis.ui.widget.VisLabel) ChangeListener(com.badlogic.gdx.scenes.scene2d.utils.ChangeListener) 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