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