com.kotcrab.vis.ui.widget.VisTextField Java Examples

The following examples show how to use com.kotcrab.vis.ui.widget.VisTextField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestIssue131.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
public TestIssue131 () {
	super("issue #131");

	TableUtils.setSpacingDefaults(this);
	columnDefaults(0).left();

	VisTextField field1 = new VisTextField("0.1234");
	VisTextField field2 = new VisTextField("4.5678");
	field1.setTextFieldFilter(new FloatDigitsOnlyFilter(true));
	field2.setTextFieldFilter(new FloatDigitsOnlyFilter(true));

	add(new LinkLabel("issue #131 - decimal point lost", "https://github.com/kotcrab/vis-ui/issues/131")).colspan(2).row();
	add(field1);
	add(field2);

	setResizable(true);
	setModal(false);
	addCloseButton();
	closeOnEscape();
	pack();
	centerWindow();
}
 
Example #2
Source File: TestIssue326.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
public TestIssue326 () {
	super("issue #326");

	final VisTextField passwordTextField = new VisTextField("password");

	final IntSpinnerModel intModel = new IntSpinnerModel(10, -5, 20, 2);
	Spinner intSpinner = new Spinner("int", intModel);
	intSpinner.addListener(new ChangeListener() {
		@Override
		public void changed (ChangeEvent event, Actor actor) {
			passwordTextField.setDisabled(true);
		}
	});

	add(new LinkLabel("issue #326 - FocusManager crash", "https://github.com/kotcrab/vis-ui/issues/326")).colspan(2).row();
	add(passwordTextField);
	row();
	add(intSpinner);

	setResizable(false);
	setModal(false);
	addCloseButton();
	closeOnEscape();
	pack();
	centerWindow();
}
 
Example #3
Source File: BasicColorPicker.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: FloatDigitsOnlyFilter.java    From vis-ui with Apache License 2.0 6 votes vote down vote up
@Override
public boolean acceptChar (VisTextField field, char c) {
	int selectionStart = field.getSelectionStart();
	int cursorPos = field.getCursorPosition();
	String text;
	if (field.isTextSelected()) { //issue #131
		String beforeSelection = field.getText().substring(0, Math.min(selectionStart, cursorPos));
		String afterSelection = field.getText().substring(Math.max(selectionStart, cursorPos));
		text = beforeSelection + afterSelection;
	} else {
		text = field.getText();
	}

	if (c == '.' && text.contains(".") == false) return true;
	return super.acceptChar(field, c);
}
 
Example #5
Source File: FormValidator.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/** @see FormValidator#fileExists(VisValidatableTextField, VisTextField, String, boolean) */
public FileExistsValidator (VisTextField relativeTo, String errorMsg, boolean mustNotExist, boolean errorIfRelativeEmpty) {
	super(errorMsg);
	this.relativeTo = relativeTo;
	this.mustNotExist = mustNotExist;
	this.errorIfRelativeEmpty = errorIfRelativeEmpty;
}
 
Example #6
Source File: FileSuggestionPopup.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
public void pathFieldKeyTyped (Stage stage, Array<FileHandle> files, VisTextField pathField) {
	if (pathField.getText().length() == 0) {
		remove();
		return;
	}

	int suggestions = createSuggestions(files, pathField);
	if (suggestions == 0) {
		remove();
		return;
	}

	showMenu(stage, pathField);
}
 
Example #7
Source File: Scene2dUtils.java    From gdx-texture-packer-gui with Apache License 2.0 5 votes vote down vote up
/** Checks if the text could fit the current textField's width. */
public static boolean isTextFitTextField(VisTextField textField, String text) {
    float availableWidth = textField.getWidth();
    Drawable fieldBg = textField.getStyle().background;
    if (fieldBg != null) {
        availableWidth = availableWidth - fieldBg.getLeftWidth() - fieldBg.getRightWidth();
    }
    BitmapFont font = textField.getStyle().font;
    return isTextFitWidth(font, availableWidth, text);
}
 
Example #8
Source File: FormValidator.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * Validates if relative path entered in text field points to an non existing file.
 * @param relativeTo path entered in this field is used to create absolute path from entered in field (see {@link FileExistsValidator}).
 */
public FormInputValidator fileNotExists (VisValidatableTextField field, VisTextField relativeTo, String errorMsg) {
	FileExistsValidator validator = new FileExistsValidator(relativeTo, errorMsg, true);
	field.addValidator(validator);
	add(field);
	return validator;

}
 
Example #9
Source File: FormValidator.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * Validates if relative path entered in text field points to an existing file.
 * @param relativeTo path entered in this field is used to create absolute path from entered in field (see {@link FileExistsValidator}).
 * @param errorIfRelativeEmpty if true field input will be valid if 'relativeTo' field is empty, usually used with notEmpty validator on 'relativeTo' field to
 * avoid form errors. Settings this to true improves UX, errors are not displayed until user types something in 'relativeTo' field.
 */
public FormInputValidator fileExists (VisValidatableTextField field, VisTextField relativeTo, String errorMsg, boolean errorIfRelativeEmpty) {
	FileExistsValidator validator = new FileExistsValidator(relativeTo, errorMsg, false, errorIfRelativeEmpty);
	field.addValidator(validator);
	add(field);
	return validator;
}
 
Example #10
Source File: FormValidator.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
/**
 * Validates if relative path entered in text field points to an existing file.
 * @param relativeTo path entered in this field is used to create absolute path from entered in field (see {@link FileExistsValidator}).
 */
public FormInputValidator fileExists (VisValidatableTextField field, VisTextField relativeTo, String errorMsg) {
	FileExistsValidator validator = new FileExistsValidator(relativeTo, errorMsg);
	field.addValidator(validator);
	add(field);
	return validator;
}
 
Example #11
Source File: IntDigitsOnlyFilter.java    From vis-ui with Apache License 2.0 5 votes vote down vote up
@Override
public boolean acceptChar (VisTextField field, char c) {
	if (isAcceptNegativeValues()) {
		if (isUseFieldCursorPosition()) {
			if (c == '-' && (field.getCursorPosition() > 0 || field.getText().startsWith("-"))) return false;
		} else {
			if (c == '-' && field.getText().startsWith("-")) return false;
		}

		if (c == '-') return true;
	}
	return Character.isDigit(c);
}
 
Example #12
Source File: FileChooserField.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public FileChooserField(int width) {
    super();
    this.width = width;
    textField = new VisTextField();
    fcBtn = new VisTextButton("Select");

    setupUI();
    setupListeners();
}
 
Example #13
Source File: TextFieldWithLabel.java    From Mundus with Apache License 2.0 5 votes vote down vote up
public TextFieldWithLabel(String labelText, int width) {
    super();
    this.width = width;
    textField = new VisTextField();
    label = new VisLabel(labelText);
    setupUI();
}
 
Example #14
Source File: FormValidator.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public FileExistsValidator (VisTextField relativeTo, String errorMsg) {
	this(relativeTo, errorMsg, false);
}
 
Example #15
Source File: FormValidator.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public FileExistsValidator (VisTextField relativeTo, String errorMsg, boolean mustNotExist) {
	super(errorMsg);
	this.relativeTo = relativeTo;
	this.mustNotExist = mustNotExist;
}
 
Example #16
Source File: FormValidator.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public void setRelativeToTextField (VisTextField relativeTo) {
	if (relativeToFile != null)
		throw new IllegalStateException("This validator already has relativeToFile set.");

	this.relativeTo = relativeTo;
}
 
Example #17
Source File: DirsSuggestionPopup.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
public DirsSuggestionPopup (FileChooser chooser, VisTextField pathField) {
	super(chooser);
	this.pathField = pathField;
}
 
Example #18
Source File: ColorInputField.java    From vis-ui with Apache License 2.0 4 votes vote down vote up
@Override
public boolean acceptChar (VisTextField textField, char c) {
	return Character.isDigit(c);
}