package be.iminds.ilabt.jfed.experimenter_gui.util.ui;

import impl.org.controlsfx.skin.DecorationPane;
import javafx.scene.Node;
import javafx.scene.control.TextField;

/**
 * User: twalcari
 * Date: 7/10/2015
 * Time: 12:03
 */
public class UIUtils {
    private UIUtils(){}

    public static void setTextLimit(TextField textField, int length) {
        textField.setOnKeyTyped(event -> {
            String string = textField.getText();

            if (string.length() > length) {
                textField.setText(string.substring(0, length));
                textField.positionCaret(string.length());
            }
        });
    }

    /**
     * Workaround for https://bitbucket.org/controlsfx/controlsfx/issues/539/multiple-dialog-fields-with-validation
     */
    public static DecorationPane wrapWithDecorationPane(Node node){
        DecorationPane decorationPane = new DecorationPane();
        decorationPane.setRoot(node);

        return decorationPane;
    }
}
