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;
}
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());
}
}
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());
}
}
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);
}
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;
}
Aggregations