All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cdc.bench.support.ui.swing.CheckedTextField Maven / Gradle / Ivy

There is a newer version: 0.2.1
Show newest version
package cdc.bench.support.ui.swing;

import javax.swing.JTextField;

import cdc.bench.support.checks.CheckResult;
import cdc.bench.support.checks.Checker;
import cdc.bench.support.ui.swing.InputChecker.FocusPolicy;

public class CheckedTextField extends JTextField {
    private static final long serialVersionUID = 1L;
    private Checker checker;

    public CheckedTextField() {
        super();
    }

    public CheckedTextField(Checker checker) {
        this();
        setChecker(checker);
    }

    public void setChecker(Checker checker) {
        this.checker = checker;
        setInputVerifier(new TextInputChecker(this, FocusPolicy.NORMAL_TRANSFER, checker));
    }

    public CheckResult.Status getStatus() {
        if (checker == null) {
            return CheckResult.Status.OK;
        } else {
            return checker.check(getText()).getStatus();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy